about summary refs log tree commit diff
path: root/usth/ICT3.16/labworks/2.md
blob: 02a7ae9b59103261db53f445f0922a50986976ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Network Simulation: Labwork 2
Consider the ns-3 example `tutorial/first.cc`.

## Logging
Enable LOG_LEVEL_FUNCTION for UdpEchoServer and UdpEchoClient:

```diff
diff --git a/examples/tutorial/first.cc b/examples/tutorial/first.cc
index f68eb6a8e..38a277a69 100644
--- a/examples/tutorial/first.cc
+++ b/examples/tutorial/first.cc
@@ -38,8 +38,8 @@ main (int argc, char *argv[])
   cmd.Parse (argc, argv);
   
   Time::SetResolution (Time::NS);
-  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
-  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
+  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_FUNCTION);
+  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_FUNCTION);
 
   NodeContainer nodes;
   nodes.Create (2);
```

List out functions used by the two classes:

```console
$ waf --run first.cc 2>&1 | grep UdpEcho
UdpEchoServerApplication:UdpEchoServer(0x55d1742cdd30)
UdpEchoClientApplication:UdpEchoClient(0x55d1742f4820)
UdpEchoClientApplication:SetDataSize(0x55d1742f4820, 1024)
UdpEchoServerApplication:StartApplication(0x55d1742cdd30)
UdpEchoClientApplication:StartApplication(0x55d1742f4820)
UdpEchoClientApplication:ScheduleTransmit(0x55d1742f4820, +0ns)
UdpEchoClientApplication:Send(0x55d1742f4820)
UdpEchoServerApplication:HandleRead(0x55d1742cdd30, 0x55d1742bdcf0)
UdpEchoClientApplication:HandleRead(0x55d1742f4820, 0x55d1742ba420)
UdpEchoClientApplication:StopApplication(0x55d1742f4820)
UdpEchoServerApplication:StopApplication(0x55d1742cdd30)
UdpEchoClientApplication:DoDispose(0x55d1742f4820)
UdpEchoServerApplication:DoDispose(0x55d1742cdd30)
UdpEchoClientApplication:~UdpEchoClient(0x55d1742f4820)
UdpEchoServerApplication:~UdpEchoServer(0x55d1742cdd30)
```

## Attributes
1. Set up data rate of 10 Mbps and propagation delay of 10 ms:

   ```diff
   diff --git a/examples/tutorial/first.cc b/examples/tutorial/first.cc
   index f68eb6a8e..973b6fc14 100644
   --- a/examples/tutorial/first.cc
   +++ b/examples/tutorial/first.cc
   @@ -45,8 +45,8 @@ main (int argc, char *argv[])
      nodes.Create (2);
    
      PointToPointHelper pointToPoint;
   -  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
   -  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
   +  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
   +  pointToPoint.SetChannelAttribute ("Delay", StringValue ("10ms"));
    
      NetDeviceContainer devices;
      devices = pointToPoint.Install (nodes);
   ```

2. Run the updated script and compute the average delay of received packets
   at the server and client:

   ```console
   $ waf --run first.cc
   At time +2s client sent 1024 bytes to 10.1.1.2 port 9
   At time +2.01084s server received 1024 bytes from 10.1.1.1 port 49153
   At time +2.01084s server sent 1024 bytes to 10.1.1.1 port 49153
   At time +2.02169s client received 1024 bytes from 10.1.1.2 port 9
   ```

3. Compare the average delay of received packets at server and client
   between device and channel attributes of (5 Mbps, 1 ms) and (10 Mbps, 10 ms)
   with the number of packets set to 100:

   ```diff
   diff --git a/examples/tutorial/first.cc b/examples/tutorial/first.cc
   index f68eb6a8e..62169f460 100644
   --- a/examples/tutorial/first.cc
   +++ b/examples/tutorial/first.cc
   @@ -66,8 +66,8 @@ main (int argc, char *argv[])
      serverApps.Stop (Seconds (10.0));
    
      UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
   -  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
   -  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
   +  echoClient.SetAttribute ("MaxPackets", UintegerValue (100));
   +  echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.0)));
      echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
    
      ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
   ```

   To make best use of the bandwidth, we send all packets at the same time.
   The average delay of received packets is calculated as follows:

   ```bash
   waf --run first.cc 2>&1 |
     sed -rn 's/.*\+2([.0-9]+)s client received .*/\1/p' |
     awk '{sum+=$1} END {print "Packet delivery ratio =", NR,
          "%\nAverage delay =", sum/NR/2*1000, "ms"}'
   ```

   For attributes of (5 Mbps, 1 ms), we get:

       Packet delivery ratio = 100 %
       Average delay = 44.4248 ms

   For attributes of (10 Mbps, 10 ms), we get:

       Packet delivery ratio = 100 %
       Average delay = 31.7124 ms

   In short, the latter has lower *mean* latency.

## Packet Traces Capturing
### ASCII Tracing
We revert to the initial configuration (10 Mbps rate, 10 ms delay)
and apply the following patch:

```diff
diff --git a/examples/tutorial/first.cc b/examples/tutorial/first.cc
index f68eb6a8e..a63f43835 100644
--- a/examples/tutorial/first.cc
+++ b/examples/tutorial/first.cc
@@ -74,6 +74,9 @@ main (int argc, char *argv[])
   clientApps.Start (Seconds (2.0));
   clientApps.Stop (Seconds (10.0));
 
+  AsciiTraceHelper ascii;
+  pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("first.tr"));
+
   Simulator::Run ();
   Simulator::Destroy ();
   return 0;
```

The content of `first.tr` is pasted below:

    + 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024)
    - 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024)
    r 2.01084 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.1 > 10.1.1.2) ns3::UdpHeader (length: 1032 49153 > 9) Payload (size=1024)
    + 2.01084 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 9 > 49153) Payload (size=1024)
    - 2.01084 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 9 > 49153) Payload (size=1024)
    r 2.02169 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 1052 10.1.1.2 > 10.1.1.1) ns3::UdpHeader (length: 1032 9 > 49153) Payload (size=1024)

It can be seen that the total packet size is 1052 bytes
and thus the delay for packet receival can be computed as

    1052 B / 10 Mbps + 10 ms = 0.8416 ms + 10 ms = 10.8416 ms

which matches the simulated figures.

### PCAP Tracing
The following patch is used for PCAP tracing:

```diff
diff --git a/examples/tutorial/first.cc b/examples/tutorial/first.cc
index f68eb6a8e..1f5a7fa08 100644
--- a/examples/tutorial/first.cc
+++ b/examples/tutorial/first.cc
@@ -74,6 +74,8 @@ main (int argc, char *argv[])
   clientApps.Start (Seconds (2.0));
   clientApps.Stop (Seconds (10.0));

+  pointToPoint.EnablePcapAll ("first");
+
   Simulator::Run ();
   Simulator::Destroy ();
   return 0;
```

## Results
The result of each simulation has been detailed in the respective section.