10#include "ns3/address.h"
11#include "ns3/application-container.h"
12#include "ns3/bridge-helper.h"
13#include "ns3/callback.h"
14#include "ns3/config.h"
15#include "ns3/csma-helper.h"
16#include "ns3/csma-star-helper.h"
17#include "ns3/data-rate.h"
18#include "ns3/inet-socket-address.h"
19#include "ns3/internet-stack-helper.h"
20#include "ns3/ipv4-address-helper.h"
21#include "ns3/ipv4-global-routing-helper.h"
22#include "ns3/ipv4-static-routing-helper.h"
23#include "ns3/node-container.h"
25#include "ns3/on-off-helper.h"
26#include "ns3/packet-sink-helper.h"
27#include "ns3/packet-socket-address.h"
28#include "ns3/packet-socket-helper.h"
29#include "ns3/packet.h"
30#include "ns3/ping-helper.h"
31#include "ns3/pointer.h"
32#include "ns3/simple-channel.h"
33#include "ns3/simulator.h"
34#include "ns3/string.h"
36#include "ns3/uinteger.h"
54 void DoRun()
override;
67 :
TestCase(
"Bridge example for Carrier Sense Multiple Access (CSMA) networks"),
101 csmaSwitch.Create(1);
104 csma.SetChannelAttribute(
"DataRate",
DataRateValue(5000000));
110 for (
int i = 0; i < 4; i++)
113 terminalDevices.Add(link.Get(0));
114 switchDevices.Add(link.Get(1));
118 Ptr<Node> switchNode = csmaSwitch.Get(0);
120 bridge.
Install(switchNode, switchDevices);
123 internet.Install(terminals);
126 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
127 ipv4.Assign(terminalDevices);
137 onoff.SetConstantRate(
DataRate(5000));
145 app =
sink.Install(terminals.Get(1));
171 void DoRun()
override;
196 :
TestCase(
"Broadcast example for Carrier Sense Multiple Access (CSMA) networks"),
257 ipv4.SetBase(
"10.1.0.0",
"255.255.255.0");
259 ipv4.SetBase(
"192.168.1.0",
"255.255.255.0");
273 onoff.SetConstantRate(
DataRate(5000));
284 app.Add(
sink.Install(c1.
Get(1)));
314 void DoRun()
override;
335 :
TestCase(
"Multicast example for Carrier Sense Multiple Access (CSMA) networks"),
399 ipv4Addr.
SetBase(
"10.1.1.0",
"255.255.255.0");
401 ipv4Addr.
SetBase(
"10.1.2.0",
"255.255.255.0");
426 outputDevices.
Add(nd1.
Get(0));
444 uint16_t multicastPort = 9;
452 onoff.SetConstantRate(
DataRate(5000));
497 void DoRun()
override;
521 :
TestCase(
"One subnet example for Carrier Sense Multiple Access (CSMA) networks"),
567 csma.SetChannelAttribute(
"DataRate",
DataRateValue(5000000));
576 internet.Install(
nodes);
581 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
594 onoff.SetConstantRate(
DataRate(5000));
647 void DoRun()
override;
668 :
TestCase(
"Packet socket example for Carrier Sense Multiple Access (CSMA) networks"),
720 csma.SetDeviceAttribute(
"EncapsulationMode",
StringValue(
"Llc"));
732 onoff.SetConstantRate(
DataRate(5000));
773 void DoRun()
override;
796 :
TestCase(
"Ping example for Carrier Sense Multiple Access (CSMA) networks"),
845 csma.SetDeviceAttribute(
"EncapsulationMode",
StringValue(
"Llc"));
854 ip.
SetBase(
"192.168.1.0",
"255.255.255.0");
864 onoff.SetConstantRate(
DataRate(5000));
914 void DoRun()
override;
936 "Raw internet protocol socket example for Carrier Sense Multiple Access (CSMA) networks"),
979 csma.SetDeviceAttribute(
"EncapsulationMode",
StringValue(
"Llc"));
988 ip.
SetBase(
"192.168.1.0",
"255.255.255.0");
998 onoff.SetConstantRate(
DataRate(5000));
1005 apps =
sink.Install(c.
Get(3));
1032 void DoRun()
override;
1053 :
TestCase(
"Star example for Carrier Sense Multiple Access (CSMA) networks"),
1101 csma.SetChannelAttribute(
"DataRate",
StringValue(
"100Mbps"));
1102 csma.SetChannelAttribute(
"Delay",
StringValue(
"1ms"));
1121 fillNodes.
Add(newNodes);
1122 fillDevices.
Add(csma.Install(newNodes, csmaChannel));
1127 internet.Install(fillNodes);
1144 std::ostringstream subnet;
1145 subnet <<
"10.1." << i <<
".0";
1146 address.SetBase(subnet.str().c_str(),
"255.255.255.0",
"0.0.0.3");
1148 for (
uint32_t j = 0; j < nFill; ++j)
1150 address.Assign(fillDevices.
Get(i * nFill + j));
1157 uint16_t
port = 50000;
1159 PacketSinkHelper packetSinkHelper(
"ns3::TcpSocketFactory", hubLocalAddress);
1170 onOffHelper.SetConstantRate(
DataRate(5000));
1177 onOffHelper.SetAttribute(
"Remote", remoteAddress);
1197 onOffHelper.SetAttribute(
"Remote", remoteAddress);
1198 fillApps.
Add(onOffHelper.Install(fillNodes.
Get(i)));
1219 10 * (nSpokes * (nFill + 1)),
1220 "Hub node did not receive the proper number of packets");
~CsmaBridgeTestCase() override
uint32_t m_count
Counter of received packets.
void DoRun() override
Implementation to actually run this TestCase.
void SinkRx(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received.
CSMA Broadcast mode test.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_countNode2
Counter of received packets on node 2.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
void SinkRxNode1(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
void SinkRxNode2(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
uint32_t m_countNode1
Counter of received packets on node 1.
uint32_t m_drops
Counter of dropped packets.
~CsmaBroadcastTestCase() override
CSMA Multicast mode test.
~CsmaMulticastTestCase() override
void SinkRx(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_count
Counter of received packets.
uint32_t m_drops
Counter of dropped packets.
CSMA One Subnet mode test.
uint32_t m_countNode1
Counter of received packets on node 1.
~CsmaOneSubnetTestCase() override
void SinkRxNode0(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
uint32_t m_countNode0
Counter of received packets on node 0.
void SinkRxNode1(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_drops
Counter of dropped packets.
uint32_t m_count
Counter of received packets.
CsmaPacketSocketTestCase()
void SinkRx(std::string path, Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
uint32_t m_drops
Counter of dropped packets.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
~CsmaPacketSocketTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
void DropEvent(Ptr< const Packet >)
Sink called when a packet is dropped.
void DoRun() override
Implementation to actually run this TestCase.
void PingRtt(std::string, uint16_t, Time)
Sink called when a PING is received.
void SinkRx(Ptr< const Packet >, const Address &)
Sink called when a packet is received by a node.
~CsmaPingTestCase() override
uint32_t m_drops
Counter of dropped packets.
uint32_t m_countSinkRx
Counter of received packets.
uint32_t m_countPingRtt
Counter of PING received.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
~CsmaRawIpSocketTestCase() override
void SinkRx(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
CsmaRawIpSocketTestCase()
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_drops
Counter of dropped packets.
uint32_t m_count
Counter of received packets.
void DropEvent(Ptr< const Packet > p)
Sink called when a packet is dropped.
uint32_t m_count
Counter of received packets.
uint32_t m_drops
Counter of dropped packets.
void DoRun() override
Implementation to actually run this TestCase.
void SinkRx(Ptr< const Packet > p, const Address &ad)
Sink called when a packet is received by a node.
~CsmaStarTestCase() override
a polymophic address class
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
Add capability to bridge multiple LAN segments (IEEE 802.1D bridging)
NetDeviceContainer Install(Ptr< Node > node, NetDeviceContainer c)
This method creates an ns3::BridgeNetDevice with the attributes configured by BridgeHelper::SetDevice...
build a set of CsmaNetDevice objects
A helper to make it easier to create a star topology with Csma links.
void InstallStack(InternetStackHelper stack)
Ipv4Address GetHubIpv4Address(uint32_t i) const
void AssignIpv4Addresses(Ipv4AddressHelper address)
Ptr< Node > GetSpokeNode(uint32_t i) const
Ptr< Node > GetHub() const
NetDeviceContainer GetSpokeDevices() const
uint32_t SpokeCount() const
Class for representing data rates.
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...
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()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class that adds ns3::Ipv4StaticRouting objects.
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>
void SetDefaultMulticastRoute(Ptr< Node > n, Ptr< NetDevice > nd)
Add a default route to the static routing protocol to forward packets out a particular interface.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Create a ping application and associate it to a node.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
static CsmaSystemTestSuite csmaSystemTestSuite
Do not forget to allocate an instance of this TestSuite.
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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...
Ptr< PacketSink > sink
Pointer to the packet sink application.