281 #include "ns3/applications-module.h"
282 #include "ns3/core-module.h"
283 #include "ns3/csma-module.h"
284 #include "ns3/internet-module.h"
285 #include "ns3/network-module.h"
286 #include "ns3/point-to-point-module.h"
312 void CommandSetup(
int argc,
char** argv);
327 bool m_useIpv6{
false};
328 bool m_enableLog{
false};
329 bool m_useChannel{
false};
330 bool m_useNetDeviceContainer{
332 bool m_useInterfaceContainer{
334 bool m_noGenerate{
false};
335 bool m_sendTraffic{
false};
349 std::cout <<
"Rx pkt from " << from <<
" to " << dst <<
" -> " << header << std::endl;
356 cmd.AddValue(
"useIPv6",
"Use IPv6 instead of IPv4", m_useIpv6);
357 cmd.AddValue(
"enableLog",
"Enable ArpL3Protocol and Icmpv6L4Protocol logging", m_enableLog);
358 cmd.AddValue(
"useChannel",
"Generate neighbor cache for specific Channel", m_useChannel);
359 cmd.AddValue(
"useNetDeviceContainer",
360 "Generate neighbor cache for specific netDeviceContainer",
361 m_useNetDeviceContainer);
362 cmd.AddValue(
"useInterfaceContainer",
363 "Generate neighbor cache for specific interfaceContainer",
364 m_useInterfaceContainer);
365 cmd.AddValue(
"noGenerate",
"do not generate neighbor cache automatically", m_noGenerate);
366 cmd.AddValue(
"sendTraffic",
"send data stream from n0 to n1", m_sendTraffic);
368 cmd.Parse(argc, argv);
372 main(
int argc,
char* argv[])
388 uint32_t nCsmaLeft = 2;
389 uint32_t nCsmaRight = 2;
392 csmaNodesLeft.
Create(nCsmaLeft);
394 csmaNodesRight.
Add(csmaNodesLeft.
Get(1));
395 csmaNodesRight.
Create(nCsmaRight);
407 csmaDevicesLeft = csmaLeft.
Install(csmaNodesLeft);
409 csmaDevicesRight = csmaRight.
Install(csmaNodesRight);
414 stack.SetIpv6StackInstall(
false);
418 stack.SetIpv4StackInstall(
false);
421 stack.SetIpv4ArpJitter(
false);
422 stack.SetIpv6NsRsJitter(
false);
423 stack.Install(csmaNodesLeft.
Get(0));
424 stack.Install(csmaNodesRight);
429 address.SetBase(
"10.1.1.0",
"255.255.255.0");
431 csmaInterfacesLeft =
address.Assign(csmaDevicesLeft);
432 address.SetBase(
"10.1.2.0",
"255.255.255.0");
434 csmaInterfacesRight =
address.Assign(csmaDevicesRight);
444 else if (m_useNetDeviceContainer)
449 else if (m_useInterfaceContainer)
451 std::pair<Ptr<Ipv4>, uint32_t> txInterface = csmaInterfacesLeft.
Get(0);
453 uint32_t index1 = txInterface.second;
454 std::pair<Ptr<Ipv4>, uint32_t> rxInterface = csmaInterfacesRight.
Get(nCsmaRight);
456 uint32_t index2 = rxInterface.second;
464 else if (!m_noGenerate)
485 apps =
sink.Install(csmaNodesLeft);
505 csmaInterfacesLeft =
address.Assign(csmaDevicesLeft);
511 csmaInterfacesRight =
address.Assign(csmaDevicesRight);
523 else if (m_useNetDeviceContainer)
528 else if (m_useInterfaceContainer)
530 std::pair<Ptr<Ipv6>, uint32_t> txInterface = csmaInterfacesLeft.
Get(0);
532 uint32_t index1 = txInterface.second;
533 std::pair<Ptr<Ipv6>, uint32_t> rxInterface = csmaInterfacesRight.
Get(nCsmaRight);
535 uint32_t index2 = rxInterface.second;
543 else if (!m_noGenerate)
554 "ns3::UdpSocketFactory",
565 apps =
sink.Install(csmaNodesLeft);
neighbor Cache example class.
void CommandSetup(int argc, char **argv)
description the command-line parameters.
void ReceivePacket(Ptr< const Packet > pkt, const Address &from, const Address &dst, const SeqTsSizeHeader &header)
Print the information of receive data.
void Run()
Run the example.
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
AttributeValue implementation for Boolean.
Parse command-line arguments.
build a set of CsmaNetDevice objects
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
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).
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
std::pair< Ptr< Ipv6 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv6> and interface stored at the location specified by the index.
Describes an IPv6 prefix.
static void PrintNeighborCacheAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the neighbor cache of all nodes at a particular time.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
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 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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
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.
AttributeValue implementation for Time.
void ReceivePacket(Ptr< Socket > socket)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
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...
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
Ptr< PacketSink > sink
Pointer to the packet sink application.