26#include "ns3/boolean.h"
27#include "ns3/config.h"
28#include "ns3/double.h"
29#include "ns3/inet-socket-address.h"
30#include "ns3/internet-stack-helper.h"
31#include "ns3/ipv4-address-helper.h"
32#include "ns3/ipv4-l3-protocol.h"
33#include "ns3/ipv4-list-routing-helper.h"
34#include "ns3/ipv4-static-routing-helper.h"
35#include "ns3/ipv4-static-routing.h"
39#include "ns3/random-variable-stream.h"
40#include "ns3/simple-channel.h"
41#include "ns3/simple-net-device-helper.h"
42#include "ns3/simple-net-device.h"
43#include "ns3/simulator.h"
44#include "ns3/socket.h"
45#include "ns3/string.h"
47#include "ns3/traffic-control-layer.h"
48#include "ns3/udp-socket-factory.h"
49#include "ns3/udp-socket.h"
50#include "ns3/uinteger.h"
146 std::map<std::string, uint32_t>
148 std::map<std::string, uint32_t>
152 void DoRun()
override;
185 :
TestCase(MakeName(enable, expire)),
203 availableData = socket->GetRxAvailable();
204 Ptr<Packet> packet = socket->Recv(std::numeric_limits<uint32_t>::max(), 0);
207 "Received packet size is not equal to the Rx buffer size");
209 auto node = socket->GetNode();
234 auto node = ipv4->GetNetDevice(interface)->GetNode();
274 std::ostringstream oss;
275 oss <<
"IP v4 RFC 6621 De-duplication: ";
280 else if (expire >
DELAY)
297 const std::string targetAddr =
"239.192.100.1";
326 listRouting.
Add(staticRouting, 0);
329 internet.SetIpv6StackInstall(
false);
330 internet.SetIpv4ArpJitter(
true);
331 internet.SetRoutingHelper(listRouting);
332 internet.Install(
nodes);
335 ipv4address.
SetBase(
"10.0.0.0",
"255.255.255.0");
336 ipv4address.
Assign(devices);
339 auto diter = devices.Begin();
357 auto ipv4 = (*iter)->GetObject<
Ipv4>();
362 routing->AddHostRouteTo(targetAddr.c_str(), ipv4->GetInterfaceForDevice(*diter), 0);
368 auto channel = devices.Get(0)->GetChannel();
372 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"A/dev"),
373 Names::Find<SimpleNetDevice>(
"D/dev"));
374 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"D/dev"),
375 Names::Find<SimpleNetDevice>(
"A/dev"));
377 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"A/dev"),
378 Names::Find<SimpleNetDevice>(
"E/dev"));
379 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"E/dev"),
380 Names::Find<SimpleNetDevice>(
"A/dev"));
382 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"B/dev"),
383 Names::Find<SimpleNetDevice>(
"E/dev"));
384 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"E/dev"),
385 Names::Find<SimpleNetDevice>(
"B/dev"));
387 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"C/dev"),
388 Names::Find<SimpleNetDevice>(
"E/dev"));
389 simplechannel->BlackList(Names::Find<SimpleNetDevice>(
"E/dev"),
390 Names::Find<SimpleNetDevice>(
"C/dev"));
393 std::list<Ptr<Socket>> sockets;
398 socket->SetAllowBroadcast(
true);
405 udpSocket->SetAttribute(
"IpMulticastTtl",
StringValue(
"4"));
408 sockets.push_back(socket);
416 auto txSocket = sockets.front();
449 std::map<std::string, uint32_t> packets = {
458 std::map<std::string, uint32_t> packetsDuped = {
470 std::map<std::string, uint32_t> degenerates = {
483 "Wrong number of packets received for node " << name);
488 "Wrong number of packets received for node " << name);
493 "Wrong number of packets received for node " << name);
501 std::map<std::string, uint32_t> drops;
509 drops = {{
"A", 2}, {
"B", 2}, {
"C", 2}, {
"D", 2}, {
"E", 0}};
513 drops = {{
"A", 10}, {
"B", 9}, {
"C", 9}, {
"D", 12}, {
"E", 2}};
525 drops = {{
"A", 4}, {
"B", 5}, {
"C", 5}, {
"D", 5}, {
"E", 1}};
533 "No drops for node " << name);
536 "Wrong number of drops for node " << name);
542 "Non-0 drops for node " << name);
598 void DoRun()
override;
615 :
TestCase(
"Ipv4Deduplication performance test")
624 const std::string targetAddr =
"239.192.100.1";
637 listRouting.
Add(staticRouting, 0);
640 internet.SetIpv6StackInstall(
false);
641 internet.SetIpv4ArpJitter(
true);
642 internet.SetRoutingHelper(listRouting);
643 internet.Install(
nodes);
646 ipv4address.
SetBase(
"10.0.0.0",
"255.255.255.0");
647 ipv4address.
Assign(devices);
650 auto diter = devices.Begin();
668 auto ipv4 = (*iter)->GetObject<
Ipv4>();
671 "Node " << (*iter)->GetId() <<
" does not have Ipv4 aggregate");
673 routing->AddHostRouteTo(targetAddr.c_str(), ipv4->GetInterfaceForDevice(*diter), 0);
680 CreateObjectWithAttributes<UniformRandomVariable>(
"Max",
DoubleValue(4));
685 m_sockets.push_back(udpSocketFactory->CreateSocket());
692 Seconds(4 + jitter->GetValue()),
714 socket->SendTo(Create<Packet>(512), 0, to);
740 :
TestSuite(
"ipv4-deduplication-performance", PERFORMANCE)
void ReceivePkt(Ptr< Socket > socket)
Receive data.
Ipv4DeduplicationTest(bool enable, Time expire=Seconds(1))
Constructor.
std::map< std::string, uint32_t > m_dropCountMap
map of received packets (node name, counter)
void CheckDrops(const std::string &name)
Check packet drops.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
Time m_expire
Expiration delay for duplicate cache entries.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
void DoRun() override
Implementation to actually run this TestCase.
static const Time DELAY
Channel delay.
static std::string MakeName(bool enable, Time expire)
Creates the test name according to the parameters.
void DoSendPacket(Ptr< Socket > socket, Ptr< Packet > packet, std::string to)
Send data.
void DropPkt(const Ipv4Header &ipHeader, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Register dropped packet.
std::map< std::string, uint32_t > m_packetCountMap
map of received packets (node name, counter)
void SendPacket(Ptr< Socket > socket, Ptr< Packet > packet, std::string to)
Send data.
void CheckPackets(const std::string &name)
Check packet receptions.
IPv4 Deduplication TestSuite.
Ipv4DeduplicationTestSuite()
a polymophic address class
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
DropReason
Reason why a packet has been dropped.
@ DROP_DUPLICATE
Duplicate packet received.
@ DROP_TTL_EXPIRED
Packet TTL has expired.
Helper class that adds ns3::Ipv4ListRouting objects.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
void AddMulticastRoute(Ptr< Node > n, Ipv4Address source, Ipv4Address group, Ptr< NetDevice > input, NetDeviceContainer output)
Add a multicast route to a node and net device using explicit Ptr<Node> and Ptr<NetDevice>
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
static void Clear()
Clear the list of objects associated with names.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
A simple channel, for simple things and testing.
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
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 uint64_t GetEventCount()
Get the number of events executed.
Object to create transport layer instances that provide a socket API to applications.
virtual Ptr< Socket > CreateSocket()=0
Hold variables of type string.
@ EXTENSIVE
Medium length test.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
AttributeValue implementation for Time.
API to create UDP socket instances.
(abstract) base class of all UdpSockets
virtual int MulticastJoinGroup(uint32_t interface, const Address &groupAddress)=0
Corresponds to socket option MCAST_JOIN_GROUP.
void SetDefault(std::string name, const AttributeValue &value)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#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.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
static Ipv4DeduplicationPerformanceTestSuite g_ipv4DeduplicationPerformanceTestSuite
Static variable for test initialization.
static Ipv4DeduplicationTestSuite g_ipv4DeduplicationTestSuite
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...