63 // Make the random number generators generate reproducible results. |
63 // Make the random number generators generate reproducible results. |
64 // |
64 // |
65 RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
65 RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
66 |
66 |
67 // Set a few parameters |
67 // Set a few parameters |
68 Config::SetDefault ("ns3::RateErrorModel::ErrorRate", Double (0.01)); |
68 Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01)); |
69 Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", String ("EU_PKT")); |
69 Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT")); |
70 |
70 |
71 Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210)); |
71 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); |
72 Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s")); |
72 Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s"))); |
73 |
73 |
74 |
74 |
75 // Allow the user to override any of the defaults and the above |
75 // Allow the user to override any of the defaults and the above |
76 // Bind()s at run-time, via command-line arguments |
76 // Bind()s at run-time, via command-line arguments |
77 CommandLine cmd; |
77 CommandLine cmd; |
90 internet.Install (c); |
90 internet.Install (c); |
91 |
91 |
92 // We create the channels first without any IP addressing information |
92 // We create the channels first without any IP addressing information |
93 NS_LOG_INFO ("Create channels."); |
93 NS_LOG_INFO ("Create channels."); |
94 PointToPointHelper p2p; |
94 PointToPointHelper p2p; |
95 p2p.SetChannelParameter ("BitRate", DataRate (5000000)); |
95 p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate (5000000))); |
96 p2p.SetChannelParameter ("Delay", MilliSeconds (2)); |
96 p2p.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2))); |
97 NetDeviceContainer d0d2 = p2p.Install (n0n2); |
97 NetDeviceContainer d0d2 = p2p.Install (n0n2); |
98 |
98 |
99 NetDeviceContainer d1d2 = p2p.Install (n1n2); |
99 NetDeviceContainer d1d2 = p2p.Install (n1n2); |
100 |
100 |
101 p2p.SetChannelParameter ("BitRate", DataRate (1500000)); |
101 p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate (1500000))); |
102 p2p.SetChannelParameter ("Delay", MilliSeconds (10)); |
102 p2p.SetChannelParameter ("Delay", TimeValue (MilliSeconds (10))); |
103 NetDeviceContainer d3d2 = p2p.Install (n3n2); |
103 NetDeviceContainer d3d2 = p2p.Install (n3n2); |
104 |
104 |
105 // Later, we add IP addresses. |
105 // Later, we add IP addresses. |
106 NS_LOG_INFO ("Assign IP Addresses."); |
106 NS_LOG_INFO ("Assign IP Addresses."); |
107 Ipv4AddressHelper ipv4; |
107 Ipv4AddressHelper ipv4; |
122 NS_LOG_INFO ("Create Applications."); |
122 NS_LOG_INFO ("Create Applications."); |
123 uint16_t port = 9; // Discard port (RFC 863) |
123 uint16_t port = 9; // Discard port (RFC 863) |
124 |
124 |
125 OnOffHelper onoff ("ns3::Udp", |
125 OnOffHelper onoff ("ns3::Udp", |
126 Address (InetSocketAddress (i3i2.GetAddress (1), port))); |
126 Address (InetSocketAddress (i3i2.GetAddress (1), port))); |
127 onoff.SetAttribute ("OnTime", ConstantVariable(1)); |
127 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1))); |
128 onoff.SetAttribute ("OffTime", ConstantVariable(0)); |
128 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); |
129 |
129 |
130 ApplicationContainer apps = onoff.Install (c.Get (0)); |
130 ApplicationContainer apps = onoff.Install (c.Get (0)); |
131 apps.Start(Seconds(1.0)); |
131 apps.Start(Seconds(1.0)); |
132 apps.Stop (Seconds(10.0)); |
132 apps.Stop (Seconds(10.0)); |
133 |
133 |
138 apps.Start (Seconds (1.0)); |
138 apps.Start (Seconds (1.0)); |
139 apps.Stop (Seconds (10.0)); |
139 apps.Stop (Seconds (10.0)); |
140 |
140 |
141 // Create a similar flow from n3 to n1, starting at time 1.1 seconds |
141 // Create a similar flow from n3 to n1, starting at time 1.1 seconds |
142 onoff.SetAttribute ("Remote", |
142 onoff.SetAttribute ("Remote", |
143 Address (InetSocketAddress (i1i2.GetAddress (0), port))); |
143 AddressValue (InetSocketAddress (i1i2.GetAddress (0), port))); |
144 apps = onoff.Install (c.Get (3)); |
144 apps = onoff.Install (c.Get (3)); |
145 apps.Start(Seconds(1.1)); |
145 apps.Start(Seconds(1.1)); |
146 apps.Stop (Seconds(10.0)); |
146 apps.Stop (Seconds(10.0)); |
147 |
147 |
148 // Create a packet sink to receive these packets |
148 // Create a packet sink to receive these packets |
149 sink.SetAttribute ("Local", |
149 sink.SetAttribute ("Local", |
150 Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
150 AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port))); |
151 apps = sink.Install (c.Get (1)); |
151 apps = sink.Install (c.Get (1)); |
152 apps.Start (Seconds (1.1)); |
152 apps.Start (Seconds (1.1)); |
153 apps.Stop (Seconds (10.0)); |
153 apps.Stop (Seconds (10.0)); |
154 |
154 |
155 // |
155 // |
156 // Error model |
156 // Error model |
157 // |
157 // |
158 // Create an ErrorModel based on the implementation (constructor) |
158 // Create an ErrorModel based on the implementation (constructor) |
159 // specified by the default classId |
159 // specified by the default classId |
160 Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", UniformVariable (0.0, 1.0), |
160 Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)), |
161 "ErrorRate", Double (0.001)); |
161 "ErrorRate", DoubleValue (0.001)); |
162 d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", Pointer (em)); |
162 d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em)); |
163 |
163 |
164 // Now, let's use the ListErrorModel and explicitly force a loss |
164 // Now, let's use the ListErrorModel and explicitly force a loss |
165 // of the packets with pkt-uids = 11 and 17 on node 2, device 0 |
165 // of the packets with pkt-uids = 11 and 17 on node 2, device 0 |
166 std::list<uint32_t> sampleList; |
166 std::list<uint32_t> sampleList; |
167 sampleList.push_back (11); |
167 sampleList.push_back (11); |
168 sampleList.push_back (17); |
168 sampleList.push_back (17); |
169 // This time, we'll explicitly create the error model we want |
169 // This time, we'll explicitly create the error model we want |
170 Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> (); |
170 Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> (); |
171 pem->SetList (sampleList); |
171 pem->SetList (sampleList); |
172 d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", Pointer (pem)); |
172 d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem)); |
173 |
173 |
174 std::ofstream ascii; |
174 std::ofstream ascii; |
175 ascii.open ("simple-error-model.tr"); |
175 ascii.open ("simple-error-model.tr"); |
176 PointToPointHelper::EnablePcap ("simple-error-model"); |
176 PointToPointHelper::EnablePcap ("simple-error-model"); |
177 PointToPointHelper::EnableAscii (ascii); |
177 PointToPointHelper::EnableAscii (ascii); |