about summary refs log tree commit diff
path: root/usth/ICT3.16/labworks/1.md
blob: d551eff038a5d154c7949d592b2b857b51bcc309 (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
# Network Simulation: Labwork 1
Consider the ns-3 example `first.cc`.

## Scenario
Two P2P UDP/IPv4 nodes are simulated for a simple echo operation
over the network 10.1.1.0 subnet mask 255.255.255.0
of bandwidth 5 Mbps and latency 2 ms:

```c++
NodeContainer nodes;
nodes.Create (2);

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

NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");

Ipv4InterfaceContainer interfaces = address.Assign (devices);
```

## Protocols
In the example, Internet Protocol version 4 and User Datagram Protocol
are simulated.

## Setup
### Nodes
There are two UDP nodes set up: a client and a server,
whose addresses are automatically assigned:

```c++
Ipv4InterfaceContainer interfaces = address.Assign (devices);
```

#### Server
The echo server is bound to port 9 and kept alive from second 1 to 10:

```c++
UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
```

#### Client
The echo client is created to communicate with the aforementioned server
and stay alive from second 2 to 10:

```c++
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
```

### Traffic
The echo client is configured to send one 1 KiB packet:

```c++
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
```

The interval between packets has no effect here since we only send one.

The simulated traffic is logged as follows:

```console
$ waf --run first.cc
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
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
At time +2.00737s client received 1024 bytes from 10.1.1.2 port 9
```

It can be seen that the round-trip time (RTT) is 7.37 ms
and delays in both direction are approximately equal (3.69 ms vs 3.68 ms)
since both send and receive a 1 KiB packet over the same network configuration.
Theoretically, the RTT can be computed as

    RTT = 2 * (1 KiB / 5 Mbps + 2 ms)
        = 2 * (1.6384 ms + 2 ms)
        = 2 * 3.6384 ms
        = 7.2768 ms

The difference from the simulated figure might be explained
through non-network delays, such as processing time.