author | Craig Dowell <craigdo@ee.washington.edu> |
Thu, 03 Jul 2008 15:44:54 -0700 | |
changeset 3381 | 3cdd9d60f7c7 |
parent 3181 | 26e7f865c548 |
child 3713 | 9f5d59e52e38 |
permissions | -rw-r--r-- |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* ns-2 simple.tcl script (ported from ns-2) |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
* Originally authored by Steve McCanne, 12/19/1996 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
*/ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
// Port of ns-2/tcl/ex/simple.tcl to ns-3 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
// |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
// Network topology |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
// |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
// n0 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
// \ 5 Mb/s, 2ms |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
// \ 1.5Mb/s, 10ms |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
// n2 -------------------------n3 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
// / |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
// / 5 Mb/s, 2ms |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
// n1 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
// |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
// - all links are point-to-point links with indicated one-way BW/delay |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
// - CBR/UDP flows from n0 to n3, and from n3 to n1 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
// (i.e., DataRate of 448,000 bps) |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
// - DropTail queues |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
// - Tracing of queues and packet receptions to file |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
// "simple-error-model.tr" |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
|
2788
ad1404dcfad4
port to new pcap/ascii trace helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2760
diff
changeset
|
41 |
#include <fstream> |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
42 |
#include "ns3/core-module.h" |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
43 |
#include "ns3/common-module.h" |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
44 |
#include "ns3/simulator-module.h" |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
45 |
#include "ns3/node-module.h" |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
46 |
#include "ns3/helper-module.h" |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
47 |
#include "ns3/global-route-manager.h" |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
using namespace ns3; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample"); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
int |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
main (int argc, char *argv[]) |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
{ |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
// Users may find it convenient to turn on explicit debugging |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
// for selected modules; the below lines suggest how to do this |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
#if 0 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
#endif |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
|
2861 | 62 |
// |
63 |
// Make the random number generators generate reproducible results. |
|
64 |
// |
|
65 |
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
|
66 |
||
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3181
diff
changeset
|
67 |
// Set a few attributes |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
68 |
Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
69 |
Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT")); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2481
diff
changeset
|
70 |
|
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
71 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
72 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s"))); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
// Allow the user to override any of the defaults and the above |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
// Bind()s at run-time, via command-line arguments |
2575
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
77 |
CommandLine cmd; |
1aae382e65e2
rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2502
diff
changeset
|
78 |
cmd.Parse (argc, argv); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
// Here, we will explicitly create four nodes. In more sophisticated |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
// topologies, we could configure a node factory. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
NS_LOG_INFO ("Create nodes."); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
83 |
NodeContainer c; |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
84 |
c.Create (4); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
85 |
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
86 |
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
87 |
NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
88 |
|
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
89 |
InternetStackHelper internet; |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
90 |
internet.Install (c); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
91 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
92 |
// We create the channels first without any IP addressing information |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
93 |
NS_LOG_INFO ("Create channels."); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
94 |
PointToPointHelper p2p; |
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3181
diff
changeset
|
95 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (5000000))); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3181
diff
changeset
|
96 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
97 |
NetDeviceContainer d0d2 = p2p.Install (n0n2); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
99 |
NetDeviceContainer d1d2 = p2p.Install (n1n2); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
100 |
|
3381
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3181
diff
changeset
|
101 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (1500000))); |
3cdd9d60f7c7
bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents:
3181
diff
changeset
|
102 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
103 |
NetDeviceContainer d3d2 = p2p.Install (n3n2); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
// Later, we add IP addresses. |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
NS_LOG_INFO ("Assign IP Addresses."); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
107 |
Ipv4AddressHelper ipv4; |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
108 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
109 |
ipv4.Assign (d0d2); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
|
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
111 |
ipv4.SetBase ("10.1.2.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
112 |
Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
|
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
114 |
ipv4.SetBase ("10.1.3.0", "255.255.255.0"); |
2888
872dc8466352
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2887
diff
changeset
|
115 |
Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
116 |
|
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
117 |
NS_LOG_INFO ("Use global routing."); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
118 |
GlobalRouteManager::PopulateRoutingTables (); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
119 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
120 |
// Create the OnOff application to send UDP datagrams of size |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
121 |
// 210 bytes at a rate of 448 Kb/s |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
122 |
NS_LOG_INFO ("Create Applications."); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
123 |
uint16_t port = 9; // Discard port (RFC 863) |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
124 |
|
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
125 |
OnOffHelper onoff ("ns3::UdpSocketFactory", |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
126 |
Address (InetSocketAddress (i3i2.GetAddress (1), port))); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
127 |
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1))); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
128 |
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
129 |
|
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
130 |
ApplicationContainer apps = onoff.Install (c.Get (0)); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
131 |
apps.Start(Seconds(1.0)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
132 |
apps.Stop (Seconds(10.0)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
// Create an optional packet sink to receive these packets |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
2997
diff
changeset
|
135 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
136 |
Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
137 |
apps = sink.Install (c.Get (3)); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
138 |
apps.Start (Seconds (1.0)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
139 |
apps.Stop (Seconds (10.0)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
141 |
// Create a similar flow from n3 to n1, starting at time 1.1 seconds |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
142 |
onoff.SetAttribute ("Remote", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
143 |
AddressValue (InetSocketAddress (i1i2.GetAddress (0), port))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
144 |
apps = onoff.Install (c.Get (3)); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
145 |
apps.Start(Seconds(1.1)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
146 |
apps.Stop (Seconds(10.0)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
148 |
// Create a packet sink to receive these packets |
2890
172baa5960ff
rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents:
2889
diff
changeset
|
149 |
sink.SetAttribute ("Local", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
150 |
AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port))); |
2887
9a637e6daee0
Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2861
diff
changeset
|
151 |
apps = sink.Install (c.Get (1)); |
2760
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
152 |
apps.Start (Seconds (1.1)); |
d745bd7a18e8
port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2613
diff
changeset
|
153 |
apps.Stop (Seconds (10.0)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
154 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
// |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
// Error model |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
// |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
// Create an ErrorModel based on the implementation (constructor) |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
// specified by the default classId |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
160 |
Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)), |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
161 |
"ErrorRate", DoubleValue (0.001)); |
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
162 |
d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
164 |
// Now, let's use the ListErrorModel and explicitly force a loss |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
165 |
// of the packets with pkt-uids = 11 and 17 on node 2, device 0 |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
166 |
std::list<uint32_t> sampleList; |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
167 |
sampleList.push_back (11); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
168 |
sampleList.push_back (17); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
169 |
// This time, we'll explicitly create the error model we want |
2230
9f13ac3291e0
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1820
diff
changeset
|
170 |
Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> (); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
171 |
pem->SetList (sampleList); |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2927
diff
changeset
|
172 |
d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
173 |
|
2789
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
174 |
std::ofstream ascii; |
47e92324cf4b
configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2788
diff
changeset
|
175 |
ascii.open ("simple-error-model.tr"); |
2996
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2890
diff
changeset
|
176 |
PointToPointHelper::EnablePcapAll ("simple-error-model"); |
a83b94e277d4
EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents:
2890
diff
changeset
|
177 |
PointToPointHelper::EnableAsciiAll (ascii); |
1820
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
178 |
|
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
179 |
NS_LOG_INFO ("Run Simulation."); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
180 |
Simulator::Run (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
181 |
Simulator::Destroy (); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
182 |
NS_LOG_INFO ("Done."); |
736919bd4874
Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
183 |
} |