70#include "ns3/core-module.h"
71#include "ns3/internet-apps-module.h"
72#include "ns3/internet-module.h"
73#include "ns3/network-module.h"
74#include "ns3/nix-vector-routing-module.h"
75#include "ns3/point-to-point-module.h"
85main(
int argc,
char* argv[])
91 std::string destinationStr;
93 std::string sourceStr;
96 std::optional<Ipv4Address> v4Dst;
97 std::optional<Ipv6Address> v6Dst;
98 std::optional<Ipv4Address> v4Src;
99 std::optional<Ipv6Address> v6Src;
104 cmd.AddValue(
"logging",
"Tell application to log if true", logging);
105 cmd.AddValue(
"interval",
"The time to wait between two packets", interPacketInterval);
106 cmd.AddValue(
"size",
"Data bytes to be sent, per-packet", size);
107 cmd.AddValue(
"count",
"Number of packets to be sent", count);
108 cmd.AddValue(
"destination",
109 "Destination IPv4 or IPv6 address, e.g., \"10.1.2.2\"",
111 cmd.AddValue(
"source",
112 "Source address, needed only for multicast or broadcast destinations",
114 cmd.Parse(argc, argv);
116 if (!destinationStr.empty())
122 destination = v4Dst.value();
128 destination = v6Dst.value();
132 NS_ABORT_MSG(
"Can't parse destination address " << destinationStr);
136 if (!sourceStr.empty())
142 source = v4Src.value();
148 source = v6Src.value();
152 NS_ABORT_MSG(
"Can't parse destination address " << destinationStr);
155 if (sourceStr.empty())
159 if (v6Dst && v6Dst->IsMulticast())
161 std::cout <<
"Specify a source address to use when pinging multicast addresses"
163 std::cout <<
"Program exiting..." << std::endl;
169 if (v4Dst && (v4Dst->IsBroadcast() || v4Dst->IsMulticast()))
171 std::cout <<
"Specify a source address to use when pinging broadcast or multicast "
174 std::cout <<
"Program exiting..." << std::endl;
207 std::list<uint32_t> dropList;
215 errorModel->SetList(dropList);
216 p2pSender->SetReceiveErrorModel(errorModel);
222 stack.SetRoutingHelper(nixRouting);
223 stack.SetIpv6StackInstall(
false);
227 addressV4.
SetBase(
"10.1.1.0",
"255.255.255.0");
228 addressV4.
Assign(link1Devices);
234 destination = link2InterfacesV4.
GetAddress(1, 0);
241 stack.SetRoutingHelper(nixRouting);
242 stack.SetIpv4StackInstall(
false);
246 addressV6.
SetBase(
"2001:1::", 64);
247 addressV6.
Assign(link1Devices);
253 destination = link2InterfacesV6.
GetAddress(1, 1);
259 pingHelper.SetAttribute(
"Interval",
TimeValue(interPacketInterval));
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.
AttributeValue implementation for Boolean.
Parse command-line arguments.
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
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.
Ipv4Address NewNetwork()
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
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 bool CheckCompatible(const std::string &addressStr)
Checks if the string contains an Ipv4Address.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
void NewNetwork()
Allocate a new network.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
static bool CheckCompatible(const std::string &addressStr)
Checks if the string contains an Ipv6Address.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
holds a vector of ns3::NetDevice pointers
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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Create a ping application and associate it to a node.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
Hold an unsigned integer type.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
NixVectorHelper< Ipv6RoutingHelper > Ipv6NixVectorHelper
Create the typedef Ipv6NixVectorHelper with T as Ipv6RoutingHelper.
NixVectorHelper< Ipv4RoutingHelper > Ipv4NixVectorHelper
Create the typedef Ipv4NixVectorHelper with T as Ipv4RoutingHelper.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
LogLevel
Logging severity classes and levels.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.