### Install and Start Applications Source: https://www.nsnam.org/docs/release/3.45/doxygen/d6/d3c/wifi-sleep_8cc_source.html Installs OnOff applications and packet sinks on specified nodes and starts them at a given time. Applications are started at 0.01 seconds and stopped at a specified duration. ```c++ apps = onOff.Install(c.Get(0)); apps.Start(Seconds(0.01)); apps.Stop(duration); // Create a packet sink to receive these packets PacketSinkHelper sink(transportProto, InetSocketAddress(Ipv4Address::GetAny(), 9001)); apps = sink.Install(c.Get(1)); apps.Start(Seconds(0.01)); apps.Stop(duration); ``` -------------------------------- ### Main Function Setup for Sixth Example Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/dcc/sixth_8cc_source.html Initializes the ns-3 simulation environment, parses command-line arguments, and sets up the network topology for the sixth tutorial example. ```c++ int main(int argc, char* argv[]) { CommandLine cmd(__FILE__); ``` -------------------------------- ### Install and Start UDP Client Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d99/wifi-80211e-txop_8cc_source.html Installs and starts an OnOff UDP client application on a specified Wi-Fi station node. ```c++ ApplicationContainer clientAppB = clientB.Install(wifiStaNodes.Get(1)); clientAppB.Start(Seconds(1)); clientAppB.Stop(simulationTime + Seconds(1)); ``` -------------------------------- ### ns-3 Main Simulation Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d9/d41/main-simple_8cc_source.html Sets up a basic ns-3 simulation. It creates a node, installs the internet stack, configures UDP sockets for sending and receiving, and starts the simulation. This is a foundational example for running ns-3 simulations. ```c++ int main(int argc, char* argv[]) { CommandLine cmd(__FILE__); cmd.Parse(argc, argv); NodeContainer c; c.Create(1); InternetStackHelper internet; internet.Install(c); TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory"); Ptr sink = Socket::CreateSocket(c.Get(0), tid); InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 80); sink->Bind(local); Ptr source = Socket::CreateSocket(c.Get(0), tid); InetSocketAddress remote = InetSocketAddress(Ipv4Address::GetLoopback(), 80); source->Connect(remote); GenerateTraffic(source, 500); sink->SetRecvCallback(MakeCallback(&SocketPrinter)); Simulator::Run(); Simulator::Destroy(); return 0; } ``` -------------------------------- ### TutorialApp::Setup() Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d58/classns3_1_1_tutorial_app.html Sets up the socket, destination address, packet size, number of packets, and data rate for the application. ```APIDOC ## ◆ Setup() void TutorialApp::Setup | ( | Ptr< Socket > | _socket_ , ---|---|--- | | Address | _address_ , | | uint32_t | _packetSize_ , | | uint32_t | _nPackets_ , | | DataRate | _dataRate_ ) Setup the socket. Parameters socket| The socket. ---|--- address| The destination address. packetSize| The packet size to transmit. nPackets| The number of packets to transmit. dataRate| the data rate to use. Definition at line 40 of file tutorial-app.cc. References m_dataRate, m_nPackets, m_packetSize, m_peer, m_socket, and packetSize. ``` -------------------------------- ### TutorialApp Setup Method Source: https://www.nsnam.org/docs/release/3.45/doxygen/d1/de6/tutorial-app_8cc_source.html Configures the TutorialApp with necessary parameters for network communication, including the socket, peer address, packet size, number of packets, and data rate. ```cc void TutorialApp::Setup(Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) { m_socket = socket; m_peer = address; m_packetSize = packetSize; m_nPackets = nPackets; m_dataRate = dataRate; } ``` -------------------------------- ### Install and Start UDP Echo Applications Source: https://www.nsnam.org/docs/release/3.45/doxygen/db/d9e/lte-test-ipv6-routing_8cc_source.html Installs and starts UDP echo servers on specific nodes and UDP echo clients on UEs. This setup is used to test network connectivity and packet transmission. ```c++ UdpEchoServerHelper echoServer1(10); UdpEchoServerHelper echoServer2(11); UdpEchoServerHelper echoServer3(12); ApplicationContainer serverApps = echoServer1.Install(remoteHost); serverApps.Add(echoServer2.Install(ueNodes.Get(1))); serverApps.Add(echoServer3.Install(ueNodes.Get(2))); serverApps.Start(Seconds(4)); serverApps.Stop(Seconds(12)); UdpEchoClientHelper echoClient1(m_remoteHostAddr, 10); UdpEchoClientHelper echoClient2(m_ueIpIface.GetAddress(1, 1), 11); UdpEchoClientHelper echoClient3(m_ueIpIface.GetAddress(2, 1), 12); echoClient1.SetAttribute("MaxPackets", UintegerValue(1000)); echoClient1.SetAttribute("Interval", TimeValue(Seconds(0.2))); echoClient1.SetAttribute("PacketSize", UintegerValue(1024)); echoClient2.SetAttribute("MaxPackets", UintegerValue(1000)); echoClient2.SetAttribute("Interval", TimeValue(Seconds(0.2))); echoClient2.SetAttribute("PacketSize", UintegerValue(1024)); echoClient3.SetAttribute("MaxPackets", UintegerValue(1000)); echoClient3.SetAttribute("Interval", TimeValue(Seconds(0.2))); echoClient3.SetAttribute("PacketSize", UintegerValue(1024)); ApplicationContainer clientApps1 = echoClient1.Install(ueNodes.Get(0)); ApplicationContainer clientApps2 = echoClient2.Install(ueNodes.Get(0)); ApplicationContainer clientApps3 = echoClient3.Install(ueNodes.Get(0)); clientApps1.Start(Seconds(4)); clientApps1.Stop(Seconds(6)); clientApps2.Start(Seconds(6.1)); clientApps2.Stop(Seconds(8)); clientApps3.Start(Seconds(8.1)); clientApps3.Stop(Seconds(10)); ``` -------------------------------- ### Setup Network and Routing Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/df3/nix-simple-multi-address_8cc_source.html Configures network nodes, point-to-point links, and installs the Nix vector routing protocol. This is the initial setup for the simulation. ```c++ using namespace ns3; NS_LOG_COMPONENT_DEFINE("NixSimpleMultiAddressExample"); int main(int argc, char* argv[]) { CommandLine cmd(__FILE__); cmd.Parse(argc, argv); LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes12; nodes12.Create(2); NodeContainer nodes23; nodes23.Add(nodes12.Get(1)); nodes23.Create(1); NodeContainer nodes34; nodes34.Add(nodes23.Get(1)); nodes34.Create(1); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")); pointToPoint.SetChannelAttribute("Delay", StringValue("2ms")); NodeContainer allNodes = NodeContainer(nodes12, nodes23.Get(1), nodes34.Get(1)); // NixHelper to install nix-vector routing // on all nodes Ipv4NixVectorHelper nixRouting; InternetStackHelper stack; stack.SetRoutingHelper(nixRouting); // has effect on the next Install () stack.Install(allNodes); NetDeviceContainer devices12; NetDeviceContainer devices23; NetDeviceContainer devices34; devices12 = pointToPoint.Install(nodes12); devices23 = pointToPoint.Install(nodes23); devices34 = pointToPoint.Install(nodes34); Ipv4AddressHelper address1; address1.SetBase("10.1.1.0", "255.255.255.0"); Ipv4AddressHelper address2; address2.SetBase("10.1.2.0", "255.255.255.0"); Ipv4AddressHelper address3; address3.SetBase("10.1.3.0", "255.255.255.0"); Ipv4AddressHelper address4; address4.SetBase("10.2.1.0", "255.255.255.0"); Ipv4AddressHelper address5; address5.SetBase("10.2.3.0", "255.255.255.0"); address1.Assign(devices12); address2.Assign(devices23); Ipv4InterfaceContainer interfaces34 = address3.Assign(devices34); Ipv4InterfaceContainer interfaces12 = address4.Assign(devices12); UdpEchoServerHelper echoServer(9); ApplicationContainer serverApps = echoServer.Install(nodes34.Get(1)); serverApps.Start(Seconds(1)); serverApps.Stop(Seconds(10)); // Set the destination address as 10.1.3.2 UdpEchoClientHelper echoClient(interfaces34.GetAddress(1), 9); echoClient.SetAttribute("MaxPackets", UintegerValue(1)); echoClient.SetAttribute("Interval", TimeValue(Seconds(1.))); echoClient.SetAttribute("PacketSize", UintegerValue(1024)); ApplicationContainer clientApps = echoClient.Install(nodes12.Get(0)); clientApps.Start(Seconds(2)); clientApps.Stop(Seconds(10)); // Trace routing paths for different source and destinations. Ptr routingStream = Create("nix-simple-multi-address.routes", std::ios::out); // Check the path from n0 to n1 (10.1.3.2). nixRouting.PrintRoutingPathAt(Seconds(3), nodes12.Get(0), interfaces12.GetAddress(1, 1), routingStream); // Trace routing tables. Ipv4NixVectorHelper::PrintRoutingTableAllAt(Seconds(4), routingStream); // Assign address5 addresses to n2 and n3. // n2 gets 10.2.3.1 and n3 gets 10.2.3.2 on the same interface. Simulator::Schedule(Seconds(5), &Ipv4AddressHelper::Assign, &address5, devices34); // Trace routing tables. // Notice that NixCache and Ipv4RouteCache becomes empty for each node. // This happens because new addresses are added at t = +5s, due to which // existing caches get flushed. Ipv4NixVectorHelper::PrintRoutingTableAllAt(Seconds(6), routingStream); // Check the path from n0 to n3 (10.2.3.2). nixRouting.PrintRoutingPathAt(Seconds(7), nodes12.Get(0), Ipv4Address("10.2.3.2"), routingStream); Simulator::Run(); Simulator::Destroy(); return 0; } ``` -------------------------------- ### Main Function: Setup and Run IPv6 Socket Options Example Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/daa/socket-options-ipv6_8cc_source.html This is the main entry point for the example. It parses command-line arguments, sets up the network topology, assigns IP addresses, and configures sockets with IPv6 options. ```cc int main(int argc, char* argv[]) { // // Allow the user to override any of the defaults and the above Bind() at // run-time, via command-line arguments // uint32_t packetSize = 1024; uint32_t packetCount = 10; double packetInterval = 1.0; // Socket options for IPv6, currently TCLASS, HOPLIMIT, RECVTCLASS, and RECVHOPLIMIT uint32_t ipv6Tclass = 0; bool ipv6RecvTclass = true; uint32_t ipv6Hoplimit = 0; bool ipv6RecvHoplimit = true; CommandLine cmd(__FILE__); cmd.AddValue("PacketSize", "Packet size in bytes", packetSize); cmd.AddValue("PacketCount", "Number of packets to send", packetCount); cmd.AddValue("Interval", "Interval between packets", packetInterval); cmd.AddValue("IPV6_TCLASS", "IPV6_TCLASS", ipv6Tclass); cmd.AddValue("IPV6_RECVTCLASS", "IPV6_RECVTCLASS", ipv6RecvTclass); cmd.AddValue("IPV6_HOPLIMIT", "IPV6_HOPLIMIT", ipv6Hoplimit); cmd.AddValue("IPV6_RECVHOPLIMIT", "IPV6_RECVHOPLIMIT", ipv6RecvHoplimit); cmd.Parse(argc, argv); NS_LOG_INFO("Create nodes."); NodeContainer n; n.Create(2); InternetStackHelper internet; internet.Install(n); Address serverAddress; NS_LOG_INFO("Create channels."); CsmaHelper csma; csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000))); csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2))); csma.SetDeviceAttribute("Mtu", UintegerValue(1400)); NetDeviceContainer d = csma.Install(n); NS_LOG_INFO("Assign IP Addresses."); Ipv6AddressHelper ipv6; ipv6.SetBase("2001:0000:f00d:cafe::", Ipv6Prefix(64)); Ipv6InterfaceContainer i6 = ipv6.Assign(d); serverAddress = Address(i6.GetAddress(1, 1)); NS_LOG_INFO("Create sockets."); // Receiver socket on n1 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory"); ``` -------------------------------- ### TCP Variants Comparison Example Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/db7/tcp-variants-comparison_8cc_source.html Includes necessary ns-3 modules and defines static variables for logging TCP parameters like congestion window, slow start threshold, RTT, and RTO. This setup is common for all TCP variant comparisons. ```c++ #include "ns3/applications-module.h" #include "ns3/core-module.h" #include "ns3/enum.h" #include "ns3/error-model.h" #include "ns3/event-id.h" #include "ns3/flow-monitor-helper.h" #include "ns3/internet-module.h" #include "ns3/ipv4-global-routing-helper.h" #include "ns3/network-module.h" #include "ns3/point-to-point-module.h" #include "ns3/tcp-header.h" #include "ns3/traffic-control-module.h" #include "ns3/udp-header.h" #include #include #include using namespace ns3; NS_LOG_COMPONENT_DEFINE("TcpVariantsComparison"); static std::map firstCwnd; //!< First congestion window. static std::map firstSshThr; //!< First SlowStart threshold. static std::map firstRtt; //!< First RTT. static std::map firstRto; //!< First RTO. static std::map> cWndStream; //!< Congstion window output stream. static std::map> ssThreshStream; //!< SlowStart threshold output stream. static std::map> rttStream; //!< RTT output stream. static std::map> rtoStream; //!< RTO output stream. static std::map> nextTxStream; //!< Next TX output stream. static std::map> nextRxStream; //!< Next RX output stream. static std::map> inFlightStream; //!< In flight output stream. static std::map cWndValue; //!< congestion window value. static std::map ssThreshValue; //!< SlowStart threshold value. /** * Get the Node Id From Context. * * @param context The context. * @return the node ID. */ static uint32_t ``` -------------------------------- ### Setup Packet Socket Server Source: https://www.nsnam.org/docs/release/3.45/doxygen/d3/d1b/channel-access-manager-test_8cc_source.html Configures and installs a packet socket server on the STA node. The server listens on a specific device index and protocol, with defined start and stop times. ```c++ PacketSocketAddress srvAddr; srvAddr.SetSingleDevice(staDevice->GetIfIndex()); srvAddr.SetProtocol(1); auto server = CreateObject(); server->SetLocal(srvAddr); server->SetStartTime(Seconds(0)); server->SetStopTime(Seconds(1)); staNode->AddApplication(server); ``` -------------------------------- ### Install and Control Applications Source: https://www.nsnam.org/docs/release/3.45/doxygen/dc/d15/nsclick-simple-lan_8cc_source.html Installs the OnOff application on a specific node and manages its start and stop times within the simulation. Ensure the application is installed before starting the simulation. ```c++ ApplicationContainer appcont; appcont.Add(onOffHelper.Install(csmaNodes.Get(0))); appcont.Start(Seconds(5)); appcont.Stop(Seconds(10)); ``` -------------------------------- ### Basic CommandLine Setup and Parsing Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d1a/classns3_1_1_command_line.html Shows how to initialize CommandLine, set a usage message, add arguments, and parse them. ```cpp int intArg = 1; bool boolArg = false; std::string strArg = "strArg default"; CommandLine cmd (__FILE__); cmd.Usage ("CommandLine example program.\n" "\n" "This little program demonstrates how to use CommandLine."); cmd.AddValue ("intArg", "an int argument", intArg); cmd.AddValue ("boolArg", "a bool argument", boolArg); cmd.AddValue ("strArg", "a string argument", strArg); cmd.AddValue ("anti", "ns3::RandomVariableStream::Antithetic"); cmd.AddValue ("cbArg", "a string via callback", MakeCallback (SetCbArg)); cmd.Parse (argc, argv); ``` -------------------------------- ### Main Function Setup for FileHelperExample Source: https://www.nsnam.org/docs/release/3.45/doxygen/d9/d72/file-helper-example_8cc_source.html Initializes the ns-3 simulation environment and creates an instance of the custom Emitter object. This setup is preparatory for demonstrating file output using ns3::FileHelper. ```c++ int main(int argc, char* argv[]) { CommandLine cmd(__FILE__); cmd.Parse(argc, argv); // // This Emitter has a trace source object that will emit values at // random times. // Ptr emitter = CreateObject(); Names::Add("/Names/Emitter", emitter); // // This file helper will be used to put data values into a file. // ``` -------------------------------- ### DHCP Server and Client Setup and Execution Source: https://www.nsnam.org/docs/release/3.45/doxygen/df/d39/dhcp-test_8cc_source.html Configures and runs a DHCP server and multiple DHCP clients. The server is started at time 0 and stopped at 20 seconds. Clients are installed on specific network devices, started at 1 second, and stopped at 20 seconds. The simulator runs until 21 seconds. ```c++ dhcpServerApp.Start(Seconds(0)); dhcpServerApp.Stop(Seconds(20)); DynamicCast(dhcpServerApp.Get(0)) ->AddStaticDhcpEntry(devNet.Get(3)->GetAddress(), Ipv4Address("172.30.0.14")); NetDeviceContainer dhcpClientNetDevs; dhcpClientNetDevs.Add(devNet.Get(1)); dhcpClientNetDevs.Add(devNet.Get(2)); dhcpClientNetDevs.Add(devNet.Get(3)); ApplicationContainer dhcpClientApps = dhcpHelper.InstallDhcpClient(dhcpClientNetDevs); dhcpClientApps.Start(Seconds(1)); dhcpClientApps.Stop(Seconds(20)); Simulator::Stop(Seconds(21)); Simulator::Run(); Simulator::Destroy(); ``` -------------------------------- ### Main Function: Socket Options IPv4 Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d1/de4/socket-options-ipv4_8cc_source.html This is the main entry point for the example. It sets up the network topology, assigns IP addresses, creates sockets, and configures IPV4 socket options like TOS and TTL. ```cpp int main(int argc, char* argv[]) { // // Allow the user to override any of the defaults and the above Bind() // at // run-time, via command-line arguments // uint32_t packetSize = 1024; uint32_t packetCount = 10; double packetInterval = 1.0; // Socket options for IPv4, currently TOS, TTL, RECVTOS, and RECVTTL uint32_t ipTos = 0; bool ipRecvTos = true; uint32_t ipTtl = 0; bool ipRecvTtl = true; CommandLine cmd(__FILE__); cmd.AddValue("PacketSize", "Packet size in bytes", packetSize); cmd.AddValue("PacketCount", "Number of packets to send", packetCount); cmd.AddValue("Interval", "Interval between packets", packetInterval); cmd.AddValue("IP_TOS", "IP_TOS", ipTos); cmd.AddValue("IP_RECVTOS", "IP_RECVTOS", ipRecvTos); cmd.AddValue("IP_TTL", "IP_TTL", ipTtl); cmd.AddValue("IP_RECVTTL", "IP_RECVTTL", ipRecvTtl); cmd.Parse(argc, argv); NS_LOG_INFO("Create nodes."); NodeContainer n; n.Create(2); InternetStackHelper internet; internet.Install(n); Address serverAddress; NS_LOG_INFO("Create channels."); CsmaHelper csma; csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000))); csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2))); csma.SetDeviceAttribute("Mtu", UintegerValue(1400)); NetDeviceContainer d = csma.Install(n); NS_LOG_INFO("Assign IP Addresses."); Ipv4AddressHelper ipv4; ipv4.SetBase("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign(d); serverAddress = Address(i.GetAddress(1)); NS_LOG_INFO("Create sockets."); // Receiver socket on n1 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory"); Ptr recvSink = Socket::CreateSocket(n.Get(1), tid); InetSocketAddress local = InetSocketAddress(Ipv4Address::GetAny(), 4477); recvSink->SetIpRecvTos(ipRecvTos); ``` -------------------------------- ### WiMAX Simple Example Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/daa/wimax-simple_8cc_source.html Initializes the simulation, parses command-line arguments for scheduler type, duration, and verbosity, and enables logging for UDP client and server components. It configures the WiMAX scheduler based on the input argument. ```cc #include "ns3/applications-module.h" #include "ns3/core-module.h" #include "ns3/global-route-manager.h" #include "ns3/internet-module.h" #include "ns3/ipcs-classifier-record.h" #include "ns3/mobility-module.h" #include "ns3/network-module.h" #include "ns3/service-flow.h" #include "ns3/wimax-module.h" #include using namespace ns3; NS_LOG_COMPONENT_DEFINE("WimaxSimpleExample"); int main(int argc, char* argv[]) { bool verbose = false; int duration = 7; int schedType = 0; WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; CommandLine cmd(__FILE__); cmd.AddValue("scheduler", "type of scheduler to use with the network devices", schedType); cmd.AddValue("duration", "duration of the simulation in seconds", duration); cmd.AddValue("verbose", "turn on all WimaxNetDevice log components", verbose); cmd.Parse(argc, argv); LogComponentEnable("UdpClient", LOG_LEVEL_INFO); LogComponentEnable("UdpServer", LOG_LEVEL_INFO); switch (schedType) { case 0: scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; break; case 1: scheduler = WimaxHelper::SCHED_TYPE_MBQOS; break; case 2: scheduler = WimaxHelper::SCHED_TYPE_RTPS; break; default: scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; } NodeContainer ssNodes; NodeContainer bsNodes; ssNodes.Create(2); bsNodes.Create(1); WimaxHelper wimax; NetDeviceContainer ssDevs; NetDeviceContainer bsDevs; ssDevs = wimax.Install(ssNodes, WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler); bsDevs = wimax.Install(bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler); wimax.EnableAscii("bs-devices", bsDevs); wimax.EnableAscii("ss-devices", ssDevs); Ptr ss[2]; for (int i = 0; i < 2; i++) { ``` -------------------------------- ### Install and Start BulkSendApplication Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/de8/tcp-bbr-example_8cc_source.html Installs and starts a BulkSendApplication on a given node. Ensure the socket factory and address are correctly configured. ```cc BulkSendHelper source("ns3::TcpSocketFactory", InetSocketAddress(ir1.GetAddress(1), port)); source.SetAttribute("MaxBytes", UintegerValue(0)); ApplicationContainer sourceApps = source.Install(sender.Get(0)); sourceApps.Start(Seconds(0.1)); sourceApps.Stop(stopTime); ``` -------------------------------- ### LR-WPAN Network Setup and Configuration Source: https://www.nsnam.org/docs/release/3.45/doxygen/dc/d1a/example-ping-lr-wpan-beacon_8cc_source.html Main function to set up and run the LR-WPAN beacon example. It parses command-line arguments for verbosity, creates nodes, configures mobility, and installs LR-WPAN devices with specified propagation models. ```c++ int main(int argc, char** argv) { bool verbose = false; CommandLine cmd(__FILE__); cmd.AddValue("verbose", "turn on log components", verbose); cmd.Parse(argc, argv); if (verbose) { LogComponentEnableAll(LogLevel(LOG_PREFIX_TIME | LOG_PREFIX_FUNC | LOG_PREFIX_NODE)); LogComponentEnable("LrWpanMac", LOG_LEVEL_INFO); LogComponentEnable("LrWpanCsmaCa", LOG_LEVEL_INFO); LogComponentEnable("LrWpanHelper", LOG_LEVEL_ALL); LogComponentEnable("Ping", LOG_LEVEL_INFO); } NodeContainer nodes; nodes.Create(2); MobilityHelper mobility; mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.SetPositionAllocator("ns3::GridPositionAllocator", "MinX", DoubleValue(0.0), "MinY", DoubleValue(0.0), "DeltaX", DoubleValue(20), "DeltaY", DoubleValue(20), "GridWidth", UintegerValue(3), "LayoutType", StringValue("RowFirst")); mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install(nodes); LrWpanHelper lrWpanHelper; lrWpanHelper.SetPropagationDelayModel("ns3::ConstantSpeedPropagationDelayModel"); lrWpanHelper.AddPropagationLossModel("ns3::LogDistancePropagationLossModel"); // Add and install the LrWpanNetDevice for each node NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(nodes); ``` -------------------------------- ### Main Function Setup and Execution Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d41/hash-example_8cc_source.html Initializes the command-line parser, sets up the Dictionary with various hashers, reads words from dictionary files, and optionally runs a timing test. ```cpp int main(int argc, char* argv[]) { std::cout << std::endl; std::cout << "Hasher" << std::endl; bool timing = false; DictFiles files; CommandLine cmd(__FILE__); cmd.Usage("Find hash collisions in the dictionary."); cmd.AddValue("dict", "Dictionary file to hash", MakeCallback(&DictFiles::Add, &files), DictFiles::GetDefault()); cmd.AddValue("time", "Run timing test", timing); cmd.Parse(argc, argv); Dictionary dict; dict.Add(Collider("FNV1a", Hasher(Create()), Collider::Bits32)); dict.Add(Collider("FNV1a", Hasher(Create()), Collider::Bits64)); dict.Add(Collider("Murmur3", Hasher(Create()), Collider::Bits32)); dict.Add(Collider("Murmur3", Hasher(Create()), Collider::Bits64)); files.ReadInto(dict); dict.Report(); if (timing) { dict.Time(); } return 0; } ``` -------------------------------- ### Install and Start UDP Server Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d99/wifi-80211e-txop_8cc_source.html Installs and starts a UDP server application on a specified Wi-Fi Access Point node. ```c++ UdpServerHelper serverC(port); ApplicationContainer serverAppC = serverC.Install(wifiApNodes.Get(2)); serverAppC.Start(Seconds(0)); serverAppC.Stop(simulationTime + Seconds(1)); ``` -------------------------------- ### TutorialApp::Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d58/classns3_1_1_tutorial_app.html Sets up the socket for the application, configuring packet size, count, and data rate. ```APIDOC ## Setup ### Description Sets up the socket for the application, configuring packet size, count, and data rate. ### Method Signature void Setup (Ptr< Socket > socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) ``` -------------------------------- ### Main Function Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/db/dfb/tcp-pacing_8cc_source.html Initializes the simulation, parses command-line arguments, and sets default configurations for TCP pacing and other network parameters. ```c++ int main(int argc, char* argv[]) { bool tracing = false; uint32_t maxBytes = 0; // value of zero corresponds to unlimited send std::string transportProtocol = "ns3::TcpCubic"; Time simulationEndTime = Seconds(5); DataRate bottleneckBandwidth("10Mbps"); // value of x as shown in the above network topology Time bottleneckDelay = MilliSeconds(40); DataRate regLinkBandwidth(4 * bottleneckBandwidth.GetBitRate()); Time regLinkDelay = MilliSeconds(5); DataRate maxPacingRate("4Gbps"); bool isPacingEnabled = true; bool useEcn = true; bool useQueueDisc = true; bool shouldPaceInitialWindow = true; // Configure defaults that are not based on explicit command-line arguments // They may be overridden by general attribute configuration of command line Config::SetDefault("ns3::TcpL4Protocol::SocketType", TypeIdValue(TypeId::LookupByName(transportProtocol))); Config::SetDefault("ns3::TcpSocket::InitialCwnd", UintegerValue(10)); CommandLine cmd(__FILE__); cmd.AddValue("tracing", "Flag to enable/disable Ascii and Pcap tracing", tracing); cmd.AddValue("maxBytes", "Total number of bytes for application to send", maxBytes); cmd.AddValue("isPacingEnabled", "Flag to enable/disable pacing in TCP", isPacingEnabled); cmd.AddValue("maxPacingRate", "Max Pacing Rate", maxPacingRate); cmd.AddValue("useEcn", "Flag to enable/disable ECN", useEcn); cmd.AddValue("useQueueDisc", "Flag to enable/disable queue disc on bottleneck", useQueueDisc); cmd.AddValue("shouldPaceInitialWindow", "Flag to enable/disable pacing of TCP initial window", shouldPaceInitialWindow); cmd.AddValue("simulationEndTime", "Simulation end time", simulationEndTime); cmd.Parse(argc, argv); // Configure defaults based on command-line arguments Config::SetDefault("ns3::TcpSocketState::EnablePacing", BooleanValue(isPacingEnabled)); Config::SetDefault("ns3::TcpSocketState::PaceInitialWindow", BooleanValue(shouldPaceInitialWindow)); } ``` -------------------------------- ### Main Function Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d3/d9c/wifi-phy-configuration_8cc_source.html Initializes the ns-3 simulation environment, parses command-line arguments for test case and attribute printing, and sets up basic Wi-Fi components like nodes, channel, and PHY helper. ```cpp int main(int argc, char* argv[]) { uint32_t testCase = 0; bool printAttributes = false; bool exceptionThrown = false; CommandLine cmd(__FILE__); cmd.AddValue("testCase", "Test case", testCase); cmd.AddValue("printAttributes", "If true, print out attributes", printAttributes); cmd.Parse(argc, argv); NodeContainer wifiStaNode; wifiStaNode.Create(1); NodeContainer wifiApNode; wifiApNode.Create(1); YansWifiChannelHelper channel = YansWifiChannelHelper::Default(); YansWifiPhyHelper phy; phy.SetChannel(channel.Create()); WifiHelper wifi; wifi.SetRemoteStationManager("ns3::IdealWifiManager"); ``` -------------------------------- ### Install Packet Sink and Start Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/dd3/tap-wifi-dumbbell_8cc_source.html Installs a PacketSink application on a node and starts it at a specified time. Ensure the node and port are correctly configured. ```c++ ns3::PacketSinkHelper sink("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny(), port)); apps = sink.Install(nodesRight.Get(0)); apps.Start(Seconds(1)); ``` -------------------------------- ### SetUp() Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/de5/classns3_1_1_ipv6_interface.html Enables this IPv6 interface, making it operational. ```APIDOC ## SetUp() ### Description Enables this interface. ### Signature void ns3::Ipv6Interface::SetUp(void) ### Definition File: ipv6-interface.cc, Line: 170 ``` -------------------------------- ### Install and Start UDP Client Application (Node 3) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d99/wifi-80211e-txop_8cc_source.html Installs and starts an OnOff UDP client application on the third Wi-Fi station node. ```c++ ApplicationContainer clientAppD = clientD.Install(wifiStaNodes.Get(3)); clientAppD.Start(Seconds(1)); clientAppD.Stop(simulationTime + Seconds(1)); ``` -------------------------------- ### Main Function Setup and Configuration Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d43/nsclick-raw-wlan_8cc_source.html Initializes the simulation, parses command-line arguments for the Click configuration folder, and sets up Wi-Fi node containers. It configures default Wi-Fi parameters like fragmentation and RTS/CTS thresholds. ```c++ int main(int argc, char* argv[]) { double rss = -80; std::string clickConfigFolder = "src/click/examples"; CommandLine cmd(__FILE__); cmd.AddValue("clickConfigFolder", "Base folder for click configuration files", clickConfigFolder); cmd.Parse(argc, argv); // Setup nodes NodeContainer wifiNodes; wifiNodes.Create(2); // Get Wifi devices installed on both nodes. // Adapted from examples/wireless/wifi-simple-adhoc.cc std::string phyMode("DsssRate1Mbps"); // disable fragmentation for frames below 2200 bytes Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode)); WifiHelper wifi; wifi.SetStandard(WIFI_STANDARD_80211b); YansWifiPhyHelper wifiPhy; // This is one parameter that matters when using FixedRssLossModel // set it to zero; otherwise, gain will be added wifiPhy.Set("RxGain", DoubleValue(0)); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); // The below FixedRssLossModel will cause the rss to be fixed regardless ``` -------------------------------- ### Install and Start UDP Server Application (Node 3) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d99/wifi-80211e-txop_8cc_source.html Installs and starts a UDP server application on the third Wi-Fi Access Point node. ```c++ UdpServerHelper serverD(port); ApplicationContainer serverAppD = serverD.Install(wifiApNodes.Get(3)); serverAppD.Start(Seconds(0)); serverAppD.Stop(simulationTime + Seconds(1)); ``` -------------------------------- ### Install and Start UDP Client Application (Node 2) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d4/d99/wifi-80211e-txop_8cc_source.html Installs and starts an OnOff UDP client application on the second Wi-Fi station node. ```c++ ApplicationContainer clientAppC = clientC.Install(wifiStaNodes.Get(2)); clientAppC.Start(Seconds(1)); clientAppC.Stop(simulationTime + Seconds(1)); ``` -------------------------------- ### Main Function Setup (C++) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d7/d2e/radvd-two-prefix_8cc_source.html Initializes the ns-3 simulation environment, parses command-line arguments for verbosity, and sets up logging for various ns-3 modules. ```cpp int main(int argc, char** argv) { bool verbose = false; CommandLine cmd(__FILE__); cmd.AddValue("verbose", "turn on log components", verbose); cmd.Parse(argc, argv); if (verbose) { LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL); LogComponentEnable("Ipv6RawSocketImpl", LOG_LEVEL_ALL); LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL); LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL); LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL); LogComponentEnable("RadvdApplication", LOG_LEVEL_ALL); LogComponentEnable("Ping", LOG_LEVEL_ALL); } NS_LOG_INFO("Create nodes."); Ptr n0 = CreateObject(); Ptr r = CreateObject(); Ptr n1 = CreateObject(); NodeContainer net1(n0, r); NodeContainer net2(r, n1); NodeContainer all(n0, r, n1); NS_LOG_INFO("Create IPv6 Internet Stack"); InternetStackHelper internetv6; ``` -------------------------------- ### Setup OnOff Application for TCP Client (Connection Two) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/d91/red-tests_8cc_source.html Configures and installs a second OnOff application for TCP client functionality, similar to the first but potentially with different start times. It sends data at a specified rate and packet size. ```cpp OnOffHelper clientHelper2("ns3::TcpSocketFactory", Address()); clientHelper2.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]")); clientHelper2.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]")); clientHelper2.SetAttribute("DataRate", DataRateValue(DataRate("10Mb/s"))); clientHelper2.SetAttribute("PacketSize", UintegerValue(1000)); ApplicationContainer clientApps2; clientHelper2.SetAttribute("Remote", remoteAddress); clientApps2.Add(clientHelper2.Install(n1n2.Get(0))); clientApps2.Start(Seconds(3)); clientApps2.Stop(Seconds(client_stop_time)); ``` -------------------------------- ### Running the CommandLine Example (Help) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d1a/classns3_1_1_command_line.html Example output when requesting help for the command-line example program. ```text $ ./ns3 run "command-line-example --help" ``` -------------------------------- ### Main Function: Simulation Setup Source: https://www.nsnam.org/docs/release/3.45/doxygen/d8/d72/generic-battery-wifiradio-example_8cc_source.html Initializes the simulation, parses command-line arguments, and sets up default configurations for Wi-Fi. ```c++ int main(int argc, char* argv[]) { LogComponentEnableAll(LogLevel(LOG_PREFIX_TIME | LOG_PREFIX_FUNC)); LogComponentEnable("GenericBatteryWifiRadioExample", LOG_LEVEL_DEBUG); std::string phyMode("DsssRate1Mbps"); double rss = -80; // dBm uint32_t packetSize = 200; // bytes bool verbose = false; // simulation parameters uint32_t numPackets = 10000; // number of packets to send double interval = 1; // seconds double startTime = 0.0; // seconds double distanceToRx = 100.0; // meters CommandLine cmd(__FILE__); cmd.AddValue("phyMode", "Wifi Phy mode", phyMode); cmd.AddValue("rss", "Intended primary RSS (dBm)", rss); cmd.AddValue("packetSize", "size of application packet sent (Bytes)", packetSize); cmd.AddValue("numPackets", "Total number of packets to send", numPackets); cmd.AddValue("startTime", "Simulation start time (seconds)", startTime); cmd.AddValue("distanceToRx", "X-Axis distance between nodes (meters)", distanceToRx); cmd.AddValue("verbose", "Turn on all device log components", verbose); cmd.Parse(argc, argv); Time interPacketInterval = Seconds(interval); Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue("2200")); Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200")); Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode)); NodeContainer nodeContainer; nodeContainer.Create(2); WifiHelper wifi; if (verbose) { WifiHelper::EnableLogComponents(); } wifi.SetStandard(WIFI_STANDARD_80211b); ////////////////////// // Wifi PHY and MAC // ////////////////////// YansWifiPhyHelper wifiPhy; YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel"); Ptr wifiChannelPtr = wifiChannel.Create(); wifiPhy.SetChannel(wifiChannelPtr); WifiMacHelper wifiMac; wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", StringValue(phyMode), "ControlMode", StringValue(phyMode)); wifiMac.SetType("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodeContainer); ////////////////// // Mobility // ////////////////// MobilityHelper mobility; Ptr positionAlloc = CreateObject(); positionAlloc->Add(Vector(0.0, 0.0, 0.0)); positionAlloc->Add(Vector(2 * distanceToRx, 0.0, 0.0)); mobility.SetPositionAllocator(positionAlloc); mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install(nodeContainer); //////////////////// // Energy Model // //////////////////// // Use a preset PANASONIC Li-Ion batteries arranged in a cell pack (2 series, 2 parallel) GenericBatteryModelHelper batteryHelper; EnergySourceContainer energySourceContainer = batteryHelper.Install(nodeContainer, PANASONIC_CGR18650DA_LION); batteryHelper.SetCellPack(energySourceContainer, 2, 2); Ptr battery0 = DynamicCast(energySourceContainer.Get(0)); Ptr battery1 = DynamicCast(energySourceContainer.Get(1)); // Energy consumption quantities have been exaggerated for // demonstration purposes, real consumption values are much smaller. WifiRadioEnergyModelHelper radioEnergyHelper; radioEnergyHelper.Set("TxCurrentA", DoubleValue(4.66)); radioEnergyHelper.Set("RxCurrentA", DoubleValue(0.466)); radioEnergyHelper.Set("IdleCurrentA", DoubleValue(0.466)); DeviceEnergyModelContainer deviceModels = ``` -------------------------------- ### Get Start Time Source: https://www.nsnam.org/docs/release/3.45/doxygen/d5/d42/radio-bearer-stats-calculator_8cc_source.html Retrieves the start time of the statistics collection. ```APIDOC ## GetStartTime ### Description Gets the start time of the statistics collection. ### Method GET ### Endpoint /GetStartTime ### Response #### Success Response (200) - **Time** - The start time of the statistics collection. ``` -------------------------------- ### Install and Start UDP Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/dd/d88/global-routing-multi-switch-plus-router_8cc_source.html Installs a UDP echo client application on a node and starts it. Configures application attributes like packet count, interval, and size. ```c++ client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount)); client.SetAttribute("Interval", TimeValue(interPacketInterval)); client.SetAttribute("PacketSize", UintegerValue(packetSize)); ApplicationContainer clientApp = client.Install(b3); clientApp.Start(Seconds(0.5)); clientApp.Stop(Seconds(simDurationSeconds)); ``` -------------------------------- ### Running the CommandLine Example (With Arguments) Source: https://www.nsnam.org/docs/release/3.45/doxygen/d0/d1a/classns3_1_1_command_line.html Example output when running the command-line example program with specific arguments provided. ```text $ ./ns3 run "command-line-example --intArg=2 --boolArg --strArg=Hello --cbArg=World" intArg: 2 boolArg: true strArg: "Hello" cbArg: "World" ``` -------------------------------- ### Complete Setup UE Source: https://www.nsnam.org/docs/release/3.45/doxygen/d3/d7a/lte-enb-rrc_8h_source.html Implements the LteEnbRrcSapProvider::CompleteSetupUe interface. ```APIDOC ## CompleteSetupUe ### Description Implements the LteEnbRrcSapProvider::CompleteSetupUe interface. ### Method void ### Parameters #### Path Parameters - **params** (LteEnbRrcSapProvider::CompleteSetupUeParameters) - Required - CompleteSetupUeParameters. ``` -------------------------------- ### Install and Start BulkSend Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/d2/d0d/ns3tcp-cubic-test-suite_8cc_source.html Installs a BulkSend application on the sender node to generate traffic. The application starts shortly after the simulation begins and stops at a specified time. ```c++ BulkSendHelper source("ns3::TcpSocketFactory", InetSocketAddress(ir1.GetAddress(1), port)); source.SetAttribute("MaxBytes", UintegerValue(0)); ApplicationContainer sourceApps = source.Install(sender.Get(0)); sourceApps.Start(Seconds(0.1)); // Hook trace source after application starts Simulator::Schedule(Seconds(0.1) + MilliSeconds(1), &Ns3TcpCubicTestCase::ConnectCwndTrace, this, 0, 0); sourceApps.Stop(stopTime); ``` -------------------------------- ### Install and Start Echo Client Application Source: https://www.nsnam.org/docs/release/3.45/doxygen/d9/d88/fragmentation-ipv6_8cc_source.html Installs the UDP echo client application on the first node of the first network and starts it. The application is configured to run for a specific duration. ```c++ ApplicationContainer clientApps = echoClient.Install(net1.Get(0)); clientApps.Start(Seconds(2)); clientApps.Stop(Seconds(20)); ```