author | Mirko Banchi <mk.banchi@gmail.com> |
Fri, 24 Apr 2009 09:07:00 +0200 | |
changeset 4401 | 427cec7079f3 |
parent 4264 | 9d2e96c4e6e4 |
permissions | -rw-r--r-- |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
*/ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
// Network topology |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
// n0 n1 n2 n3 |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
// | | | | |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
// ================= |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
// LAN |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
// - UDP flows from n0 to n1 and back |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
// - DropTail queues |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
// - Tracing of queues and packet receptions to file "udp-echo.tr" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
#include <fstream> |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
#include "ns3/core-module.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
#include "ns3/simulator-module.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
#include "ns3/helper-module.h" |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
using namespace ns3; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
NS_LOG_COMPONENT_DEFINE ("RealtimeUdpEchoExample"); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
int |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
main (int argc, char *argv[]) |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
{ |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
// Allow the user to override any of the defaults and the above Bind() at |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
// run-time, via command-line arguments |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
CommandLine cmd; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
cmd.Parse (argc, argv); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
// But since this is a realtime script, don't allow the user to mess with |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
// that. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
GlobalValue::Bind ("SimulatorImplementationType", |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
StringValue ("ns3::RealtimeSimulatorImpl")); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
// Explicitly create the nodes required by the topology (shown above). |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
NS_LOG_INFO ("Create nodes."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
NodeContainer n; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
n.Create (4); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
InternetStackHelper internet; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
internet.Install (n); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
// Explicitly create the channels required by the topology (shown above). |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
NS_LOG_INFO ("Create channels."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
CsmaHelper csma; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000))); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
3629 | 71 |
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400)); |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
NetDeviceContainer d = csma.Install (n); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
// We've got the "hardware" in place. Now we need to add IP addresses. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
NS_LOG_INFO ("Assign IP Addresses."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
Ipv4AddressHelper ipv4; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
Ipv4InterfaceContainer i = ipv4.Assign (d); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
NS_LOG_INFO ("Create Applications."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
// Create a UdpEchoServer application on node one. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
uint16_t port = 9; // well-known echo port number |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
UdpEchoServerHelper server (port); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
ApplicationContainer apps = server.Install (n.Get(1)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
apps.Start (Seconds (1.0)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
apps.Stop (Seconds (10.0)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
// Create a UdpEchoClient application to send UDP datagrams from node zero to |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
// node one. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
uint32_t packetSize = 1024; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
uint32_t maxPacketCount = 500; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
Time interPacketInterval = Seconds (0.01); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
UdpEchoClientHelper client (i.GetAddress (1), port); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
client.SetAttribute ("Interval", TimeValue (interPacketInterval)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
client.SetAttribute ("PacketSize", UintegerValue (packetSize)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
apps = client.Install (n.Get (0)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
apps.Start (Seconds (2.0)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
apps.Stop (Seconds (10.0)); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
std::ofstream ascii; |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
ascii.open ("realtime-udp-echo.tr"); |
4264
9d2e96c4e6e4
Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents:
4225
diff
changeset
|
110 |
CsmaHelper::EnablePcapAll ("realtime-udp-echo", false); |
3560
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
CsmaHelper::EnableAsciiAll (ascii); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
|
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
// Now, do the actual simulation. |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
// |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
NS_LOG_INFO ("Run Simulation."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
Simulator::Run (); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
Simulator::Destroy (); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
NS_LOG_INFO ("Done."); |
5aa65b1ea001
add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
} |