author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 17 Apr 2008 13:42:25 -0700 | |
changeset 2965 | 4b28e9740e3b |
parent 2890 | 172baa5960ff |
child 3026 | 4ef834f6b67d |
permissions | -rw-r--r-- |
987 | 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 |
// Port of ns-2/tcl/ex/simple.tcl to ns-3 |
|
18 |
// |
|
19 |
// Network topology |
|
20 |
// |
|
21 |
// n0 n1 n2 n3 |
|
22 |
// | | | | |
|
23 |
// ===================== |
|
24 |
// |
|
25 |
// - CBR/UDP flows from n0 to n1, and from n3 to n0 |
|
26 |
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. |
|
27 |
// (i.e., DataRate of 448,000 bps) |
|
28 |
// - DropTail queues |
|
1272 | 29 |
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" |
987 | 30 |
|
31 |
#include <iostream> |
|
32 |
#include <fstream> |
|
33 |
#include <string> |
|
34 |
#include <cassert> |
|
35 |
||
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
36 |
#include "ns3/core-module.h" |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
37 |
#include "ns3/simulator-module.h" |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
38 |
#include "ns3/node-module.h" |
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
39 |
#include "ns3/helper-module.h" |
987 | 40 |
|
41 |
#include "ns3/ascii-trace.h" |
|
42 |
#include "ns3/pcap-trace.h" |
|
43 |
||
44 |
using namespace ns3; |
|
45 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
46 |
NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample"); |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
47 |
|
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
48 |
int |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
49 |
main (int argc, char *argv[]) |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
50 |
{ |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
51 |
#if 0 |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
52 |
LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO); |
2860
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2739
diff
changeset
|
53 |
#endif |
987 | 54 |
|
2860
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2739
diff
changeset
|
55 |
// |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2739
diff
changeset
|
56 |
// Make the random number generators generate reproducible results. |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2739
diff
changeset
|
57 |
// |
9105a5cf6535
use global seed in examples, new regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
2739
diff
changeset
|
58 |
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
59 |
|
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
60 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2533
diff
changeset
|
61 |
cmd.Parse (argc, argv); |
987 | 62 |
|
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
63 |
// Here, we will explicitly create four nodes. |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
64 |
NS_LOG_INFO ("Create nodes."); |
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
65 |
NodeContainer c; |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
66 |
c.Create (4); |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
67 |
|
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
68 |
PacketSocketHelper packetSocket; |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
69 |
packetSocket.Install (c); |
987 | 70 |
|
1272 | 71 |
// create the shared medium used by all csma devices. |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
72 |
NS_LOG_INFO ("Create channels."); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
73 |
Ptr<CsmaChannel> channel = CreateObject<CsmaChannel> ("BitRate", DataRateValue (DataRate(5000000)), |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
74 |
"Delay", TimeValue (MilliSeconds(2))); |
1193
ea2185e4e097
example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1190
diff
changeset
|
75 |
|
ea2185e4e097
example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1190
diff
changeset
|
76 |
// use a helper function to connect our nodes to the shared channel. |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
77 |
NS_LOG_INFO ("Build Topology."); |
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
78 |
CsmaHelper csma; |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
79 |
csma.SetDeviceParameter ("EncapsulationMode", StringValue ("Llc")); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
80 |
NetDeviceContainer devs = csma.Install (c, channel); |
987 | 81 |
|
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
82 |
NS_LOG_INFO ("Create Applications."); |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
83 |
// Create the OnOff application to send raw datagrams |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
84 |
PacketSocketAddress socket; |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
85 |
socket.SetSingleDevice(devs.Get (0)->GetIfIndex ()); |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
86 |
socket.SetPhysicalAddress (devs.Get (1)->GetAddress ()); |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
87 |
socket.SetProtocol (2); |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
88 |
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
89 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
90 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
91 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
92 |
ApplicationContainer apps = onoff.Install (c.Get (0)); |
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
93 |
apps.Start (Seconds (1.0)); |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
94 |
apps.Stop (Seconds (10.0)); |
987 | 95 |
|
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
96 |
socket.SetSingleDevice (devs.Get (3)->GetIfIndex ()); |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
97 |
socket.SetPhysicalAddress (devs.Get (0)->GetAddress ()); |
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2887
diff
changeset
|
98 |
socket.SetProtocol (3); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
99 |
onoff.SetAttribute ("Remote", AddressValue (socket)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2890
diff
changeset
|
100 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2860
diff
changeset
|
101 |
apps = onoff.Install (c.Get (3)); |
2739
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
102 |
apps.Start (Seconds (1.0)); |
5234783968ff
convert PacketSocket scripts to PacketSocketHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
103 |
apps.Stop (Seconds (10.0)); |
987 | 104 |
|
105 |
// Configure tracing of all enqueue, dequeue, and NetDevice receive events |
|
1272 | 106 |
// Trace output will be sent to the csma-packet-socket.tr file |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
107 |
NS_LOG_INFO ("Configure Tracing."); |
1272 | 108 |
AsciiTrace asciitrace ("csma-packet-socket.tr"); |
991 | 109 |
asciitrace.TraceAllNetDeviceRx (); |
110 |
asciitrace.TraceAllQueues (); |
|
111 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
112 |
NS_LOG_INFO ("Run Simulation."); |
987 | 113 |
Simulator::Run (); |
114 |
Simulator::Destroy (); |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1494
diff
changeset
|
115 |
NS_LOG_INFO ("Done."); |
987 | 116 |
} |