20 #include "ns3/boolean.h"
22 #include "ns3/icmpv6-l4-protocol.h"
23 #include "ns3/inet6-socket-address.h"
24 #include "ns3/internet-stack-helper.h"
25 #include "ns3/ipv6-address-helper.h"
26 #include "ns3/ipv6-l3-protocol.h"
28 #include "ns3/node-container.h"
30 #include "ns3/ripng-helper.h"
31 #include "ns3/ripng.h"
32 #include "ns3/simple-channel.h"
33 #include "ns3/simple-net-device.h"
34 #include "ns3/simulator.h"
35 #include "ns3/socket-factory.h"
36 #include "ns3/socket.h"
38 #include "ns3/udp-l4-protocol.h"
39 #include "ns3/udp-socket-factory.h"
60 void DoSendData(
Ptr<Socket> socket, std::string to);
69 void DoRun()
override;
87 uint32_t availableData [[maybe_unused]] = socket->
GetRxAvailable();
91 "Received packet size is not equal to Rx buffer size");
105 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
122 Ptr<Node> routerA = CreateObject<Node>();
123 Ptr<Node> routerB = CreateObject<Node>();
124 Ptr<Node> routerC = CreateObject<Node>();
133 internetv6routers.
Install(routers);
146 txDev = CreateObject<SimpleNetDevice>();
156 fwDev1routerA = CreateObject<SimpleNetDevice>();
157 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
160 net1.
Add(fwDev1routerA);
163 fwDev2routerA = CreateObject<SimpleNetDevice>();
164 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
167 net2.
Add(fwDev2routerA);
173 fwDev1routerB = CreateObject<SimpleNetDevice>();
174 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
177 net2.
Add(fwDev1routerB);
180 fwDev2routerB = CreateObject<SimpleNetDevice>();
181 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
184 net3.
Add(fwDev2routerB);
190 fwDev1routerC = CreateObject<SimpleNetDevice>();
191 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
194 net3.
Add(fwDev1routerC);
197 fwDev2routerC = CreateObject<SimpleNetDevice>();
198 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
201 net4.
Add(fwDev2routerC);
206 rxDev = CreateObject<SimpleNetDevice>();
214 txDev->SetChannel(channel1);
215 fwDev1routerA->SetChannel(channel1);
218 fwDev2routerA->SetChannel(channel2);
219 fwDev1routerB->SetChannel(channel2);
222 fwDev2routerB->SetChannel(channel3);
223 fwDev1routerC->SetChannel(channel3);
226 fwDev2routerC->SetChannel(channel4);
227 rxDev->SetChannel(channel4);
252 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
260 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
261 txSocket->SetAllowBroadcast(
true);
266 SendData(txSocket,
"2001:2::200:ff:fe00:8");
271 Simulator::Destroy();
299 void DoRun()
override;
310 :
TestCase(
"RIPng counting to infinity")
317 uint32_t availableData [[maybe_unused]] = socket->
GetRxAvailable();
321 "Received packet size is not equal to Rx buffer size");
335 Simulator::ScheduleWithContext(socket->
GetNode()->
GetId(),
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>();
393 fwDev1routerA = CreateObject<SimpleNetDevice>();
394 fwDev1routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
397 net1.
Add(fwDev1routerA);
400 fwDev2routerA = CreateObject<SimpleNetDevice>();
401 fwDev2routerA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
404 net2.
Add(fwDev2routerA);
410 fwDev1routerB = CreateObject<SimpleNetDevice>();
411 fwDev1routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
414 net2.
Add(fwDev1routerB);
417 fwDev2routerB = CreateObject<SimpleNetDevice>();
418 fwDev2routerB->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
421 net3.
Add(fwDev2routerB);
427 fwDev1routerC = CreateObject<SimpleNetDevice>();
428 fwDev1routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:06"));
431 net3.
Add(fwDev1routerC);
434 fwDev2routerC = CreateObject<SimpleNetDevice>();
435 fwDev2routerC->SetAddress(
Mac48Address(
"00:00:00:00:00:07"));
438 net4.
Add(fwDev2routerC);
443 rxDev = CreateObject<SimpleNetDevice>();
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);
489 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
497 Ptr<Socket> txSocket = txSocketFactory->CreateSocket();
498 txSocket->SetAllowBroadcast(
true);
502 SendData(txSocket,
"2001:2::200:ff:fe00:8");
505 Simulator::Destroy();
519 void DoRun()
override;
535 :
TestCase(
"RIPng Split Horizon strategy")
543 uint32_t availableData [[maybe_unused]] = socket->
GetRxAvailable();
548 receivedPacketProbe->
GetSize(),
549 "ReceivedPacketProbe size is not equal to the Rx buffer size");
550 Ipv6Address senderAddress = Inet6SocketAddress::ConvertFrom(srcAddr).GetIpv6();
552 if (senderAddress ==
"fe80::200:ff:fe00:4")
559 for (
auto iter = rtes.begin(); iter != rtes.end(); iter++)
561 if (iter->GetPrefix() ==
"2001:1::")
563 bool correct =
false;
564 if (iter->GetRouteMetric() == 16)
569 else if (iter->GetRouteMetric() == 2)
576 "RIPng: unexpected metric value: " << iter->GetRouteMetric());
587 Ptr<Node> fakeNode = CreateObject<Node>();
588 Ptr<Node> listener = CreateObject<Node>();
590 Ptr<Node> routerA = CreateObject<Node>();
591 Ptr<Node> routerB = CreateObject<Node>();
602 internetv6routers.
Install(routers);
605 internetv6nodes.
Install(listeners);
613 silentDev = CreateObject<SimpleNetDevice>();
614 silentDev->SetAddress(
Mac48Address(
"00:00:00:00:00:01"));
623 silentDevRouterA = CreateObject<SimpleNetDevice>();
624 silentDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:02"));
627 net0.
Add(silentDevRouterA);
630 fwDevRouterA = CreateObject<SimpleNetDevice>();
631 fwDevRouterA->SetAddress(
Mac48Address(
"00:00:00:00:00:03"));
634 net1.
Add(fwDevRouterA);
639 fwDevRouterB = CreateObject<SimpleNetDevice>();
640 fwDevRouterB->SetAddress(
Mac48Address(
"00:00:00:00:00:04"));
643 net1.
Add(fwDevRouterB);
648 listenerDev = CreateObject<SimpleNetDevice>();
649 listenerDev->SetAddress(
Mac48Address(
"00:00:00:00:00:05"));
652 net1.
Add(listenerDev);
656 silentDev->SetChannel(channel0);
657 silentDevRouterA->SetChannel(channel0);
660 fwDevRouterA->SetChannel(channel1);
661 fwDevRouterB->SetChannel(channel1);
662 listenerDev->SetChannel(channel1);
676 Ptr<Socket> rxSocket = rxSocketFactory->CreateSocket();
677 rxSocket->BindToNetDevice(listenerDev);
681 rxSocket->SetRecvCallback(
693 Simulator::Destroy();
IPv6 RIPng count to infinity Test.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
Ipv6RipngCountToInfinityTest()
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet.
void DoRun() override
Implementation to actually run this TestCase.
IPv6 RIPng SplitHorizon strategy Test.
Ipv6RipngSplitHorizonStrategyTest(RipNg::SplitHorizonType_e strategy)
Constructor.
RipNg::SplitHorizonType_e m_setStrategy
Strategy set.
void DoRun() override
Implementation to actually run this TestCase.
RipNg::SplitHorizonType_e m_detectedStrategy
Strategy detected.
void ReceivePktProbe(Ptr< Socket > socket)
Receive data.
Ptr< Packet > m_receivedPacket
Received packet.
void DoRun() override
Implementation to actually run this TestCase.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
void ReceivePkt(Ptr< Socket > socket)
Receive 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)
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer AssignWithoutOnLink(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses, but do not set the on-link property ...
Describes an IPv6 address.
Keep track of a set of IPv6 interfaces.
void SetForwarding(uint32_t i, bool state)
Set the state of the stack (act as a router or as an host) for the specified index.
void SetDefaultRouteInAllNodes(uint32_t router)
Set the default route for all the devices (except the router itself).
Describes an IPv6 prefix.
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 RIPng routing to nodes.
void SetInterfaceMetric(Ptr< Node > node, uint32_t interface, uint8_t metric)
Set a metric for an interface.
void Set(std::string name, const AttributeValue &value)
SplitHorizonType_e
Split Horizon strategy type.
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 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 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 Ipv6RipngTestSuite g_ipv6ripngTestSuite
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...