|
26 |
#include "ns3/double.h" |
26 |
#include "ns3/double.h" |
27 |
#include "ns3/uinteger.h" |
27 |
#include "ns3/uinteger.h" |
28 |
#include "ns3/string.h" |
28 |
#include "ns3/string.h" |
29 |
#include "ns3/pcap-test.h" |
|
|
30 |
#include "ns3/pcap-file.h" |
31 |
#include "ns3/olsr-helper.h" |
29 |
#include "ns3/olsr-helper.h" |
32 |
#include "ns3/internet-stack-helper.h" |
30 |
#include "ns3/internet-stack-helper.h" |
33 |
#include "ns3/point-to-point-helper.h" |
|
|
34 |
#include "ns3/ipv4-address-helper.h" |
31 |
#include "ns3/ipv4-address-helper.h" |
35 |
#include "ns3/abort.h" |
32 |
#include "ns3/abort.h" |
36 |
#include "ns3/yans-wifi-helper.h" |
33 |
#include "ns3/socket-factory.h" |
37 |
#include "ns3/mobility-helper.h" |
34 |
#include "ns3/ipv4-raw-socket-factory.h" |
38 |
#include "ns3/nqos-wifi-mac-helper.h" |
35 |
#include "ns3/udp-l4-protocol.h" |
|
|
36 |
#include "ns3/udp-header.h" |
37 |
#include "ns3/olsr-header.h" |
38 |
#include "ns3/simple-net-device-helper.h" |
39 |
#include "ns3/simple-net-device.h" |
39 |
|
40 |
|
40 |
namespace ns3 |
41 |
namespace ns3 |
41 |
{ |
42 |
{ |
42 |
namespace olsr |
43 |
namespace olsr |
43 |
{ |
44 |
{ |
44 |
|
45 |
|
45 |
const char * const TcRegressionTest::PREFIX = "olsr-tc-regression-test"; |
|
|
46 |
|
47 |
TcRegressionTest::TcRegressionTest() : |
46 |
TcRegressionTest::TcRegressionTest() : |
48 |
TestCase ("Test OLSR Topology Control message generation"), |
47 |
TestCase ("Test OLSR Topology Control message generation"), |
49 |
m_time (Seconds (20)), |
48 |
m_time (Seconds (20)), |
50 |
m_step (120) |
49 |
m_countA (0), m_countB (0), m_countC (0) |
51 |
{ |
50 |
{ |
52 |
} |
51 |
} |
53 |
|
52 |
|
|
64 |
|
63 |
|
65 |
Simulator::Stop (m_time); |
64 |
Simulator::Stop (m_time); |
66 |
Simulator::Run (); |
65 |
Simulator::Run (); |
|
|
66 |
|
67 |
m_rxSocketA = 0; |
68 |
m_rxSocketB = 0; |
69 |
m_rxSocketC = 0; |
67 |
Simulator::Destroy (); |
70 |
Simulator::Destroy (); |
68 |
|
|
|
69 |
CheckResults (); |
70 |
} |
71 |
} |
71 |
|
72 |
|
72 |
void |
73 |
void |
|
76 |
NodeContainer c; |
77 |
NodeContainer c; |
77 |
c.Create (3); |
78 |
c.Create (3); |
78 |
|
79 |
|
79 |
// place nodes in the chain |
|
|
80 |
MobilityHelper mobility; |
81 |
mobility.SetPositionAllocator ("ns3::GridPositionAllocator", |
82 |
"MinX", DoubleValue (0.0), |
83 |
"MinY", DoubleValue (0.0), |
84 |
"DeltaX", DoubleValue (m_step), |
85 |
"DeltaY", DoubleValue (0), |
86 |
"GridWidth", UintegerValue (3), |
87 |
"LayoutType", StringValue ("RowFirst")); |
88 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
89 |
mobility.Install (c); |
90 |
|
91 |
// install TCP/IP & OLSR |
80 |
// install TCP/IP & OLSR |
92 |
OlsrHelper olsr; |
81 |
OlsrHelper olsr; |
93 |
InternetStackHelper internet; |
82 |
InternetStackHelper internet; |
94 |
internet.SetRoutingHelper (olsr); |
83 |
internet.SetRoutingHelper (olsr); |
95 |
internet.Install (c); |
84 |
internet.Install (c); |
96 |
int64_t streamsUsed = olsr.AssignStreams (c, 0); |
85 |
int64_t streamsUsed = olsr.AssignStreams (c, 0); |
97 |
NS_TEST_EXPECT_MSG_EQ (streamsUsed, 3, "Should have assigned 2 streams"); |
86 |
NS_TEST_EXPECT_MSG_EQ (streamsUsed, 3, "Should have assigned 3 streams"); |
98 |
|
87 |
|
99 |
// create wifi channel & devices |
88 |
// create channel & devices |
100 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
89 |
SimpleNetDeviceHelper simpleNetHelper; |
101 |
wifiMac.SetType ("ns3::AdhocWifiMac"); |
90 |
simpleNetHelper.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
102 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
91 |
simpleNetHelper.SetChannelAttribute ("Delay", StringValue ("2ms")); |
103 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
92 |
NetDeviceContainer nd = simpleNetHelper.Install (c); |
104 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
93 |
|
105 |
// This test suite output was originally based on YansErrorRateModel |
94 |
// Blacklist some devices (equivalent to Wireless out of range) |
106 |
wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel"); |
95 |
Ptr<SimpleNetDevice> nd0 = DynamicCast<SimpleNetDevice> (nd.Get (0)); |
107 |
WifiHelper wifi = WifiHelper::Default (); |
96 |
Ptr<SimpleNetDevice> nd2 = DynamicCast<SimpleNetDevice> (nd.Get (2)); |
108 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211a); |
97 |
Ptr<SimpleChannel> ch = DynamicCast<SimpleChannel> (nd.Get (0)->GetChannel ()); |
109 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", StringValue ("2200")); |
98 |
ch->BlackList (nd0, nd2); |
110 |
NetDeviceContainer nd = wifi.Install (wifiPhy, wifiMac, c); |
99 |
ch->BlackList (nd2, nd0); |
111 |
|
100 |
|
112 |
// setup IP addresses |
101 |
// setup IP addresses |
113 |
Ipv4AddressHelper ipv4; |
102 |
Ipv4AddressHelper ipv4; |
114 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
103 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
115 |
ipv4.Assign (nd); |
104 |
ipv4.Assign (nd); |
116 |
|
105 |
|
117 |
// setup PCAP traces |
106 |
// Create the sockets |
118 |
wifiPhy.EnablePcapAll (CreateTempDirFilename(PREFIX)); |
107 |
Ptr<SocketFactory> rxSocketFactoryA = c.Get (0)->GetObject<Ipv4RawSocketFactory> (); |
|
|
108 |
m_rxSocketA = DynamicCast<Ipv4RawSocketImpl> (rxSocketFactoryA->CreateSocket ()); |
109 |
m_rxSocketA->SetProtocol (UdpL4Protocol::PROT_NUMBER); |
110 |
m_rxSocketA->SetRecvCallback (MakeCallback (&TcRegressionTest::ReceivePktProbeA, this)); |
111 |
|
112 |
Ptr<SocketFactory> rxSocketFactoryB = c.Get (1)->GetObject<Ipv4RawSocketFactory> (); |
113 |
m_rxSocketB = DynamicCast<Ipv4RawSocketImpl> (rxSocketFactoryB->CreateSocket ()); |
114 |
m_rxSocketB->SetProtocol (UdpL4Protocol::PROT_NUMBER); |
115 |
m_rxSocketB->SetRecvCallback (MakeCallback (&TcRegressionTest::ReceivePktProbeB, this)); |
116 |
|
117 |
Ptr<SocketFactory> rxSocketFactoryC = c.Get (2)->GetObject<Ipv4RawSocketFactory> (); |
118 |
m_rxSocketC = DynamicCast<Ipv4RawSocketImpl> (rxSocketFactoryC->CreateSocket ()); |
119 |
m_rxSocketC->SetProtocol (UdpL4Protocol::PROT_NUMBER); |
120 |
m_rxSocketC->SetRecvCallback (MakeCallback (&TcRegressionTest::ReceivePktProbeC, this)); |
121 |
} |
122 |
|
123 |
// Note: this is identical to ReceivePktProbeC, but the packet counter needs to be different. |
124 |
void |
125 |
TcRegressionTest::ReceivePktProbeA (Ptr<Socket> socket) |
126 |
{ |
127 |
uint32_t availableData; |
128 |
availableData = socket->GetRxAvailable (); |
129 |
Ptr<Packet> receivedPacketProbe = socket->Recv (std::numeric_limits<uint32_t>::max (), 0); |
130 |
NS_ASSERT (availableData == receivedPacketProbe->GetSize ()); |
131 |
|
132 |
Ipv4Header ipHdr; |
133 |
receivedPacketProbe->RemoveHeader (ipHdr); |
134 |
UdpHeader udpHdr; |
135 |
receivedPacketProbe->RemoveHeader (udpHdr); |
136 |
PacketHeader pktHdr; |
137 |
receivedPacketProbe->RemoveHeader (pktHdr); |
138 |
|
139 |
if (m_countA == 0) |
140 |
{ |
141 |
MessageHeader msgHdr; |
142 |
receivedPacketProbe->RemoveHeader (msgHdr); |
143 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
144 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
145 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 0, "0 - Hello, No messages."); |
146 |
} |
147 |
else if (m_countA == 1) |
148 |
{ |
149 |
MessageHeader msgHdr; |
150 |
receivedPacketProbe->RemoveHeader (msgHdr); |
151 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
152 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
153 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 2, "1 - Hello, one message."); |
154 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 1, "1 - Asymmetric Link."); |
155 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses.size (), 1, "1 - Neighbor."); |
156 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.3"), "1 - Neighbor."); |
157 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].linkCode, 1, "1 - Asymmetric Link."); |
158 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses.size (), 1, "1 - Neighbor."); |
159 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.1"), "1 - Neighbor."); |
160 |
} |
161 |
else |
162 |
{ |
163 |
if (m_countA == 5 || m_countA == 8) |
164 |
{ |
165 |
MessageHeader msgHdr; |
166 |
receivedPacketProbe->RemoveHeader (msgHdr); |
167 |
const olsr::MessageHeader::Tc &tc = msgHdr.GetTc (); |
168 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
169 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses.size (), 2, int(m_countA) << " - TC, one message."); |
170 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses[0], Ipv4Address ("10.1.1.3"), int(m_countA) << " - Neighbor."); |
171 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses[1], Ipv4Address ("10.1.1.1"), int(m_countA) << " - Neighbor."); |
172 |
} |
173 |
if (m_countA != 8) |
174 |
{ |
175 |
MessageHeader msgHdr; |
176 |
receivedPacketProbe->RemoveHeader (msgHdr); |
177 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
178 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
179 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 2, int(m_countA) << " - Hello, one message."); |
180 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 6, int(m_countA) << " - Symmetric Link."); |
181 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses.size (), 1, int(m_countA) << " - Neighbor."); |
182 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.3"), int(m_countA) << " - Neighbor."); |
183 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].linkCode, 6, int(m_countA) << " - Symmetric Link."); |
184 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses.size (), 1, int(m_countA) << " - Neighbor."); |
185 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.1"), int(m_countA) << " - Neighbor."); |
186 |
} |
187 |
} |
188 |
m_countA ++; |
119 |
} |
189 |
} |
120 |
|
190 |
|
121 |
void |
191 |
void |
122 |
TcRegressionTest::CheckResults () |
192 |
TcRegressionTest::ReceivePktProbeB (Ptr<Socket> socket) |
123 |
{ |
193 |
{ |
124 |
for (uint32_t i = 0; i < 3; ++i) |
194 |
uint32_t availableData; |
|
|
195 |
availableData = socket->GetRxAvailable (); |
196 |
Ptr<Packet> receivedPacketProbe = socket->Recv (std::numeric_limits<uint32_t>::max (), 0); |
197 |
NS_ASSERT (availableData == receivedPacketProbe->GetSize ()); |
198 |
|
199 |
Ipv4Header ipHdr; |
200 |
receivedPacketProbe->RemoveHeader (ipHdr); |
201 |
UdpHeader udpHdr; |
202 |
receivedPacketProbe->RemoveHeader (udpHdr); |
203 |
PacketHeader pktHdr; |
204 |
receivedPacketProbe->RemoveHeader (pktHdr); |
205 |
|
206 |
MessageHeader msgHdr; |
207 |
receivedPacketProbe->RemoveHeader (msgHdr); |
208 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
209 |
|
210 |
if (m_countB == 0 || m_countB == 2 || m_countB == 5 || m_countB == 6 || m_countB == 8 || |
211 |
m_countB == 10 || m_countB == 13 || m_countB == 15 || m_countB == 17 || m_countB == 19) |
125 |
{ |
212 |
{ |
126 |
NS_PCAP_TEST_EXPECT_EQ (PREFIX << "-" << i << "-1.pcap"); |
213 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.3"), "Originator address."); |
127 |
} |
214 |
} |
|
|
215 |
else |
216 |
{ |
217 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.1"), "Originator address."); |
218 |
} |
219 |
|
220 |
if (m_countB == 0 || m_countB == 1) |
221 |
{ |
222 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 0, int(m_countC) << " - Hello, links announced."); |
223 |
} |
224 |
else |
225 |
{ |
226 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 1, int(m_countC) << " - Hello, links announced."); |
227 |
if (m_countB == 2 || m_countB == 3) |
228 |
{ |
229 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 1, int(m_countC) << " - Asymmetric Link."); |
230 |
} |
231 |
else if (m_countB == 4 || m_countB == 5) |
232 |
{ |
233 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 6, int(m_countC) << " - Symmetric Link."); |
234 |
} |
235 |
else |
236 |
{ |
237 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 10, int(m_countC) << " - MPR Link."); |
238 |
} |
239 |
|
240 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.2"), int(m_countC) << " - Neighbor."); |
241 |
} |
242 |
|
243 |
m_countB ++; |
244 |
} |
245 |
|
246 |
// Note: this is identical to ReceivePktProbeA, but the packet counter needs to be different. |
247 |
void |
248 |
TcRegressionTest::ReceivePktProbeC (Ptr<Socket> socket) |
249 |
{ |
250 |
uint32_t availableData; |
251 |
availableData = socket->GetRxAvailable (); |
252 |
Ptr<Packet> receivedPacketProbe = socket->Recv (std::numeric_limits<uint32_t>::max (), 0); |
253 |
NS_ASSERT (availableData == receivedPacketProbe->GetSize ()); |
254 |
|
255 |
Ipv4Header ipHdr; |
256 |
receivedPacketProbe->RemoveHeader (ipHdr); |
257 |
UdpHeader udpHdr; |
258 |
receivedPacketProbe->RemoveHeader (udpHdr); |
259 |
PacketHeader pktHdr; |
260 |
receivedPacketProbe->RemoveHeader (pktHdr); |
261 |
|
262 |
if (m_countC == 0) |
263 |
{ |
264 |
MessageHeader msgHdr; |
265 |
receivedPacketProbe->RemoveHeader (msgHdr); |
266 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
267 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
268 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 0, "0 - Hello, No messages."); |
269 |
} |
270 |
else if (m_countC == 1) |
271 |
{ |
272 |
MessageHeader msgHdr; |
273 |
receivedPacketProbe->RemoveHeader (msgHdr); |
274 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
275 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
276 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 2, "1 - Hello, one message."); |
277 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 1, "1 - Asymmetric Link."); |
278 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses.size (), 1, "1 - Neighbor."); |
279 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.3"), "1 - Neighbor."); |
280 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].linkCode, 1, "1 - Asymmetric Link."); |
281 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses.size (), 1, "1 - Neighbor."); |
282 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.1"), "1 - Neighbor."); |
283 |
} |
284 |
else |
285 |
{ |
286 |
if (m_countC == 5 || m_countC == 8) |
287 |
{ |
288 |
MessageHeader msgHdr; |
289 |
receivedPacketProbe->RemoveHeader (msgHdr); |
290 |
const olsr::MessageHeader::Tc &tc = msgHdr.GetTc (); |
291 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
292 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses.size (), 2, int(m_countC) << " - TC, one message."); |
293 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses[0], Ipv4Address ("10.1.1.3"), int(m_countC) << " - Neighbor."); |
294 |
NS_TEST_EXPECT_MSG_EQ (tc.neighborAddresses[1], Ipv4Address ("10.1.1.1"), int(m_countC) << " - Neighbor."); |
295 |
} |
296 |
if (m_countC != 8) |
297 |
{ |
298 |
MessageHeader msgHdr; |
299 |
receivedPacketProbe->RemoveHeader (msgHdr); |
300 |
NS_TEST_EXPECT_MSG_EQ (msgHdr.GetOriginatorAddress (), Ipv4Address ("10.1.1.2"), "Originator address."); |
301 |
const olsr::MessageHeader::Hello &hello = msgHdr.GetHello (); |
302 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages.size (), 2, int(m_countC) << " - Hello, one message."); |
303 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].linkCode, 6, int(m_countC) << " - Symmetric Link."); |
304 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses.size (), 1, int(m_countC) << " - Neighbor."); |
305 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[0].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.3"), int(m_countC) << " - Neighbor."); |
306 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].linkCode, 6, int(m_countC) << " - Symmetric Link."); |
307 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses.size (), 1, int(m_countC) << " - Neighbor."); |
308 |
NS_TEST_EXPECT_MSG_EQ (hello.linkMessages[1].neighborInterfaceAddresses[0], Ipv4Address ("10.1.1.1"), int(m_countC) << " - Neighbor."); |
309 |
} |
310 |
} |
311 |
m_countC ++; |
128 |
} |
312 |
} |
129 |
|
313 |
|
130 |
} |
314 |
} |