# 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.