Computer Network
Computer Network
PRACTICAL- 1
AIM: To implement connection oriented client/server mechanism using
socket programming. Mini Project based on Socket programming in group of
TWO students. (In any programming language).
Hardware requirements: Pc/Laptop.
Theory :
Socket Programming
➢ Sockets provide the communication mechanism between two computers using TCP. A
client program creates a socket on its end of the communication and attempts to connect
that socket to a server.
➢ When the connection is made, the server creates a socket object on its end of the
communication. The client and the server can now communicate by writing to and
reading from the socket.
➢ The java.net.Socket class represents a socket, and the java.net.ServerSocket class
provides a mechanism for the server program to listen for clients and establish
connections with them.
The following steps occur when establishing a TCP connection between two
computers using sockets −
● The server invokes the accept() method of the ServerSocket class. This method waits
until a client connects to the server on the given port.
● After the server is waiting, a client instantiates a Socket object, specifying the server
name and the port number to connect to.
● The constructor of the Socket class attempts to connect the client to the specified server
and the port number. If communication is established, the client now has a Socket object
capable of communicating with the server.
● On the server side, the accept() method returns a reference to a new socket on the server
that is connected to the client's socket.
1
Subject code : CE 344 Id : 16ce068
After the connections are established, communication can occur using I/O streams. TCP is a
two-way communication protocol; hence data can be sent across both streams at the same
time. Following are the useful classes providing complete set of methods to implement
sockets.
2 Similar to the previous constructor, the backlog parameter specifies how many
incoming clients to store in a wait queue.
Similar to the previous constructor, the InetAddress parameter specifies the local
3
IP address to bind to. The InetAddress is used for servers that may have multiple
IP addresses, allowing the server to specify which of its IP addresses to accept
client requests on.
4 Creates an unbound server socket. When using this constructor, use the bind()
method when you are ready to bind the server socket.
➢ If the ServerSocket constructor does not throw an exception, it means that your
application has successfully bound to the specified port and is ready for client requests.
Following are some of the common methods of the ServerSocket class −
2
Subject code : CE 344 Id : 16ce068
1 Returns the port that the server socket is listening on. This method is useful if
you passed in 0 as the port number in a constructor and let the server find a port
for you.
Waits for an incoming client. This method blocks until either a client connects to
2 the server on the specified port or the socket times out, assuming that the time-
out value has been set using the setSoTimeout() method. Otherwise, this method
blocks indefinitely.
3 Sets the time-out value for how long the server socket waits for a client during
the accept().
Binds the socket to the specified server and port in the SocketAddress object.
4
Use this method if you have instantiated the ServerSocket using the no-argument
constructor.
➢ When the ServerSocket invokes accept(), the method does not return until a client
connects. After a client does connect, the ServerSocket creates a new Socket on an
unspecified port and returns a reference to this new Socket. A TCP connection now
exists between the client and the server, and communication can begin.
Socket Class Methods
➢ The java.net.Socket class represents the socket that both the client and the server use to
communicate with each other. The client obtains a Socket object by instantiating one,
whereas the server obtains a Socket object from the return value of the accept() method.
The Socket class has five constructors that a client uses to connect to a server –
3
Subject code : CE 344 Id : 16ce068
2 This method is identical to the previous constructor, except that the host is
denoted by an InetAddress object.
public Socket()
5 Creates an unconnected socket. Use the connect() method to connect this socket
to a server.
When the Socket constructor returns, it does not simply instantiate a Socket object but it
actually attempts to connect to the specified server and port.
Some methods of interest in the Socket class are listed here. Notice that both the client and the
server have a Socket object, so these methods can be invoked by both the client and the server.
4
Subject code : CE 344 Id : 16ce068
2 This method returns the address of the other computer that this socket is
connected to.
6 Returns the input stream of the socket. The input stream is connected to the
output stream of the remote socket.
7 Returns the output stream of the socket. The output stream is connected to the
input stream of the remote socket.
5
Subject code : CE 344 Id : 16ce068
6
Subject code : CE 344 Id : 16ce068
Socket Server
➢ The following Chatserver program is an example of a server application that uses the
Socket class to listen for clients on a port number specified by a command-line
argument
package Socket;
import java.net.*;
import java.io.*;
7
Subject code : CE 344 Id : 16ce068
Output:
Server
Client
Conclusion
Thus we have checked Response of Established Connection from both client and server Side
Connection.
8
Subject code : CE 344 Id : 16ce068
PRACTICAL-2
AIM: Introduction of Packet Tracer and configure network topology for Static
and Dynamic Routing Protocol using packet tracer.
Hardware requirements: pc/laptop.
Theory:
Packet Tracer
➢ Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that
allows users to create network topologies and imitate modern computer networks.
➢ The software allows users to simulate the configuration of Cisco routers and switches
using a simulated command line interface.
➢ Packet Tracer makes use of a drag and drop user interface, allowing users to add and
remove simulated network devices as they see fit.
➢ The software is mainly focused towards Certified Cisco Network Associate Academy
students as an educational tool for helping them learn fundamental CCNA concepts.
Overview
➢ Packet Tracer can be run on Linux and Microsoft Windows.
Similar Android and iOS apps are also available. Packet Tracer allows users to create
simulated network topologies by dragging and dropping routers, switches and various
other types of network devices.
➢ A physical connection between devices is represented by a "cable" item.
➢ Packet Tracer supports an array of simulated Application Layer protocols, as well as
basic routing with RIP, OSPF, EIGRP, BGP, to the extents required by the
current CCNA curriculum.
➢ In addition to simulating certain aspects of computer networks, Packet Tracer can also be
used for collaboration. As of Packet Tracer 5.0, Packet Tracer supports a multi-user
system that enables multiple users to connect multiple topologies together over
a computer network.
➢ Packet Tracer also allows instructors to create activities that students have to complete.
Packet Tracer is often used in educational settings as a learning aid.
Static
➢ Routers forward packets using either route information from route table entries that you
manually configure or the route information that is calculated using dynamic routing
algorithms.
9
Subject code : CE 344 Id : 16ce068
➢ Static routes, which define explicit paths between two routers, cannot be automatically
updated; you must manually reconfigure static routes when network changes occur. Static
routes use less bandwidth than dynamic routes. No CPU cycles are used to calculate and
analyze routing updates.
➢ You can supplement dynamic routes with static routes where appropriate. You can
redistribute static routes into dynamic routing algorithms, but you cannot redistribute
routing information calculated by dynamic routing algorithms into the static routing table.
10
Subject code : CE 344 Id : 16ce068
11
Subject code : CE 344 Id : 16ce068
12
Subject code : CE 344 Id : 16ce068
13
Subject code : CE 344 Id : 16ce068
14
Subject code : CE 344 Id : 16ce068
15
Subject code : CE 344 Id : 16ce068
16
Subject code : CE 344 Id : 16ce068
17
Subject code : CE 344 Id : 16ce068
18
Subject code : CE 344 Id : 16ce068
19
Subject code : CE 344 Id : 16ce068
20
Subject code : CE 344 Id : 16ce068
Conclusion
We establish connection between routers, PCs and switches and we can able to send message
from one Pc to another Pc.
21
Subject code : CE 344 Id : 16ce068
PRACTICAL-3
AIM: To configure the concept of Sub-netting and Issues of Sub-netting.
Hardware requirements: pc/laptop.
Knowledge requirements: Basic knowledge about addresses, switch, routers, subnet mask.
Theory:
Subnet :
An IP address has two components, the network address and the host address. A subnet mask
separates the IP address into the network and host addresses (<network><host>). Subnetting
further divides the host part of an IP address into a subnet and host address
(<network><subnet><host>) if additional subnetwork is needed.
A Subnet mask is a 32-bit number that masks an IP address, and divides the IP address into
network address and host address. Subnet Mask is made by setting network bits to all "1"s and
setting host bits to all "0"s. Within a given network, two host addresses are reserved for special
purpose, and cannot be assigned to hosts. The "0" address is assigned a network address and
"255" is assigned to a broadcast address, and they cannot be assigned to hosts.
Examples of commonly used netmasks for classed networks are 8-bits (Class A), 16-bits (Class
B) and 24-bits (Class C), and classless networks are as follows:
Subnetting an IP network is to separate a big network into smaller multiple networks for
reorganization and security purposes. All nodes (hosts) in a subnetwork see all packets
transmitted by any node in a network. Performance of a network is adversely affected under
heavy traffic load due to collisions and retransmissions.
Applying a subnet mask to an IP address separates network address from host address. The
network bits are represented by the 1's in the mask, and the host bits are represented by 0's.
Performing a bitwise logical AND operation on the IP address with the subnet mask produces the
network address. For example, applying the Class C subnet mask to our IP address 216.3.128.12
produces the following network address:
IP: 1101 1000. 0000 0011. 1000 0000. 0000 1100 (216.003.128.012)
Mask: 1111 1111. 1111 1111. 1111 1111. 0000 0000 (255.255.255.000)
22
Subject code : CE 344 Id : 16ce068
---------------------------------------------
1101 1000. 0000 0011. 1000 0000. 0000 0000 (216.003.128.000)
Subnetting Network
Here is another scenario where subnetting is needed. Pretend that a web host with a Class C
network needs to divide the network so that parts of the network can be leased to its customers.
Let's assume that a host has a network address of 216.3.128.0 (as shown in the example above).
Let's say that we're going to divide the network into 2 and dedicate the first half to itself, and the
other half to its customers.
216. 3. 128. (0000 0000) (1st half assigned to the web host)
216. 3. 128. (1000 0000) (2nd half assigned to the customers)
The web host will have the subnet mask of 216.3.128.128 (/25). Now, we'll further divide the
2nd half into eight blocks of 16 IP addresses.
23
Subject code : CE 344 Id : 16ce068
For given IP address 192.168.12.0 create six extra such a way that subnet 1 has 128 host,
Subnet 2 has 64 host, subnet 3 has 32 host and subnet 4,5,6 has 4 host each.
Subnet 1 (128 Host) : -
From: -192.168.12.0 to 192.168.12.127
Subnet mask: -255.255.255.128
No. of address: -25
Network Address: - 192.168.12.0
Wildcard: - 0.0.0.127
Subnet 4 (4 Host): -
From: -192.168.12.224 to 192.168.12.227
Subnet mask: -255.255.255.252
No. of address: -30
Network Address: - 192.168.12.224
Wildcard: - 0.0.0.3
Subnet 5 (4 Host): -
From: -192.168.12.228 to 192.168.12.231
Subnet mask: -255.255.255.252
No. of address: -3
Network Address: - 192.168.12.228
Wildcard: - 0.0.0.3
Subnet 6 (4 Host): -
From: -192.168.12.232 to 192.168.12.235
Subnet mask: -255.255.255.252
No. of address: -30
Network Address: - 192.168.12.232
Wildcard: - 0.0.0.3
24
Subject code : CE 344 Id : 16ce068
25
Subject code : CE 344 Id : 16ce068
26
Subject code : CE 344 Id : 16ce068
27
Subject code : CE 344 Id : 16ce068
28
Subject code : CE 344 Id : 16ce068
For Router 1: -
For Router 2: -
Conclusion
In this practical we learn concept of sub-netting.
29
Subject code : CE 344 Id : 16ce068
PRACTICAL- 4
AIM: To configure DHCP and HTTP server.
Hardware requirements: None
Software requirements: CISCO packet tracer
Knowledge requirements: Basic knowledge about addresses, switch, routers, subnet mask.
Theory :
What is DHCP?
Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a server
to automatically assign an IP address to a computer from a defined range of numbers (i.e., a
scope) configured for a given network.
How DHCP assigns IP addresses
DHCP assigns an IP address when a system is started, for example:
3. The router directs the DISCOVER packet to the correct DHCP server.
4. The server receives the DISCOVER packet. Based on availability and usage policies set
on the server, the server determines an appropriate address (if any) to give to the client.
The server then temporarily reserves that address for the client and sends back to the
client an OFFER (or DHCPOFFER) packet, with that address information. The server
also configures the client's DNS servers, WINS servers, NTP servers, and sometimes
other services as well.
5. The client sends a REQUEST (or DHCPREQUEST) packet, letting the server know that
it intends to use the address.
6. The server sends an ACK (or DHCPACK) packet, confirming that the client has a been
given a lease on the address for a server-specified period of time.
30
Subject code : CE 344 Id : 16ce068
31
Subject code : CE 344 Id : 16ce068
Conclusion
In this practical we are studied about DHCP server and create configure DHCP.
32
Subject code : CE 344 Id : 16ce068
PRACTICAL-5
AIM: To configure DNS server.
Hardware requirements: None
Software requirements: CISCO packet tracer
Knowledge requirements: Basic knowledge about addresses, switch, routers, subnet mask.
Theory :
A DNS server is a type of name server that manages, maintains and processes
Internet domain names and their associated records. In other words, a DNS server is the
primary component that implements the DNS (Domain Name System) protocol and
provisions domain name resolution services to Web hosts and clients on an IP-based
network.
33
Subject code : CE 344 Id : 16ce068
Screenshot
Step 1 Create This Topology
34
Subject code : CE 344 Id : 16ce068
35
Subject code : CE 344 Id : 16ce068
Response by Name
Conclusion
In this practical we are studied What is DNS server and how to configure DNS server.
36
Subject code : CE 344 Id : 16ce068
PRACTICAL-6
AIM: Create a network topology of CE department.
Hardware Requirements : pc / laptop
Theory :
Packet Tracer
➢ Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that
allows users to create network topologies and imitate modern computer networks.
➢ The software allows users to simulate the configuration of Cisco routers and switches
using a simulated command line interface.
➢ Packet Tracer makes use of a drag and drop user interface, allowing users to add and
remove simulated network devices as they see fit.
➢ The software is mainly focused towards Certified Cisco Network Associate Academy
students as an educational tool for helping them learn fundamental CCNA concepts.
RIP (Routing Information Protocol)
➢ The Routing Information Protocol (RIP) is one of the oldest distance-vector routing
protocols which employ the hop count as a routing metric.
➢ RIP prevents routing loops by implementing a limit on the number of hops allowed in a
path from source to destination.
➢ The largest number of hops allowed for RIP is 15, which limits the size of networks that
RIP can support.
➢ RIP implements the split horizon, route poisoning and hold-down mechanisms to prevent
incorrect routing information from being propagated.
Implementation :
37
Subject code : CE 344 Id : 16ce068
38
Subject code : CE 344 Id : 16ce068
Conclusion
In this practical we learn how to implement network topology of any department.
39
Subject code : CE 344 Id : 16ce068
PRACTICAL-7
AIM: Analyze TCP window performance using wireshark.
Theory: Wireshark is very similar to tcpdump, but has a graphical front-end, plus some
integrated sorting and filtering options.
Wireshark lets the user put network interface controllers into promiscuous mode (if supported
by the network interface controller), so they can see all the traffic visible on that interface
including unicast traffic not sent to that network interface controller's MAC address. However,
when capturing with a packet analyzer in promiscuous mode on a port on a network switch, not
all traffic through the switch is necessarily sent to the port where the capture is done, so
capturing in promiscuous mode is not necessarily sufficient to see all network traffic. Port
mirroring or various network taps extend capture to any point on the network. Simple passive
taps are extremely resistant to tampering.
On GNU/Linux, BSD, and macOS, with libpcap 1.0.0 or later, Wireshark 1.4 and later can also
put wireless network interface controllers into monitor mode.
If a remote machine captures packets and sends the captured packets to a machine running
Wireshark using the TZSP protocol or the protocol used by Omni Peek, Wireshark dissects
those packets, so it can analyze packets captured on a remote machine at the time that they are
captured.
Features:
Data can be captured "from the wire" from a live network connection or read from a file
of already-captured packets.
Live data can be read from different types of networks, including Ethernet, IEEE
802.11, PPP, and loopback.
Captured network data can be browsed via a GUI, or via the terminal (command line)
40
Subject code : CE 344 Id : 16ce068
VoIP calls in the captured traffic can be detected. If encoded in a compatible encoding,
the media flow can even be played.
When Wire shark’s install is started or the portable version is run for the first time, you will
be asked to install the included ‘Windows Packet Capture’ (WinPcap) library and driver as
well. This is obviously a drawback if you want a truly portable application but
unfortunately, is required to capture the network packets. If WinPcap is already detected on
the system, this part will be automatically skipped. Once installed under Windows or
Linux, the default interface is pretty much the same.
Implementation:
First of all open wireshark tool and then click on LAN, Ethernet or Wi-Fi as per your wish.
Click on it and go to the option for starting the scan after it wait for some time. And then it will
display something like this
41
Subject code : CE 344 Id : 16ce068
After it there has been mentioned the time, source, destination and the protocols in which
they work and it’s some general information.
Click on the any of the option provided here clicking on the Domain name system and so on
you can monitor and capture the packets of that network
Here you can see that here there is a possibility that you can only capture packets on the Http
or Tcp protocol you cannot capture packets on the Https.After wards you can save It to the
.pcap file for further purpose.
The best one you can try on the http website click on login in the website and the start scan
you will see that website in it after you click on it will show you the username and password
of that site that you have been login.
Conclusion
From this Practical I understood about the wireshark tool how to capture packets etc.
42
Subject code : CE 344 Id : 16ce068
PRACTICAL-8
AIM: Find and Compare latency using Wireshark.
Theory:
The first way to show IO information is the Wireshark IO Graph, in Statistics > IO Graph.The IO
graph shows a time series of network traffic, which you can change the resolution and scale of,
and filter.User configurable graph of the captured network packets.We can define up to five
differently colored graphs.The user can configure the following things:
● Graphs
o Graph 1-5: enable the specific graph 1-5 (only graph 1 is enabled by default)
o Color: the color of the graph (cannot be changed)
o Filter: a display filter for this graph (only the packets that pass this filter will be taken into
account for this graph)
o Style: the style of the graph (Line/Impulse/FBar/Dot)
● X Axis
o Tick interval: an interval in x direction lasts (10/1 minutes or 10/1/0.1/0.01/0.001 seconds)
o Pixels per tick: use 10/5/2/1 pixels per tick interval
o View as time of day: option to view x direction labels as time of day instead of seconds or
minutes since beginning of capture
● Y Axis
o Unit: the unit for the y direction (Packets/Tick, Bytes/Tick, Bits/Tick, Advanced…)
[XXX - describe the Advanced feature.]
o Scale: the scale for the y unit (Logarithmic,Auto,10,20,50,100,200,500,…)
The Save button will save the currently displayed portion of the graph as one of various file
formats.
The Copy button will copy values from selected graphs to the clipboard in CSV (Comma
Separated Values) format.
43
Subject code : CE 344 Id : 16ce068
Conclusion
Studied to compare the overall traffic in different capture files using wireshark.
44
Subject code : CE 344 Id : 16ce068
PRACTICAL-9
AIM: Create a simple point-to-point link between two nodes and
echo a single packet between the nodes using NS-3.
Script:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
45
Subject code : CE 344 Id : 16ce068
46
Subject code : CE 344 Id : 16ce068
47
Subject code : CE 344 Id : 16ce068
Conclusion
Studied how to create a point-to-point link using NS-3 and analyzed it using wireshark.
48
Subject code : CE 344 Id : 16ce068
PRACTICAL-10
AIM: Add a CSMA network to the point-to-point simulation of
practical-9.
Script :
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
NS_LOG_COMPONENT_DEFINE ("Practical6Example");
int main (int argc, char *argv[]) {
CommandLinecmd;
cmd.Parse (argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (3);
PointToPointHelperpointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainerdevice,device1;
device = pointToPoint.Install (nodes.Get(0),nodes.Get(1));
device1 = pointToPoint.Install (nodes.Get(2),nodes.Get(1));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interface = address.Assign (device);
Ipv4InterfaceContainer interface1 = address.Assign (device1);
UdpEchoServerHelperechoServer (9);
ApplicationContainerserverApps = echoServer.Install (nodes.Get (1));
49
Subject code : CE 344 Id : 16ce068
MobilityHelper mobility;
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
AnimationInterfaceanim ("prac6.xml");
AnimationInterface::SetConstantPosition (nodes.Get (0), 10, 25);
AnimationInterface::SetConstantPosition (nodes.Get (1), 30, 25);
AnimationInterface::SetConstantPosition (nodes.Get (2), 50, 25);
anim.EnablePacketMetadata (true);
pointToPoint.EnablePcapAll ("prac6");
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Output:
50
Subject code : CE 344 Id : 16ce068
Conclusion
Studied how to create a point-to-point link using NS-3 and analyzed it using wireshark.
51
Subject code : CE 344 Id : 16ce068
PRACTICAL-11
AIM: Create Wireless Network using Wi-Fi helper object in
NS-3.
Script:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[]) {
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = false;
CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
if (nWifi > 18) {
std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the bounding box" <<
std::endl;
return 1; }
if (verbose) {
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); }
NodeContainer p2pNodes;
52
Subject code : CE 344 Id : 16ce068
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
53
Subject code : CE 344 Id : 16ce068
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
address.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
if (tracing == true) {
pointToPoint.EnablePcapAll ("third");
phy.EnablePcap ("third", apDevices.Get (0));
csma.EnablePcap ("third", csmaDevices.Get (0), true); }
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
54
Subject code : CE 344 Id : 16ce068
Output:
Conclusion
Studied how to create a point-to-point link using NS-3 and analyzed it using wireshark.
55
Subject code : CE 344 Id : 16ce068
PRACTICAL-12
AIM: Introduction and demonstration of simulation in Contiki
OS with Cooja tool.
Hardware Requirement:- N/A.
Software Requirement:- Contiki-OS, Cooja tool
Theory:-
Contiki-OS
Contiki is an operating system for networked, memory-constrained systems with a focus on low-
power wireless Internet of Things devices. Extant uses for Contiki include systems for street
lighting, sound monitoring for smart cities, radiation monitoring, and alarms. It is open-source
software released under a BSD license.
Step to simulation in Contiki-OS with Cooja tool:-
Step-1: Start Instant Contiki by running InstantContiki2.6.vmx. Wait for the virtual Ubuntu
Linux boot up. Log into Instant Contiki. The password is “user”.
56
Subject code : CE 344 Id : 16ce068
Step-2: To start Cooja, first open a terminal window. In the terminal window, go to the
Cooja directory. Start Cooja with the command: “ ant run “.
Step-3: To create new simulation, click the “File” menu and click “New simulation”. Cooja
now opens up the Create new simulation dialog. In this dialog, we may choose to give our
simulation a new name. Click the Create button.
57
Subject code : CE 344 Id : 16ce068
58
Subject code : CE 344 Id : 16ce068
Step-5: To add new motes go to the Motes menu, click on Add motes. Click Create new mote
type... and select one of the available mote types.
Step-6: Cooja opens the Create Mote Type dialog, in which we can choose a name for our
mote type as well as the Contiki application that our mote type will run. Click on the Browse...
button on the right hand side to choose our Contiki application.
59
Subject code : CE 344 Id : 16ce068
Step-7: Now Cooja will verify that the selected Contiki application compiles for the platform
that we have selected. Click the Compile button.
60
Subject code : CE 344 Id : 16ce068
Step-8: Cooja will now ask us if we want to add motes from the newly created mote type to the
simulation.
61
Subject code : CE 344 Id : 16ce068
62
Subject code : CE 344 Id : 16ce068
Here, Mote 1 is working as sink so it will receive all the message from this radio
environment. All other mote will send message to mote 1.
Step-10: We see printouts from the simulated motes appearing in the Mote output window.
The Network window shows communication going on in the network. The Timeline window
shows communication and radio events over time - the small gray lines are ContikiMAC
periodically waking the radio up. We can click the Pause button to pause the simulation.
63
Subject code : CE 344 Id : 16ce068
Conclusion
From this practical, we know about how we can perform simulation in Contiki-OS with Cooja
tool.
64