20#include "ns3/boolean.h"
22#include "ns3/icmpv4-l4-protocol.h"
23#include "ns3/inet-socket-address.h"
24#include "ns3/internet-stack-helper.h"
25#include "ns3/ipv4-address-helper.h"
26#include "ns3/ipv4-l3-protocol.h"
27#include "ns3/ipv4-static-routing.h"
29#include "ns3/node-container.h"
31#include "ns3/rip-helper.h"
33#include "ns3/simple-channel.h"
34#include "ns3/simple-net-device.h"
35#include "ns3/simulator.h"
36#include "ns3/socket-factory.h"
37#include "ns3/socket.h"
39#include "ns3/udp-l4-protocol.h"
40#include "ns3/udp-socket-factory.h"
70 void DoRun()
override;
88 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
92 "Received Packet size is not equal to the Rx buffer size");
123 Ptr<Node> routerA = CreateObject<Node>();
124 Ptr<Node> routerB = CreateObject<Node>();
125 Ptr<Node> routerC = CreateObject<Node>();
134 internetRouters.
Install(routers);
147 txDev = CreateObject<SimpleNetDevice>();
149 txNode->AddDevice(txDev);
157 fwDev1routerA = CreateObject<SimpleNetDevice>();
158 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
159 routerA->AddDevice(fwDev1routerA);
161 net1.
Add(fwDev1routerA);
164 fwDev2routerA = CreateObject<SimpleNetDevice>();
165 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
166 routerA->AddDevice(fwDev2routerA);
168 net2.
Add(fwDev2routerA);
174 fwDev1routerB = CreateObject<SimpleNetDevice>();
175 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
176 routerB->AddDevice(fwDev1routerB);
178 net2.
Add(fwDev1routerB);
181 fwDev2routerB = CreateObject<SimpleNetDevice>();
182 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
183 routerB->AddDevice(fwDev2routerB);
185 net3.
Add(fwDev2routerB);
191 fwDev1routerC = CreateObject<SimpleNetDevice>();
192 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
193 routerC->AddDevice(fwDev1routerC);
195 net3.
Add(fwDev1routerC);
198 fwDev2routerC = CreateObject<SimpleNetDevice>();
199 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
200 routerC->AddDevice(fwDev2routerC);
202 net4.
Add(fwDev2routerC);
207 rxDev = CreateObject<SimpleNetDevice>();
209 rxNode->AddDevice(rxDev);
215 txDev->SetChannel(channel1);
216 fwDev1routerA->SetChannel(channel1);
219 fwDev2routerA->SetChannel(channel2);
220 fwDev1routerB->SetChannel(channel2);
223 fwDev2routerB->SetChannel(channel3);
224 fwDev1routerC->SetChannel(channel3);
227 fwDev2routerC->SetChannel(channel4);
228 rxDev->SetChannel(channel4);
246 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
248 staticRouting->SetDefaultRoute(
"10.0.1.2", 1);
249 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
251 staticRouting->SetDefaultRoute(
"10.0.2.1", 1);
255 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
262 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
263 txSocket->SetAllowBroadcast(
true);
299 void DoRun()
override;
310 :
TestCase(
"RIP counting to infinity")
317 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
321 "Received Packet size is not equal to the Rx buffer size");
352 Ptr<Node> routerA = CreateObject<Node>();
353 Ptr<Node> routerB = CreateObject<Node>();
354 Ptr<Node> routerC = CreateObject<Node>();
370 internetv6routers.
Install(routers);
383 txDev = CreateObject<SimpleNetDevice>();
385 txNode->AddDevice(txDev);
393 fwDev1routerA = CreateObject<SimpleNetDevice>();
394 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
395 routerA->AddDevice(fwDev1routerA);
397 net1.
Add(fwDev1routerA);
400 fwDev2routerA = CreateObject<SimpleNetDevice>();
401 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
402 routerA->AddDevice(fwDev2routerA);
404 net2.
Add(fwDev2routerA);
410 fwDev1routerB = CreateObject<SimpleNetDevice>();
411 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
412 routerB->AddDevice(fwDev1routerB);
414 net2.
Add(fwDev1routerB);
417 fwDev2routerB = CreateObject<SimpleNetDevice>();
418 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
419 routerB->AddDevice(fwDev2routerB);
421 net3.
Add(fwDev2routerB);
427 fwDev1routerC = CreateObject<SimpleNetDevice>();
428 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
429 routerC->AddDevice(fwDev1routerC);
431 net3.
Add(fwDev1routerC);
434 fwDev2routerC = CreateObject<SimpleNetDevice>();
435 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
436 routerC->AddDevice(fwDev2routerC);
438 net4.
Add(fwDev2routerC);
443 rxDev = CreateObject<SimpleNetDevice>();
445 rxNode->AddDevice(rxDev);
451 txDev->SetChannel(channel1);
452 fwDev1routerA->SetChannel(channel1);
455 fwDev2routerA->SetChannel(channel2);
456 fwDev1routerB->SetChannel(channel2);
459 fwDev2routerB->SetChannel(channel3);
460 fwDev1routerC->SetChannel(channel3);
463 fwDev2routerC->SetChannel(channel4);
464 rxDev->SetChannel(channel4);
482 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
484 staticRouting->SetDefaultRoute(
"10.0.1.2", 1);
485 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
487 staticRouting->SetDefaultRoute(
"10.0.2.1", 1);
491 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
498 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
499 txSocket->SetAllowBroadcast(
true);
520 void DoRun()
override;
536 :
TestCase(
"RIP Split Horizon strategy")
544 uint32_t availableData [[maybe_unused]] = socket->GetRxAvailable();
547 socket->RecvFrom(std::numeric_limits<uint32_t>::max(), 0, srcAddr);
549 receivedPacketProbe->GetSize(),
550 "Received Packet size is not equal to the Rx buffer size");
553 if (senderAddress ==
"192.168.0.2")
556 receivedPacketProbe->RemoveHeader(hdr);
561 for (std::list<RipRte>::iterator iter = rtes.begin(); iter != rtes.end(); iter++)
563 if (iter->GetPrefix() ==
"10.0.1.0")
565 bool correct =
false;
566 if (iter->GetRouteMetric() == 16)
571 else if (iter->GetRouteMetric() == 2)
578 "RIP: unexpected metric value: " << iter->GetRouteMetric());
589 Ptr<Node> fakeNode = CreateObject<Node>();
590 Ptr<Node> listener = CreateObject<Node>();
592 Ptr<Node> routerA = CreateObject<Node>();
593 Ptr<Node> routerB = CreateObject<Node>();
604 internetRouters.
Install(routers);
607 internetNodes.
Install(listeners);
615 silentDev = CreateObject<SimpleNetDevice>();
616 silentDev->SetAddress(
Mac48Address(
"00:00:00:00:00:01"));
617 fakeNode->AddDevice(silentDev);
625 silentDevRouterA = CreateObject<SimpleNetDevice>();
626 silentDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
627 routerA->AddDevice(silentDevRouterA);
629 net0.
Add(silentDevRouterA);
632 fwDevRouterA = CreateObject<SimpleNetDevice>();
633 fwDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
634 routerA->AddDevice(fwDevRouterA);
636 net1.
Add(fwDevRouterA);
641 fwDevRouterB = CreateObject<SimpleNetDevice>();
642 fwDevRouterB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
643 routerB->AddDevice(fwDevRouterB);
645 net1.
Add(fwDevRouterB);
650 listenerDev = CreateObject<SimpleNetDevice>();
651 listenerDev->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
652 listener->AddDevice(listenerDev);
654 net1.
Add(listenerDev);
658 silentDev->SetChannel(channel0);
659 silentDevRouterA->SetChannel(channel0);
662 fwDevRouterA->SetChannel(channel1);
663 fwDevRouterB->SetChannel(channel1);
664 listenerDev->SetChannel(channel1);
677 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
678 rxSocket->BindToNetDevice(listenerDev);
682 rxSocket->SetRecvCallback(
IPv4 RIP count to infinity Test.
void DoRun() override
Implementation to actually run this TestCase.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
Ipv4RipCountToInfinityTest()
void SendData(Ptr< Socket > socket, std::string to)
Send data.
Ptr< Packet > m_receivedPacket
Received packet.
IPv4 RIP SplitHorizon strategy Test.
void ReceivePktProbe(Ptr< Socket > socket)
Receive data.
Rip::SplitHorizonType_e m_detectedStrategy
Strategy detected.
Ipv4RipSplitHorizonStrategyTest(Rip::SplitHorizonType_e strategy)
Constructor.
Rip::SplitHorizonType_e m_setStrategy
Strategy set.
void DoRun() override
Implementation to actually run this TestCase.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet.
void DoRun() override
Implementation to actually run this TestCase.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
a polymophic address class
Hold variables of type enum.
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const =0
Get the routing protocol to be used by this Ipv4 stack.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
a class to represent an Ipv4 address mask
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void RemoveAllByteTags()
Remove all byte tags stored in this packet.
Smart pointer class similar to boost::intrusive_ptr.
Helper class that adds RIP routing to nodes.
void Set(std::string name, const AttributeValue &value)
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
SplitHorizonType_e
Split Horizon strategy type.
@ SPLIT_HORIZON
Split Horizon.
@ NO_SPLIT_HORIZON
No Split Horizon.
@ POISON_REVERSE
Poison Reverse Split Horizon.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
@ UNIT
This test suite implements a Unit Test.
API to create UDP socket instances.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
static Ipv4RipTestSuite g_ipv4ripTestSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...