26 #include "ns3/ipv4-l3-protocol.h"
27 #include "ns3/simple-net-device.h"
28 #include "ns3/ipv4-click-routing.h"
29 #include "ns3/click-internet-stack-helper.h"
31 #include <click/simclick.h>
38 ClickInternetStackHelper internet;
39 internet.SetClickFile (node,
"src/click/test/nsclick-test-lan-single-interface.click");
40 internet.Install (node);
48 rxDev1 = CreateObject<SimpleNetDevice> ();
53 uint32_t netdev_idx = ipv4->AddInterface (rxDev1);
55 ipv4->AddAddress (netdev_idx, ipv4Addr);
56 ipv4->SetUp (netdev_idx);
59 class ClickIfidFromNameTest :
public TestCase
62 ClickIfidFromNameTest ();
63 virtual void DoRun ();
66 ClickIfidFromNameTest::ClickIfidFromNameTest ()
67 :
TestCase (
"Test SIMCLICK_IFID_FROM_NAME")
72 ClickIfidFromNameTest::DoRun ()
75 AddClickInternetStack (node);
79 click->DoInitialize ();
83 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"tap0");
86 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"tun0");
89 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"eth0");
92 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"tap1");
95 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"tun1");
98 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IFID_FROM_NAME,
"eth1");
102 class ClickIpMacAddressFromNameTest :
public TestCase
105 ClickIpMacAddressFromNameTest ();
106 virtual void DoRun ();
109 ClickIpMacAddressFromNameTest::ClickIpMacAddressFromNameTest ()
110 :
TestCase (
"Test SIMCLICK_IPADDR_FROM_NAME")
115 ClickIpMacAddressFromNameTest::DoRun ()
118 AddClickInternetStack (node);
123 click->DoInitialize ();
126 buf =
new char [255];
128 simclick_sim_command (click->m_simNode, SIMCLICK_IPADDR_FROM_NAME,
"eth0", buf, 255);
131 simclick_sim_command (click->m_simNode, SIMCLICK_MACADDR_FROM_NAME,
"eth0", buf, 255);
132 NS_TEST_EXPECT_MSG_EQ (strcmp (buf,
"00:00:00:00:00:01"), 0,
"eth0 has Mac Address 00:00:00:00:00:01");
134 simclick_sim_command (click->m_simNode, SIMCLICK_IPADDR_FROM_NAME,
"eth1", buf, 255);
137 simclick_sim_command (click->m_simNode, SIMCLICK_MACADDR_FROM_NAME,
"eth1", buf, 255);
138 NS_TEST_EXPECT_MSG_EQ (strcmp (buf,
"00:00:00:00:00:02"), 0,
"eth0 has Mac Address 00:00:00:00:00:02");
144 simclick_sim_command (click->m_simNode, SIMCLICK_IPADDR_FROM_NAME,
"tap0", buf, 255);
147 simclick_sim_command (click->m_simNode, SIMCLICK_MACADDR_FROM_NAME,
"tap0", buf, 255);
153 class ClickTrivialTest :
public TestCase
157 virtual void DoRun ();
160 ClickTrivialTest::ClickTrivialTest ()
161 :
TestCase (
"Test SIMCLICK_GET_NODE_NAME and SIMCLICK_IF_READY")
166 ClickTrivialTest::DoRun ()
169 AddClickInternetStack (node);
173 click->SetNodeName (
"myNode");
174 click->DoInitialize ();
178 buf =
new char [255];
180 ret = simclick_sim_command (click->m_simNode, SIMCLICK_GET_NODE_NAME, buf, 255);
183 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IF_READY, 0);
186 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IF_READY, 1);
189 ret = simclick_sim_command (click->m_simNode, SIMCLICK_IF_READY, 2);
195 class ClickIfidFromNameTestSuite :
public TestSuite
198 ClickIfidFromNameTestSuite () :
TestSuite (
"routing-click", UNIT)
200 AddTestCase (
new ClickTrivialTest, TestCase::QUICK);
201 AddTestCase (
new ClickIfidFromNameTest, TestCase::QUICK);
202 AddTestCase (
new ClickIpMacAddressFromNameTest, TestCase::QUICK);
204 } g_ipv4ClickRoutingTestSuite;
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.