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"
71 void DoRun()
override;
93 "Received Packet size is not equal to the Rx buffer size");
107 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
124 Ptr<Node> routerA = CreateObject<Node>();
125 Ptr<Node> routerB = CreateObject<Node>();
126 Ptr<Node> routerC = CreateObject<Node>();
135 internetRouters.
Install(routers);
148 txDev = CreateObject<SimpleNetDevice>();
158 fwDev1routerA = CreateObject<SimpleNetDevice>();
159 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
162 net1.
Add(fwDev1routerA);
165 fwDev2routerA = CreateObject<SimpleNetDevice>();
166 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
169 net2.
Add(fwDev2routerA);
175 fwDev1routerB = CreateObject<SimpleNetDevice>();
176 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
179 net2.
Add(fwDev1routerB);
182 fwDev2routerB = CreateObject<SimpleNetDevice>();
183 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
186 net3.
Add(fwDev2routerB);
192 fwDev1routerC = CreateObject<SimpleNetDevice>();
193 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
196 net3.
Add(fwDev1routerC);
199 fwDev2routerC = CreateObject<SimpleNetDevice>();
200 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
203 net4.
Add(fwDev2routerC);
208 rxDev = CreateObject<SimpleNetDevice>();
216 txDev->SetChannel(channel1);
217 fwDev1routerA->SetChannel(channel1);
220 fwDev2routerA->SetChannel(channel2);
221 fwDev1routerB->SetChannel(channel2);
224 fwDev2routerB->SetChannel(channel3);
225 fwDev1routerC->SetChannel(channel3);
228 fwDev2routerC->SetChannel(channel4);
229 rxDev->SetChannel(channel4);
247 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
249 staticRouting->SetDefaultRoute(
"10.0.1.2", 1);
250 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
252 staticRouting->SetDefaultRoute(
"10.0.2.1", 1);
256 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
263 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
264 txSocket->SetAllowBroadcast(
true);
274 Simulator::Destroy();
301 void DoRun()
override;
312 :
TestCase(
"RIP counting to infinity")
323 "Received Packet size is not equal to the Rx buffer size");
337 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
354 Ptr<Node> routerA = CreateObject<Node>();
355 Ptr<Node> routerB = CreateObject<Node>();
356 Ptr<Node> routerC = CreateObject<Node>();
372 internetv6routers.
Install(routers);
385 txDev = CreateObject<SimpleNetDevice>();
395 fwDev1routerA = CreateObject<SimpleNetDevice>();
396 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
399 net1.
Add(fwDev1routerA);
402 fwDev2routerA = CreateObject<SimpleNetDevice>();
403 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
406 net2.
Add(fwDev2routerA);
412 fwDev1routerB = CreateObject<SimpleNetDevice>();
413 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
416 net2.
Add(fwDev1routerB);
419 fwDev2routerB = CreateObject<SimpleNetDevice>();
420 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
423 net3.
Add(fwDev2routerB);
429 fwDev1routerC = CreateObject<SimpleNetDevice>();
430 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
433 net3.
Add(fwDev1routerC);
436 fwDev2routerC = CreateObject<SimpleNetDevice>();
437 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
440 net4.
Add(fwDev2routerC);
445 rxDev = CreateObject<SimpleNetDevice>();
453 txDev->SetChannel(channel1);
454 fwDev1routerA->SetChannel(channel1);
457 fwDev2routerA->SetChannel(channel2);
458 fwDev1routerB->SetChannel(channel2);
461 fwDev2routerB->SetChannel(channel3);
462 fwDev1routerC->SetChannel(channel3);
465 fwDev2routerC->SetChannel(channel4);
466 rxDev->SetChannel(channel4);
484 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
486 staticRouting->SetDefaultRoute(
"10.0.1.2", 1);
487 staticRouting = Ipv4RoutingHelper::GetRouting<Ipv4StaticRouting>(
489 staticRouting->SetDefaultRoute(
"10.0.2.1", 1);
493 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
500 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
501 txSocket->SetAllowBroadcast(
true);
508 Simulator::Destroy();
523 void DoRun()
override;
539 :
TestCase(
"RIP Split Horizon strategy")
552 receivedPacketProbe->
GetSize(),
553 "Received Packet size is not equal to the Rx buffer size");
554 Ipv4Address senderAddress = InetSocketAddress::ConvertFrom(srcAddr).GetIpv4();
556 if (senderAddress ==
"192.168.0.2")
564 for (std::list<RipRte>::iterator iter = rtes.begin(); iter != rtes.end(); iter++)
566 if (iter->GetPrefix() ==
"10.0.1.0")
568 bool correct =
false;
569 if (iter->GetRouteMetric() == 16)
574 else if (iter->GetRouteMetric() == 2)
581 "RIP: unexpected metric value: " << iter->GetRouteMetric());
592 Ptr<Node> fakeNode = CreateObject<Node>();
593 Ptr<Node> listener = CreateObject<Node>();
595 Ptr<Node> routerA = CreateObject<Node>();
596 Ptr<Node> routerB = CreateObject<Node>();
607 internetRouters.
Install(routers);
610 internetNodes.
Install(listeners);
618 silentDev = CreateObject<SimpleNetDevice>();
619 silentDev->SetAddress(
Mac48Address(
"00:00:00:00:00:01"));
628 silentDevRouterA = CreateObject<SimpleNetDevice>();
629 silentDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
632 net0.
Add(silentDevRouterA);
635 fwDevRouterA = CreateObject<SimpleNetDevice>();
636 fwDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
639 net1.
Add(fwDevRouterA);
644 fwDevRouterB = CreateObject<SimpleNetDevice>();
645 fwDevRouterB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
648 net1.
Add(fwDevRouterB);
653 listenerDev = CreateObject<SimpleNetDevice>();
654 listenerDev->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
657 net1.
Add(listenerDev);
661 silentDev->SetChannel(channel0);
662 silentDevRouterA->SetChannel(channel0);
665 fwDevRouterA->SetChannel(channel1);
666 fwDevRouterB->SetChannel(channel1);
667 listenerDev->SetChannel(channel1);
680 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
681 rxSocket->BindToNetDevice(listenerDev);
685 rxSocket->SetRecvCallback(
697 Simulator::Destroy();
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.
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.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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 AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
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.
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.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
virtual uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
virtual Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
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...