63 p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
63 p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); |
64 p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
64 p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); |
65 NetDeviceContainer dAdB = p2p.Install (nAnB); |
65 NetDeviceContainer dAdB = p2p.Install (nAnB); |
66 |
66 |
67 NetDeviceContainer dBdC = p2p.Install (nBnC);; |
67 NetDeviceContainer dBdC = p2p.Install (nBnC);; |
68 |
68 |
69 Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> (); |
69 Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> (); |
70 deviceA->SetAddress (Mac48Address::Allocate ()); |
70 deviceA->SetAddress (Mac48Address::Allocate ()); |
71 nA->AddDevice (deviceA); |
71 nA->AddDevice (deviceA); |
72 |
72 |
73 Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> (); |
73 Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> (); |
74 deviceC->SetAddress (Mac48Address::Allocate ()); |
74 deviceC->SetAddress (Mac48Address::Allocate ()); |
75 nC->AddDevice (deviceC); |
75 nC->AddDevice (deviceC); |
76 |
76 |
77 // Later, we add IP addresses. |
77 // Later, we add IP addresses. |
78 Ipv4AddressHelper ipv4; |
78 Ipv4AddressHelper ipv4; |
79 ipv4.SetBase ("10.1.1.0", "255.255.255.252"); |
79 ipv4.SetBase ("10.1.1.0", "255.255.255.252"); |
80 Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB); |
80 Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB); |
81 |
81 |
82 ipv4.SetBase ("10.1.1.4", "255.255.255.252"); |
82 ipv4.SetBase ("10.1.1.4", "255.255.255.252"); |
83 Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC); |
83 Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC); |
84 |
84 |
85 Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> (); |
85 Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> (); |
86 Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> (); |
86 Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> (); |
87 Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> (); |
87 Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> (); |
88 |
88 |
89 int32_t ifIndexA = ipv4A->AddInterface (deviceA); |
89 int32_t ifIndexA = ipv4A->AddInterface (deviceA); |
90 int32_t ifIndexC = ipv4C->AddInterface (deviceC); |
90 int32_t ifIndexC = ipv4C->AddInterface (deviceC); |
91 |
91 |
92 Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32")); |
92 Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32")); |
93 ipv4A->AddAddress (ifIndexA, ifInAddrA); |
93 ipv4A->AddAddress (ifIndexA, ifInAddrA); |
94 ipv4A->SetMetric (ifIndexA, 1); |
94 ipv4A->SetMetric (ifIndexA, 1); |
95 ipv4A->SetUp (ifIndexA); |
95 ipv4A->SetUp (ifIndexA); |
96 |
96 |
109 staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2); |
109 staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2); |
110 // Create the OnOff application to send UDP datagrams of size |
110 // Create the OnOff application to send UDP datagrams of size |
111 // 210 bytes at a rate of 448 Kb/s |
111 // 210 bytes at a rate of 448 Kb/s |
112 uint16_t port = 9; // Discard port (RFC 863) |
112 uint16_t port = 9; // Discard port (RFC 863) |
113 OnOffHelper onoff ("ns3::UdpSocketFactory", |
113 OnOffHelper onoff ("ns3::UdpSocketFactory", |
114 Address (InetSocketAddress (ifInAddrC.GetLocal (), port))); |
114 Address (InetSocketAddress (ifInAddrC.GetLocal (), port))); |
115 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
115 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
116 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
116 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
117 onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000))); |
117 onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000))); |
118 ApplicationContainer apps = onoff.Install (nA); |
118 ApplicationContainer apps = onoff.Install (nA); |
119 apps.Start (Seconds (1.0)); |
119 apps.Start (Seconds (1.0)); |
120 apps.Stop (Seconds (10.0)); |
120 apps.Stop (Seconds (10.0)); |
121 |
121 |
122 // Create a packet sink to receive these packets |
122 // Create a packet sink to receive these packets |
123 PacketSinkHelper sink ("ns3::UdpSocketFactory", |
123 PacketSinkHelper sink ("ns3::UdpSocketFactory", |
124 Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
124 Address (InetSocketAddress (Ipv4Address::GetAny (), port))); |
125 apps = sink.Install (nC); |
125 apps = sink.Install (nC); |
126 apps.Start (Seconds (1.0)); |
126 apps.Start (Seconds (1.0)); |
127 apps.Stop (Seconds (10.0)); |
127 apps.Stop (Seconds (10.0)); |
128 |
128 |
129 AsciiTraceHelper ascii; |
129 AsciiTraceHelper ascii; |