0% found this document useful (0 votes)
22 views

Labwork 2 Logging Attribute and Tracing

This document discusses logging, attributes, and command line arguments in NS-3 simulations. It shows how to: 1. Enable logging to view output from applications like sending and receiving packets. 2. Edit attributes like data rate and delay of point-to-point network devices to alter simulation parameters. 3. Add and parse command line arguments to set values like number of packets to send from the command line. This allows easy experimentation with different parameter values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Labwork 2 Logging Attribute and Tracing

This document discusses logging, attributes, and command line arguments in NS-3 simulations. It shows how to: 1. Enable logging to view output from applications like sending and receiving packets. 2. Edit attributes like data rate and delay of point-to-point network devices to alter simulation parameters. 3. Add and parse command line arguments to set values like number of packets to send from the command line. This allows easy experimentation with different parameter values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Labwork 2: Logging, Attribute, and Tracing

Logging
Code addition

#include "ns3/applications-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/log.h" //include the log library

using namespace ns3;

NS_LOG_COMPONENT_DEFINE("FirstScriptExample");

int
main(int argc, char* argv[])
{
CommandLine cmd(__FILE__);
cmd.Parse(argc, argv);

Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

// Enable function-level logging


LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_FUNCTION);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_FUNCTION);

// the rest of the code


}

Output after running

UdpEchoServerApplication:UdpEchoServer(0x600000b20410)
UdpEchoClientApplication:UdpEchoClient(0x7fb4e8706f60)
UdpEchoClientApplication:SetDataSize(0x7fb4e8706f60, 1024)
UdpEchoServerApplication:StartApplication(0x600000b20410)
UdpEchoClientApplication:StartApplication(0x7fb4e8706f60)
UdpEchoClientApplication:ScheduleTransmit(0x7fb4e8706f60, +0ns)
UdpEchoClientApplication:Send(0x7fb4e8706f60)
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
UdpEchoServerApplication:HandleRead(0x600000b20410, 0x7fb4e8707090)
At time +2.00369s server received 1024 bytes from 10.1.1.1 port 49153
At time +2.00369s server sent 1024 bytes to 10.1.1.1 port 49153
UdpEchoClientApplication:HandleRead(0x7fb4e8706f60, 0x7fb4e8707330)
At time +2.00737s client received 1024 bytes from 10.1.1.2 port 9
UdpEchoClientApplication:StopApplication(0x7fb4e8706f60)
UdpEchoServerApplication:StopApplication(0x600000b20410)
UdpEchoClientApplication:DoDispose(0x7fb4e8706f60)

Labwork 2: Logging, Attribute, and Tracing 1


UdpEchoServerApplication:DoDispose(0x600000b20410)
UdpEchoClientApplication:~UdpEchoClient(0x7fb4e8706f60)
UdpEchoServerApplication:~UdpEchoServer(0x600000b20410)

Editing Attributes
The logging function from last exercise is disabled for better observation

Results after editing attributes

DataRate: 10Mbps (originally 5Mpbs)

Delay: 10ms (originally 2ms)

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
pointToPoint.SetChannelAttribute("Delay", StringValue("10ms"));

Before After

At time +2s client sent 1024 bytes to 10.1.1 At time +2s client sent 1024 bytes to 10.1.1
At time +2.00369s server received 1024 bytes At time +2.01084s server received 1024 bytes
At time +2.00369s server sent 1024 bytes to 1 At time +2.01084s server sent 1024 bytes to 1
At time +2.00737s client received 1024 bytes At time +2.02169s client received 1024 bytes

The delay of received packets

At the client (Round Trip Time): 21.69ms

At the server: 0.0ms

Using Command Line Arguments

Setting number of sending packets to 100

main(int argc, char* argv[])


{
uint32_t nPackets = 1;
CommandLine cmd(__FILE__);
cmd.AddValue("nPackets", "Number of packets to send", nPackets);
cmd.Parse(argc, argv);

Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

// rest of the code

UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);


echoClient.SetAttribute("MaxPackets", UintegerValue(nPackets));

// rest of the code


}

And edit the value in command line argument by

./ns3 run first -- --nPackets=100

Labwork 2: Logging, Attribute, and Tracing 2


Edit point-to-point network device and channel attributes to (10Mbps,0.01s), default (5Mbps, 1ms)

main(int argc, char* argv[])


{
uint32_t nPackets = 1;
std::string dataRate = "5Mbps"; //original/base value
std::string delay = "2ms"; //original/base value
CommandLine cmd(__FILE__);
cmd.AddValue("nPackets", "Number of packets to send", nPackets);
cmd.AddValue("dataRate", "Data rate for point-to-point network", dataRate);
cmd.AddValue("delay", "Delay for point-to-point network", delay);
cmd.Parse(argc, argv);

Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);

// rest of the code

// edited the value of dataRate and delay in PointToPoint object


// to prevent overwriting
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue(dataRate));
pointToPoint.SetChannelAttribute("Delay", StringValue(delay));
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes);

//rest of the code


}

And edit the value in command line argument by

nPackets=100 nPackets=100

dataRate: 5Mbps dataRate: 10Mbps

delay: 1ms delay: 10ms

./ns3 run first -- --nPackets=100 --dataRate=5Mbps --delay=1ms ./ns3 run first

Terminal output after alteration Terminal output after

At time +2s client sent 1024 bytes to 10.1.1.2 port 9 At time +2s cli
At time +2.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +2.0108
At time +2.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +2.0108
At time +2.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +2.0216
At time +3s client sent 1024 bytes to 10.1.1.2 port 9 At time +3s cli
At time +3.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +3.0108
At time +3.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +3.0108
At time +3.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +3.0216
At time +4s client sent 1024 bytes to 10.1.1.2 port 9 At time +4s cli
At time +4.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +4.0108
At time +4.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +4.0108
At time +4.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +4.0216
At time +5s client sent 1024 bytes to 10.1.1.2 port 9 At time +5s cli

Labwork 2: Logging, Attribute, and Tracing 3


At time +5.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +5.0108
At time +5.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +5.0108
At time +5.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +5.0216
At time +6s client sent 1024 bytes to 10.1.1.2 port 9 At time +6s cli
At time +6.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +6.0108
At time +6.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +6.0108
At time +6.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +6.0216
At time +7s client sent 1024 bytes to 10.1.1.2 port 9 At time +7s cli
At time +7.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +7.0108
At time +7.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +7.0108
At time +7.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +7.0216
At time +8s client sent 1024 bytes to 10.1.1.2 port 9 At time +8s cli
At time +8.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +8.0108
At time +8.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +8.0108
At time +8.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +8.0216
At time +9s client sent 1024 bytes to 10.1.1.2 port 9 At time +9s cli
At time +9.00269s server received 1024 bytes from 10.1.1.1 port 49153 At time +9.0108
At time +9.00269s server sent 1024 bytes to 10.1.1.1 port 49153 At time +9.0108
At time +9.00537s client received 1024 bytes from 10.1.1.2 port 9 At time +9.0216

Result
After editing point-to-point network device and channel attributes to:

nPackets=100, (5Mbps, 1ms), the average delay is:

at client: 5.37ms

at server: 0.0ms

nPackets=100, (10Mbps, 10ms), the average delay is:

at client: 21.69ms

at server: 0.0ms
Capture Packet Traces
ASCII Tracing: Output the trace to a text file

To enable the ASCII Tracing:

// Enable ASCII tracing


AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll(ascii.CreateFileStream("first.tr")); //placeholder name

The output file “first.tr”:

+ 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Po


- 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Po
r 2.00269 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-
+ 2.00269 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHead
- 2.00269 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHead
r 2.00537 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-

PCAP Tracing: Capturing sent and received packets

To anble the PCAP Tracing:

Labwork 2: Logging, Attribute, and Tracing 4


pointToPoint.EnablePcapAll("first"); //placeholder name

The program will output 2 files

“first-0-0.pcap”: packet trace for the first network device on the first node (client node)

“first-1-0.pcap”: packet trace for the first network device on the second node (server node)
Report Results
Set 1: nPackets=100, dataRate=5Mbps, delay=1ms Set 2: nPackets=100, dataRate=10Mbps, delay=10ms

Average delay of received packets Average delay of received packets

at client: 5.37ms at client: 21.69ms

at server: 0.0ms (virtually instantaneous at server: 0.0ms (virtually instantaneous


processing) processing)

Packet delivery ratio: 100% Packet delivery ratio: 100%

8 packets sent 8 packets sent

8 packets received 8 packets received

Labwork 2: Logging, Attribute, and Tracing 5

You might also like