author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Tue, 11 Mar 2008 13:30:12 -0700 | |
changeset 2592 | 3ebf97150166 |
parent 2494 | 1c69ea12779c |
child 2600 | 6c389d0c717d |
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" |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
30 |
#include "ns3/inet-socket-address.h" |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
31 |
#include "ns3/uinteger.h" |
1842 | 32 |
|
1848 | 33 |
#include "point-to-point-ipv4-topology.h" |
34 |
||
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
35 |
NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation"); |
1842 | 36 |
|
37 |
using namespace ns3; |
|
38 |
||
39 |
// Network topology |
|
40 |
// |
|
41 |
// n3 n2 |
|
42 |
// | / |
|
43 |
// | / |
|
44 |
// n4 --- n0 --- n1 |
|
45 |
// / | |
|
46 |
// / | |
|
47 |
// n5 n6 |
|
48 |
||
49 |
int |
|
50 |
main (int argc, char *argv[]) |
|
51 |
{ |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
52 |
LogComponentEnable ("StarRoutingSimulation", LOG_LEVEL_INFO); |
1842 | 53 |
|
1843
1267bcc23b04
tutorial topologies
Craig Dowell <craigdo@ee.washington.edu>
parents:
1842
diff
changeset
|
54 |
NS_LOG_INFO ("Star Topology with Routing Simulation"); |
1842 | 55 |
|
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
Ptr<Node> n6 = CreateObject<InternetNode> (); |
1842 | 63 |
|
64 |
Ptr<PointToPointChannel> link01 = |
|
65 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
66 |
MilliSeconds (20)); |
|
67 |
||
68 |
uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
69 |
link01); |
|
70 |
||
71 |
Ptr<PointToPointChannel> link02 = |
|
72 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
73 |
MilliSeconds (20)); |
|
74 |
||
75 |
uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
76 |
link02); |
|
77 |
||
78 |
Ptr<PointToPointChannel> link03 = |
|
79 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
80 |
MilliSeconds (20)); |
|
81 |
||
82 |
uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
83 |
link03); |
|
84 |
||
85 |
Ptr<PointToPointChannel> link04 = |
|
86 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
87 |
MilliSeconds (20)); |
|
88 |
||
89 |
uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
90 |
link04); |
|
91 |
||
92 |
Ptr<PointToPointChannel> link05 = |
|
93 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
94 |
MilliSeconds (20)); |
|
95 |
||
96 |
uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0, |
|
97 |
link05); |
|
98 |
||
99 |
Ptr<PointToPointChannel> link06 = |
|
100 |
PointToPointIpv4Topology::CreateChannel (DataRate (38400), |
|
101 |
MilliSeconds (20)); |
|
102 |
||
103 |
uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06); |
|
104 |
||
105 |
uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01); |
|
106 |
uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02); |
|
107 |
uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03); |
|
108 |
uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04); |
|
109 |
uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05); |
|
110 |
uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06); |
|
111 |
||
112 |
PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", |
|
113 |
"255.255.255.252"); |
|
114 |
||
115 |
PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", |
|
116 |
"255.255.255.252"); |
|
117 |
||
118 |
PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", |
|
119 |
"255.255.255.252"); |
|
120 |
||
121 |
PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", |
|
122 |
"255.255.255.252"); |
|
123 |
||
124 |
PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", |
|
125 |
"255.255.255.252"); |
|
126 |
||
127 |
PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", |
|
128 |
"255.255.255.252"); |
|
129 |
||
130 |
PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", |
|
131 |
"255.255.255.252"); |
|
132 |
||
133 |
PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", |
|
134 |
"255.255.255.252"); |
|
135 |
||
136 |
PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", |
|
137 |
"255.255.255.252"); |
|
138 |
||
139 |
PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", |
|
140 |
"255.255.255.252"); |
|
141 |
||
142 |
PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", |
|
143 |
"255.255.255.252"); |
|
144 |
||
145 |
PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", |
|
146 |
"255.255.255.252"); |
|
147 |
||
148 |
uint16_t port = 7; |
|
149 |
||
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
150 |
Ptr<UdpEchoClient> client = |
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
151 |
CreateObject<UdpEchoClient> ("Node", n4, |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
152 |
"RemoteIpv4", Ipv4Address ("10.1.1.2"), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
153 |
"RemotePort", Uinteger (port), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
154 |
"MaxPackets", Uinteger (1), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
155 |
"Interval", Seconds(1.), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
156 |
"PacketSize", Uinteger (1024)); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
157 |
n0->AddApplication (client); |
1842 | 158 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
159 |
Ptr<UdpEchoServer> server = |
2592
3ebf97150166
get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
160 |
CreateObject<UdpEchoServer> ("Node", n1, |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
161 |
"Port", Uinteger (port)); |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2311
diff
changeset
|
162 |
n1->AddApplication (server); |
1842 | 163 |
|
164 |
server->Start(Seconds(1.)); |
|
165 |
client->Start(Seconds(2.)); |
|
166 |
||
167 |
server->Stop (Seconds(10.)); |
|
168 |
client->Stop (Seconds(10.)); |
|
169 |
||
170 |
AsciiTrace asciitrace ("tutorial.tr"); |
|
171 |
asciitrace.TraceAllQueues (); |
|
172 |
asciitrace.TraceAllNetDeviceRx (); |
|
173 |
||
174 |
GlobalRouteManager::PopulateRoutingTables (); |
|
175 |
||
176 |
Simulator::Run (); |
|
177 |
Simulator::Destroy (); |
|
178 |
} |