You are on page 1of 68

PANIMALAR ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS


REG.NO: 211422244178

EX.NO: 1 IMPLEMENTATION OF NETWORK COMMANDS

PROGRAM:

import java.util.*;

public class PingDemo

public void Ping(String host)

try

Process p=Runtime.getRuntime().exec("Ping "+host);

Scanner scan=new Scanner(p.getInputStream());

while(scan.hasNextLine())

System.out.println(scan.nextLine());

catch (Exception ex)

System.out.println("error"+ex);

public static void main (String args[])

PingDemo P1=new PingDemo();


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

P1.Ping(args[0]);

OUTPUT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: SIMULATION OF PING PROGRAM

PROGRAM:

import java.util.*;

public class TraceDemo

public void trace(String host)

try

Process p=Runtime.getRuntime(). exec("Tracert "+host);

Scanner scan=new Scanner(p.getInputStream());

while(scan.hasNextLine())

System.out.println(scan.nextLine());

catch (Exception ex)

System.out.println("error"+ex);

public static void main (String args[])

TraceDemo p=new TraceDemo();


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

p.trace(args[0]);

OUTPUT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: HTTP FOR WEB PAGE UPLOAD AND DOWNLOAD

PROGRAM:

import java.io.*;

import java.net.*;

public class ruff

public static void main(String ar[]) throws Exception

InetAddress add=InetAddress.getByName("www.google.com");

Socket s=new Socket(add,80);

boolean flag=true;

PrintWriter out=new PrintWriter(s.getOutputStream(),flag);

BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));

out.println("GET / HTTP/1.1");

out.println("HOST:www.google.com:80");

out.println("Connection:close");

out.println();

boolean loop=true;

StringBuilder sb= new StringBuilder(8096);

while(loop)

if(in.ready())

int i=0;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

while(i!=-1)

i=in.read();

sb.append((char)i);

loop=false;

System.out.println(sb.toString());

s.close();

OUTPUT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: TCP ECHO SERVER/CLIENT

PROGRAM:

SERVER PROGRAM:

import java.net.*;

import java.io.*;

public class Eserver

public static void main(String arg[])

ServerSocket s=null;

String line;

DataInputStream is=null,is1=null;

PrintStream os=null;

Socket c=null;

try

s=new ServerSocket(99);

catch(IOException e)

System.out.println(e);

try

{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

c=s.accept();

is=new DataInputStream(c.getInputStream());

is1=new DataInputStream(System.in);

os=new PrintStream(c.getOutputStream());

do

line=is.readLine();

System.out.println("Client"+line);

System.out.println("Server");

line=is1.readLine();

os.println(line);

while(line.equalsIgnoreCase("quit")==false);

is.close();

os.close();

catch(IOException e)

System.out.println(e);

CLIENT PROGRAM:

import java.net.*;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

import java.io.*;

public class Eclient

public static void main(String arg[])

Socket c=null;

String line;

DataInputStream is,is1;

PrintStream os;

try

InetAddress ia = InetAddress.getLocalHost();

c=new Socket(ia,99);

catch(IOException e)

System.out.println(e);

try

os=new PrintStream(c.getOutputStream());

is=new DataInputStream(System.in);

is1=new DataInputStream(c.getInputStream());

while(true)
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

System.out.println("Client");

line=is.readLine();

os.println(line);

System.out.println("Server"+is1.readLine());

catch(IOException e)

System.out.println("Socket closed");

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: TCP CHAT SERVER/CLIENT

PROGRAM:

SERVER PROGRAM:

import java.io.*;

import java.net.*;

public class ChatServer

public static void main(String arg[]) throws Exception

ServerSocket sersock = new ServerSocket(99);

System.out.println("Server ready for Chatting");

Socket sock=sersock.accept();

BufferedReader sendRead= new BufferedReader(new InputStreamReader(System.in));

OutputStream ofstream = sock.getOutputStream();

PrintWriter pwrite=new PrintWriter(ofstream,true);

InputStream istream=sock.getInputStream();

BufferedReader receivedread= new BufferedReader(new InputStreamReader(istream));

String receivemessage,sendmessage;

while(true)

if((receivemessage=receivedread.readLine())!=null)

System.out.println(receivemessage);

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

sendmessage=sendRead.readLine();

pwrite.println(sendmessage);

System.out.flush();

CLIENT PROGRAM:

import java.io.*;

import java.net.*;

public class ChatClient

public static void main(String arg[]) throws Exception

Socket sock = new Socket("172.16.27.5",99);

BufferedReader sendRead= new BufferedReader(new InputStreamReader(System.in));

OutputStream ofstream = sock.getOutputStream();

PrintWriter pwrite=new PrintWriter(ofstream,true);

InputStream istream=sock.getInputStream();

BufferedReader receivedread= new BufferedReader(new InputStreamReader(istream));

System.out.println("Client ready for chatting");

String receivemessage,sendmessage;

while(true)

sendmessage=sendRead.readLine();
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

pwrite.println(sendmessage);

System.out.flush();

if((receivemessage=receivedread.readLine())!=null)

System.out.println(receivemessage);

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: FILE TRANSFER USING TCP

PROGRAM:

SERVER PROGRAM:

import java.net.*;

import java.io.*;

public class ex3cserver

public static void main(String arg[]) throws Exception

ServerSocket sersock=new ServerSocket(4000);

System.out.println("Server ready for connection");

Socket sock=sersock.accept();

System.out.println("Connection is Successful");

InputStream istream=sock.getInputStream();

BufferedReader fileRead=new BufferedReader(new InputStreamReader(istream));

String fname=fileRead.readLine();

BufferedReader contentRead= new BufferedReader(new FileReader(fname));

OutputStream ostream=sock.getOutputStream();

PrintWriter pwrite=new PrintWriter(ostream,true);

String str;

while((str=contentRead.readLine())!=null)

pwrite.println(str);

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

sock.close();

sersock.close();

pwrite.close();

fileRead.close();

contentRead.close();

CLIENT PROGRAM:

import java.net.*;

import java.io.*;

public class ex3cclient

public static void main(String args[]) throws Exception

Socket sock=new Socket("127.0.0.1",4000);

System.out.println("Enter the file name:");

BufferedReader keyRead= new BufferedReader(new InputStreamReader(System.in));

String fname=keyRead.readLine();

OutputStream ostream=sock.getOutputStream();

PrintWriter pwrite= new PrintWriter(ostream,true);

pwrite.println(fname);

InputStream istream=sock.getInputStream();

BufferedReader socketRead= new BufferedReader(new InputStreamReader(istream));

String str;

while((str=socketRead.readLine())!=null)
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

System.out.println(str);

pwrite.close();

socketRead.close();

keyRead.close();

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: SIMULATION OF DNS USING UDP SOCKETS

PROGRAM:

SERVER PROGRAM:

import java.io.*;

import java.net.*;

public class Dnserver

private static int indexOf(String[] array, String str)

str = str.trim();

for(int i=0;i<array.length;i++)

if(array[i].equals(str)) return i;

return -1;

public static void main(String arg[])throws IOException

String[] hosts={"yahoo.com","gmail.com","cricinfo.com","facebook.com"};

String[] ip={"68.180.206.184","209.85.148.19","80.168.92.140","69.63.189.16"};

System.out.println("Press Ctrl+c to Quit");

while(true){

DatagramSocket serversocket=new DatagramSocket(1362);

byte[] senddata=new byte[1021];


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

byte[] receivedata=new byte[1021];

DatagramPacket recvpack=new DatagramPacket(receivedata,receivedata.length);

serversocket.receive(recvpack);

String sen = new String(recvpack.getData());

InetAddress ipaddress = recvpack.getAddress();

int port=recvpack.getPort();

String capsent;

System.out.println("Request for host"+sen);

if(indexOf(hosts,sen)!=-1)

capsent=ip[indexOf(hosts,sen)]; else capsent ="Host Not Found";

senddata=capsent.getBytes();

DatagramPacket pack=new DatagramPacket(senddata,senddata.length,ipaddress,port);

serversocket.send(pack);

serversocket.close();

CLIENT PROGRAM:

import java.io.*;

import java.net.*;

public class Dnsclient

public static void main(String arg[])throws IOException

{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

byte[] senddata1=new byte[1024];

byte[] receivedata=new byte[1024];

int portaddr=1362;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

DatagramSocket clientsocket=new DatagramSocket();

InetAddress ipaddress;

if(arg.length==0)

ipaddress= InetAddress.getLocalHost();

else

ipaddress=InetAddress.getByName(arg[0]);

System.out.println("Enter the hostname:");

String sentence =br.readLine();

senddata1=sentence.getBytes();

DatagramPacket pack=new DatagramPacket(senddata1,senddata1.length,ipaddress,portaddr);

clientsocket.send(pack);

DatagramPacket recvpack=new DatagramPacket(receivedata,receivedata.length);

clientsocket.receive(recvpack);

String modified=new String (recvpack.getData());

System.out.println("Ip address"+modified);

clientsocket.close();

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: SIMULATION OF ARP PROTOCOLS

PROGRAM:

SERVER PROGRAM:

import java.io.*;

import java.net.*;

import java.util.*;

class Serverarp

public static void main(String args[])throws IOException

try

ServerSocket obj=new ServerSocket(99);

Socket obj1=obj.accept();

while(true)

DataInputStream din=new DataInputStream(obj1.getInputStream());

DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());

String str=din.readLine();

String ip[]={"172.16.27.99","172.16.27.3","172.16.27.4"};

String

mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};

for(int i=0;i<ip.length;i++)

{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

if(str.equals(ip[i]))

dout.writeBytes(mac[i]+'\n');

break;

obj.close();

catch(Exception e)

System.out.println(e);

CLIENT PROGRAM:

import java.io.*;

import java.net.*;

import java.util.*;

class Clientarp

public static void main(String args[])throws IOException

try
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

Socket s=new Socket("localhost",99);

DataInputStream din=new DataInputStream(s.getInputStream());

DataOutputStream dout=new DataOutputStream(s.getOutputStream());

System.out.print("Enter the Logical address(IP):");

String str1=in.readLine();

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

String str=din.readLine();

System.out.println("The Physical Address is:"+str);

s.close();

catch (Exception e)

System.out.println(e);

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: SIMULATION OF RARP PROTOCOLS

PROGRAM:

SERVER PROGRAM:

import java.io.*;

import java.net.*;

import java.util.*;

class Serverarp

public static void main(String arg[])

try

DatagramSocket server=new DatagramSocket(8888);

while(true)

byte[] sendbyte = new byte[1024];

byte[] receivebyte = new byte[1024];

DatagramPacket receiver = new DatagramPacket(receivebyte,receivebyte.length);

server.receive(receiver);

String str = new String(receiver.getData());

String s = str.trim();

InetAddress addr = receiver.getAddress();

int port = receiver.getPort();

String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};

for(int i=0;i<ip.length;i++)

if(s.equals(mac[i]))

sendbyte = ip[i].getBytes();

DatagramPacket sender = new DatagramPacket(sendbyte,sendbyte.length,addr,port);

server.send(sender);

break;

break;

catch(Exception e)

System.out.println(e);

CLIENT PROGRAM:

import java.io.*;

import java.net.*;

import java.util.*;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

class Clientrarp

public static void main(String args[])

try

DatagramSocket client=new DatagramSocket();

InetAddress addr=InetAddress.getByName("localhost");

byte[] sendbyte=new byte[1024];

byte[] receivebyte=new byte[1024];

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the Physical address (MAC):");

String str=in.readLine();

sendbyte=str.getBytes();

DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,8888);

client.send(sender);

DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);

client.receive(receiver);

String s=new String(receiver.getData());

System.out.println("The Logical Address is(IP): "+s);

client.close();

catch(Exception e)

{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

System.out.println(e);

OUTPUT:

SERVER:

CLIENT:

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX.NO: STUDY OF NETWORK SIMULATOR (NS)

NS2 SIMULATOR:

A simulator is a device, software or system which behaves or operates like a given system when
provided with a set of controlled inputs. The need for simulators is:

 Provide users with practical feedback such as accuracy, efficiency, cost, etc., when designing
real world systems.
 Permit system designers to study at several different levels of abstraction.
 Simulation can give results that are not experimentally measurable with our current level of
technology.
 Simulations take the building/rebuilding phase out of the loop by using the model already created
in the design phase.
 Effective means for teaching or demonstrating concepts to students.

A few popular network simulators are NS-2, OPNET, GLOMOSIM, etc. Network Simulator NS2.

NS2 is an object-oriented, discrete event driven network simulator developed at UC Berkley written in
C++ and OTcl. NS is primarily useful for simulating local and wide area networks. NS2 is an
opensource simulation tool that primarily runs on Linux (cygwin for Windows). The features of NS2 are

 Is a discrete event simulator for networking research.


 Works at packet level.
 Provide support to simulate bunch of protocols like TCP, UDP, FTP, etc.
 Simulate wired and wireless network.
 Is a standard experiment environment in research community.

How to start:

First of all, you need to create a simulator object. This is done with the command Now we open a file for
writing that is going to be used for the nam trace data.

set nf [open out.nam w]

$ns namtrace-all $nf

The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In thesecond line we tell
the simulator object that we created above to write all simulation data that is going to be relevant for
nam into this file.The next step is to add a 'finish' procedure that closes the trace file and starts nam.
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam out.nam &amp;

, The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds of simulation
time.

$ns at 5.0 "finish"

ns provides you with a very simple way to schedule events with the 'at' command. The last line finally
starts the simulation.

$ns run

We can actually save the file now and try to run it with 'ns example1.tcl'. We are going to get an error
message like 'nam: empty trace file out.nam' though, because until now we haven't defined any objects
(nodes, links, etc.) or events.

#Create a simulator object

set ns [new Simulator]

#Open the nam trace file

set nf [open out.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

global ns nf

$ns flush-trace

#Close the trace file

close $nf

#Execute nam on the trace file


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

exec nam out.nam & amp;

exit 0

# Insert your own code for topology creation

# and agent definitions, etc.

#Call the finish procedure after 5 seconds simulation time $ns at 5.0 "finish"

#Run the simulation

$ns run

set n0 [$ns node]

set n1 [$ns node]

A new node object is created with the command '$ns node'. The above code creates two nodes and
assigns them to the handles 'n0' and 'n1'. The next line connects the two nodes.

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth
1Megabit, a delay of 10ms and a DropTail queue. Now you can save your file and start the script with
'ns example1.tcl'. nam will be started automatically and you should see an output that resembles the
picture below.

Commands to create a link between nodes:

$ns_ simplex-link <node1> <node2> <bw> <delay> <qtype> <args>

This command creates an unidirectional link between node1 and node2 with specified bandwidth (BW)
and delay characteristics. The link uses a queue type of <qtype> and depending on the queue type
different arguments are passed through <args>.

$ns_ duplex-link <node1> <node2> <bw> <delay> <qtype> <args>

This creates a bi-directional link between node1 and node2. This procedure essentially creates a duplex-
link from two simplex links, one from node1 to node2 and the other from node2 to node1. The syntax
for duplexlink is same as that of simplex-link described above.

$ns_ simplex-link-op <n1> <n2> <op> <args>


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

This is used to set attributes for a simplex link. The attributes may be the orientation, color, label, or
queue-position.

$ns_ duplex-link-op <n1> <n2> <op> <args>

This command is used to set link attributes (like orientation of the links, color, label, or queue-position)
for duplex links.

Sending data:

The next step is to send some data from node n0 to node n1. In ns, data is always being sent from one
'agent' to another. So the next step is to create an agent object that sends data from node n0, and another
agent object that receives the data on node n1.

#Create a UDP agent and attach it to node n0

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

These lines create a UDP agent and attach it to the node n0, then attach a CBR traffic generator to the
UDP agent. CBR stands for 'constant bit rate'. Line 7 and 8 should be self-explaining. The packet Size is
being set to 500 bytes and a packet will be sent every 0.005 seconds (i.e. 200 packets per second). The
next lines create a Null agent which acts as traffic sink and attach it to node n1.

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

Now the two agents have to be connected with each other. $ns connect $udp0 $null0 And now we have
to tell the CBR agent when to send data and when to stop sending.

This code should be self-explaining again. Now you can save the file and start the simulation again.
When you click on the 'play' button in the nam window, you will see that after 0.5 simulation
seconds,node 0 starts sending data packets to node 1. You might want to slow nam down then with the
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

'Step' slider. Now you start some experiments with nam and the Tcl script. You can click on any packet
in the nam window to monitor it, and you can also click directly on the link to get some graphs with
statistics.Try to change the 'packetsize_' and 'interval_' parameters in the Tcl script to see what happens.

Agents

Agents represent endpoints where network-layer packets are constructed or consumed, and are used in
the implementation of protocols at various layers.

ns_ attach-agent <node> <agent>


This command attaches the <agent> to the <node>. We assume here that the <agent> has already been
created. An agent is typically created by set agent [new Agent/AgentType] where Agent/AgentType
defines the class definiton of the specified agent type.

Topology

You will always have to create a simulator object, you will always have to start the simulation with the
same command, and if you want to run nam automatically, you will always have to open a trace file,
initialize it, and define a procedure which closes it and starts nam.

Now insert the following lines into the code to create four nodes.

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

The following piece of Tcl code creates three duplex links between the nodes.

$ns duplex-link $n0 $n2 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail

$ns duplex-link $n3 $n2 1Mb 10ms DropTail

You can save and start the script now. You might notice that the topology looks a bit awkward in nam.
You can hit the 'relayout' button to make it look better, but it would be nice to have some more control
over the layout. Add the next three lines to your Tcl script and start it again.

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n1 $n2 orient right-up


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns duplex-link-op $n2 $n3 orient right

#Create a simulator object

set ns [new Simulator]

#Open the nam trace file

set nf [open out.nam w]

$ns namtrace-all $nf

After successful installation, path setting and validation, execute NS2 programs.

$ ns filename.tcl

RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

EX NO: 6B SIMULATION OF CONGESTION CONTROL ALGORITHM USING NS

PROGRAM:

set ns [new Simulator]

set nr [open thro_red.tr w]

$ns trace-all $nr

set nf [open thro.nam w]

$ns namtrace-all $nf

proc finish { } {

global ns nr nf

$ns flush-trace

close $nf

close $nr

exec nam thro.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]

set n6 [$ns node]

set n7 [$ns node]

$ns duplex-link $n0 $n3 1Mb 10ms RED

$ns duplex-link $n1 $n3 1Mb 10ms RED


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns duplex-link $n2 $n3 1Mb 10ms RED

$ns duplex-link $n3 $n4 1Mb 10ms RED

$ns duplex-link $n4 $n5 1Mb 10ms RED

$ns duplex-link $n4 $n6 1Mb 10ms RED

$ns duplex-link $n4 $n7 1Mb 10ms RED

$ns duplex-link-op $n0 $n3 orient right-up

$ns duplex-link-op $n3 $n4 orient middle

$ns duplex-link-op $n2 $n3 orient right-down

$ns duplex-link-op $n4 $n5 orient right-up

$ns duplex-link-op $n4 $n7 orient right-down

$ns duplex-link-op $n1 $n3 orient right

$ns duplex-link-op $n6 $n4 orient left

set udp0 [new Agent/UDP]

$ns attach-agent $n2 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n5 $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

set null0 [new Agent/Null]

$ns attach-agent $n6 $null0

$ns connect $udp1 $null0

set udp2 [new Agent/UDP]

$ns attach-agent $n0 $udp2

set cbr2 [new Application/Traffic/CBR]

$cbr2 set packetSize_ 500

$cbr2 set interval_ 0.005

$cbr2 attach-agent $udp2

set null0 [new Agent/Null]

$ns attach-agent $n7 $null0

$ns connect $udp2 $null0

$udp0 set fid_ 1

$udp1 set fid_ 2

$udp2 set fid_ 3

$ns color 1 Red

$ns color 2 Green

$ns color 2 blue

$ns at 0.1 "$cbr0 start"

$ns at 0.2 "$cbr1 start"

$ns at 0.5 "$cbr2 start"


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns at 4.0 "$cbr2 stop"

$ns at 4.2 "$cbr1 stop"

$ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish"

$ns run

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 7 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL

PROGRAM:

set ns [new Simulator]

set nr [open thro_dt.tr w]


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns trace-all $nr

set nf [open thro.nam w]

$ns namtrace-all $nf

proc finish { } {

global ns nr nf

$ns flush-trace

close $nf

close $nr

exec nam thro.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]

set n6 [$ns node]

set n7 [$ns node]

$ns duplex-link $n0 $n3 1Mb 10ms DropTail

$ns duplex-link $n1 $n3 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 1Mb 10ms DropTail

$ns duplex-link $n3 $n4 1Mb 10ms DropTail

$ns duplex-link $n4 $n5 1Mb 10ms DropTail


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns duplex-link $n4 $n6 1Mb 10ms DropTail

$ns duplex-link $n4 $n7 1Mb 10ms DropTail

$ns duplex-link-op $n0 $n3 orient right-up

$ns duplex-link-op $n1 $n3 orient right

$ns duplex-link-op $n2 $n3 orient right-down

$ns duplex-link-op $n3 $n4 orient middle

$ns duplex-link-op $n4 $n5 orient right-up

$ns duplex-link-op $n4 $n7 orient right-down

$ns duplex-link-op $n6 $n4 orient left

set udp0 [new Agent/UDP]

$ns attach-agent $n2 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n5 $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

set null0 [new Agent/Null]

$ns attach-agent $n6 $null0

$ns connect $udp1 $null0

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set cbr2 [new Application/Traffic/CBR]

$cbr2 set packetSize_ 500

$cbr2 set interval_ 0.005

$cbr2 attach-agent $tcp0

set tcpsink0 [new Agent/TCPSink]

$ns attach-agent $n7 $tcpsink0

$ns connect $tcp0 $tcpsink0

$udp0 set fid_ 1

$udp1 set fid_ 2

$tcp0 set fid_ 3

$ns color 1 Red

$ns color 2 Green

$ns color 3 blue

$ns at 0.2 "$cbr0 start"

$ns at 3.5 "$cbr0 stop"

$ns at 0.3 "$cbr1 start"

$ns at 4.5 "$cbr1 stop"

$ns at 0.4 "$cbr2 start"

$ns at 4.5 "$cbr2 stop"


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns at 5.0 "finish"

$ns run

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 8A SIMULATION OF DISTANCE VECTOR ALGORITHM

PROGRAM:

set ns1 [new Simulator]

set nr1 [open ds.tr w]

$ns1 trace-all $nr1

set nf1 [open ds.nam w]

$ns1 namtrace-all $nf1

set n0 [$ns1 node]


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

set n1 [$ns1 node]

set n2 [$ns1 node]

set n3 [$ns1 node]

set n4 [$ns1 node]

$ns1 duplex-link $n0 $n1 1Mb 10ms DropTail

$ns1 duplex-link $n0 $n2 1Mb 10ms DropTail

$ns1 duplex-link $n1 $n2 1Mb 10ms DropTail

$ns1 duplex-link $n1 $n4 1Mb 10ms DropTail

$ns1 duplex-link $n2 $n3 1Mb 10ms DropTail

$ns1 duplex-link $n3 $n4 1Mb 10ms DropTail

$ns1 duplex-link-op $n0 $n1 orient left-up

$ns1 duplex-link-op $n0 $n2 orient left-down

$ns1 duplex-link-op $n4 $n1 orient right-up

$ns1 duplex-link-op $n3 $n2 orient right-down

$ns1 cost $n0 $n1 1

$ns1 cost $n0 $n2 5

$ns1 cost $n1 $n0 1

$ns1 cost $n1 $n4 9

$ns1 cost $n1 $n2 3

$ns1 cost $n2 $n0 5

$ns1 cost $n2 $n1 3

$ns1 cost $n2 $n3 4

$ns1 cost $n3 $n2 4

$ns1 cost $n3 $n4 2


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns1 cost $n4 $n3 2

$ns1 cost $n4 $n1 9

set udp0 [new Agent/UDP]

$ns1 attach-agent $n1 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetsize_ 1000

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set Null0 [new Agent/Null]

$ns1 attach-agent $n4 $Null0

$ns1 connect $udp0 $Null0

$ns1 rtproto DV

$ns1 at 0.5 "$cbr0 start"

$ns1 at 4.5 "$cbr0 stop"

proc finish { } {

global ns1 nr1 nf1

$ns1 flush-trace

close $nf1

close $nr1

exec nam ds.nam &

exit 0 }

$ns1 at 5.0 "finish"

$ns1 run
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 8B SIMULATION OF LINK STATE ROUTING ALGORITHM

PROGRAM:

set ns [new Simulator]

$ns rtproto LS

set nf [open linkstate.nam w]

$ns namtrace

all $nf

set f0 [open linkstate.tr w]

$ns trace

all $f0

proc finish {}

global ns f0 nf
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns flush trace

close $f0

close $nf

exec nam linkstate.nam &

exit 0

for {set i 0} {$i <7} {incr i} {

set n($i) [$ns node]

for {set i 0} {$i <7} {incr i} {

$ns duplex link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail

set udp0 [new Agent/UDP]

$ns attach

agent $n(0) $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach

agent $udp0

set null0 [new Agent/Null]

$ns attach

agent $n(3) $null0

$ns con
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

nect $udp0 $null0

$ns at 0.5 "$cbr0 start"

$ns rtmodel

at 1.0 down $n(1) $n(2)

$ns rtmodel

at 2.0 up $n(1) $n(2)

$ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish"

$ns run

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 9A PERFORMANCE EVALUATION OF UNICAST ROUTING

PROTOCOLS USING SIMULATION TOOL

PROGRAM:

set ns [new Simulator]

$ns color 1 Blue

$ns color 2 Red

set file1 [open out.tr w]

$ns trace-all $file1

set file2 [open out.nam w]

$ns namtrace-all $file2

proc finish {} {

global ns file1 file2

$ns flush-trace
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

close $file1

close $file2

exec nam out.nam &

exit 0

$ns rtproto DV

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail

$ns duplex-link $n1 $n2 0.3Mb 10ms DropTail

$ns duplex-link $n2 $n3 0.3Mb 10ms DropTail

$ns duplex-link $n1 $n4 0.3Mb 10ms DropTail

$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail

$ns duplex-link $n4 $n5 0.5Mb 10ms DropTail

$ns duplex-link-op $n0 $n1 orient right

$ns duplex-link-op $n1 $n2 orient right

$ns duplex-link-op $n2 $n3 orient up

$ns duplex-link-op $n1 $n4 orient up-left

$ns duplex-link-op $n3 $n5 orient left-up

$ns duplex-link-op $n4 $n5 orient right-up


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

# Setup a TCP connection

set tcp [new Agent/TCP/Newreno]

$ns attach-agent $n0 $tcp

set sink [new Agent/TCPSink/DelAck]

$ns attach-agent $n5 $sink

$ns connect $tcp $sink

$tcp set fid_ 1

# Setup an FTP over TCP connection

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

$ns rtmodel-at 1.0 down $n1 $n4

$ns rtmodel-at 4.5 up $n1 $n4

$ns at 0.1 "$ftp start"

$ns at 6.0 "finish"

$ns run

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 9B PERFORMANCE EVALUATION OF MULTICAST ROUTING

PROTOCOLS USING SIMULATION TOOL

PROGRAM:

# Create scheduler

set ns [new Simulator -multicast on]

# 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
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

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]

# Create links

$ns duplex-link $n0 $n2 1.5Mb 10ms DropTail

$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail

$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail

$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail

$ns duplex-link $n3 $n7 1.5Mb 10ms DropTail

$ns duplex-link $n4 $n5 1.5Mb 10ms DropTail

$ns duplex-link $n4 $n6 1.5Mb 10ms DropTail

# Set multicast protocol to Distance Multicast (DM)

set mproto DM

set mrthandle [$ns mrtproto $mproto {}]

# Allocate group addresses

set group1 [Node allocaddr]

set group2 [Node allocaddr]

# UDP Transport agent for the traffic source 1

set udp0 [new Agent/UDP]


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns attach-agent $n0 $udp0

$udp0 set dst_addr_ $group1

$udp0 set dst_port_ 0

# UDP Transport agent for the traffic source 2

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

$udp1 set dst_addr_ $group2

$udp1 set dst_port_ 0

# Create CBR traffic source 1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp0

# Create CBR traffic source 2

set cbr2 [new Application/Traffic/CBR]

$cbr2 attach-agent $udp1

# Create receivers

set rcvr1 [new Agent/Null]

$ns attach-agent $n5 $rcvr1

$ns at 1.0 "$n5 join-group $rcvr1 $group1"

set rcvr2 [new Agent/Null]

$ns attach-agent $n6 $rcvr2

$ns at 1.5 "$n6 join-group $rcvr2 $group1"

set rcvr3 [new Agent/Null]

$ns attach-agent $n7 $rcvr3

$ns at 2.0 "$n7 join-group $rcvr3 $group1"


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

set rcvr4 [new Agent/Null]

$ns attach-agent $n5 $rcvr4

$ns at 2.5 "$n5 join-group $rcvr4 $group2"

set rcvr5 [new Agent/Null]

$ns attach-agent $n6 $rcvr5

$ns at 3.0 "$n6 join-group $rcvr5 $group2"

set rcvr6 [new Agent/Null]

$ns attach-agent $n7 $rcvr6

$ns at 3.5 "$n7 join-group $rcvr6 $group2"

# Schedule events

$ns at 0.5 "$cbr1 start"

$ns at 9.5 "$cbr1 stop"

$ns at 0.5 "$cbr2 start"

$ns at 9.5 "$cbr2 stop"

# Post-processing

$ns at 10.0 "finish"

proc finish {} {

global ns tf

$ns flush-trace

close $tf

exec nam mcast.nam &

exit 0

# Colors for packets from two multicast groups


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

$ns color 10 red

$ns color 11 green

# Labels and colors for nodes

$n0 color red

$n0 label "Source 1"

$n1 color red

$n1 label "Source 2"

$n5 label "Receiver 1"

$n5 color blue

$n6 label "Receiver 2"

$n6 color blue

$n7 label "Receiver 3"

$n7 color blue

# Animation rate

$ns set-animation-rate 3.0ms

$ns run
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

EX NO: 10 SIMULATION OF ERROR CORRECTION CODE (LIKE CRC)

PROGRAM:

import java.io.*;

class crc_gen

public static void main(String args[]) throws IOException

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));

int[] data;

int[] div;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

int[] divisor;

int[] rem;

int[] crc;

int data_bits, divisor_bits, tot_length;

System.out.println("Enter number of data bits : ");

data_bits=Integer.parseInt(br.readLine());

data=new int[data_bits];

System.out.println("Enter data bits : ");

for(int i=0; i<data_bits; i++)

data[i]=Integer.parseInt(br.readLine());

System.out.println("Enter no. of bits in divisor: ");

divisor_bits=Integer.parseInt(br.readLine());

divisor=new int[divisor_bits];

System.out.println("Enter Divisor bits : ");

for(int i=0; i<divisor_bits; i++)

divisor[i]=Integer.parseInt(br.readLine());

tot_length=data_bits+divisor_bits-1;

div=new int[tot_length];

rem=new int[tot_length];

crc=new int[tot_length];

/*------------------ CRC GENERATION---------------------*/

for(int i=0;i<data.length;i++)

div[i]=data[i];

System.out.print("Dividend (after appending 0's): ");


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

for(int i=0; i< div.length; i++)

System.out.print(div[i]);

System.out.println();

for(int j=0; j<div.length; j++)

rem[j] = div[j];

rem=divide(div, divisor, rem);

for(int i=0;i<div.length;i++) //append dividend & rem

crc[i]=(div[i]^rem[i]);

System.out.println();

System.out.println("CRC code : ");

for(int i=0;i<crc.length;i++)

System.out.print(crc[i]);

/*-------------------ERROR DETECTION---------------------*/

System.out.println();

System.out.println("Enter CRC code of " + tot_length

+ " bits : ");

for(int i=0; i<crc.length; i++)

crc[i]=Integer.parseInt(br.readLine());

for(int j=0; j<crc.length; j++)

rem[j] = crc[j];

rem=divide(crc, divisor, rem);

for(int i=0; i< rem.length; i++)


PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

if(rem[i]!=0)

System.out.println("Error");

break;

if(i==rem.length-1)

System.out.println("No Error");

static int[] divide(int div[],int divisor[], int rem[])

int cur=0;

while(true)

for(int i=0;i<divisor.length;i++)

rem[cur+i]=(rem[cur+i]^divisor[i]);

while(rem[cur]==0 && cur!=rem.length-1)

cur++;

if((rem.length-cur)<divisor.length)

break;

return rem;

}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178

RESULT:

You might also like