From 8e654a5f94c8d633b4e6e46ffdffdd79b829e772 Mon Sep 17 00:00:00 2001 From: Lalith Suresh Date: Mon, 28 Mar 2011 19:46:05 +0100 Subject: [PATCH] Fixes Click test suite, updates it to use ClickInternetStackHelper, and fixes sanity check in Ipv4ClickRouting --- .../nsclick-udp-client-server-wifi.cc | 30 +++++++++++-------- src/click/model/ipv4-click-routing.cc | 2 +- src/click/test/ipv4-click-routing-test.cc | 21 +++---------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/click/examples/nsclick-udp-client-server-wifi.cc b/src/click/examples/nsclick-udp-client-server-wifi.cc index 319974876..3a029767b 100644 --- a/src/click/examples/nsclick-udp-client-server-wifi.cc +++ b/src/click/examples/nsclick-udp-client-server-wifi.cc @@ -46,7 +46,7 @@ NS_LOG_COMPONENT_DEFINE ("NsclickUdpClientServerWifi"); #ifdef NS3_CLICK void -readArp (Ptr clickRouter) +ReadArp (Ptr clickRouter) { // Access the handlers NS_LOG_INFO (clickRouter->ReadHandler ("wifi/arpquerier", "table")); @@ -54,11 +54,21 @@ readArp (Ptr clickRouter) } void -writeArp (Ptr clickRouter) +WriteArp (Ptr clickRouter) { // Access the handler NS_LOG_INFO (clickRouter->WriteHandler ("wifi/arpquerier", "insert", "172.16.1.2 00:00:00:00:00:02")); } + +void SetPromisc (Ptr clickRouter) +{ + // 4th node can listen to traffic in promisc mode + // Note: Promiscuous mode support for Click has + // been added ahead of the official Wifi support + // for promiscuous mode. Thus, the below line will + // not work until then. + clickRouter->SetPromiscuous ("eth0"); +} #endif int @@ -135,13 +145,6 @@ main (int argc, char *argv[]) clickinternet.SetClickFile (n, "src/click/examples/nsclick-wifi-single-interface.click"); clickinternet.SetRoutingTableElement (n, "rt"); clickinternet.Install (n); - // 4th node can listen to traffic in promisc mode - // Note: Promiscuous mode support for Click has - // been added ahead of the official Wifi support - // for promiscuous mode. Thus, the below line will - // not work until then. - n.Get (3)->GetObject ()->SetPromiscuous ("eth0"); - Ipv4AddressHelper ipv4; // // We've got the "hardware" in place. Now we need to add IP addresses. @@ -177,6 +180,9 @@ main (int argc, char *argv[]) wifiPhy.EnablePcap ("nsclick-udp-client-server-wifi", d); + // Call SetPromiscuous mode on Click Router for node 4 + Simulator::Schedule (Seconds (0.1), &SetPromisc, n.Get (3)->GetObject ()); + // Force the MAC address of the second node: The current ARP // implementation of Click sends only one ARP request per incoming // packet for an unknown destination and does not retransmit if no @@ -184,9 +190,9 @@ main (int argc, char *argv[]) // requests of node 3 are lost due to interference from node // 1. Hence, we fill in the ARP table of node 2 before at the // beginning of the simulation - Simulator::Schedule (Seconds (0.5), &readArp,n.Get (2)->GetObject ()); - Simulator::Schedule (Seconds (0.6), &writeArp,n.Get (2)->GetObject ()); - Simulator::Schedule (Seconds (0.7), &readArp,n.Get (2)->GetObject ()); + Simulator::Schedule (Seconds (0.5), &ReadArp, n.Get (2)->GetObject ()); + Simulator::Schedule (Seconds (0.6), &WriteArp, n.Get (2)->GetObject ()); + Simulator::Schedule (Seconds (0.7), &ReadArp, n.Get (2)->GetObject ()); // // Now, do the actual simulation. diff --git a/src/click/model/ipv4-click-routing.cc b/src/click/model/ipv4-click-routing.cc index 11e7bc8af..3f05043fc 100644 --- a/src/click/model/ipv4-click-routing.cc +++ b/src/click/model/ipv4-click-routing.cc @@ -193,7 +193,7 @@ Ipv4ClickRouting::GetInterfaceId (const char *ifname) // more interfaces defined in the Click graph // for a Click node than are defined for it in // the simulation script - if (retval > (int) m_ipv4->GetNInterfaces ()) + if (retval >= (int) m_ipv4->GetNInterfaces ()) { return -1; } diff --git a/src/click/test/ipv4-click-routing-test.cc b/src/click/test/ipv4-click-routing-test.cc index 3c16846a5..330ad0d25 100644 --- a/src/click/test/ipv4-click-routing-test.cc +++ b/src/click/test/ipv4-click-routing-test.cc @@ -26,8 +26,7 @@ #include "ns3/ipv4-l3-protocol.h" #include "ns3/simple-net-device.h" #include "ns3/ipv4-click-routing.h" -#include "ns3/icmpv4-l4-protocol.h" -#include "ns3/arp-l3-protocol.h" +#include "ns3/click-internet-stack-helper.h" #include @@ -36,19 +35,9 @@ namespace ns3 { static void AddClickInternetStack (Ptr node) { - // Setup ArpL3Protocol - Ptr arp = CreateObject (); - node->AggregateObject (arp); - - // Setup Ipv4L3Protocol - Ptr ipv4l3 = CreateObject (); - node->AggregateObject (ipv4l3); - - // Setup Click instance - Ptr ipv4 = node->GetObject (); - Ptr click = CreateObject (); - click->SetClickFile ("src/click/examples/nsclick-lan-single-interface.click"); - ipv4->SetRoutingProtocol (click); + ClickInternetStackHelper internet; + internet.SetClickFile (node, "src/click/examples/nsclick-lan-single-interface.click"); + internet.Install (node); } static void @@ -108,7 +97,6 @@ ClickIfidFromNameTest::DoRun () ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME, "eth1"); NS_TEST_EXPECT_MSG_EQ (ret, -1, "No eth1 on node"); - } class ClickIpMacAddressFromNameTest : public TestCase @@ -203,7 +191,6 @@ ClickTrivialTest::DoRun () NS_TEST_EXPECT_MSG_EQ (ret, 0, "eth1 does not exist, so return 0"); delete [] buf; - ret = 1; } class ClickIfidFromNameTestSuite : public TestSuite