You are on page 1of 47

Student Lab Manual

Third Year Semester-VI


Electronics & Telecommunication Engineering

Subject: Computer Communication Network

Even Semester

Faculty: Mr.Somnath Tandale


Institutional Vision, Mission and Quality Policy

Our Vision
To foster and permeate higher and quality education with value added engineering, technology
programs, providing all facilities in terms of technology and platforms for all round development with
societal awareness and nurture the youth with international competencies and exemplary level of
employability even under highly competitive environment so that they are innovative adaptable and
capable of handling problems faced by our country and world at large.

RAIT’s firm belief in new form of engineering education that lays equal stress on academics and
leadership building extracurricular skills has been a major contribution to the success of RAIT as one
of the most reputed institution of higher learning. The challenges faced by our country and world in the
21 Century needs a whole new range of thought and action leaders, which a conventional educational
system in engineering disciplines are ill equipped to produce. Our reputation in providing good
engineering education with additional life skills ensure that high grade and highly motivated students
join us. Our laboratories and practical sessions reflect the latest that is being followed in the Industry.
The project works and summer projects make our students adept at handling the real life problems and
be Industry ready. Our students are well placed in the Industry and their performance makes reputed
companies visit us with renewed demands and vigour.

Our Mission
The Institution is committed to mobilize the resources and equip itself with men and materials of
excellence thereby ensuring that the Institution becomes pivotal center of service to Industry, academia,
and society with the latest technology. RAIT engages different platforms such as technology enhancing
Student Technical Societies, Cultural platforms, Sports excellence centers, Entrepreneurial
Development Center and Societal Interaction Cell. To develop the college to become an autonomous
Institution & deemed university at the earliest with facilities for advanced research and development
programs on par with international standards. To invite international and reputed national Institutions
and Universities to collaborate with our institution on the issues of common interest of teaching and
learning sophistication.

RAIT’s Mission is to produce engineering and technology professionals who are innovative and
inspiring thought leaders, adept at solving problems faced by our nation and world by providing quality
education.

The Institute is working closely with all stake holders like industry, academia to foster knowledge
generation, acquisition, dissemination using best available resources to address the great challenges
being faced by our country and World. RAIT is fully dedicated to provide its students skills that make
them leaders and solution providers and are Industry ready when they graduate from the Institution.

iii
We at RAIT assure our main stakeholders of students 100% quality for the programmes we deliver. This
quality assurance stems from the teaching and learning processes we have at work at our campus and
the teachers who are handpicked from reputed institutions IIT/NIT/MU, etc. and they inspire the
students to be innovative in thinking and practical in approach. We have installed internal procedures
to better skills set of instructors by sending them to training courses, workshops, seminars and
conferences. We have also a full fledged course curriculum and deliveries planned in advance for a
structured semester long programme.

We have well developed feedback system employers, alumni, students and parents from to fine tune
Learning and Teaching processes. These tools help us to ensure same quality of teaching independent
of any individual instructor. Each classroom is equipped with Internet and other digital learning
resources.

The effective learning process in the campus comprises a clean and stimulating classroom environment
and availability of lecture notes and digital resources prepared by instructor from the comfort of home.
In addition student is provided with good number of assignments that would trigger his thinking process.
The testing process involves an objective test paper that would gauge the understanding of concepts by
the students. The quality assurance process also ensures that the learning process is effective. The
summer internships and project work based training ensure learning process to include practical and
industry relevant aspects. Various technical events, seminars and conferences make the student learning
complete.

Our Quality Policy

Our Quality Policy


It is our earnest Endeavour to produce high quality engineering professionals who are
innovative and inspiring, thought and action leaders, competent to solve problems faced
by society, nation and world at large by striving towards very high standards in learning,
teaching and training methodologies.
Our Motto: If it is not of quality, it is NOT RAIT!

Dr. Vijay D.Patil


President, RAES

iv
Departmental Vision, Mission
Mission
 To impart quality and value based education to be at par with the state of art technology.

 To provide strong foundation for analyzing and designing various communication systems and
develop an intuition to implement global information transportation and computing
communication system.

 To create competent professionals who are trained in the design and development of the
system using software and hardware tools such as Matlab, Simulation Network (NS2), Qualnet
etc.

 To build the team spirit, develop the area for higher and continuing education and develop
better outlook skills driven by social, economical and technological reasons.

 To bridge the gap between the curriculum and industries, expertise guest lectures are arranged
by eminent persons from industries and various reputed organizations.

 Students are promoted to participate in industrial training and NGO camps for welfare of
society during semester break.

Vision
To be a place of academic excellence by imparting quality education and carrying out research and
technology in frontier areas of Electronics And Telecommunication and to produce competent leaders
to face challenges of the global village, strive towards producing world class engineers who will
continuously innovate, upgrade telecommunication technology and provide advanced, hazard-free
solutions to the mankind inspire, educate and empower students to ensure green and sustainable society.

v
Index
Sr. No. Contents Page No.

1. List of Experiments 1

2. Experiment Plan and Course Outcomes 2

3. Study and Evaluation Scheme 3

4. Experiment No. 1 5

5. Experiment No. 2 20

6. Experiment No. 3 24

7. Experiment No. 4 28

8. Experiment No. 5 32

9. Experiment No. 6 37

10. Experiment No. 7 42

11. Experiment No. 8 50

12. Experiment No. 9 55

13. Experiment No. 10 61

14 Experiment No. 11 67

vi
List of Experiments
Sr. No. Experiment Name
1
2
3
4
5
6
7
8
9
10

11

1
Experiment Plan & Course Outcome
Course Outcomes:

CO1

CO2

CO3

CO4

CO5

CO6

2
Study and Evaluation Scheme
Course
Course Name Teaching Scheme Credits Assigned
Code
Computer Theory Practical Tutorial Theory Practical Tutorial Total
ECL
Communic
602 ation -- 02 -- -- 01 -- 01
Network
Laboratory

Course Code Course Name Examination Scheme


Computer Term Work Oral Total
ECL
Communicat
602 25 25 50
ion Network
Laboratory

Term Work:

1. Term work assessment must be based on the overall performance of the student with every
experiment graded from time to time. The grades should be converted into marks as per
the Credit and Grading System manual and should be added and averaged.
2. The final certification and acceptance of term work ensures satisfactory performance of
laboratory work and minimum passing marks in term work.

Oral: Oral exam will be based on the entire syllabus.

3
Computer

Communication Network

4
Experiment No. 1

1A. Study of Network Hardware Components.


1B.To prepare Patch Cable

5
EXPERIMENT-1(A)

Aim: To study network hardware components.


Objective: To study the operation of Repeater, bridge, router, hub and other
networking components in detail.

THEORY:-
Some of the important network hardware components are repeaters, hubs, bridges, switches,
routers, brouters, gateways and Network interface cards. Each one of them is described in
brief as follows:
Repeaters: Repeater is a length of cable used to influence the quality of communication. It
is a physical layer device. It only works with the physical signal. Repeaters cannot reformat,
resize, or manipulate the data. Repeaters repeat signals. They boost digital transmission.
Analog networks use amplifiers to boost signal.

Advantages of using repeaters:


 Extend network physical distance
 Do not seriously affect network performance
 Special repeaters connect different media
(e.g. Copper to fiber)
Disadvantages of using repeaters:
 Cannot connect different network architectures
 (e.g. Token Ring and Ethernet)

6
 Cannot reduce network traffic
 Do not segment the network
 Repeat everything without discrimination
 Number of repeaters must be limited
 Repeaters are part of a collision domain

Hubs: Hub is a Physical layer (layer 1) device. It connects several networking cables together. A
hub connects individual devices on an Ethernet network so that they can communicate with one
another. The hub operates by gathering the signals from individual network devices, optionally
amplifying the signals, and then sending them onto all other connected devices.

Bridges: Bridges operate at the Data Link layer. They forward or drop frames. They cannot filter
broadcasts.
Transparent Bridges:

• Also called learning bridges


• Build a table of MAC addresses as frames arrive
• Ethernet networks use transparent bridges
• Token Ring networks use source-routing bridges

Source-Routing Bridges:
• Used in Token Ring networks

7
• Rely on source for the frame transmission
• Explore frames

Translation Bridges:
• Connect networks with different network architecture
• Example:
• Token ring connecting to Ethernet

Advantages of using a bridge:


• Extend physical network
• Reduce network traffic with minor segmentation
• Creates separate collision domains
• Reduce collisions
• Connect different architecture

Disadvantages of using a bridge:


• Slower than repeaters due to filtering
• Do not filter broadcasts
• More expensive than repeaters

Switches:
• Operate at the Data Link layer
• Increase network performance
• Virtual circuits between source and destination
8
• Micro segmentation
• Multiple virtual circuits are called “switched bandwidth”
• Between two computers using a switch two collision domains are created each with
dedicated bandwidth
• Between two hubs using a switch two collision domains are created each with shared
bandwidth
• Filter based on MAC addresses
• Build tables in memory

Advantages of switches:
• Increase available network bandwidth
• Reduced workload, computers only receive packets intended for them
specifically
• Increase network performance
• Smaller collision domains
Disadvantages of switches:
• More expensive than hubs and bridges
• Difficult to trace network connectivity problems through a switch
• Does not filter broadcast traffic
Routers:

• Provide filtering and network traffic control


• Used on LANs and WANs
• Connect multiple segments and networks
• Multiple routers create an “internetwork”
• Operate at the Network layer
• Create a table to determine how to forward packets
• Filtering and traffic control base on logical addresses

9
Advantages of routers:
• Can connect networks of different architecture (e.g.
Token Ring to Ethernet)
• Choose best path through or to a network
• Create smaller collision domains
• Create smaller broadcast domains

Disadvantages of routers:

• Only work with routable protocols


• More expensive than hubs, bridges, and switches
• Routing table updates consume bandwidth
• Increase latency due to a greater degree of packet filtering and/or
analyzing

10
Brouters :

• Hybrid device
• Functions as a router for routable protocols

• Functions as a bridge for non-routable protocols


• Operates at Data Link and Network layers

Gateways:

• A gateway is a combination of hardware and software


• Translate between different protocol suites
• Operates on all 7 layers of the OSI model
• Most negative on network performance Latency.

11
EXPERIMENT-1(B)

OBJECTIVE: - To prepare patch cable.

PATCH CABLE:-
Patch cable is hardware media which is used for interconnection between PC, Hub, Router,
Switch and other network components. Equipments required for that are UTP cable
(10m or more), RJ-45 connector, and crimping tool. We will prepare a patch cable in
laboratory.

THEORY:

• The pairs of wires in UTP cable are colored so that you can identify the same wire
at each end.
• Furthermore, they are usually color coded by pair so that the pairs can also be
identified from end to end.
• When the pairs are inserted into the RJ-45 plug the colors should be as shown in the
pin outs for different cables below:
Pin out for straight through cable:

12
(1) White /Orange >> White / Orange (1)
(2) Orange >> Orange (2)
(3) White / Green >> White / Green (3)

(4) Blue >> Blue (4)


(5) White / Blue >> White / Blue (5)

(6) Green >> Green (6)


(7) White/Brown >> White / Brown (7)
(8) Brown >> Brown (8)

Pin out for crossover cable:

(1) White /Orange >> White / Green (3)


(2) Orange >> Green (6)
(3) White / Green >> White / Orange (1)

(4) Blue >> Blue (4)


(5) White / Blue >> White / Blue (5)
(6) Green >> Orange (2)

(7) White/Brown >> White / Brown (7)


(8) Brown >> Brown (8)

Pin out for Rollover cable:

(1) White /Orange >> Brown (8)


(2) Orange >> White/Brown (7)
(3) White / Green >> Green (6)
(4) Blue >> White / Blue (5) 13
(5) White / Blue >> Blue (4)
(6) Green >> White / Green (3)
(7) White/Brown >> Orange (2)
(8) Brown >> White /Orange (1)

APPLICATIONS:
To connect:
1) PC to PC: crossover cable.
2) Hub to hub : Straight through
3) Router to PC: crossover cable.
4) Switch to Switch: crossover cable.
5) Router to Switch : Straight through
6) Switch to Hub : Straight through

To connect manageable devices to the PC for the purpose of configuring We use


the rollover cable.
E.g. Router to PC ,Manageable switch
to PC. Layer 3 switch.

PROCEDURE:

Crimping Procedure:

 The correct type of cable must be selected and this must be stranded UTP for a patch
cable.
 A suitable length of cable is cut.
 At least 2 cm of the cable sheath has to be stripped to expose the inner pairs.
 Then the pair of cables has to be untwisted.
 The colored wires should be placed in the correct order using the wiring diagram,
according to the stranded color coding.

14
 The inner wires should be cut such that they are exactly the same length and just long
enough to reach the RJ 45 connector , with the bridge positioned over the cable sheath.
 The connector has to be positioned with the spring lever at the bottom.
 The wires are pushed into the connector such that the copper core should be visible from
the end of the connector.
 The wires have to be checked to see if they are in the correct order.
 The RJ 45 connection is pushed into the crimping tool and the handles are squeezed.
 The cables are checked to see if they are pierced and the bridge is over the cable sheath.

 The same procedure is repeated for the other end of the cable.
 The cable is tested using a cable tester. This is useful in identifying Any
crossed wires or those which do not make contact.

CONCLUSION:

15
EXPERIMENT NO. 2(A)

AIM: To Linux Basic Commands


REQUIREMENT: Ubuntu Operating System
THEORY:

Some of the basic Linux Ubuntu commands are as follows:


 ls :
List contents of the directory
 ls -l :
Use long listing format to list contents of the directory
 ls -la :
List all hidden files in the directory
 ls -li :
Print Index number of each file
 touch file_name :
Make an empty file
 cat > file_name :
To write contents to the file
 gedit:
To open an empty document
 gedit file1:
To open a file with its name
 mkdir directory_name :
To make a directory
 rm file_name :
To delete the file
 rmdir directory_name :
To delete the directory

16
 cp file1 file2 :
Copy contents of file1 to file2 (Overwrite file2)
 pwd :
To view the present working directory
 cd :

17
To change the present directory

 cd ..
To move one directory back.
 mv file1 file2 :
Overwrites file2 with contents of file1 and file1 gets deleted
 useradd user_name :
Used to create a new user
 groupadd grp_name :
Used to add a new group
 userdel user_name :
Used to delete an existing user
 groupdel grp_name :
Used to delete an existing group
 cp /home/siesgst/directory2/file2 /home/siesgst/directory1/file1

To copy a file from one directory to another directory


 cal:
To display current calendar
 hostname :
To display hostname of computer
 shutdown now :
To shut down the computer
Output: Run above all Linux command in Ubuntu/Linux ,and attach its print copy as output

CONCLUSION:

18
Experiment No. : 2(B)

AIM: Introduction to network commands (ifconfig, ping, Netstat, traceroute, nslookup, tcpdump,
ethtool, arp)
REQUIREMENT: Ubuntu operating System
THEORY:

Ifconfig commands:
ifconfig is used to configure, or view the configuration of, a network interface. ifconfig stands
for "interface configuration". It is used to view and change the configuration of the network
interfaces on your system.
ifconfig displays information about all network interfaces currently in operation (all active interfaces
like eth0, lo).
Ifconfig -a
This will produce output similar to simply running ifconfig, but if there are any inactive

interfaces on the system, their configuration will also be displayed.

Ifconfig eth0 will display the configuration of device eth0 only


Ifconfig eth0 up To activate eth0 interface if it is inactive
Ifconfig eth0 down To deactivate eth0 interface
Ifconfig eth0 To assign IP address on eth0 interface
10.0.0.1 netmask
255.0.0.0 up
Ifconfig eth0 To remove the IP address from eth0 interface
10.0.0.1 netmask
255.0.0.0 down

Ping commands:

Ping is a simple way to send network data to, and receive network data from, another computer
on a network. It is frequently used to test, at the most basic level, whether another system is
reachable over a network, and if so, how much time it takes for that data to be exchanged. The
ping utility uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP
ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams ("pings") have an
IP and ICMP header, followed by a struct timeval and then an arbitrary number of "pad" bytes
used to fill out the packet.

19
Ping www.google Ping www.google.com to see if it is alive
.com
Ping 10.0.0.1 Ping self machine (computer) with its IP address
Ping 10.0.0.2 Ping any other machine with its IP address to see if it is reachable.
Ping 10.0.0.2 –i 6 Generate Ping statistics at an interval of every seconds.
Ping 10.0.0.2 –c 5 Generate Ping statistics for packet count of 5.

Traceroute commands

Traceroute prints the route that packets take to a network host. traceroute attempts to trace the
route an IP packet would follow to some internet host by launching probe packets with a small ttl
(time to live) then listening for an ICMP "time exceeded" reply from a gateway. It start its probes
with a ttl of one and increases this by one until it gets an ICMP "port unreachable" (or TCP reset),
which means we got to the "host", or hit a max (which defaults to 30 hops). Three probes (by
default) are sent at each ttl setting and a line is printed showing the ttl, address of the gateway and
round trip time of each probe. The address can be followed by additional information when
requested. If the probe answers come from different gateways, the address of each responding
system will be printed. If there is no response within a 5.0 seconds (default), an "*" (asterisk) is
printed for that probe.

Traceroute Trace the route that packets take between your system and the www.google.com, using the
www.google.com default method (udp datagram, 16 simultaneous probes).

nslookup commands:

The nslookup command is used to query internet name servers interactively for information.
nslookup, which stands for "name server lookup", is a useful tool for finding out information
about a named domain. By default, nslookup will translate a domain name to an IP address (or
vice versa)

nslookup Finds out the IP address of www.google.com


www.google.com
nslookup Finds out the domain name for the IP address
134.170.185.46

20
Ethtool commands:
In Linux kernel-based operating systems, ethtool is a utility for viewing and modifying network
interface controller parameters and device drivers.
ethtool eth0 displays the parameters for the primary NIC
ethtool –s eth0 Sets the speed of NIC to 100 Mega bits per second
speed 100

ARP commands:
Short for Address Resolution Protocol, ARP is a used with the IP for mapping a 32-bit Internet
Protocol address to a MAC address that is recognized in the local network.
arp -a Display current ARP entries. Can include more than one network interface.
If ip_addr is specified, the IP and Physical addresses for only the specified computer are
displayed.

Netstat commands:
Netstat is a command line utility that can be used to list out all the network (socket) connections
on a system. It lists out all the tcp, udp socket connections and the unix socket connections. Apart
from connected sockets it can also list listening sockets that are waiting for incoming connections.
So by verifying an open port 80 you can confirm if a web server is running on the system or not.
This makes it a very useful tool for network and system administrators.
$ netstat –a The first and most simple command is to list out all the current connections from different
protocols like tcp, udp and unix sockets. Simply run the netstat command with the a option.
$ netstat –at To list out only tcp connections use the t options.
$ netstat –au to list out only udp connections use the u option.
$ netstat -l Display all listening ports
$ netstat -lt Display all TCP listening ports
$ netstat -lu Display all UDP listening ports
$ netstat -lx Display all Unix listening ports
$ netstat -s Print statistics. The netstat command can also print out network statistics like total number
of packets received and transmitted by protocol type and so on.
$ netstat –i Print network interfaces. The netstat command can also print out the information about the
network interfaces. The i option does the task.
$ netstat –ct Netstat can output connection information continuously with the c option.
$ netstat –g The g option will display the multicast group information for IPv4 and IPv6 protocols.
$ netstat -r to show the IP routing table. This is the same as using the route command to execute route
print.

21
nslookup commands:

The nslookup command is used to query internet name servers interactively for information.
nslookup, which stands for "name server lookup", is a useful tool for finding out information
about a named domain.
nslookup microsoft.com By default, nslookup will translate a domain name to an IP address
nslookup 134.170.185.46 perform the above operation in reverse by providing the IP address rather than
the domain name.
nslookup -type=ns The NS Record of a domain is a map of all name servers that are authoritative for
microsoft.com that domain. You can query a domain's NS Record using the option -type=ns,

22
nslookup -type=mx You can query a domain for its MX Record using the -type=mx option.
microsoft.com
nslookup -type=soa The SOA ("Start Of Authority") Record for a domain provides technical
microsoft.com information about the domain. It can be queried with the option -type=soa.
nslookup -type=any view all available NS records for a domain by using the option -type=any.
microsoft.com
nslookup microsoft.com By default, nslookup will query the same DNS the system is configured to use for
ns1.msft.net all network operations. You can specify a custom DNS to query, however, by
specifying it on the command line.
nslookup -port=54 By default, domain name servers accept queries on port 53. If this is configured
microsoft.com differently on the server you are trying to query, you can specify another port
number using the -port= option: Here, the query attempt failed because our DNS
uses the standard port, number 53.
nslookup -debug to examine more closely the details of the query transaction.
microsoft.com

PING Commands
PING (Packet INternet Groper) command is the best way to test connectivity between two nodes.
Whether it is Local Area Network (LAN) or Wide Area Network (WAN). Ping use ICMP
(Internet Control Message Protocol) to communicate to other devices. You can ping host name
of ip address using below command. ping uses the ICMP protocol’s mandatory
ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.
ECHO_REQUEST datagrams (“pings”) have an IP and ICMP header, followed by a struct
timeval and then an arbitrary number of “pad” bytes used to fill
out the packet.
$ ping google.com Ping the host to see if its alive

$ ping -i 5 google.com Increase or Decrease the Time Interval Between Packets

$ ping -c 4 google.com Send N packets and stop

$ ping -c 5 -q 127.0.0.1 Print Only Ping Command Summary Statistics

$ ping -s 100 localhost Change Ping Packet Size


$ ping -w 5 localhost Timeout. The following example will ping for 5 seconds. i.e ping command will
exit after 5 seconds irrespective of how many packets are sent or received.
$ ping -R 192.168.1.63 Record and print route of how ECHO_REQUEST sent and ECHO_REPLY
received
$ ping -a IP Audible ping: Give beep when the peer is reachable

23
Tcpdump commands
Tcpdump command is also called as packet analyzer. tcpdump allows us to save the packets that are
captured, so that we can use it for future analysis. The saved file can be viewed by the same
tcpdump command. We can also use open source software like wireshark to read the tcpdump
pcap files.

$ tcpdump -i eth1 Capture packets from a particular ethernet interface using tcpdump -i
$ tcpdump -c 2 -i eth1 Capture only N number of packets using tcpdump -c
$ tcpdump -A -i eth1 Display Captured Packets in ASCII using tcpdump -A
$tcpdump -XX -i eth1 Display Captured Packets in HEX and ASCII using tcpdump -XX
$ tcpdump -w file.pcap -i eth1 Capture the packets and write into a file using tcpdump -w
$tcpdump -tttt -r file.pcap Reading the packets from a saved file using tcpdump -r
$ tcpdump -n -i eth1 Capture packets with IP address using tcpdump -n
$ tcpdump -n -tttt -i eth1 Capture packets with proper readable timestamp using tcpdump -tttt
$ tcpdump -w g_1024.pcap greater Read packets longer than N bytes
1024
$ tcpdump -w l_1024.pcap less Read packets lesser than N bytes
1024
$ tcpdump -i eth1 arp Receive only the packets of a specific protocol type

CONCLUSION:

24
Experiment No. : 3

1. Aim: Study of Network Simulator: -NS2

2. What will you learn by studying this experiment?


Students can understand and learn about an open-source simulation tool NS-2, that runs on
Linux. It is a discreet event simulator targeted at networking research and provides
substantial support for simulation of routing, multicast protocols and IP protocols.

3. Software Required: NS-2

4. Theory:

Introduction to NS-2:
 Widely known as NS2, is simply an event driven simulation tool.
 Useful in studying the dynamic nature of communication networks.
 Simulation of wired as well as wireless network functions and protocols (e.g., routing
algorithms, TCP, UDP) can be done using NS2.
 In general, NS2 provides users with a way of specifying such network protocols and
simulating their corresponding behaviors.

Basic Architecture of NS2:

Figure 1: Architecture of NS2

25
TCL scripting
• Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as UNIX, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.

Basics of TCL
Syntax: command arg1 arg2 arg3
 Hello World!
Puts stdout{Hello, World!}
Hello, world!
 Variables Command Substitution
set a 5 set len [string length foobar]
set b $a set len [expr [string length foobar] + 9]

 Procedures
proc Diag {a b} {
set c [expsqrt($a*$a+ $b * $b)]
return $c }
puts ―Diagonal of a 3, 4 right triangle is [Diag 3 4]‖
Output: Diagonal of a 3, 4 right triangle is 5.0
 Loops
while{$i < $n} { for {set i 0} {$i < $n} {incr i} {
... ...
} }
Wired TCL Script Components
 Create the event scheduler
 Open new files & turn on the tracing
 Create the nodes
 Setup the links
 Configure the traffic type (e.g., TCP, UDP, etc)
 Set the time of traffic generation (e.g., CBR, FTP)
 Terminate the simulation
26
NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.

Initialization and Termination of TCL Script in NS-2


An ns simulation starts with the command

Set ns [new simulator]

Which is thus the first line in the tcl script? This line declares a new variable as using the set command,
you can call this variable as you wish, In general people declares it as ns because it is an instance of the
Simulator class, so an object the code [new Simulator] is indeed the installation of the class Simulator
using the reserved word new. In order to have output files with data on the simulation (trace files) or
files used for visualization (nam files), we need to create the files using ―open command:

#Open the Trace file

set tracefile1 [open out.tr w]


$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open out.nam w]


$ns namtrace –all $namfile

The above creates a dta trace file called ―out.tr and a nam visualization trace file
called out.nam. Within the tcl script, these files are not called explicitly by their names, but instead by
pointers that are declared above and called ―tracefile1 and ―namfile respectively. Remark that they
begins with a # symbol. The second line open the file ―out.tr to be used for writing, declared with the
letter ―w‖. The third line uses a simulator method called trace-all that have as parameter the name of
the file where the traces will go.The last line tells the simulator to record all simulation traces in NAM
input format. It also gives the file name that the trace will be written to later by the command $ns flush-
trace. In our case, this will be the file pointed at by the pointer ―$namfile,i.e the file ―out.tr.
The termination of the program is done using a ―finish procedure.

#Define a finish procedure


27
Proc finish {}{
global ns tracefile namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
}

The word proc declares a procedure in this case called finish and without arguments. The word global
is used to tell that we are using variables declared outside the procedure. The simulator method ―flush-
C
trace” will dump the traces on the respective files. The tcl command ―close” closes the trace files
defined before and exec executes the nam program for visualization.l The command exit will ends the
application and return the number 0 as status to the system. Zero isothe default for a clean exit. Other
values can be used to say that is a exit because something fails.
s
At the end of ns program we should call the procedure ―finish and specify at what time the termination
should occur. For example, e

$
$ns at 125.0 “finish”
n
will be used to call ―finish at time 125sec. Indeed,the at method of the simulator allows us to
schedule events explicitly. The simulation can then begin using theacommand
m
$ns run
 f
 i
Definition of a network of links and nodes
The way to define a node is l
 set n0[$ns node] e

 E

 x

 e
 c
The node is created which is printed by the variable n0. When we shall refer to that node in the
n
28
a

m
script we shall thus write $n0. Once we define several nodes, we can define the links that connect
them. An example of a definition of a link is

$ns duplex-link $n0- $n2 10 Mb 10 ms Drop Tail

which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of propagation
delay and a capacity of 10Mb per sec for each direction. To define a directional link instead of a bi-
directional one, we should replace ―duplex-link by ―simplex-link. In NS, an output queue of a
node is implemented as a part of each link whose input is that node. The definition of the link then
includes the way to handle overflow at that queue.

In our case, if the buffer capacity of the output queue is exceeded then the last packet to arrive is
dropped. Many alternative options exist, such as the RED (Random Early Discard) mechanism, the
FQ (Fair Queuing), the DRR (Deficit Round Robin), the stochastic Fair Queuing (SFQ) and the CBQ
(which including a priority and a round-robin scheduler).
In ns, an output queue of a node is implemented as a part of each link whose input is that node. We
should also define the buffer capacity of the queue related to each link.

An example would be:

#set Queue Size of link (n0-n2) to 20

$ns queue-limit $n0 $n2 20

Agents and Applications


29
We need to define routing (sources, destinations) the agents (protocols) the application that use them.

FTP over TCP


TCP is a dynamic reliable congestion control protocol. It uses Acknowledgements created by the
destination to know whether packets are well received.
There are number variants of the TCP protocol, such as Tahoe, Reno, New Reno, Vegas. The type of
agent appears in the first line:

set tcp [new Agent/TCP]

The command $ns attach-agent $n0 $tcp defines the source node of the tcp connection.
The command

set sink [ new agent/TCP sink]

Defines the behavior of the destination node of TCP and assigns to it a pointer called sink.

#Setup a UDP connection

Set udp[ new agent/UDP]


$ns attach-agent $n1 $udp
Set null[ new agent/Null]
$ns attach- agent $n5 $null
$ns connect $udp $null
$udp set fid 2

$
n
s
a
t
t
a
c
h
-
a
g
#setup a CBR over UDP connection
e
n 30
t
$
n
1
The below shows the definition of a CBR application using a UDP agent
The command $ns attach-agent $n4 $sink defines the destination node. The command $ns connect
$tcp$sink finally makes the TCP connection between the source and destination nodes.

Set cbr[ new Application/Traffic/CBR]


$cbr attach-agent $udp
$cbr set packetsize_100
$cbr set rate_0.01MB
$cbr set random_false

TCP has many parameters with initial fixed defaults values that can be changed if mentioned explicitly.
For example, the default TCP packet size has a size of 1000bytes.This can be changed to another value,
say 552bytes, using the command $tcp set packet Size_ 552.
When we have several flows, we may wish to distinguish them so that we can identify them with
different colors in the visualization part. This is done by the command $tcp set fid_ 1 that assigns to
the TCP connection a flow identification of ―1‖.We shall later give the flow identification of ―2 to the
UDP connection.

CBR over UDP


A UDP source and destination is defined in a similar way as in the case of TCP.
Instead of defining the rate in the command $cbr set rate_ 0.01Mb, one can define the time interval
between transmission of packets using the command.

$cbr set interval _0.005

The packet size can be set to some value using

cbr set packet size_<packet size>

Scheduling Events
31
NS is a discrete event based simulation. The tcp script defines when event should occur. The
initializing command set ns [new Simulator] creates an event scheduler, and events are then scheduled
using the format:

$ns at <time> <event>

The scheduler is started when running ns that is through the command $ns run.
The beginning and end of the FTP and CBR application can be done through the following command

$ns at 0.1 “$cbr start”


$ns at 1.0 “$ftp start”
$ns at 124.0 “$ftp stop”
$ns at 124.5 “$cbr stop”

Structure of Trace Files


When tracing into an output ASCII file, the trace is organized in 12 fields as follows in fig shown
below, The meaning of the fields are:

Event Time From To PKT PKT Flags Fid Src Dest Seq Pkt
Node
Node Type Size Addr Addr Num id

1. The first field is the event type. It is given by one of four possible symbols r, +, -, d which
correspond respectively to receive (at the output of the link), enqueued, dequeued and dropped.
2. The second field gives the time at which the event occurs.
3. Gives the input node of the link at which the event occurs.
4. Gives the output node of the link at which the event occurs.
5. Gives the packet type (eg CBR or TCP)
6. Gives the packet size
7. Some flags

8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script one can
32
further use this field for analysis purposes; it is also used when specifying stream color for the
NAM display.
9. This is the source address given in the form of ―node port.
10. This is the destination address, given in the same form.
11. This is the network layer protocol’s packet sequence number. Even though UDP
implementations in a real network do not use sequence number, ns keeps track of UDP packet
sequence number for analysis purposes.
12. The last field shows the unique id of the packet
XGRAPH

The xgraph program draws a graph on an x-display given data read from either data file or from standard
input if no files are specified. It can display upto 64 independent data sets using different colors and
line styles for each set. It annotates the graph with a title, axis labels, grid lines or tick marks, grid labels
and a legend.

Syntax:

Xgraph [options] file-name

Options are listed here


/-bd <color> (Border)
This specifies the border color of the xgraph window.
/-bg <color> (Background)
This specifies the background color of the xgraph window.
/-fg<color> (Foreground)
This specifies the foreground color of the xgraph window.
/-lf <fontname> (LabelFont)
All axis labels and grid labels are drawn using this font.
/-t<string> (Title Text)
This string is centered at the top of the graph.
/-x <unit name> (XunitText)

This is the unit name for the x-axis. Its default is ―X.

33
/-y <unit name> (YunitText)
This is the unit name for the y-axis. Its default is ―Y.

Awk- An Advanced

awk is a programmable, pattern-matching, and processing tool available in UNIX. It works equally
well with text and numbers. Awk is not just a command, but a programming language too. In other
words, awk utility is a pattern scanning and processing language. It searches one or more files to see
if they contain lines that match specified patterns and then perform associated actions, such as writing
the line to the standard output or incrementing a counter each time it finds a match.
Syntax:
awk option selection_criterion{action}file(s)

Here, selection_criteria filters input and select lines for the action component to act upon. The
selection_criteria is enclosed within single quotes and the action within the curly braces. Both the
selection_criteria and action forms an awk program.

Example: $ awk /manager/ {print}emp.lst

Variables
Awk allows the user to use variables of there choice. You can now print a serial number, using the
variable kount, and apply it those directors drawing a salary exceeding 6700:
$ awk –F”|” „$3 == “director” && $6
> 6700 { kount =kount+1
printf “ %3f %20s %-12s %d\n”, kount,$2,$3,$6 }‟ empn.lst

THE –f OPTION: STORING awk PROGRAMS IN A FILE

You should holds large awk programs in separate file and provide them with the awk extension for
easier identification. Let’s first store the previous program in the file empawk.awk:
$ cat empawk.awk
Observe that this time we haven’t used quotes to enclose the awk program. You can now use awk
with the –f filename option to obtain the same output:

Awk- F –f empawk.awk empn.lst

THE BEGIN AND END SECTIONS


34
Awk statements are usually applied to all lines selected by the address, and if there are no addresses,
then they are applied to every line of input. But, if you have to print something before processing the
first line, for example, a heading, then the BEGIN section can be used gainfully. Similarly, the end
section useful in printing some totals after processing is over.
The BEGIN and END sections are optional and take the form

BEGIN{ACTION}

END {ACTION}

These two sections, when present, are delimited by the body of the awk program. You can use them
to print a suitable heading at the beginning and the average salary at the end.
BUILT-IN VARIABLES
Awk has several built-in variables. They are all assigned automatically, though it is also
possible for a user to reassign some of them. You have already used NR, which signifies the record
number of the current line. We’ll now have a brief look at some of the other variable.The FS Variable:
as stated elsewhere, awk uses a contiguous string of spaces as the default field delimiter. FS redefines
this field separator, which in the sample database happens to be the |. When used at all, it must occur
in the BEGIN section so that the body of the program knows its value before it starts processing:
BEGIN {FS=”|”}
This is an alternative to the –F option which does the same thing.
The OFS Variable: when you used the print statement with comma-separated arguments, each
argument was separated from the other by a space. This is awk’s default output field separator, and
can reassigned using the variable OFS in the BEGIN section:

BEGIN { OFS=”~” }
When you reassign this variable with a ~ (tilde), awk will use this character for delimiting the print
arguments. This is a useful variable for creating lines with delimited fields.

The NF variable: NF comes in quite handy for cleaning up a database of lines that don’t contain the
right number of fields. By using it on a file, say emp.lst, you can locate those lines not having 6 fields,
35
and which have crept in due to faulty data entry:
$awk „BEGIN {FS = “|”}
NF! =6 {
Print “Record No “, NR, “has”, “fields”}‟ empx.lst

5. Conclusion and Discussion:

6. QUIZ / Viva Questions:

 What is NS-2? Explain in brief.


 Draw the basic architecture of NS-2?
 What is TCL Script? List the TCL Script Components.
 List the NS Simulator preliminaries.
 What is NAM?
 Draw the structure of trace file.

36
EXPERIMENT NO. 4(A)

AIM: Study of Networking Devices using cisco packet tracer


REQUIREMENT: Cisco packet tracer
THEORY:
Cisco network devices such as routers, switches, and other generic devices such as bridges, hubs,
repeaters, and WAN emulators are available to work in the cisco packet tracer. Network devices
enable the end devices to communicate with each other. These devices can be configured from
the config tab. You will be able to configure routers and switches using the config tab without
using Cisco commands.

Output: Make network using hub,switch and router in cisco packet tracer and attach print copy
here as output

PROCEDURE:
HUB:
1. Connect four PCs to a HUB in cisco packet tracer.

2. Configure each PC with IP address and subnet mask.

3. Select the simulation tab.

4. Edit filters for ARP and ICMP.

5. Take a simple PDU, and select a source and destination PC for it.

6. Press Auto Capture/Play button

7. Observe the HUB operation.

SWITCH:
1. Connect four PCs to a switch in cisco packet tracer.

2. Configure each PC with IP address and subnet mask.

37
3. Select the simulation tab.

4. Take a simple PDU, and select a source and destination PC for it.

5. Press Auto Capture/Play button

6. Observe the switch operation.

7. ping all other PCs from each PC

ROUTER:
1. Connect Two routers with a serial connection and connect a switch to each router in cisco packet
tracer.

2. Connect four PCs to each switch.

3. Configure the serial and fastethernet interfaces for ip addresses on each router

4. Define static routes on each router

5. Configure each PC with IP address and subnet mask.

6. Check the connectivity between two PCs belonging to different networks (routers)

7. Select the simulation tab.

8. Take a simple PDU, and select a source and destination PC for it.

9. Press Auto Capture/Play button

10. Observe the router operation.

CONCLUSION:

38
EXPERIMENT NO. 4(B)

AIM: Study of Networking Topologies (Star, Ring, Mesh, Bus, Tree and Hybrid) using cisco
packet tracer
REQUIREMENT: Cisco packet tracer
THEORY: Write theory about all mentioned topologies with their diagrams.

Output: Make network topologies in cisco packet tracer and attach print copy here as output

PROCEDURE:
Star Toplogies:
1. Connect four PCs to a HUB in cisco packet tracer.

2. Configure each PC with IP address and subnet mask.

3. Take a simple PDU, and select a source and destination PC for it.

4. Press Auto Capture/Play button

5. Observe the HUB operation.

Note: Write procedure for remaining topologies as per the network

CONCLUSION:

39
EXPERIMENT NO. 5

AIM: Simulation of dynamic routing protocols (RIP and OSPF) using Cisco Packet Tracer.

OBJECTIVES: Part 1: To Simulate RIP routing protocol, check the updated routing tables and
check the connectivity among devices.
Part 2: To Simulate OSPF routing protocol and, check the updated routing tables and
check the connectivity among devices.

REQUIREMENT: Cisco Packet Tracer

Theory: Have you ever imagined how you can access the servers in America from India? How
are they connected? Our systems are connected to the routers which in turn is connected to many
other routers which eventually are connected to the servers.
So whenever we want to access any server, the link between our computer and server is established
through these routers only.
But how the routers are selected so that the distance between our computer and the server is
minimum? This is what RIP does. It selects the shortest path between the computer and the remote
server.
RIP: It is a vector routing protocol that uses the hop count as the routing unit for finding the most
suitable path betwee the source and the destination.
Vector Routing Protocol: In a vector routing protocol, the routers interchange the network
accessibility information with the nearest neighbours. They interchange the information of the set of
destinations that they can reach and the next-hop address to which the data packet should be sent so
that the data reaches the destination.
Hop Count: Hop count Is the number of routers that are between the source and the destination in a
network.

RIP considers the path with the shortest number of hops as the best path to a remote network hence
placed in the routing table.
RIP allows only 15 hops to reach any network.
If the packet does not reach the destination in 15 hop counts then the destination is considered
as unreachable.
Routing Table
Every RIP router maintains a routing table. These tables store the information of all the
destinations that the router knows it can reach.
Each router interchange the information of their routing table to their nearest neighbours.
The routers broadcast the routing table information every 30 seconds to their closest neighbours.
Example: If you are the user and you want to reach google.com. There can be many paths through
which you can reach the server of Google. In the example below, the user has three paths. RIP will
count the number of routers required to reach the destination server from each route. Then it would
select that route that has a minimum number of paths.

40
The route 1 has 2 hop counts, route 2 has 3 hop counts and route 3 has 4 hop counts to reach the
destination server. So, the RIP will choose Route 1.
We can trace the route of the data packet and know about the router that comes in its path before
it reaches the destination. Open the Command Prompt and type → “tracert google.com” (without
double quotes) to see the path the data packets would take i.e. the routers that are between your
computer and the destination server of google.
RIP timers: Update Timers: All the routers configured with RIP send their update(a complete
copy of their routing table) every 30 seconds to the neighbouring routers.
Invalid Timers: If any router gets disconnected from the network then the nearing routers wait for
180 seconds for the update. When it doesn't hear the update until 180 seconds then it will put it
into hold-down.
Hold-Down Timer: Hold-downs ensure that regular update messages do not inappropriately cause
a routing loop( A routing loop is a serious network problem in which the data packets continue to
be routed within the network in an endless circle). The router doesn’t act on new information(of
routing table which it receives after every 30 seconds) for a certain period of time. It is 180
seconds by default.
Flush Timer: RIP will wait for an additional 60 seconds(total=180+60 =240 seconds) after the
route has been declared invalid. Even now if it doesn't hear any update then it removes the route
from the routing table.

41
Procedure for RIP:
Step 1: Configure the router interfaces for IP addresses as shown in the scenario
Step 2: Set clock rate on at least one serial interface belonging to different networks
Step 3: Activate all the interfaces
Step 4: Check directly connected networks for each router. (Using show ip route)
Step 5: Check updated routing tables on each router. (Using router RIP)
Step 6: Set gateways on each PC, Now successful ping is possible among the PCs belonging to different
networks.

Procedure for OSPF:


Step 1: Configure the router interfaces for IP addresses as shown in the
scenario Step 2: Configure each router with OSPF
o 2.1 Router OSPF processID
o 2.2 Network networkIPaddress wildcard mask areaID
o 2.3 repeat step 2.2 for all neighboring networks of each router
Step 3: run show IP route on each router
Step 6: Set gateways on each PC, Now successful ping is possible among the PCs belonging to
different networks

CONCLUSION:

OUTPUT: (Attach print copy of RIP Network layout)

Questions on RIP and OSPF:

1) Explain how RIP updates routing tables

2) Explain how OSPF updates routing tables

3) Compare RIP and OSPF

42

You might also like