You are on page 1of 14

1.

For graphical simulation using netanim the following lines of code should be added:
 The netanim header file
#include "ns3/netanim-module.h"
 Add the Code that specifies xml file for graphical display just before Simulator::Run ();
AnimationInterface anim ("mysecond.xml");
 Add the codes for setting the position of the nodes
anim.SetConstantPosition (csmaNodes.Get(0), 2.5, 1);
anim.SetConstantPosition (csmaNodes.Get(1), 0.0, 2.0);
anim.SetConstantPosition (csmaNodes.Get(2), 3.0, 4.0);
anim.SetConstantPosition (csmaNodes.Get(3), 5.0, 2.0);

The simulation result is:

 When Node 0 (the first P2P node) sends packet to the server (the last CSMA extra node, Node 4)
it will be faced by the next hop (the second P2P node and the first CSMA node, Node 1).

 Since the Node 1 is on both p2p and CSMA mode and it doesn’t know the MAC address of the
destination it broadcasts on the CSMA network asking for the device that has the server IP
address .

 Then the server(Node 4) responds back with its MAC address


 then node one goes ahead and sends the packet to the server with its IP address

 Now the server receives the packet and wants to respond back the client (Node 0) with the echo
packet. But the two nodes are on different network. The server knows it has to send the packet
via Node 1, since we initialized global routing capability for each CSMA nodes and the server
doesn’t know the MAC address of Node 1. So it has to broadcast ARP for it just like the first
CSMA node had to do.
 The Node 1 replies the server with its MAC address

 Based on the received MAC address the server sends the echo back to the forwarding
node(Node 1)

 Node 1 receives the packet and forward it to the original source node (Node 0)
 Since we selected node 2 as the promiscuous sniffer node for the CSMA network so we can
also look at second-2-0.pcap trace output to summarize the above simulation result.
$ tcpdump -nn -tt -r second-2-0.pcap
reading from file second-2-0.pcap, link-type EN10MB (Ethernet)
2.007698 ARP, Request who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1, length 50
2.007710 ARP, Reply 10.1.2.4 is-at 00:00:00:00:00:06, length 50
2.007803 IP 10.1.1.1.49153 > 10.1.2.4.9: UDP, length 1024
2.013815 ARP, Request who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4, length 50
2.013828 ARP, Reply 10.1.2.1 is-at 00:00:00:00:00:03, length 50
2.013921 IP 10.1.2.4.9 > 10.1.1.1.49153: UDP, length 1024

2. To instantiate the server on the node having only a point to point device (Node 0) the codes used to
set up the server and client applications should be edited as follows.
 The server should be instantiated on the node only with point to point device, which is Node
0 created with only P2P characteristic and start it at 1second.
ApplicationContainer serverApps = echoServer.Install (p2pNodes.Get (0));
serverApps.Start (Seconds (1.0));
 Then the clients can be set up on the last nodes of CSMA devices. Before setting up the
clients we have to tell the client to send packets to the server we just installed on the P2P
node only (Node 0). So the code will be edited as ,
UdpEchoClientHelper echoClient (p2pInterfaces.GetAddress (0), 9);
 Now we can install the clients on the last two CSMA nodes. Install the first client on the last
CSMA node (Node 4) and make it send echo to server 1.5 second, and then install the
second client on the third CSMA node (Node 3) and make it send echo to the server at 2.5
second.

ApplicationContainer clientApps = echoClient.Install (csmaNodes.Get (nCsma));


clientApps.Start (Seconds (1.5));
clientApps.Stop (Seconds (10.0));

ApplicationContainer clientApps1 = echoClient.Install (csmaNodes.Get (nCsma-1));


clientApps1.Start (Seconds (2.5));
clientApps1.Stop (Seconds (10.0));

3. The output of the result will be:


 The Node 4, our first client, starts to send packets to the sever at 1.5 second.
When Node 4 (the last CSMA node) sends packet to the server (the first P2P node only
device, Node 0) it will be faced by the next hop (the second P2P node and the first CSMA
node, Node 1). Since the Node 1 is on both p2p and CSMA mode it will act as forwarding
device for the communication between the server and the clients .Even if Node 4 knows the
IP address of Node 1, it doesn’t know the MAC address. So it broadcasts ARP on the CSMA
network asking for the device that has the next hope IP address.

 Then the Node 1 responds back the Node 4 with its MAC address

 Based on the received MAC address and IP address Node 4 sends the packets to the
forwarding Node (Node 1). And the Node 1 forwards the packet to the sever (Node 0).
 When Node 0 (the server) echo back the client (the last CSMA extra node, Node 4) it will be
faced by the next hop (the second P2P node and the first CSMA node, Node 1). After Node 1
receives the echo back from the server it doesn’t know where to forward it since it has no MAC
information of the destination (Node 4). So it broadcasts ARP.

 Then the Node 4 client responds Node 1 with its MAC address.
 Based on the MAC address received the Node 1 forwarded the packet to the destined client
Node 4.

 At 2.5 seconds our second client starts to send packets to the server.
With the same procedure as that of the first client (Node 4), the second client (Node 3)
broadcasts ARP to the entire CSMA network asking for MAC address with Node 1 IP address.

 Node 1 responds back with its MAC address and with the information provided the Node 3
sends its packet to Node 1.
 Then the Node 1 forwards the packet to server (Node 0).

 When the server (Node 0) echo back ,the Node 1 receive it initiate ARP to identify the MAC
address of the device with the second client( Node 3) IP address.

 Finally the Node 3 responds with its MAC address and the Node 1 forwards the echo back
packet to the destined client (Node 3).
 Since we selected node 2 as the promiscuous sniffer node for the CSMA network so we can
also look at second-2-0.pcap trace output to summarize the above simulation result.
$ tcpdump -nn -tt -r second-2-0.pcap
reading from file second-2-0.pcap, link-type EN10MB (Ethernet)
1.506011 ARP, Request who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4, length 50
1.506024 ARP, Reply 10.1.2.1 is-at 00:00:00:00:00:03, length 50
1.506117 IP 10.1.2.4.49153 > 10.1.1.1.9: UDP, length 1024
1.517502 ARP, Request who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1, length 50
1.517514 ARP, Reply 10.1.2.4 is-at 00:00:00:00:00:06, length 50
1.517607 IP 10.1.1.1.9 > 10.1.2.4.49153: UDP, length 1024
2.503011 ARP, Request who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.3, length 50
2.503024 ARP, Reply 10.1.2.1 is-at 00:00:00:00:00:03, length 50
2.503117 IP 10.1.2.3.49153 > 10.1.1.1.9: UDP, length 1024
2.513502 ARP, Request who-has 10.1.2.3 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1, length 50
2.513514 ARP, Reply 10.1.2.3 is-at 00:00:00:00:00:05, length 50
2.513607 IP 10.1.1.1.9 > 10.1.2.3.49153: UDP, length 1024

4. when the two clients send packets at the same at 1.5 second
 the code for starting clients will be edited as:
clientApps.Start (Seconds (1.5));
clientApps1.Start (Seconds (1.5));
 Since the network is CSMA LAN only one client at a time can send packet to the server. So
the two clients compete for accessing the medium to send their packet. In this case Node 3
(client 2) gets the chance to send the packet. But as explained in the above cases this node
doesn’t know where the server is located. It only knows it has to send the packet via Node 1.
Additionally Node 3 only knows the IP address of but not the MAC address of the forwarding
node (Node 1). So it initiates ARP broadcast.
 Then Node 1 responds back with its MAC address and Node 3 sends its packet to Node 1.

 The Node 1 receives the packet from Node 3 and forwards it to the server.
 After the server receives the packet sent from Node 3 via Node 1, the second client (Node 4)
senses the media is idle and it immediately started to send its packet. So the server is forced
to wait for the second client finishes to respond back the Node 3. With the same reason as
that of the first client Node 4 broadcasts ARP to ask for forwarding Node MAC.

 Node 1 responds Node 4 with its MAC address and based on this information Node 4 sends
its packet to Node 1.

 Then node 1 forwards the packet to the server. At this instant the server knows the CSMA
media is free. So the server receives the packet sent from Node 4(first client) and echoes
back the clients via Node 1. Then node 1 buffers the two echo backs from the server.
 Then Node 1 asks for destination MAC address with ARP broadcast for the first echo back
packet( destined for Node 3) it received from server.

 Then the Node 3 (our second client) responds with its MAC address and Node 1 forwards
the echo back packet to Node 3.
 After finishing echo backing Node 3, Node 1 initiates another ARP broadcast for the second
echo back packet, destined for Node 4.

 Finally the Node 4 responds with its MAC address and Node 1 forwards the echo back
packet to Node 4.

 Since we selected node 2 as the promiscuous sniffer node for the CSMA network so we can
also look at second-2-0.pcap trace output to summarize the above simulation result.
$ tcpdump -nn -tt -r second-2-0.pcap
reading from file second-2-0.pcap, link-type EN10MB (Ethernet)
1.503011 ARP, Request who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.3, length 50
1.503024 ARP, Reply 10.1.2.1 is-at 00:00:00:00:00:03, length 50
1.503117 IP 10.1.2.3.49153 > 10.1.1.1.9: UDP, length 1024
1.506011 ARP, Request who-has 10.1.2.1 (ff:ff:ff:ff:ff:ff) tell 10.1.2.4, length 50
1.506024 ARP, Reply 10.1.2.1 is-at 00:00:00:00:00:03, length 50
1.506117 IP 10.1.2.4.49153 > 10.1.1.1.9: UDP, length 1024
1.514502 ARP, Request who-has 10.1.2.3 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1, length 50
1.514514 ARP, Reply 10.1.2.3 is-at 00:00:00:00:00:05, length 50
1.514607 IP 10.1.1.1.9 > 10.1.2.3.49153: UDP, length 1024
1.520502 ARP, Request who-has 10.1.2.4 (ff:ff:ff:ff:ff:ff) tell 10.1.2.1, length 50
1.520514 ARP, Reply 10.1.2.4 is-at 00:00:00:00:00:06, length 50
1.520607 IP 10.1.1.1.9 > 10.1.2.4.49153: UDP, length 1024

You might also like