Showing posts with label CS 6411- Computer Network Lab Manual. Show all posts
Showing posts with label CS 6411- Computer Network Lab Manual. Show all posts

Thursday, March 24, 2016

CARRIER SENSE MULTIPLE ACCESS

Aim:
To write a ns2 program for implementing carrier sense multiple access.

Algorithm:

Step 1: start the program.
Step 2: declare the global variables ns for creating a new simulator.
Step 3: set the color for packets.
Step 4: open the network animator file in the write mode.
Step 5: open the trace file and the win file in the write mode.
Step 6: transfer the packets in network.
Step 7: create the capable no of nodes.
Step 8: create the duplex-link between the nodes including the delay time,bandwidth and dropping . queue mechanism.
Step 9: give the position for the links between the nodes.
Step 10: set a tcp connection for source node.
Step 11: set the destination node using tcp sink.
Step 12: set the window size and the packet size for the tcp.
Step 13: set up the ftp over the tcp connection.
Step 14:.set the udp and tcp connection for the source and destination.
Step 15: create the traffic generator CBR for the source and destination files.
Step 15: define the plot window and finish procedure.
Step 16: in the definition of the finish procedure declare the global variables.
Step 17: close the trace file and namefile and execute the network animation file.
Step 18: at the particular time call the finish procedure.
Step 19: stop the program.


Program:

set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
set fi1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $fi1
set fi2 [open out.nam w]
$ns namtrace-all $fi2
proc finish {} {
global ns fi1 fi2
$ns flush-trace
close $fi1
close $fi2
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color red
$n1 shape box
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetsize_ 552
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
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
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 24.0 "$ftp stop"
$ns at 24.5 "$cbr stop"
proc plotwindow { tcpSource file } {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotwindow $tcpSource $file"
}
$ns at 1.0 "plotwindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
$ns at 125.0 "finish"
$ns run



Wednesday, March 23, 2016

MULTICASTING ROUTING PROTOCOL

Aim:
To write a ns2 program for implementing multicasting routing protocol.

Algorithm:

Step 1: start the program.
Step 2: declare the global variables ns for creating a new simulator.
Step 3: set the color for packets.
Step 4: open the network animator file in the name of file2 in the write mode.
Step 5: open the trace file in the name of file 1 in the write mode.
Step 6: set the multicast routing protocol to transfer the packets in network.
Step 7: create the multicast capable no of nodes.
Step 8: create the duplex-link between the nodes including the delay time,bandwidth and dropping . queue mechanism.
Step 9: give the position for the links between the nodes.
Step 10: set a udp connection for source node.
Step 11: set the destination node ,port and random false for the source and destination files.
Step 12: setup a traffic generator CBR for the source and destination files.
Step 13: down the connection between any nodes at a particular time.
Step 14: create the receive agent for joining and leaving if the nodes in the group.
Step 15: define the finish procedure.
Step 16: in the definition of the finish procedure declare the global variables.
Step 17: close the trace file and namefile and execute the network animation file.
Step 18: at the particular time call the finish procedure.
Step 19: stop the program.


Program:
# Create scheduler
#Create an event scheduler wit multicast turned on
set ns [new Simulator -multicast on]

#$ns multicast
#Turn on Tracing
set tf [open output.tr w]
$ns trace-all $tf

# Turn on nam Tracing
set fd [open mcast.nam w]
$ns namtrace-all $fd

# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]

Monday, March 21, 2016

Distance vector

In computer communication theory relating to packet-switched networks, a distance-vector routing protocol is one of the two major classes of routing protocols, the other major class being the link-state protocol. Distance-vector routing protocols use the Bellman–Ford algorithm, Ford–Fulkerson algorithm, or DUAL FSM (in the case of Cisco Systems's protocols) to calculate paths.

A distance-vector routing protocol requires that a router informs its neighbors of topology changes periodically. Compared to link-state protocols, which require a router to inform all the nodes in a network of topology changes, distance-vector routing protocols have less computational complexity and message overhead.

The term distance vector refers to the fact that the protocol manipulates vectors (arrays) of distances to other nodes in the network. The vector distance algorithm was the original ARPANET routing algorithm and was also used in the internet under the name of RIP (Routing Information Protocol).

Examples of distance-vector routing protocols include RIPv1 and RIPv2 and IGRP.

Method

Routers using distance-vector protocol do not have knowledge of the entire path to a destination. Instead they use two methods:

  1. Direction in which router or exit interface a packet should be forwarded.

  1. Distance from its destination

Distance-vector protocols are based on calculating the direction and distance to any link in a network. "Direction" usually means the next hop address and the exit interface. "Distance" is a

measure of the cost to reach a certain node. The least cost route between any two nodes is the route with minimum distance. Each node maintains a vector (table) of minimum distance to every node. The cost of reaching a destination is calculated using various route metrics. RIP uses the hop count of the destination whereas IGRP takes into account other information such as node delay and available bandwidth.

Sunday, March 20, 2016

Flooding

Flooding s a simple routing algorithm in which every incoming packet is sent through every outgoing link except the one it arrived on.Flooding is used in bridging and in systems such as Usenet and peer-to-peer file sharing and as part of some routing protocols, including OSPF, DVMRP, and those used in ad-hoc wireless networks.There are generally two types of flooding available, Uncontrolled Flooding and Controlled Flooding.Uncontrolled Flooding is the fatal law of flooding. All nodes have neighbours and route packets indefinitely. More than two neighbours creates a broadcast storm.

Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence Number Controlled Flooding) and RPF (Reverse Path Flooding). In SNCF, the node attaches its own address and sequence number to the packet, since every node has a memory of addresses and sequence numbers. If it receives a packet in memory, it drops it immediately while in RPF, the node will only send the packet forward. If it is received from the next node, it sends it back to the sender.

Algorithm

There are several variants of flooding algorithm. Most work roughly as follows:

  1. Each node acts as both a transmitter and a receiver.

  1. Each node tries to forward every message to every one of its neighbours except the source node.

This results in every message eventually being delivered to all reachable parts of the network.

Algorithms may need to be more complex than this, since, in some case, precautions have to be taken to avoid wasted duplicate deliveries and infinite loops, and to allow messages to eventually expire from the system. A variant of flooding called selective flooding partially addresses these issues by only sending packets to routers in the same direction. In selective flooding the routers don't send every incoming packet on every line but only on those lines which are going approximately in the right direction.




Advantages

  • f a packet can be delivered, it will (probably multiple times).

  • Since flooding naturally utilizes every path through the network, it will also use the shortest path.
  • This algorithm is very simple to implement.

Sunday, March 13, 2016

Link State routing

Aim:

To study the link state routing

Link State routing

Routing is the process of selecting best paths in a network. In the past, the term routing was also used to mean forwarding network traffic among networks. However this latter function is much better described as simply forwarding. Routing is performed for many kinds of networks, including the telephone network (circuit switching), electronic data networks (such as the Internet), and transportation networks. This article is concerned primarily with routing in electronic data networks using packet switching technology.

In packet switching networks, routing directs packet forwarding (the transit of logically addressed network packets from their source toward their ultimate destination) through intermediate nodes. Intermediate nodes are typically network hardware devices such as routers, bridges, gateways, firewalls, or switches. General-purpose computers can also forward packets and perform routing, though they are not specialized hardware and may suffer from limited performance. The routing process usually directs forwarding on the basis of routing tables which maintain a record of the routes to various network destinations. Thus, constructing routing tables, which are held in the router's memory, is very important for efficient routing. Most routing algorithms use only one network path at a time. Multipath routing techniques enable the use of multiple alternative paths.

In case of overlapping/equal routes, the following elements are considered in order to decide which routes get installed into the routing table (sorted by priority):

  1. Prefix-Length: where longer subnet masks are preferred (independent of whether it is within a routing protocol or over different routing protocol)

  1. Metric: where a lower metric/cost is preferred (only valid within one and the same routing protocol)

  1. Administrative distance: where a lower distance is preferred (only valid between different routing protocols)


Routing, in a more narrow sense of the term, is often contrasted with bridging in its assumption that network addresses are structured and that similar addresses imply proximity within the network. Structured addresses allow a single routing table entry to represent the route to a group of devices. In large networks, structured addressing (routing, in the narrow sense) outperforms unstructured addressing (bridging). Routing has become the dominant form of addressing on the Internet. Bridging is still widely used within localized environments.

Saturday, March 12, 2016

TCP and UDP Sockets Links

AIM

To write a java program for application using TCP and UDP Sockets Links

Program

File Client import java.io.*; import java.net.*; import java.util.*; class Clientfile

{ public static void main(String args[])

{

Try

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); Socket clsct=new Socket("127.0.0.1",139);

DataInputStream din=new DataInputStream(clsct.getInputStream()); DataOutputStream dout=new DataOutputStream(clsct.getOutputStream()); System.out.println("Enter the file name:");
String str=in.readLine(); dout.writeBytes(str+'\n'); System.out.println("Enter the new file name:"); String str2=in.readLine();

String str1,ss;

FileWriter f=new FileWriter(str2); char buffer[];

while(true)

{ str1=din.readLine(); if(str1.equals("-1")) break; System.out.println(str1); buffer=new char[str1.length()];

str1.getChars(0,str1.length(),buffer,0);

f.write(buffer);
}

f.close();

clsct.close();

}

catch (Exception e)

{

System.out.println(e);

}}}


Server

import java.io.*; import java.net.*; import java.util.*; class Serverfile

{ public static void main(String args[])

{

Try

{

ServerSocket obj=new ServerSocket(139); while(true)

{

Socket obj1=obj.accept();

DataInputStream din=new DataInputStream(obj1.getInputStream()); DataOutputStream dout=new DataOutputStream(obj1.getOutputStream()); String str=din.readLine();

FileReader f=new FileReader(str); BufferedReader b=new BufferedReader(f); String s;

while((s=b.readLine())!=null) { System.out.println(s);

dout.writeBytes(s+'\n');

}

f.close(); dout.writeBytes("-1\n");

} }

catch(Exception e)

{ System.out.println(e);}

}

}

Output

File content Computer networks jhfcgsauf

jbsdava jbvuesagv client

Enter the file name: sample.txt

server

Computer networks jhfcgsauf

jbsdava jbvuesagv client

Enter the new file name: net.txt

Computer networks jhfcgsauf

jbsdava jbvuesagv Destination file

Computer networks jhfcgsauf

jbsdava jbvuesagv

















Friday, March 11, 2016

Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using NS

Aim:

To Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using NS


NET WORK SIMULATOR (NS2)
Ns overview

  • Ns programming: A Quick start

  • Case study I: A simple Wireless network

  • Case study II: Create a new agent in Ns

Ns overview
  • Ns Status

  • Periodical release (ns-2.26, Feb 2003)

  • Platform support

  • FreeBSD, Linux, Solaris, Windows and Mac

Ns unctionalities

Routing, Transportation, Traffic sources,Queuing disciplines, QoS

Wireless

Ad hoc routing, mobile IP, sensor-MAC
Tracing, visualization and various utilitie
NS(Network Simulators)

Most of the commercial simulators are GUI driven, while some network simulators are CLI driven. The network model / configuration describes the state of the network (nodes,routers, switches, links) and the events (data transmissions, packet error etc.). An important output of simulations are the trace files. Trace files log every packet, every event that occurred in the simulation and are used for analysis. Network simulators can also provide other tools to facilitate visual analysis of trends and potential trouble spots.

Most network simulators use discrete event simulation, in which a list of pending "events" is stored, and those events are processed in order, with some events triggering future events—such as the event of the arrival of a packet at one node triggering the event of the arrival of that packet at a downstream node.

Simulation of networks is a very complex task. For example, if congestion is high, then estimation of the average occupancy is challenging because of high variance. To estimate the likelihood of a buffer overflow in a network, the time required for an accurate answer can be extremely large. Specialized techniques such as "control variates" and "importance sampling" have been developed to speed simulation.

Examples of network simulators

There are many both free/open-source and proprietary network simulators. Examples of notable network simulation software are, ordered after how often they are mentioned in research papers:

  1. ns (open source)
  2. OPNET (proprietary software)
  3. NetSim (proprietary software)

Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and time involved in setting up an entire test bed containing multiple networked computers, routers and data links, network simulators are relatively fast and inexpensive. They allow engineers, researchers to test scenarios that might be particularly difficult or expensive to emulate using real hardware - for instance, simulating a scenario with several nodes or experimenting with a new protocol in the network. Network simulators are particularly useful in allowing researchers to test new networking protocols or changes to existing protocols in a controlled and reproducible environment. A typical network simulator encompasses a wide range of networking technologies and can help the users to build complex networks from basic building blocks such as a variety of nodes and links. With the help of simulators, one can design hierarchical networks using various types of nodes like computers, hubs, bridges, routers, switches, links, mobile units etc.

Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local Area Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a typical simulator and the user can test, analyze various standard results apart from devising some novel protocol or strategy for routing etc. Network simulators are also widely used to simulate battlefield networks in Network-centric warfare

There are a wide variety of network simulators, ranging from the very simple to the very complex. Minimally, a network simulator must enable a user to represent a network topology, specifying the nodes on the network, the links between those nodes and the traffic between the nodes. More complicated systems may allow the user to specify everything about the protocols used to handle traffic in a network. Graphical applications allow users to easily visualize the workings of their simulated environment. Text-based applications may provide a less intuitive interface, but may permit more advanced forms of customization.


Packet loss

occurs when one or morepacketsof data travelling across a computer networkfail to reachtheir destination. Packet loss is distinguished as one of the three main error types encountered in digital communications; the other two being bit errorand spurious packets caused due to noise.

Packets can be lost in a network because they may be dropped when a queue in the network node overflows. The amount of packet loss during the steady state is another important property of a congestion control scheme. The larger the value of packet loss, the more difficult it is for transportlayer protocols to maintain high bandwidths, the sensitivity to loss of individual packets, as well as to frequency and patterns of loss among longer packet sequences is strongly dependent on the application itself.
Throughput

This is the main performance measure characteristic, and most widely used. Incommunicationnetworks, such asEthernetorpacket radio, throughputor network throughputis the average rate of successfulmessage delivery over a communication channel. The throughput is usually measured inbitsper second (bit/s orbps), andsometimes indata packetsper second or data packets pertime slotThis measure how soon the receiver is able to get a certain amount of data send by the sender. It is determined as the ratio of the total data received to the end to end delay. Throughput is an important factor which directly impacts the network performance


Delay

Delay is the time elapsed while a packet travels from one point e.g., source premise or network ingress to destination premise or network degrees. The larger the valueof delay, the more difficult it is for transport layer protocols to maintain highbandwidths. We will calculate end to end delay

Queue Length

A queuing system in networks can be described as packets arriving for service, waiting for service if it is not immediate, and if having waited for service, leaving thesystem after being served. Thus queue length is very important characteristic to determine that how well the active queue management of the congestion control

algorithm has been working.


























Thursday, March 10, 2016

SNMP application program

Aim
To write a java program for SNMP application program

Algorithm

1.Start the program.
2.Get the frame size from the user

3.To create the frame based on the user request. 4.To send frames to server from the client side.

5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client.

6.Stop the program


Program
import java.io.IOException;
import org.snmp4j.CommunityTarget; import org.snmp4j.PDU;
import org.snmp4j.Snmp; import org.snmp4j.Target;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress; import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString; import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class SNMPManager {


Snmp snmp = null;

String address = null;

  • Constructor

  • @param add

*/

public SNMPManager(String add)

{

address = add;
public static void main(String[] args) throws IOException {

/**

* Port 161 is used for Read and Other operations

  • Port 162 is used for the trap generation */

SNMPManager client = new SNMPManager("udp:127.0.0.1/161");

client.start();

/**

  • OID - .1.3.6.1.2.1.1.1.0 => SysDec

  • OID - .1.3.6.1.2.1.1.5.0 => SysName

* => MIB explorer will be usefull here, as discussed in previous article */


String sysDescr = client.getAsString(new OID(".1.3.6.1.2.1.1.1.0")); System.out.println(sysDescr);

}


/**

  • get any answers because the communication is asynchronous

  • and the listen() method listens for answers.

  • @throws IOException

*/

private void start() throws IOException {

TransportMapping transport = new DefaultUdpTransportMapping();

snmp = new Snmp(transport);

// Do not forget this line! transport.listen();

}


/**

  • Method which takes a single OID and returns the response from the agent as a String.

  • @param oid

  • @return

  • @throws IOException

*/


public String getAsString(OID oid) throws IOException {

ResponseEvent event = get(new OID[] { oid });

return event.getResponse().get(0).getVariable().toString();

}

/**

  • This method is capable of handling multiple OIDs

  • @param oids

  • @return

  • @throws IOException

*/

public ResponseEvent get(OID oids[]) throws IOException {
PDU pdu = new PDU();

for (OID oid : oids) {

pdu.add(new VariableBinding(oid));

}

pdu.setType(PDU.GET);

ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {

return event;

}

throw new RuntimeException("GET timed out");

}

/**

  • This method returns a Target, which contains information about

  • where the data should be fetched and how.

  • @return

*/

private Target getTarget() {

Address targetAddress = GenericAddress.parse(address); CommunityTarget target = new CommunityTarget();

target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);

target.setRetries(2);

target.setTimeout(1500);

target.setVersion(SnmpConstants.version2c);
return target;

}}


OUT PUT


Hardware: x86 Family 6 Model 23 Stepping 10 AT/AT COMPATIBLE – Software: Windows 2000 Version 5.1 (Build 2600 Multiprocessor Free)