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/examples/nsclick-lan-single-interface.click");
40 internet.Install (node);
48 rxDev1 = CreateObject<SimpleNetDevice> ();
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)
204 } g_ipv4ClickRoutingTestSuite;
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
a class to represent an Ipv4 address mask
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
virtual void SetUp(uint32_t interface)=0
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4 addresses are stored in host order in this class.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
a class to store IPv4 address information on an interface
virtual void SetAddress(Address address)
Set the address of this interface.
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0