~ubuntu-branches/ubuntu/quantal/ns3/quantal

« back to all changes in this revision

Viewing changes to ns-3.13/examples/ipv6/loose-routing-ipv6.cc

  • Committer: Package Import Robot
  • Author(s): YunQiang Su, Aron Xu, YunQiang Su, Upstream
  • Date: 2012-01-06 00:35:42 UTC
  • mfrom: (10.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120106003542-vcn5g03mhapm991h
Tags: 3.13+dfsg-1
[ Aron Xu ]:
        add tag binary and binary-indep, 
  for not build doc when --binary-arch (Closes: #654493).
[ YunQiang Su ]
        add waf 1.5/1.6 source to debian directory, 
  and build waf from there (Closes: #642217).
[ Upstream ]
  Successfully link with --as-needed option (Closes: #642225).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
 
2
/*
 
3
 * Copyright (c) 2009 Strasbourg University
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 2 as
 
7
 * published by the Free Software Foundation;
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 *
 
18
 * Author: David Gross <gdavid.devel@gmail.com>
 
19
 */
 
20
 
 
21
// Network topology
 
22
// //
 
23
// //
 
24
// //                               +------------+
 
25
// //  +------------+           |---|  Router 1  |---|
 
26
// //  |   Host 0   |--|        |   [------------]   |
 
27
// //  [------------]  |        |                    |
 
28
// //                  |  +------------+             |
 
29
// //                  +--|            |       +------------+
 
30
// //                     |  Router 0  |       |  Router 2  |
 
31
// //                  +--|            |       [------------]
 
32
// //                  |  [------------]             |
 
33
// //  +------------+  |        |                    |
 
34
// //  |   Host 1   |--|        |   +------------+   |
 
35
// //  [------------]           |---|  Router 3  |---|
 
36
// //                               [------------]
 
37
// //
 
38
// //
 
39
// // - Tracing of queues and packet receptions to file "loose-routing-ipv6.tr"
 
40
 
 
41
#include <fstream>
 
42
#include "ns3/core-module.h"
 
43
#include "ns3/internet-module.h"
 
44
#include "ns3/csma-module.h"
 
45
#include "ns3/applications-module.h"
 
46
#include "ns3/ipv6-header.h"
 
47
using namespace ns3;
 
48
 
 
49
NS_LOG_COMPONENT_DEFINE ("LooseRoutingIpv6Example");
 
50
 
 
51
int main (int argc, char **argv)
 
52
{
 
53
#if 0 
 
54
  LogComponentEnable ("Ipv6ExtensionLooseRouting", LOG_LEVEL_ALL);
 
55
  LogComponentEnable ("Ipv6Extension", LOG_LEVEL_ALL);
 
56
  LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
 
57
  LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
 
58
  LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
 
59
  LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
 
60
  LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
 
61
#endif
 
62
 
 
63
  CommandLine cmd;
 
64
  cmd.Parse (argc, argv);
 
65
 
 
66
  NS_LOG_INFO ("Create nodes.");
 
67
  Ptr<Node> h0 = CreateObject<Node> ();
 
68
  Ptr<Node> h1 = CreateObject<Node> ();
 
69
  Ptr<Node> r0 = CreateObject<Node> ();
 
70
  Ptr<Node> r1 = CreateObject<Node> ();
 
71
  Ptr<Node> r2 = CreateObject<Node> ();
 
72
  Ptr<Node> r3 = CreateObject<Node> ();
 
73
 
 
74
  NodeContainer net1 (h0, r0);
 
75
  NodeContainer net2 (h1, r0);
 
76
  NodeContainer net3 (r0, r1);
 
77
  NodeContainer net4 (r1, r2);
 
78
  NodeContainer net5 (r2, r3);
 
79
  NodeContainer net6 (r3, r0);
 
80
  NodeContainer all;
 
81
  all.Add (h0);
 
82
  all.Add (h1);
 
83
  all.Add (r0);
 
84
  all.Add (r1);
 
85
  all.Add (r2);
 
86
  all.Add (r3);
 
87
 
 
88
  NS_LOG_INFO ("Create IPv6 Internet Stack");
 
89
  InternetStackHelper internetv6;
 
90
  internetv6.Install (all);
 
91
 
 
92
  NS_LOG_INFO ("Create channels.");
 
93
  CsmaHelper csma;
 
94
  csma.SetDeviceAttribute ("Mtu", UintegerValue (1500));
 
95
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
 
96
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
 
97
  NetDeviceContainer d1 = csma.Install (net1);
 
98
  NetDeviceContainer d2 = csma.Install (net2);
 
99
  NetDeviceContainer d3 = csma.Install (net3);
 
100
  NetDeviceContainer d4 = csma.Install (net4);
 
101
  NetDeviceContainer d5 = csma.Install (net5);
 
102
  NetDeviceContainer d6 = csma.Install (net6);
 
103
 
 
104
  NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
 
105
  Ipv6AddressHelper ipv6;
 
106
 
 
107
  ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
 
108
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
 
109
  i1.SetRouter (1, true);
 
110
 
 
111
  ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
 
112
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
 
113
  i2.SetRouter (1, true);
 
114
 
 
115
  ipv6.NewNetwork (Ipv6Address ("2001:3::"), 64);
 
116
  Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
 
117
  i3.SetRouter (0, true);
 
118
  i3.SetRouter (1, true);
 
119
 
 
120
  ipv6.NewNetwork (Ipv6Address ("2001:4::"), 64);
 
121
  Ipv6InterfaceContainer i4 = ipv6.Assign (d4);
 
122
  i4.SetRouter (0, true);
 
123
  i4.SetRouter (1, true);
 
124
 
 
125
  ipv6.NewNetwork (Ipv6Address ("2001:5::"), 64);
 
126
  Ipv6InterfaceContainer i5 = ipv6.Assign (d5);
 
127
  i5.SetRouter (0, true);
 
128
  i5.SetRouter (1, true);
 
129
 
 
130
  ipv6.NewNetwork (Ipv6Address ("2001:6::"), 64);
 
131
  Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
 
132
  i6.SetRouter (0, true);
 
133
  i6.SetRouter (1, true);
 
134
 
 
135
  NS_LOG_INFO ("Create Applications.");
 
136
 
 
137
  /**
 
138
   * ICMPv6 Echo from h0 to h1 port 7
 
139
   */
 
140
  uint32_t packetSize = 1024;
 
141
  uint32_t maxPacketCount = 1;
 
142
  Time interPacketInterval = Seconds (1.0);
 
143
 
 
144
  std::vector<Ipv6Address> routersAddress;
 
145
  routersAddress.push_back (i3.GetAddress (1, 1));
 
146
  routersAddress.push_back (i4.GetAddress (1, 1));
 
147
  routersAddress.push_back (i5.GetAddress (1, 1));
 
148
  routersAddress.push_back (i6.GetAddress (1, 1));
 
149
  routersAddress.push_back (i2.GetAddress (0, 1));
 
150
 
 
151
  Ping6Helper client;
 
152
  /* remote address is first routers in RH0 => source routing */
 
153
  client.SetRemote (i1.GetAddress (1, 1));
 
154
  client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
 
155
  client.SetAttribute ("Interval", TimeValue (interPacketInterval));
 
156
  client.SetAttribute ("PacketSize", UintegerValue (packetSize));
 
157
  client.SetRoutersAddress (routersAddress);
 
158
  ApplicationContainer apps = client.Install (h0);
 
159
  apps.Start (Seconds (1.0));
 
160
  apps.Stop (Seconds (10.0));
 
161
 
 
162
  AsciiTraceHelper ascii;
 
163
  csma.EnableAsciiAll (ascii.CreateFileStream ("loose-routing-ipv6.tr"));
 
164
  csma.EnablePcapAll ("loose-routing-ipv6", true);
 
165
 
 
166
  NS_LOG_INFO ("Run Simulation.");
 
167
  Simulator::Run ();
 
168
  Simulator::Destroy ();
 
169
  NS_LOG_INFO ("Done.");
 
170
}
 
171