|
|
| 342 |
// Receiver Node |
342 |
// Receiver Node |
| 343 |
ipv4 = rxNode->GetObject<Ipv4> (); |
343 |
ipv4 = rxNode->GetObject<Ipv4> (); |
| 344 |
netdev_idx = ipv4->AddInterface (net1.Get (0)); |
344 |
netdev_idx = ipv4->AddInterface (net1.Get (0)); |
| 345 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask (0xffff0000U)); |
345 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.1"), Ipv4Mask ("/24")); |
| 346 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
346 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
| 347 |
ipv4->SetUp (netdev_idx); |
347 |
ipv4->SetUp (netdev_idx); |
| 348 |
|
348 |
|
| 349 |
netdev_idx = ipv4->AddInterface (net2.Get (0)); |
349 |
netdev_idx = ipv4->AddInterface (net2.Get (0)); |
| 350 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask (0xffff0000U)); |
350 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.1"), Ipv4Mask ("/24")); |
| 351 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
351 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
| 352 |
ipv4->SetUp (netdev_idx); |
352 |
ipv4->SetUp (netdev_idx); |
| 353 |
|
353 |
|
| 354 |
// Sender Node |
354 |
// Sender Node |
| 355 |
ipv4 = txNode->GetObject<Ipv4> (); |
355 |
ipv4 = txNode->GetObject<Ipv4> (); |
| 356 |
netdev_idx = ipv4->AddInterface (net1.Get (1)); |
356 |
netdev_idx = ipv4->AddInterface (net1.Get (1)); |
| 357 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask (0xffff0000U)); |
357 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.0.2"), Ipv4Mask ("/24")); |
| 358 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
358 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
| 359 |
ipv4->SetUp (netdev_idx); |
359 |
ipv4->SetUp (netdev_idx); |
| 360 |
|
360 |
|
| 361 |
netdev_idx = ipv4->AddInterface (net2.Get (1)); |
361 |
netdev_idx = ipv4->AddInterface (net2.Get (1)); |
| 362 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask (0xffff0000U)); |
362 |
ipv4Addr = Ipv4InterfaceAddress (Ipv4Address ("10.0.1.2"), Ipv4Mask ("/24")); |
| 363 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
363 |
ipv4->AddAddress (netdev_idx, ipv4Addr); |
| 364 |
ipv4->SetUp (netdev_idx); |
364 |
ipv4->SetUp (netdev_idx); |
| 365 |
|
365 |
|
| 366 |
// Create the UDP sockets |
366 |
// Create the UDP sockets |
| 367 |
Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> (); |
367 |
Ptr<SocketFactory> rxSocketFactory = rxNode->GetObject<UdpSocketFactory> (); |
|
|
368 |
|
| 368 |
Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket (); |
369 |
Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket (); |
| 369 |
NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0, "trivial"); |
370 |
NS_TEST_EXPECT_MSG_EQ (rxSocket->Bind (InetSocketAddress (Ipv4Address ("10.0.0.1"), 1234)), 0, "trivial"); |
| 370 |
rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this)); |
371 |
rxSocket->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt, this)); |
| 371 |
|
372 |
|
| 372 |
Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket (); |
373 |
Ptr<Socket> rxSocket2 = rxSocketFactory->CreateSocket (); |
|
|
374 |
NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0, "trivial"); |
| 373 |
rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt2, this)); |
375 |
rxSocket2->SetRecvCallback (MakeCallback (&UdpSocketImplTest::ReceivePkt2, this)); |
| 374 |
NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("10.0.1.1"), 1234)), 0, "trivial"); |
|
|
| 375 |
|
376 |
|
| 376 |
Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> (); |
377 |
Ptr<SocketFactory> txSocketFactory = txNode->GetObject<UdpSocketFactory> (); |
| 377 |
Ptr<Socket> txSocket = txSocketFactory->CreateSocket (); |
378 |
Ptr<Socket> txSocket = txSocketFactory->CreateSocket (); |
|
|
| 382 |
// Unicast test |
383 |
// Unicast test |
| 383 |
SendDataTo (txSocket, "10.0.0.1"); |
384 |
SendDataTo (txSocket, "10.0.0.1"); |
| 384 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial"); |
385 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial"); |
| 385 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should receive it"); |
386 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second interface should not receive it"); |
| 386 |
|
387 |
|
| 387 |
m_receivedPacket->RemoveAllByteTags (); |
388 |
m_receivedPacket->RemoveAllByteTags (); |
| 388 |
m_receivedPacket2->RemoveAllByteTags (); |
389 |
m_receivedPacket2->RemoveAllByteTags (); |
|
|
| 390 |
// Simple broadcast test |
391 |
// Simple broadcast test |
| 391 |
|
392 |
|
| 392 |
SendDataTo (txSocket, "255.255.255.255"); |
393 |
SendDataTo (txSocket, "255.255.255.255"); |
| 393 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial"); |
394 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address"); |
| 394 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second socket should not receive it (it is bound specifically to the second interface's address"); |
395 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 0, "second socket should not receive it (it is bound specifically to the second interface's address"); |
| 395 |
|
396 |
|
| 396 |
m_receivedPacket->RemoveAllByteTags (); |
397 |
m_receivedPacket->RemoveAllByteTags (); |
|
|
| 407 |
NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0, "trivial"); |
408 |
NS_TEST_EXPECT_MSG_EQ (rxSocket2->Bind (InetSocketAddress (Ipv4Address ("0.0.0.0"), 1234)), 0, "trivial"); |
| 408 |
|
409 |
|
| 409 |
SendDataTo (txSocket, "255.255.255.255"); |
410 |
SendDataTo (txSocket, "255.255.255.255"); |
| 410 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 123, "trivial"); |
411 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address"); |
| 411 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "trivial"); |
412 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "trivial"); |
| 412 |
|
413 |
|
| 413 |
m_receivedPacket = 0; |
414 |
m_receivedPacket = 0; |
|
|
| 417 |
|
418 |
|
| 418 |
txSocket->BindToNetDevice (net1.Get (1)); |
419 |
txSocket->BindToNetDevice (net1.Get (1)); |
| 419 |
SendDataTo (txSocket, "224.0.0.9"); |
420 |
SendDataTo (txSocket, "224.0.0.9"); |
| 420 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the second interface's address"); |
421 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket->GetSize (), 0, "first socket should not receive it (it is bound specifically to the first interface's address"); |
| 421 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: 224.0.0.9"); |
422 |
NS_TEST_EXPECT_MSG_EQ (m_receivedPacket2->GetSize (), 123, "recv2: 224.0.0.9"); |
| 422 |
|
423 |
|
| 423 |
m_receivedPacket->RemoveAllByteTags (); |
424 |
m_receivedPacket->RemoveAllByteTags (); |