author | Craig Dowell <craigdo@ee.washington.edu> |
Mon, 04 Feb 2008 12:56:08 -0800 | |
changeset 2311 | a7dbe3cba7de |
parent 2230 | 9f13ac3291e0 |
child 2494 | 1c69ea12779c |
permissions | -rw-r--r-- |
1842 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
|
16 |
||
17 |
#include "ns3/log.h" |
|
18 |
#include "ns3/ptr.h" |
|
19 |
#include "ns3/internet-node.h" |
|
20 |
#include "ns3/point-to-point-channel.h" |
|
21 |
#include "ns3/mac48-address.h" |
|
22 |
#include "ns3/point-to-point-net-device.h" |
|
23 |
#include "ns3/udp-echo-client.h" |
|
24 |
#include "ns3/udp-echo-server.h" |
|
25 |
#include "ns3/simulator.h" |
|
26 |
#include "ns3/nstime.h" |
|
27 |
#include "ns3/ascii-trace.h" |
|
28 |
#include "ns3/pcap-trace.h" |
|
29 |
#include "ns3/global-route-manager.h" |
|
30 |
||
1848 | 31 |
#include "point-to-point-ipv4-topology.h" |
32 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
33 |
NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation"); |
1842 | 34 |
|
35 |
using namespace ns3; |
|
36 |
||
37 |
// Network topology |
|
38 |
// |
|
39 |
// n3 n2 |
|
40 |
// | / |
|
41 |
// | / |
|
42 |
// n4 --- n0 --- n1 |
|
43 |
// / | |
|
44 |
// / | |
|
45 |
// n5 n6 |
|
46 |
||
47 |
int |
|
48 |
main (int argc, char *argv[]) |
|
49 |
{ |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
50 |
LogComponentEnable ("StarRoutingSimulation", LOG_LEVEL_INFO); |
1842 | 51 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
52 |
NS_LOG_INFO ("Star Topology with Routing Simulation"); |
1842 | 53 |
|
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
54 |
Ptr<Node> n0 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
55 |
Ptr<Node> n1 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
56 |
Ptr<Node> n2 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
57 |
Ptr<Node> n3 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
58 |
Ptr<Node> n4 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
59 |
Ptr<Node> n5 = CreateObject<InternetNode> (); |
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
60 |
Ptr<Node> n6 = CreateObject<InternetNode> (); |
1842 | 61 |
|
62 |
Ptr<PointToPointChannel> link01 = |
|
63 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
64 |
MilliSeconds (20)); |
|
65 |
||
66 |
uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
67 |
link01); |
|
68 |
||
69 |
Ptr<PointToPointChannel> link02 = |
|
70 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
71 |
MilliSeconds (20)); |
|
72 |
||
73 |
uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
74 |
link02); |
|
75 |
||
76 |
Ptr<PointToPointChannel> link03 = |
|
77 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
78 |
MilliSeconds (20)); |
|
79 |
||
80 |
uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
81 |
link03); |
|
82 |
||
83 |
Ptr<PointToPointChannel> link04 = |
|
84 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
85 |
MilliSeconds (20)); |
|
86 |
||
87 |
uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
88 |
link04); |
|
89 |
||
90 |
Ptr<PointToPointChannel> link05 = |
|
91 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
92 |
MilliSeconds (20)); |
|
93 |
||
94 |
uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
95 |
link05); |
|
96 |
||
97 |
Ptr<PointToPointChannel> link06 = |
|
98 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
99 |
MilliSeconds (20)); |
|
100 |
||
101 |
uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06); |
|
102 |
||
103 |
uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01); |
|
104 |
uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02); |
|
105 |
uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03); |
|
106 |
uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04); |
|
107 |
uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05); |
|
108 |
uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06); |
|
109 |
||
110 |
PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", |
|
111 |
"255.255.255.252"); |
|
112 |
||
113 |
PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", |
|
114 |
"255.255.255.252"); |
|
115 |
||
116 |
PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", |
|
117 |
"255.255.255.252"); |
|
118 |
||
119 |
PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", |
|
120 |
"255.255.255.252"); |
|
121 |
||
122 |
PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", |
|
123 |
"255.255.255.252"); |
|
124 |
||
125 |
PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", |
|
126 |
"255.255.255.252"); |
|
127 |
||
128 |
PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", |
|
129 |
"255.255.255.252"); |
|
130 |
||
131 |
PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", |
|
132 |
"255.255.255.252"); |
|
133 |
||
134 |
PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", |
|
135 |
"255.255.255.252"); |
|
136 |
||
137 |
PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", |
|
138 |
"255.255.255.252"); |
|
139 |
||
140 |
PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", |
|
141 |
"255.255.255.252"); |
|
142 |
||
143 |
PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", |
|
144 |
"255.255.255.252"); |
|
145 |
||
146 |
uint16_t port = 7; |
|
147 |
||
2311
a7dbe3cba7de
tutorial now agrees with ns3-object changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
2230
diff
changeset
|
148 |
Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n4, "10.1.1.2", |
a7dbe3cba7de
tutorial now agrees with ns3-object changes
Craig Dowell <craigdo@ee.washington.edu>
parents:
2230
diff
changeset
|
149 |
port, 1, Seconds(1.), 1024); |
1842 | 150 |
|
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1848
diff
changeset
|
151 |
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port); |
1842 | 152 |
|
153 |
server->Start(Seconds(1.)); |
|
154 |
client->Start(Seconds(2.)); |
|
155 |
||
156 |
server->Stop (Seconds(10.)); |
|
157 |
client->Stop (Seconds(10.)); |
|
158 |
||
159 |
AsciiTrace asciitrace ("tutorial.tr"); |
|
160 |
asciitrace.TraceAllQueues (); |
|
161 |
asciitrace.TraceAllNetDeviceRx (); |
|
162 |
||
163 |
GlobalRouteManager::PopulateRoutingTables (); |
|
164 |
||
165 |
Simulator::Run (); |
|
166 |
Simulator::Destroy (); |
|
167 |
} |