|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
28 #include "ns3/simulator.h"
29 #include "ns3/simple-channel.h"
30 #include "ns3/simple-net-device.h"
31 #include "ns3/socket.h"
32 #include "ns3/boolean.h"
33 #include "ns3/double.h"
34 #include "ns3/uinteger.h"
35 #include "ns3/string.h"
36 #include "ns3/config.h"
38 #include "ns3/names.h"
41 #include "ns3/inet-socket-address.h"
42 #include "ns3/random-variable-stream.h"
44 #include "ns3/ipv4-l3-protocol.h"
45 #include "ns3/ipv4-static-routing.h"
46 #include "ns3/udp-socket-factory.h"
47 #include "ns3/udp-socket.h"
48 #include "ns3/internet-stack-helper.h"
49 #include "ns3/ipv4-list-routing-helper.h"
50 #include "ns3/ipv4-static-routing-helper.h"
51 #include "ns3/ipv4-address-helper.h"
52 #include "ns3/simple-net-device-helper.h"
54 #include "ns3/traffic-control-layer.h"
94 void DoSendData (
Ptr<Socket> socket, std::string to);
107 void SendData (
Ptr<Socket> socket, std::string to);
121 void CheckPackets (
const std::string &name);
127 void CheckDrops (
const std::string &name);
137 static std::string MakeName (
bool enable,
Time expire);
151 virtual void DoRun (
void);
183 :
TestCase (MakeName (enable, expire))
199 uint32_t availableData;
204 auto node = socket->
GetNode ();
205 std::string name = Names::FindName (node);
228 std::string name = Names::FindName (node);
236 SendPacket (socket, Create<Packet> (123), to);
262 std::ostringstream oss;
263 oss <<
"IP v4 RFC 6621 De-duplication: ";
268 else if (expire >
DELAY)
276 oss <<
", expire = " << expire.
ToDouble (Time::MS) <<
"ms";
285 const std::string targetAddr =
"239.192.100.1";
296 Names::Add (
"A",
nodes.Get (0));
297 Names::Add (
"B",
nodes.Get (1));
298 Names::Add (
"C",
nodes.Get (2));
299 Names::Add (
"D",
nodes.Get (3));
300 Names::Add (
"E",
nodes.Get (4));
305 Names::Add (
"A/dev",
devices.Get (0));
306 Names::Add (
"B/dev",
devices.Get (1));
307 Names::Add (
"C/dev",
devices.Get (2));
308 Names::Add (
"D/dev",
devices.Get (3));
309 Names::Add (
"E/dev",
devices.Get (4));
313 listRouting.
Add (staticRouting, 0);
322 ipv4address.
SetBase (
"10.0.0.0",
"255.255.255.0");
327 for (
auto end =
nodes.End (),
328 iter =
nodes.Begin (); iter != end; ++iter)
341 auto ipv4 = (*iter)->GetObject <
Ipv4> ();
342 NS_ASSERT_MSG ((
bool) ipv4,
"Node " << Names::FindName (*iter) <<
" does not have Ipv4 aggregate");
344 routing->AddHostRouteTo (targetAddr.c_str (), ipv4->GetInterfaceForDevice (*diter), 0);
354 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"A/dev"), Names::Find <SimpleNetDevice> (
"D/dev"));
355 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"D/dev"), Names::Find <SimpleNetDevice> (
"A/dev"));
357 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"A/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
358 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"A/dev"));
360 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"B/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
361 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"B/dev"));
363 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"C/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
364 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"C/dev"));
367 std::list<Ptr<Socket> > sockets;
368 for (
auto end =
nodes.End (),
369 iter =
nodes.Begin (); iter != end; ++iter)
373 socket->SetAllowBroadcast (
true);
375 "Could not bind socket for node " << Names::FindName (*iter));
379 udpSocket->SetAttribute (
"IpMulticastTtl",
StringValue (
"4"));
382 sockets.push_back (socket);
390 auto txSocket = sockets.front ();
397 Simulator::Destroy ();
399 for (
auto end =
nodes.End (),
400 iter =
nodes.Begin (); iter != end; ++iter)
402 std::string name = Names::FindName (*iter);
424 std::map <std::string, uint32_t> packets = {
425 {
"A", 14}, {
"B", 16}, {
"C", 16}, {
"D", 16}, {
"E", 4}
429 std:: map <std::string, uint32_t> packetsDuped = {
430 {
"A", 0}, {
"B", 1}, {
"C", 1}, {
"D", 1}, {
"E", 1}
437 std::map <std::string, uint32_t> degenerates = {
438 {
"A", 3}, {
"B", 4}, {
"C", 4}, {
"D", 3}, {
"E", 2}
458 std::map <std::string, uint32_t> drops;
466 drops = {{
"A", 2}, {
"B", 2}, {
"C", 2}, {
"D", 2}, {
"E", 0}};
470 drops = {{
"A", 10}, {
"B", 9}, {
"C", 9}, {
"D", 12}, {
"E", 2}};
482 drops = {{
"A", 4}, {
"B", 5}, {
"C", 5}, {
"D", 5}, {
"E", 1}};
552 virtual void DoRun (
void);
568 :
TestCase (
"Ipv4Deduplication performance test")
577 const std::string targetAddr =
"239.192.100.1";
590 listRouting.
Add (staticRouting, 0);
599 ipv4address.
SetBase (
"10.0.0.0",
"255.255.255.0");
604 for (
auto iter =
nodes.Begin (); iter !=
nodes.End (); ++iter)
617 auto ipv4 = (*iter)->GetObject <
Ipv4> ();
618 NS_ASSERT_MSG ((
bool) ipv4,
"Node " << (*iter)->GetId () <<
" does not have Ipv4 aggregate");
620 routing->AddHostRouteTo (targetAddr.c_str (), ipv4->GetInterfaceForDevice (*diter), 0);
629 for (
auto iter =
nodes.Begin (); iter !=
nodes.End (); ++iter)
636 for (uint8_t i = 0; i<
nodes.GetN (); i++)
638 Simulator::ScheduleWithContext (
m_sockets[i]->GetNode ()->GetId (),
644 NS_LOG_UNCOND (
"Executed " << Simulator::GetEventCount () <<
" events");
651 Simulator::Destroy ();
657 socket->
SendTo (Create<Packet> (512), 0, to);
661 Simulator::ScheduleWithContext (
m_sockets[socketIndex]->GetNode ()->GetId (),
Seconds (.5),
680 :
TestSuite (
"ipv4-deduplication-performance", PERFORMANCE)
holds a vector of ns3::NetDevice pointers
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
API to create UDP socket instances.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
AttributeValue implementation for Boolean.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Helper class that adds ns3::Ipv4ListRouting objects.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void DoSendPacket(Ptr< Socket > socket, Ptr< Packet > packet, std::string to)
Send data.
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
Ipv4 addresses are stored in host order in this class.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
DropReason
Reason why a packet has been dropped.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
#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.
void ReceivePkt(Ptr< Socket > socket)
Receive data.
void SendData(Ptr< Socket > socket, std::string to)
Send data.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Ipv4DeduplicationTestSuite()
static std::string MakeName(bool enable, Time expire)
Creates the test name according to the parameters.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Access to the IPv4 forwarding table, interfaces, and configuration.
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
Helper class that adds ns3::Ipv4StaticRouting objects.
static Ipv4DeduplicationPerformanceTestSuite g_ipv4DeduplicationPerformanceTestSuite
Static variable for test initialization.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
(abstract) base class of all UdpSockets
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...
a polymophic address class
static const Time DELAY
Channel delay.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual Ptr< Node > GetNode(void) const =0
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
This example (inspired from tv-trans-example) enables to generate the transmitted spectra of Wi-Fi st...
build a set of SimpleNetDevice objects
Object to create transport layer instances that provide a socket API to applications.
virtual int MulticastJoinGroup(uint32_t interface, const Address &groupAddress)=0
Corresponds to socket option MCAST_JOIN_GROUP.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Simulation virtual time values and global simulation resolution.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
static Ipv4DeduplicationTestSuite g_ipv4DeduplicationTestSuite
Static variable for test initialization.
virtual Ptr< Socket > CreateSocket(void)=0
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
std::map< std::string, uint32_t > m_packetCountMap
map of received packets (node name, counter)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Hold variables of type string.
Time m_expire
Expiration delay for duplicate cache entries.
void CheckDrops(const std::string &name)
Check packet drops.
void CheckPackets(const std::string &name)
Check packet receptions.
#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.
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>
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
A simple channel, for simple things and testing.
void DropPkt(const Ipv4Header &ipHeader, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Register dropped packet.
AttributeValue implementation for Time.
keep track of a set of node pointers.
IPv4 Deduplication TestSuite.
void DoSendData(Ptr< Socket > socket, std::string to)
Send data.
Ipv4DeduplicationTest(bool enable, Time expire=Seconds(1))
Constructor.
void SetDefault(std::string name, const AttributeValue &value)
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
aggregate IP/TCP/UDP functionality to existing Nodes.
std::map< std::string, uint32_t > m_dropCountMap
map of received packets (node name, counter)
void SendPacket(Ptr< Socket > socket, Ptr< Packet > packet, std::string to)
Send data.
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.