0% found this document useful (0 votes)
308 views107 pages

CS8581 Networks+Lab

This lab manual outlines experiments to be performed in the Computer Science Networks Laboratory course. Students will learn to use network commands, implement various network protocols using TCP and UDP sockets, and use network simulation tools to analyze protocol performance. Experiments include using tools like tcpdump and traceroute, writing client-server programs, simulating protocols like ARP, and analyzing routing and error correction through simulation. The goal is for students to gain practical skills in networking concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
308 views107 pages

CS8581 Networks+Lab

This lab manual outlines experiments to be performed in the Computer Science Networks Laboratory course. Students will learn to use network commands, implement various network protocols using TCP and UDP sockets, and use network simulation tools to analyze protocol performance. Experiments include using tools like tcpdump and traceroute, writing client-server programs, simulating protocols like ARP, and analyzing routing and error correction through simulation. The goal is for students to gain practical skills in networking concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

Depar

tmentofComput
erSci
enceand
Engi
neer
ing

LabManual
CS8581-Net
wor
ksLabor
ator
y
(
Vsemest
er)
Regul
ati
on2017
LT P C
CS8581 NETWORKSLABORATORY 00 42
OBJECTI
VES:
• Tolear
nandusenet workcommands.
• Tolear
nsocketprogrammi ng.
• Toimplementandanalyzev ari
ousnetwor
kprot
ocol
s.
• Tolear
nandusesi mulati
ont ool
s.
• Tousesimulat
iontoolstoanalyzetheper
for
manceofvar
iousnet
wor
kpr
otocol
s.

LISTOFEXPERI MENTS
1. Learnt ousecommandsl iket cpdump, netstat ,if
confi
g,nslookupandt raceroute.
Capturepi ngandt r
acer out ePDUsusi nganet workprotocolanal y
zerandexami ne.
2. Wr i
teaHTTPwebcl i
entpr ogram t odownl oadawebpageusi ngTCPsocket s.
3. Applicati
onsusi ngTCPsocket slike:
•Echocl i
entandechoser v
er
•Chat
•Fi l
eTransf er
4. SimulationofDNSusi ngUDPsocket s.
5. Wr i
teacodesi mul ati
ngARP/ RARPpr ot ocols.
6. StudyofNet worksi mul ator( NS)andSi mul at ionofCongest i
onCont rolAlgorit
hmsusing
NS.
7. StudyofTCP/ UDPper f
ormanceusi ngSi mul ationtool
.
8. SimulationofDi stanceVect or/Li nkSt at eRout i
ngalgori
thm.
9. Performanceev aluationofRout ingpr ot ocolsusi ngSimul at
iont ool.
10. Simulationofer rorcor r
ect ioncode( l
ikeCRC) .
TOTAL:60PERI ODS
OUTCOMES:
UponCompl etionoft hecour se, thest udent swi llbeabl eto:
• I mpl ementv ariouspr ot ocolsusi ngTCPandUDP.
• Compar etheper for manceofdi f
fer enttr ansportl
ayerpr otocols.
• Usesi mulationt oolst oanal yzet heper for manceofv ari
ousnet workprotocols.
• Anal yzev ariousr outingal gorithms.
• I mpl ementer rorcor rectioncodes.

LI
STOFEQUI
PMENTFORABATCHOF30STUDENTS:

LABORATORYREQUI REMENTFORBATCHOF30STUDENTS:
HARDWARE:
1.Standal
onedeskt
ops 30Nos

SOFTWARE:
2.C/C++/Java/Py
thon/Equi
val
entCompi
l
er 30

Net
wor
ksi
mul
atorl
i
keNS2/
Glomosi
m/OPNET/PacketTr
acer/Equi
val
ent
I
NDEX

S.
NO LI
STOFTHEEXPERI
MENT PAGE.NO.
Learnt ousecommandsl i
ket cpdump,netst
at,
ifconf
ig,
nsl
ookup
and
tr
acer oute.Capt
urepingandtraceroutePDUsusinganetwork
1. protocol
analyzerandexami ne
Wr i
teaHTTPwebcl i
entpr
ogram t odownloadawebpageusing
TCP
2.
socket s
Applicati
on susi

ngTCPsocket slike:
Echocl
ientandechoser
ver
3. ➢
Chat

Fi
leTr
ansfer
4. Si
mul
ati
onofDNSusi
ngUDPsocket
s.
5. Wri
teacodesimulat
ingARP/RARPprotocol
s.
St
udyofNetworksimulat
or(
NS)andSimulat
ionofCongest
ion
Cont
rol
6.
Al
gori
thmsusi
ngNS
7. St
udyofTCP/
UDPper
for
manceusi
ngSi
mul
ati
ont
ool
.

8. Si
mul
ati
onofDi
stanceVect
or/Li
nkSt
ateRout
ingal
gor
it
hm.

Per
for
manceev
aluat
ionofRout
ingpr
otocol
susi
ngSi
mul
ati
ont
ool
.
9.
10. Si
mul
ati
onofer
rorcor
rect
ioncode(
li
keCRC)
.
Topi
cBey
ondSy
ll
abus
a.
UDPChatServ
erandCli
ent.
11
b.
Car
ri
erSenseMult
ipl
eAccess.
Ex.
No:
1 Learntousecommandsl i
ket
cpdump,net
stat
,if
conf
ig,
nslookupand
tr
acerout
e.Captur
epingandt
racer
out
ePDUsusi nganetworkprot
ocol
anal
yzerandexamine

AI
M:
Towr
it
ethej
avapr
ogr
am f
orsi
mul
ati
ngTr
acer
out
ecommand

THEORY:
Traceroutei sanet wor kdi agnost ictoolusedt otrackt hepat hwayt akenbyapacket
onanI Pnet workf rom sour cet odest inat i
on.Tr acerout ealsor ecor dst hetimet akenf oreach
hopt hepacketmakesdur ingi t
sr outet othedest i
nat i
on.Tr acerout eusesI nternetCont rol
MessagePr otocol( I
CMP)echopacket swi thv ari
ablet imet ol ive(TTL)v alues.Ther esponse
ti
meofeachhopi scal culated.Toguar anteeaccur acy ,eachhopi squer iedmul ti
plet i
mes
(usuall
ythreet i
mes)t obet termeasur et her esponseoft hatpar t
icularhop.Tr acer outesends
packetswi thTTLv aluest hatgr adual lyincr easef rom packett opacket ,st ar
t i
ngwi t
hTTL
valueofone.Rout ersdecr ementTTLv aluesofpacket sbyonewhenr out i
nganddi scard
packetswhoseTTLv aluehasr eachedzer o,returningt heI CMPer rormessageI CMPTi me
Exceeded.Fort hef ir
stsetofpacket s,thef i
rstrout errecei vest hepacket ,decr ement st he
TTLv alueanddr opst hepacketbecausei tt henhasTTLv aluezer o.Ther outersendsan
ICMPTi meExceededmessagebackt ot hesour ce.Thenextsetofpacket saregi venaTTL
valueoftwo,sot hef irstrout erforwar dst hepacket s,butt hesecondr outerdr opst hem and
repli
eswi thICMPTi meExceeded.Pr oceedi ngi nthisway ,tracerout eusest her eturnedI CMP
TimeExceededmessagest obui l
dal istofr out er
st hatpacket st r
av erse,unt i
lthedest i
nation
i
sr eachedandr eturnsanI CMPEchoRepl ymessage.Thet i
mest ampv aluesr eturnedf or
eachr outeralongt hepat har ethedel ay( l
atency )values,ty picall
ymeasur edi nmi l
li
seconds
foreachpacket .Thesenderexpect sar eplywi t
hinaspeci fi
ednumberofseconds.

ALGORI
THM:

1.Start
2.Creat eaUDPpacketf rom thesour cetodestinati
onwithaTTL=1
3.TheUDPpacketr eachesthef irstrouterwheret herouterdecrementst hev al
ueofTTL
by
1,thusmaki ngourUDPpacket ’sTTL=0andhencet hepacketget sdropped.
4.Ast hepacketgotdr opped, itsendsanI CMPmessage( Timeexceeded)backt o
thesour ce.
5.Rout er’
saddressandt het i
met akenf ortheround-tr
iparenot ed.
6.I
tsendst womor epacket sint hesamewayt ogetanav erageval
ueoft heround-
tr
ip
ti
me.
7.Thest eps1t o5r epeatedunt ilthedestinati
onhasbeenr eached.Butforeach
ti
me, t
heTTLi sincrementedby1whent heUDPpacketi stobesentt onext
router/host.
8.Oncet hedesti
nationisreached, anICMPmessage( t
hist i
me–Dest inat i
on
Unreachabl
e)i
ssentbacktothesour
ce.
9. Receivi
ngDest
inat
ionUnreachabl
emessage,
displ
ayt
hedet
ail
soft
her
out
etr
aced.
10.St
op.
PROGRAM:
i
mportjava.net.*;
i
mportjava.i
o.*;
cl
assWhoi sext endsThr ead
{
publi
cSt ringt raceCmdUni x=" tracert-h10;
pri
vateSt ringBuf ferresul t=nul l;
pri
vatev oidpi ngCmd( Str i
ngcommand)
{
resul t=newSt ringBuf fer( );
try{
Processp;
p=Runt i
me. get Runt i
me( ).
exec(command) ;
readResul t
(p. get InputStream( )
);
p.dest roy ()
;
}
cat ch( Except ione){
e.pr i
ntSt ackTr ace( );
}
}
pri
vatev oidr eadResul t(Input St r
eam in)
{
St ri
ngl ine=nul l;
Buf feredReaderbr=newBuf f
eredReader(new
Input StreamReader (i
n) ); t
ry{
whi le( !
this.isInt er r
upted()&&( li
ne=br .
readLi
ne(
))!
=nul
l
)
{
//this.doResul tLine(l
ine+"\
n");
Sy stem. out .
printl
n(li
ne);
}
}
cat ch( IOEx cept i
one){
e.pr i
ntSt ackTr ace( );
}
finally{
try{
br.close( )
;
}
cat ch( IOExcept ione){ }
}
if(this.isInterrupt ed( ))
Sy stem. out .print ln("
***Cancel d***"
);
}
publicst at
icvoidmain(Stri
ngar gs[])throws
Except i
on{
WhoisMy Obj=newWhoi s()
;
My Obj.
tr
aceCmdUni x=My Obj .
traceCmdUni
x+""+
"www. y
ahoo.com"; My Obj.
pingCmd( My
Obj.
tr
aceCmdUni
x);
}}
OUTPUT:
C:\>tracert-d5-w600www. y ahoo.com
Tracingr outetowww. yahoo.akadns. net
[
68. 142.226.39]overamaxi mum of30hops:
1<10ms<10ms<10ms10. 129.210. 100
2***Requestt i
medout .
3***Requestt i
medout .
4***Requestt i
medout .
5***Requestt i
medout .
6***Requestt i
medout .
7***Requestt i
medout .
8***Requestt i
medout .
9***Requestt i
medout .
10***Requestt imedout.

POSTLABVI
VAQUESTI
ONS:

1.Def inepointtopoi ntconnection.


2.Def inemul t
ipointconnection
3.Expl ai
nthedi ff
erencebet weenanunspecif
iedpassi
veopenandaf
ull
yspeci
fi
ed
passiveopen
4.Def ineSubnet t
ing.
5.Wharar etheadapt i
veroutingalgor
it
hms.
6. Wh atisthemai nreasonf orIPV6beingdevel
oped?

RESULT:
Thustheprogram wasi
mpl
ement
ingt
osi
mul
atepi
ngandt
racer
out
ecommands
execut
edsuccessful
l
y .
Ex.
No:2 Wr
it
eaHTTPwebcl
i
entpr
ogr
am t
odownl
oadawebpageusi
ngTCPsocket
s

AI
M:
Towr
it
eaj
avapr
ogr
am f
orsocketf
orHTTPf
orwebpageupl
oadanddownl
oad.

THEORY:
HTTPmeansHy perTextTr ansf erPr otocol.HTTPi st heunderlyi
ngpr otocolusedby
theWor ldWi deWebandt hispr ot
ocoldef i
neshowmessagesar eformatt edandt r
ansmi tt
ed,
andwhatact ionsWebser v
ersandbr owser sshoul dtakeinresponset ov ariouscommands.
Forexampl e,wheny ouent eraURLi ny ourbr owser ,t
hisactuall
ysendsanHTTPcommand
totheWebser verdi r
ectingitt ofetchandt ransmi ttherequestedWebpage.Theot hermai n
standardt hatcont r
olshow t heWor ldWi deWebwor ksisHTML,whi chcov ershow Web
pagesar ef ormat tedanddi splayed.HTTPf unct i
onsasar equest–responsepr otocolint he
cli
ent–servercomput i
ngmodel .Awebbr owser ,for
exampl e,maybet heclientandanappl icati
onr unningonacomput erhost ingawebsi t
emay
bet heserver.Thecl i
entsubmi t
sanHTTPr equestmessaget otheser ver
.Theser ver,which
prov i
desresour cessuchasHTMLf il
esandot hercontent,orperformsot herf uncti
onson
behalfoft he client,ret ur
ns a r esponsemessage t ot he cli
ent.The r esponse cont ains
compl eti
onst atusi nfor
mat i
onaboutt her equestandmayal socont ai
nr equest edcont entin
i
tsmessagebody .

PRELABVI
VAQUESTI
ONS:

1.CompareHTTPandFTP
2.Whatdoyoumeanbyactiv
ewebpage?
3.Whatiswebbrowser
4.Whatarethef
ourMainpr
opert
iesofHTTP?
5.Descr
ibewhyHTTPisdesi
gnedasastatel
esspr
otocol
.

ALGORI
THM:

Cl
ient:
1.Start
.
2.Createsocketandestabli
sht
heconnecti
onwi t
htheser
ver
.
3.Readt heimagetobeuploadedfr
om thedisk
4.Sendt hei
mager eadtotheser
ver
5.Terminatetheconnecti
on
6.Stop.

1.St
art
2.Cr
eatesocket,
bindIPaddr
essandpor
tnumberwi
tht
hecr
eat
edsocketand
makeserverali
steni
ngser
ver
.
3.Acceptt
heconnect
ionr
equestf
rom t
hecl
i
ent
4.Receiv
etheimagesentbyt
hecl
i
ent
.
5.Displ
aytheimage.
6.Closetheconnect
ion.
7.Stop.

PROGRAM
Cl
ient

i
mpor tjav ax.swi ng.* ;
i
mpor tjav a.net.* ;
i
mpor tjav a.awt .image. *;
i
mpor tjav ax.imagei o.*;
i
mpor tjav a.i
o. *;
i
mpor tjav a.awt .image. Buf fer edImage; i
mpor t
j
ava.i
o.By teAr ray Output Stream; i
mpor t
j
ava.i
o.File;
i
mpor tjav a.i
o. I
OExcept ion; impor t
j
avax.i
magei o.I
mageI O;
publ
iccl assCl i
ent
{
publ i
cst aticv oidmai n( Stri
ngar gs[])thr ows
Except i
on{
Socketsoc;
Buf feredImagei mg=nul l
;
soc=new
Socket ("l
ocal host ",
4000) ;
Sy stem. out.print ln("
Clientisr unni ng.
")
;
tr
y{
Sy stem. out .
printl
n("Readi ngi magef rom disk.")
;
img=I mageI O. r
ead(new
Fi l
e("digit al_i
mage_ pr ocessi ng.j
pg"));
By teArr ay Output Str
eam baos=new
By teArr ay Output Str
eam( );ImageI O.wri
te(i
mg, "j
pg",
baos)
;
baos. flush( )
;
by te[]by tes=baos. toBy teAr r
ay();baos.cl
ose();
Sy stem. out .
printl
n("Sendi ngi maget oser v
er.")
;
Out put St ream out=soc. get OutputStr
eam( );
Dat aOut put Str
eam dos=newDat aOutputStream(out)
;
dos. wr i
t eInt(bytes.l
engt h);
dos. wr i
t e( byt
es, 0,bytes.lengt h)
;
Sy stem. out .
printl
n("I
magesentt oserver.")
;
dos. close( );
out
.cl
ose(
);
}
catch(Excepti
one)
{
System.out.
pri
ntl
n("
Excepti
on:"+
e.
get Message(
));
soc.cl
ose()
;
}
soc.cl
ose();
}
}

Ser
ver

i
mportjava.net.*;
i
mportjava.i
o. *
;
i
mportjava.awt .i
mage. *;
i
mportjavax.i
magei o.*;
i
mportjavax.swi ng.* ;
cl
assServer
{
publi
cst at icv oidmai n(
Stringargs[
])throws
Except i
on{
Serv erSocketser ver=nul
l;
Socketsocket ;
serv er=newSer v
erSocket(4000);
Syst em. out.
print
ln("Ser
verWaitingforimage" )
;
socket =server.accept()
;System.out.pri
ntl
n("Cl
ient
connect ed.
");I
nput Str
eam in=socket .
getInputStr
eam();
Dat aInputStream dis=newDat aInputStr
eam( i
n);intl
en=
dis.readInt()
;

System. out.pri
ntln("I
mageSi ze:"+len/
1024+"
KB"
);by
te[
]dat
a=new
byte[l
en];
dis.
readFul ly(
data) ;
dis.
close( );
i
n.close();
I
nput Str
eam i an=new
ByteArrayInputStream( data)
;Buffer
edImage
bImage=I mageI O.read(ian)
;JFramef=new
JFrame( "Server"
);ImageI conicon=new
I
mageI con( bImage) ;
JLabel l=newJLabel ();
l
.setIcon(icon);
f
.add(l
);
f
.pack(
);
f
.set
Visi
ble(
true)
;
}
}

OUTPUT:

Wheny
our
unt
hecl
i
entcode,
fol
l
owi
ngout
putscr
eenwoul
dappearoncl
i
entsi
de.

POSTLABVI
VAQUESTI
ONS:

1.Def
ineWWW?
2.Whatarethefourgr
oupsofHTTPHeader
s?
3.WhatisURL.
4.WhathappensifACK/NACKcorr
upt
ed?
5.Whatiscongesti
on
6.Wri
tetheservi
cesprov
idedbyt
heTCP?

RESULT:
Thusthesocketpr
ogram forHTTPf
orwebpageupl
oadanddownl
oadwas
devel
opedandexecutedsuccessful
l
y.
Ex.
No:3 Appl
icat
ionsusi
ngTCPsocket
sli
ke:Echocl
ientandechoser
ver
,
ChatandFi
leTr
ansf
er

AI
M
Towr
it
eaj
avapr
ogr
am f
orappl
i
cat
ionusi
ngTCPSocket
sLi
nks

THEORY:
Int heTCPEchocl i
entasocketi scr eated.Usingt hesocketaconnect ioni smadet ot he
ser verusi ngt heconnect ()funct ion.Af teraconnect i
oni sest ablished,wesendmessages
i
nputf rom t heuseranddi splayt hedat ar eceiv
edf rom theser verusingsend( )andr ead()
funct ions.I nt heTCPEchoser v er,wecr eateasocketandbi ndt oaadv erti
zedpor tnumber .
Af terbi ndingt hepr ocessl ist
ensf ori ncomi ngconnect i
ons.Thenani nfi
niteloopi sstartedt o
processt hecl ientr equestsf orconnect i
ons.Af t
eraconnect ioni srequest ed,itaccept st he
connect ionf rom t heclientmachi neandf orksanewpr ocess.Thenewpr ocessr eceivesdat a
from t hel ientusi ngr ecv (
)f unctionandechoest hesamedat ausi ngt hesend( )function.
Pleasenot ehatt hisserveriscapabl eofhandl i
ngmul ti
pleclientsasi tforksanewpr ocessf or
ev ery cl i
entt rying t o connectt ot he ser v
er.TCP socketr outines enabl er eli
ableI P
communi cationusi ngthet r
ansmi ssioncont r
olprotocol( TCP) .Thi ssect i
ondescr i
best he
i
mpl ement ationoft heTr ansmi ssionCont rolProtocol(TCP)i nt heNet wor kComponent .TCP
runsont opoft heI nternetPr otocol( IP).TCPi saconnect ion-orientedandr el
iable,ful
ldupl ex
prot ocolsuppor t
ingapai rofby test reams, oneforeachdi recti
on.ATCPconnect i
onmustbe
est ablished bef ore exchangi ng dat a.TCP r etr
ansmi ts datat hatdo notr each the final
dest inat i
on due t o er r
ors ordat a cor r
upt i
on.Dat ai s delivered int he sequence ofi ts
transmi ssion

PRELABVI
VAQUESTI
ONS:

1.Defi
ne–Socket
2.Defi
nethethreestatesofTCPConnectionest
abl
i
shmentandt
ermi
nat
ion.
3.Li
stthety
pesofsocket s
4.Howasocketi suniquel
yidenti
fi
ed?
\
5.WhatisActi
veopen
6.Whatissocketabstract
ion?
7.Comparevari
oussocketaddr essst
ruct
ures
ALGORI
THM

Cl
ient
1.Start
2.CreatetheTCPsocket
3.Establ
ishconnecti
onwiththeserv er
4.Getthemessaget obeechoedf rom theuser
5.Sendt hemessagetotheserver
6.Receivethemessageechoedbyt heserv
er
7.Displ
ayt hemessagerecei
vedfrom theserver
8.Terminatetheconnect
ion
9.Stop

Ser
ver
1.Start
2.CreateTCPsocket ,makeitalisteni
ngsocket
3.Acceptt heconnect i
onrequestsentbyt hecli
entforconnecti
onestabli
shment
4.Receivet hemessagesentbyt hecli
ent
5.Displayther eceiv
edmessage
6.Sendt her eceiv
edmessaget ot hecli
entfrom whichitr
eceiv
es
7.Closet heconnect i
onwhencl i
entini
tiat
est er
minati
onandser verbecomesa
li
steningser ver
,waiti
ngforcl
ients.
8.Stop.

PROGRAM:
EchoSer ver
.java
i
mpor tjava.net.*;
i
mpor tjava.i
o. *
;
publ
iccl assESer ver
{
publicstaticv oi
dmai n(
Stri
ngargs[
])
{
ServerSockets=null
;
Str
ingline;
DataInputSt
ream is;
Pri
ntStream ps;
Socketc=null;
tr
y
{
s=newSer ver
Socket(
9000)
;
}
catch(
IOExcept i
one)
{
System.out .
pri
ntln(e);
}
tr
y
{
c=s.
accept ();
i
s=newDat aI
nput Str
eam(c.
get
InputSt
ream(
));
ps=newPr i
ntStream( c.
get
OutputStr
eam()
);
whil
e(true)
{
l
ine=is.r
eadLi ne(
);
ps.pri
ntln(li
ne);
}
}
catch(
IOExcept i
one)
{
System.out .
pri
ntln(e);
}
}
}

EClient.
jav a
i
mpor tj
av a.
net.*;
i
mpor tj
av a.
io.*
;
publicclassECl i
ent
{publi
cst ati
cvoidmai n(St
ri
ngarg[]
)
{
Socketc=null;St
ri
ng
l
ine;
DataInputStr
eam
i
s,i
s1; Pri
ntStr
eam os;

t
ry
{
I
netAddressia=
I
netAddress.
get
Local
Host
();
c=new
Socket
(i
a,9000)
;
}
cat
ch(
IOExcept
ione)
{
Syst
em.out.
pri
ntl
n(e)
;
}
t
ry
{
os=newPr i
ntStream( c.
get OutputStr
eam( ))
;
i
s=newDat aInputSt r
eam( System.in);
i
s1=newDat aInput Str
eam( c.getI
nputStream())
;
whil
e(t
rue)
{
Syst
em.out.pri
ntln("Cli
ent:"
);
li
ne=is.r
eadLi ne();
os.pri
ntln(l
ine);
System.out .
printl
n("Server:
"+is1.readLi
ne())
;
}
}
cat
ch(
IOExcept
ione)
{
Syst
em.out.
pri
ntl
n("
SocketCl
osed!
")
;
}
}}
OUTPUT
Server
C:\
Pr ogram Fil
es\Jav
a\j
dk1.
5.0\
bin>j
avacEServer
.j
ava
C:\
Pr ogram Fil
es\Jav
a\j
dk1.
5.0\
bin>j
avaEServer
C:\
Pr ogram Fil
es\Jav
a\j
dk1.
5.0\
bin>
Cli
ent
C:\
Pr ogram Fil
es\Jav
a\j
dk1.
5.0\
bin>j
avacECli
ent.
jav
a
C:\
Pr ogram Fil
es\Jav
a\j
dk1.
5.0\
bin>j
avaECli
ent
Cli
ent:
HaiSer v
er
Server:
Hai Server
Cli
ent:
Hell
o
Server:
Hel l
o
Cli
ent:
end
Server:
end
Cli
ent:
ds
SocketCl osed!
B.
Chat

ALGORI
THM

Cl
ient
1.Start
2.Createt heUDPdat agram socket
3.Gett her equestmessaget obesentf rom t
heuser
4.Sendt her equestmessaget ot heserver
5.Iftherequestmessagei s“ END”got ostep10
6.Wai tfort her epl
ymessagef r
om theserver
7.Recei vether eplymessagesentbyt heserver
8.Displayt her eplymessager eceiv
edf r
om theser
ver
9.Repeatt hest epsfr
om 3to8
10.
Stop

Ser
ver
1.Start
2.CreateUDPdat agram socket,makeitali
steningsocket
3.Receivet herequestmessagesentbyt heclient
4.Ifthereceivedmessagei s“END”got ostep10
5.Retri
evet heclient
’sIPaddressfrom t
herequestmessagerecei
ved
6.Displayther eceivedmessage
7.Getther eplymessagef rom theuser
8.Sendt her eplymessaget othecli
ent
9.Repeatt hest epsf r
om 3t o8.
10.
Stop.

PROGRAM
UDPserver.
java
i
mportjava.
io.*;
i
mportjava.
net.* ;
cl
assUDPser ver
{
publi
cst aticDatagr amSocketds;
publi
cst aticbytebuf f
er[]
=newby te[1024];
publi
cst aticintcl
ientport
=789,serverport=790;
publi
cst aticvoidmai n(St
ringargs[]
)throwsExcepti
on
{
ds=newDat agr amSocket(cl
ientport);
Sy stem.out.pri
ntl
n("pr
essct r
l+ct oquitt
he
progr am");
Buf
feredReaderdi s=newBuf feredReader (
new
I
nputStreamReader (Sy stem.in));InetAddress
i
a=I
net Addr ess.gey Local Host ()
; whil
e(tr
ue)
{
Dat agr amPacketp=new
Dat agr amPacket (buffer,
buf f
er.l
engt h)
;ds.r
eceiv
e(p);
St ri
ngpsx=new
St ri
ng( p.
get Dat a()
,0,
p.getLength());
Sy stem. out.printl
n( "
Cli
ent:"+psx) ;
Sy stem. out.printl
n( "
Server:")
;Stri
ng
st r
=di s.r
eadLi ne();
if(str.
equal s("end" ))
break;
buf fer=str.get Bytes();
ds. send( newDat agramPacket (buffer,
str
.l
ength(
),i
a,
serv
erpor
t))
;
}
}
}
UDPcl
ient.j
av a
i
mportjava.io.*;
i
mportjava.net.*;
cl
assUDPcl ient
{
publi
cst aticDat agr amSocketds;
publi
cst atici ntcl i
ent por t
=789, serv erport=790;
publi
cst aticv oidmai n(Stringar gs[])throwsExcept i
on
{
bytebuf f
er [
]=newby t
e[1024] ;
ds=newDat agramSocket (ser verport)
;
BufferedReaderdi s=newBuf feredReader(
new
I
nput StreamReader (Sy stem. in));
System. out .pr i
ntln("serverwai ti
ng");
I
netAddr essi a=I netAddr ess. getLocalHost()
;
while(true)
{
Sy stem. out .
pr i
ntln( "Client:"
);
Stringst r
=di s.r
eadLi ne( );
if
(st r
.equal s( "
end" )
)
break;
buff er=str.get Bytes( );
ds.send( new
Dat agramPacket (buf fer,st
r.l
ength(
),
ia,
cl
ient
por
t))
;
Dat agramPacket p=new
Datagr
amPacket
(buff
er,
buff
er.
lengt
h);ds.r
ecei
ve(
p);
St
ri
ngpsx=newString(
p.get
Data(),
0,
p.getLengt
h()
);
Sy
stem.
out
.pr
int
ln(
"Ser
ver
:"+psx)
;
}
}
}

OUTPUT:
Ser
ver

C:\Pr
ogr am Fil
es\Java\jdk1.5.
0\bi
n>j
avac
UDPser ver.
javaC:\Program
Fil
es\Jav a\
jdk1.
5.0\bin>javaUDPserv
erpressct
rl
+c
toquitthepr ogr
am Cl i
ent :
HaiServ
er

Server
:
Hell
oCl i
ent
Cli
ent:
Howar eYou
Server
:
Iam Fine

Cli
ent
C:\
Pr ogram Fi
les\Jav
a\j
dk1.
5.0\
bin>j
avacUDPcli
ent
.j
ava
C:\
Pr ogram Fi
les\Jav
a\j
dk1.
5.0\
bin>j
avaUDPcl
ient
serv
erwai ti
ng
Cli
ent:
HaiSer ver
Server:
HelloClie
Cli
ent:
Howar eYou
Server:
Iam Fine
Cli
ent:
end
C.Fi
leTr
ansf
er

ALGORI
THM

Cl
ient
1.Start
2.CreatetheTCPsocket
3.Establ
isht heconnect i
onwi t
ht hwser ver
4.Getthenameoft herequestedf i
lefrom theuser
5.Sendt her equestedfi
lenamet otheser ver
6.Getthenewnamef orstori
ngf i
lecontenttoberecei
vedf
rom t
heuser
.
7.Createaf ilebynewnamei nt hewr i
temode
8.Waitfort hetransferoffil
efrom theser ver
Receivethef il
econtentsentbyt heserv erandst
oret
hecont
entsi
nthefi
l
ecr
eat
ed
9.inwrit
e
mode
10.
Displ
ayt hef i
lecontentrecei
v edfrom theserver
11.
Stop

Ser
ver
1.Start
2.CreateTCPsocket ,makei tali
steningsocket
3.Accepttheconnect i
onrequestfrom t hecli
entforconnect
ionest
abli
shment
4.Receivethenameoft herequestedf i
l
ef rom thecli
ent
5.Displ
ayt hefi
l
econt ent
6.Transferthefi
lecontentoftherequest edvfi
letothecl
ient
7.Closetheconnectionwhent hecl i
entinit
iatesconnecti
onter
minat
ion
8.Stop.

PROGRAM
Fi
leCl
ient
i
mportjava.
io.*
;
i
mportjava.
net.*;
i
mportjava.
util
.*
;
cl
assClient
fi
le
{
publi
cstati
cvoi
dmai
n(St
ri
ngar
gs[
])
{
Try
{

Buf
fer
edReaderi
n=newBuf
fer
edReader
(newI
nput
Str
eamReader
(Sy
stem.
in)
);
Socketcl sct =newSocket (
"127. 0.0.1",139);
DataInput Stream di n=newDat aInput St r
eam( clsct
.get
Input
Str
eam()
);
DataOut put St r
eam dout =new
DataOut put St r
eam( clsct.get Out putStr eam( )
);
System. out .pr intln("Ent ert hef il
ename: ");
Stringstr=i
n.r
eadLi
ne(
);
dout.wr iteBy tes( str+'\n');
System. out .pr intln("Ent ert henewf il
ename: ");
Str
ingst r2=i n.readLi ne();
Str
ingst r1,ss;
Fi
leWr iterf =newFi l
eWr iter(str2);
charbuf fer[];
while(t
r ue)
{
str1=di n.readLi ne( );
if(str1. equal s( "-
1") )
br eak;
Sy stem. out .println(st r
1) ;
buf fer =newchar [str1.lengt h()
];
str1.get Char s( 0,
st r1.lengt h()
,buf fer
,0);
f.wr i
te( buf fer);
}
f.
close( );
cl
sct .
close( );
}
cat
ch(
Excepti
one)
{
System.out
.pr
int
ln(
e);
}
}
}

Ser
ver
i
mportjava.
io.*
;
i
mportjava.
net.*;
i
mportjava.
util
.*
;
cl
assServer
fil
e
{
publi
cstaticv
oidmain(St
ri
ngargs[
])
{
Try
{
Serv
erSocketobj
=newSer
ver
Socket
(139)
;
whi
l
e(t
rue)
{
Socketobj 1=obj.accept ();
Dat aInput Stream di n=new
DataInput Stream( obj1. getInputStream())
;DataOutput
Stream
dout=newDat aOut put Stream( obj1.get
OutputSt
ream())
;
St r
ingst r=din. r
eadLi ne();
FileReaderf =newFi leReader (
str)
;
Buf feredReaderb=newBuf feredReader
(f)
;
St r
ings;
whi le((
s=b. readLine( ))!
=nul l
)
{
Sy stem. out.pr i
ntln(s);
dout .
wr i
teByt es(s+'\n')
;
}
f.close();
dout .writeBy tes("
-1\n" )
;
}
}
cat
ch(
Except
ione)
{
Sy
stem.out
.pr
int
ln(
e);
}
}
}

OUTPUT

Fi
lecontentComput ernetworksj
hfcgsauf
j
bsdavaj bvuesagvcli
ent
Entert
hef i
lename: sample.
txt
server
Comput ernetworksjhf
cgsauf
j
bsdavaj bvuesagv
cl
ient
Entert
henewf il
ename: net
.t
xt
Comput ernetworksjhf
cgsauf
j
bsdavaj bvuesagvDesti
nati
onfil
e
Comput ernetworksjhf
cgsauf
j
bsdavaj bvuesagv
POSTLABVI
VAQUESTI
ONS:

1.Stat
ethediff
er encesbetweenTCPandUDP
2.WhatisPassiveopen?
3.\Whatishal
f-close?
4.Whatarewell-knownpor ts?
5.WhatareDynami c/Pr
ivate/Ephemeral
por
ts?
6.Whatareregisteredports?
7.WhatareSocketAddr essSt r
uct
ures?

RESULT:
Thusthejav
aappli
cat
ionpr
ogr
am usi
ngTCPSocket
swasdev
elopedand
execut
edsuccessf
ull
y.
22

Ex.No:4 Si
mul
ati
onofDNSusi
ngUDPsocket
s

AI
M
Towr
it
eaj
avapr
ogr
am f
orDNSappl
i
cat
ion

THEORY:
TheDomainNameSy st
em ( DNS)isahi er
archicaldecentr
alizednamingsyst
em
forcomput er
s,servi
ces,orot herr esourcesconnect edt otheInt er
netorapr iv
at e
network.I
tassociat
esv ar
iousinformationwi t
hdomai nnamesassi gnedtoeachofthe
part
ici
pati
ngentiti
es.Mostpr ominent l
y,i
tt r
ansl
atesmor ereadi
lymemor i
zeddomai n
namest ot henumer i
calIPaddr essesneededf orl ocatingandi denti
fyi
ngcomput er
servi
cesanddeviceswiththeunder l
yingnetworkprotocols.

PRELABVI
VAQUESTI
ONS:

1.WhatistheDomai nnameSy st
em Responsi bl
efor?
2.WhydoweneedaDomai nNameSy st
em?
3.WhatroledoestheDNSResol verplayintheDNSSy st
em.
4.HowdoesaDNSResol verbootstr
apt heDomai nNameLookupPr
ocess.
5.WhatisaPostof fi
ceProt
ocol/
6.Li
sttheTwot y
pesofDNSmessage.
7.Defi
neSNMP?
8.Whattypeoftranspor
tprot
ocol i
susedf orDNS.
9.WhatisVPN?

ALGORITHM
Server
1.Start
2.CreateUDPdat agram socket
3.Createat abl
ethatmapshostnameandI Paddress
4.Receivethehostnamef rom thecl i
ent
5.Retri
evet hecl
ient’sI
Paddr essf rom t
hereceiv
eddat agr
am
6.GettheIPaddr essmappedf ort hehostnamef rom t
hetable.
7.Displ
ayt hehostnameandcor respondingIPaddress
8.Sendt heIPaddr essfortherequest edhostnamet othecli
ent
9.Stop.
Cli
ent
1.Start
2.CreateUDPdat agram socket.
3.Getthehostnamef r
om theclient
23

4.Sendthehostnametotheserver
5.Waitforther
epl
yfrom t
heserv
er
6.Recei
v et
herepl
ydatagr
am andreadt
heI
Paddr
essf
ort
her
equest
edhostname
7.Displ
aytheIPaddr
ess.
8.Stop.

PROGRAM
DNSSer ver
j
avaimpor tjava.io.*
;
i
mportjava.net .
*;
publ
i
ccl assudpdnsser v
er
{
privatest ati
ci ntindexOf (
String[]array,St r
ingst r)
{
str=st r.tri
m( )
;
for( i
nti =0;i<ar ray.l
engt h;i++)
{
if( arr
ay[i]
.equal s(
st r)
)
returni;
}
return- 1;
}
publ i
cst aticvoi dmai n(Stringar g[])
throwsI OException
{
String[]host s={ "yahoo. com" ,
"gmai l.com","
cri
cinf
o.com","
facebook.
com"}
;
String[]ip={ "68.180. 206. 184","209.85. 148.
19",
"80.
168.92.
140",
"69.63.189. 16"};Sy stem. out.pri
ntln("PressCtrl+Ct oQuit
");whi
le(t
rue)

{
Dat agramSocketser versocket =new
Dat agramSocket (1362) ;byte[]senddat a=new
byte[1021];by te[]recei vedata=newby t
e[1021];
Dat agramPacketr ecv pack=newDat agramPacket (
recei
vedat
a,
receivedata.lengt h);ser versocket.receive(
recvpack);
Stringsen=newSt ring(recvpack. getData()
);
I
net Addressi paddr ess=r ecvpack. getAddress()
;
i
ntpor t=r ecv pack. get Port();
Stringcapsent ;
Syst em.out.printl
n( "Requestf orhost"+sen) ;
i
f(indexOf( host s,sen)! =-1)
24

capsent=i
p[i
ndexOf(
host
s,sen)
];
el
se
capsent=" HostNotFound";
senddata=capsent .get
By t
es()
;
Dat
agramPacketpack=newDat agr
amPacket(senddat
a,
senddata.l
ength,
ipaddress,
port)
;ser
ver
socket.
send(pack)
;
serv
ersocket.cl
ose();
}
}
}

UDPDNSCl ient
j
avaimpor tjava.io.*;
i
mportjava.net .
*;
publ
i
ccl assudpdnscl ient
{
publ i
cst aticv oidmai n(
Stri
ngar gs[ ])
thr ows
IOExcept ion{
Buf feredReaderbr=newBuf feredReader (new
Input StreamReader (System. in));Datagr amSocketcl ientsocket=new
Dat agramSocket (
);I
net Addr essi paddr ess;
i
f( args.lengt h==0)
ipaddr ess=I netAddr ess. getLocal Host ()
;
else
ipaddr ess=I netAddr ess. getBy Name( args[0]
);
by te[
]senddat a=newby te[
1024] ;
by te[
]r ecei
vedat a=newby te[1024] ;
intpor taddr=1362;
Sy stem. out.
print("
Ent ert hehost name: ")
;
St ri
ngsent ence=br .
readLi ne();
Senddat a=sent ence. get Bytes();
Dat agramPacketpack=newDat agr amPacket (senddata,
senddat
a.l
engt
h,
i
paddress,portaddr );
clientsocket.send( pack) ;
DatagramPacketr ecv pack=new
Dat agramPacket (receivedat a,r
eceiv edata.l
ength);
clientsocket.
receive( r
ecv pack);
St ri
ngmodi fi
ed=newSt ri
ng(recv pack.getData( )
);
Sy stem. out.
printl
n( "I
PAddr ess: "+modi f
ied)
;
clientsocket.close() ;
}
25

}
OUTPUT
Server
javacudpdnsserver.
java
javaudpdnsserv
er
PressCtrl+CtoQui tRequestf
orhosty
ahoo.
com
Requestforhostcr i
cinfo.
com
Requestforhosty outube.
com

Cli
ent
javacudpdnscl i
ent
.j
ava
javaudpdnsclient
Entert
hehost name: yahoo.com
I
PAddr ess:68.180.
206.184
j
avaudpdnsclient
Entert
hehost name: cri
cinfo.com
I
PAddr ess:80.168.
92.140
javaudpdnsclient
Enterthehostname: yout ube.com
I
PAddr ess:HostNotFound

RESULT:
Thusthej
avaappl
icat
ionprogram usi
ngUDPSocket
stoi
mpl
ementDNSwas
devel
opedandexecut
edsuccessf
ully
26

Ex.
No:
5 Wr
it
eacodesi
mul
ati
ngARP/
RARPpr
otocol
s

AI
M:

Towr i
teaj avapr ogram forsi mul at
ingARPpr otocolsusi
ngTCP.
THEORY:
Addr essResol utionPr otocol( ARP)i salow- l
evelnetworkprot ocolfortranslati
ng
networ klay
eraddr essesintol i
nklay eraddr esses.ARPl i
esbetweenl ayers2and3oft he
OSImodel ,al
t houghARPwasnoti ncludedi ntheOSIf ramewor kandal l
owscomput ers
tointroduceeachot heracr ossanet workpr iortocommuni cati
on. Becausepr ot
ocols
arebasi cnetwor kcommuni cationuni ts,addressr esoluti
onisdependentonpr ot
ocols
suchasARP,whi chi st heonl yr eli
ablemet hodofhandl i
ngr equiredt asks.When
configuri
nganewnet workcomput er,eachsy stem isassignedanI nternetProt ocol(I
P)
addressf orpr imar yidenti
ficati
onandcommuni cati
on.Acomput eral sohasauni que
medi aaccesscont r
ol(MAC)addr essi dentit
y.Manuf acturer
sembedt heMACaddr ess
i
nt helocalar eanet work(LAN)car d.TheMACaddr ess
i
sal soknownast hecomput er
’sphy sicaladdress.

PRELABVI
VAQUESTI
ONS:

1.Whatisthefunct
ionofARP&RARP?
2.Whatarethefuncti
onsoft
heIP?
3.Di
ff
erencebetweenARPandRARP.
4.Whatisthebenefi
tsofDHCP?

ALGORI
THM:

Cl
ient

1.Starttheprogr am
2.Createsocketandest abli
shconnecti
onwit
htheserver
.
3.Gett heIPaddr esstobeconvert
edintoMACaddressfrom t
heuser
.
4.Sendt hisIPaddr esst
oserver
.
5.Recei vetheMACaddr essfortheIPaddr
essfr
om theserver
.
6.Displayther ecei
vedMACaddr ess
7.Termi natetheconnecti
on

Ser
ver

1.Startt
heprogram
2.Createthesocket,
bindthesocketcreat
edwithIPaddr
essandportnumberand
makei tali
steni
ngsocket.
3.Accepttheconnectionrequestwheniti
srequest
edbythecl
ient
.
4.Servermaintai
nsthetableinwhichI
Pandcor r
espondi
ngMAC
addressesarestor
ed.
27

5.Receivet
heIPaddr esssentbythecli
ent.
6.Retri
evethecorr
espondingMACaddr essfortheIPaddressandsenditt
othe
cli
ent.
7.Closetheconnecti
onwi t
hthecli
entandnowt heserverbecomesa
l
isteni
ngserverwaiti
ngfortheconnect
ionrequestf
rom othercl
i
ents
8.Stop

PROGRAM
Cl
ient
:
i
mportjava.
io.*;
i
mportjava.
net .
* ;
i
mportjava.
util.
*;
cl
assClient
arp
{
publi
cst aticv oidmai n(Stringar gs[
])
{
tr
y
{
Buf feredReaderi n=newBuf f
eredReader (
new
Input StreamReader (Syst em.
in));Socketclsct=new
Socket (
"127.0.0.1",139)
Dat aInput St
ream di n=newDat aInputStream(clsct
.getI
nputSt
ream(
));
Dat aOut putStream dout =new
Dat aOut putStream( clsct.get
Out putSt
ream( ))
;
Sy stem. out.
pr i
ntln("EntertheLogi caladdress(I
P):
");St
ring
str1=in.readLine() ;
dout .writeBytes(str1+'\
n' ;
Stringst r=din.r
eadLi ne();
Sy stem. out.
pr i
ntln("ThePhy sicalAddr essis:"
+str
);
clsct.close();
}
catch(Except i
one)
{
Sy stem. out.
pr i
ntln(e);
}}
}

Ser
ver
:
i
mportj
ava.
io.
*;
i
mportj
ava.
net.
*;
i
mportj
ava.
uti
l.
*;
cl
assSer
ver
arp
{
publ
i
cst
ati
cvoi
dmai
n(St
ri
ngar
gs[
])
28

{
t
ry{
Ser
verSocketobj =new
Ser
verSocket (139) ; Socket
obj
1=obj.
accept ();
whi
le(
true)
{
Dat aInputSt ream di n=newDat aInputStream(obj
1.get
Input
Str
eam(
));
Dat aOut put St r
eam dout =new
Dat aOut put St r
eam( obj1.
getOut putStream());St
ri
ng
str=din.readLi ne()
;
Stringip[ ]
={ "165.165.80.80",
"165. 165.79.1"
};
Stringmac[ ]
={ "6A:08:
AA: C2"
,"8A: BC:
E3:FA"};
for(inti=0;i<ip.length;
i++){

i
f(
str
.equals(i
p[i
])
)
{
dout.wri
teByt
es(
mac[
i]
+'\
n')
;
break;
}
}
obj
.cl
ose(
);
}
}
catch(
Except
ione)
{
Sy
stem.out
.pr
int
ln(
e);
}}
}
Output:
E:
\networ ks>j
avaSer verarp
E:
\networ ks>j
avaClientarp
EntertheLogicaladdress( I
P):
165.165.80.80
ThePhy sicalAddressis: 6A:
08:AA:
C2
29

(
b)Pr
ogr
am f
orRev
erseAddr
essResol
uti
onPr
otocol(
RARP)usi
ngUDP

AI
M:

Towr
it
eaj
avapr
ogr
am f
orsi
mul
ati
ngRARPpr
otocol
susi
ngUDP.

THEORY:
Rev er
se Addr ess Resol ut i
on Pr otocol(RARP) i s an obsol ete
comput er
networkingpr otocolusedbyacl ientcomput ertor equestitsInternetPr ot
ocol(I
Pv4)
addressf r
om acomput ernetwor k,whenal lithasav ai
labl
eisi t
sl i
nklay erorhar dware
address,suchasaMACaddr essRARPr equiresoneormor eser verhostst omai ntai
na
databaseofmappi ngsofLi nkLay eraddressest ot hei
rrespectiveprotocoladdr esses.
Medi aAccessCont r
ol(MAC)addr essesneedt o bei ndiv
iduallyconf iguredont he
serversbyanadmi ni
str
ator
.RARPi sli
mi tedt oservingonlyIPaddr esses. Rever
seARP
dif
fersfrom theI nver
seAddr essResol utionPr otocolwhichisdesi gnedt oobt ai
nt heIP
addressassoci atedwithalocalFr ameRel aydatalinkconnectionidentif
ier.InARPi snot
usedinEt hernet.

ALGORI
THM:

Cl
ient
1.Startthepr ogram
2.Createdat agram socket
3.Gett heMACaddr esstobeconv ert
edint
oIPaddressfrom t
heuser.
4.Sendt hisMACaddr esstoserverusi
ngUDPdatagram.
5.Recei v
et hedat agram fr
om theserveranddi
spl
ayt hecorr
espondi
ngIPaddr
ess.
6.Stop

Ser
ver
1.Startthepr ogram.
2.Servermai nt
ainst hetabl
einwhichIPandcorr
espondi
ngMAC
addressesar est ored.
3.Createt hedat agram socket
4.Receivet hedat agram sentbyt
hecl i
entandr
eadtheMACaddresssent
.
5.Retri
ev et heIPaddr essfort
hereceivedMACaddressf
rom t
hetabl
e.
6.Displayt hecor r
espondingIPaddress.
7.Stop
30

PROGRAM:
Cl
ient
:
i
mportjava.i
o.*;
i
mportjava.net.
* ;
i
mportjava.uti
l.
*;
cl
assClientr
arp12
{
publicstaticv oidmai n(Stringar gs[ ])
{
tr
y
{
Dat agr amSocketcl ient=newDat agramSocket ();
InetAddr ess
addr =Inet Address.get ByName( "127.0.0.1");by te[]
sendby te=newby te[1024] ;by te[]receiveby te=new
byte[1024] ;
Buf feredReaderi n=newBuf feredReader (new
Input St reamReader (
Sy stem. in) );System. out .
pr int
ln("Entert hePhysical
addr ess( MAC) :"
)St ri
ngst r=in.readLine( );sendby te=str.getBytes()
;
DatagramPacket
sender =newDat agr amPacket (sendby te,sendby te.l
ength,addr,1309);
cli
ent .send( sender);
Dat agr amPacketr eceiv er=new
Dat agr amPacket (recei veby te,r
ecei veby te.lengt h);cl
ient.receive(
receiver
);
Strings=newSt r
ing( recei ver.get Data());
Sy stem. out.pr
intl
n( "TheLogi cal Addressi s(IP) :
"+s.trim( )
);cli
ent.close( );
}
catch(Except i
one)
{
Sy stem. out.pr
intl
n( e);
}}
}

Serv
er:
i
mpor tj
ava.i
o.*;
i
mpor tj
ava.net.*
;
i
mpor tj
ava.uti
l.
*;
cl
assSer v
errarp12
{
publ
icstati
cv oidmai
n(St
ri
ngar
gs[
])
{
31

t
ry{
Dat
agramSocketser ver=newDat agr amSocket (
1309);
whi
le(
true)
{
byte[]sendby t
e=newby te[1024] ;
byte[]recei
veby t
e=newby te[1024] ;
Dat agramPacketr eceiver=new
Datagr amPacket (r
eceiveby te,receiv
ebyte.l
engt
h);
ser
ver
.r
ecei
ve(
recei
ver
);
Stri
ngst r=newSt ri
ng( r
eceiv er.getData(
));
Stri
ngs=st r.tr
im();
InetAddressaddr =receiver.get Address()
;
intport=receiver.
getPort()
;
Stri
ngi p[]
={"165.165.80.80","165.165.79.1"
};
Stri
ngmac[ ]
={ "
6A:08:AA:C2" ,"8A:BC:E3:
FA"};
for(
inti=0;i
<ip.l
ength;i
++){

i
f(
s.equal
s(mac[i]
))
{
sendbyte=i
p[i]
.get
Bytes(
);
DatagramPacketsender=new
Datagr
amPacket(
sendby
te,
sendby
te.
lengt
h,addr
,po
rt
);
server
.send(sender)
;
break;
}
}
br
eak;
}
}
cat
ch(
Except
ione)
{
Sy
stem.out
.pr
int
ln(
e);
}
}}
Output:
I
:\ex>j
avaServer
r arp12
I
:\ex>j
avaCli
entrarp12
Entert
hePhy si
cal address(MAC):
6A:08:
AA:C2
TheLogicalAddressi s(
IP):
165.
165.80.
80
32

POSTLABVI
VAQUESTI
ONS:

1.WhatdoyoumeanbyMTU( Maxi
mum tr
ansf
erUni
t)
?
2.Whati
sIPC?Namet hreet
echni
ques.
3.Whati
sthemult
ipl
exing
4.Whati
sARPCache?
5.WhatdoesTTLshows?

RESULT:
Thust
heprogr
am f
orimplement
ingt
odisplaysi
mulat
ingARPandRARP
pr
otocol
swasexecut
edsuccessf
ull
yandout
putisveri
fi
ed.
33

Ex.
No:6 St
udyofNet
wor
ksi
mul
ator(
NS)andSi
mul
ati
onofCongest
ionCont
rol
Al
gor
it
hmsusi
ngNS

AI
M:
ToSt
udyNet
wor
ksi
mul
ator(
NS)
.andSi
mul
ati
onofCongest
ionCont
rol
Al
gor
it
hmsusi
ngNS

PRELABVI
VAQUESTI
ONS:

1.Whatprot
ocolsdoesnssuppor t?
2.Whatshouldyoudotocompi lenst orefl
ectmychangesi
fyou'
vemodi
fi
edsome
.ccor.
hfiles?
3.Namethef act
orst
hataf f
ecttheperformanceofthenet
work.
4.Defi
netheterms:Unicast,mult
icastandBroadcast
5.Whatarethefourf
il
esont heNS2si mulator?

NETWORKSI MULATOR( NS2)


NsOv er v
iew

NsSt atus

Per i
odical release( ns- 2.26,Feb2003)

Platform suppor t

FreeBSD, Linux, Solaris, WindowsandMac
Nsf unctionaliti
es
Rout ing,Tr anspor tation, Tr af
ficsour ces,
Queuingdiscipli
nes,QoS
Congest i
onCont rolAl gor i
thms
• Sl owst art
• Addi tiveincr ease/ mul tiplicati
v edecrease
• Fastr etr
ansmi tandFastr ecov ery
CaseSt udy :Asi mpl eWi relessnet wor k.
Adhocr out i
ng, mobi leI P, sensor -
MAC
Traci ng,visualizationandv ari
ousut ili
ti
e
NS( Net wor kSi mul ators)
Mostoft he commer cialsi mul ators are GUIdr iven,whi le some net work
si
mul atorsar eCLIdr iven.Thenet wor kmodel/conf igur
ati
ondescr i
besthest ateofthe
network( nodes,rout ers,swi tches,l inks)andt heev ents(datat ransmissions,packet
err
oret c.).Ani mpor tantout putofsi mul ati
onsar ethetracef i
les.Tracef i
l
esl ogevery
packet,ev eryev entt hatoccur redi nt hesi mul ati
onandar eusedf oranalysis.Network
si
mul atorscanal so pr ov i
deot hert ool st of acil
i
tatev i
sualanal ysi
soft rendsand
potenti
al troublespot s.
34

Mostnet wor ksi mul at orsusedi screteev entsi mul at i


on, i
nwhi chal i
stofpendi ng
"event s"isst or ed, andt hoseev ent sar epr ocessedi nor der ,wi thsomeev entst ri
gger i
ng
futureev ents—suchast heev entoft hear rivalofapacketatonenodet r
igger i
ngt he
eventoft hear rival oft hatpacketatadownst r
eam node.
Simul ationofnet wor ksi sav erycompl extask.Forexampl e,ifcongest ionishi gh,
thenest i
mat ionoft heav er ageoccupancyi schal lengingbecauseofhi ghv ar i
ance.To
estimat et hel i
kel i
hoodofabuf ferov erf
low i nanet wor k,t het imer equi redf oran
accur at e answercan be ext remel yl ar ge.Speci al
ized t echni ques such as " control
variates"and" impor tancesampl ing"hav ebeendev elopedt ospeedsi mul at i
on.
Exampl esofnet wor ksi mul at or s
Ther ear emanybot hf ree/ open- sour ceand pr opr ietar ynet wor ksi mul ators.
Exampl esofnot abl enet wor ksi mul ationsof twar ear e,or der edaf t
erhowof t
ent heyar e
ment i
onedi nr esear chpaper s:
1.ns( opensour ce)
2.OPNET( pr opr iet arysof t
war e)
3.Net Si
m( pr opr iet arysof t
war e)
Usesofnet wor ksi mul at or s
Net wor ksi mul at or sser v eav ar ietyofneeds.Compar edt ot hecostandt ime
i
nv olvedi nset tingupanent iret estbedcont ainingmul tiplenet wor kedcomput ers,
router sanddat al i
nks,net wor ksi mul atorsar er elativelyf astandi nexpensi ve.They
all
ow engi neer s,r esear cher st ot estscenar i
ost hatmi ghtbepar t i
cul arlydi ff
icultor
expensi vet oemul at eusi ngr ealhar dwar e-f ori nstance,si mul atingascenar i
owi t
h
sev eralnodesorexper iment ingwi t hanewpr otocoli nt henet wor k.Net wor ksi mul at
or s
arepar ti
cular l
yusef uli nal lowi ngr esear cher st ot estnew net wor ki
ngpr otocol sor
changest oexi stingpr ot ocol si nacont r
olledandr epr oduci bl eenv ironment .At ypical
networ ksi mul atorencompassesawi der angeofnet wor kingt echnol ogiesandcanhel p
theuser st obui ldcompl exnet wor ksf rom basi cbui l
dingbl ockssuchasav arietyof
nodesandl i
nks.Wi tht hehel pofsi mul ators, onecandesi gnhi erarchi cal networ ksusi ng
varioust ypesofnodesl ikecomput er s,hubs,br idges,r out er s,swi t ches,l inks,mobi le
unitset c.
Var i
oust ypesofWi deAr eaNet wor k( WAN)t echnol ogi esl i
keTCP,ATM,I Pet c.
andLocalAr eaNet wor k( LAN)t echnol ogi esl i
keEt her net ,tokenr i
ngset c.,canal lbe
simul at edwi that y picalsi mul atorandt heusercant est,anal yzev ar iousst andard
resultsapar tf r
om dev isingsomenov elpr otocolorst rategyf orr out i
nget c.Net wor k
simul at orsar eal sowi del yusedt osi mul at ebat tl
efieldnet wor ksi nNet wor k-centric
war fare.
Ther ear eawi dev ar ietyofnet wor ksi mul ators,r angi ngf r
om t hev erysi mpl eto
thev erycompl ex.Mi nimal ly ,anet wor ksi mul atormustenabl eausert or epresenta
networ kt opol ogy ,speci fyingt henodesont henet work,t hel i
nksbet weent hosenodes
andt het rafficbet weent henodes.Mor ecompl icatedsy stemsmayal low t heusert o
speci fyev erythingaboutt hepr otocol susedt ohandl et r
af fi
ci nanet wor k.Gr aphi cal
appli
cati
onsall
owuser st
oeasilyvi
sual
i
zet heworki
ngsofthei
rsi
mulat
edenv
ironment
.
Text-
basedapplicat
ionsmaypr ovi
deal essint
uiti
veint
erf
ace,butmaypermitmore
advancedfor
msofcust omizat
ion.
35

Packetl oss
Packetl ossoccur swhen oneormor epacket sofdat at r
avell
ing acrossa
comput ernet workf ai
ltoreacht hei
rdest i
nati
on.Packetl ossisdisti
nguishedasoneof
thet hreemai ner r
ortypesencount eredindigitalcommuni cati
ons;theot hertwobei ng
biterrorandspur iouspacket scausedduet onoi se.
Packet scanbel ostinanet workbecauset heymaybedr oppedwhenaqueuei n
thenet wor knodeov erfl
ows.Theamountofpacketl ossdur ingthest eadyst ateis
anotheri mpor t
antpr opertyofacongest ioncont rolscheme.Thel ar
gert hev al
ueof
packetl oss,t he mor e diff
icul
ti tisf ortranspor t
lay
erpr otocolsto mai ntai
n high
bandwi dt hs,thesensi t
ivit
yt olossofi ndivi
dualpacket s,aswel lastof requencyand
patterns ofl oss among l ongerpacketsequences i s str
ongly dependenton t he
applicationitself.

Throughput
Thr oughputist hemai nper for
mancemeasur echar acter
ist
ic,andmostwi del
y
used.Incommuni cat i
onnet wor ks,suchasEt hernetorpacketr adi
o,throughputor
networkt hr
oughputi st he av erage rat
e ofsuccessf ulmessage del iv
ery ov era
communi cati
onchannel.Throughputi susual
lymeasuredi nbit
spersecond(bit
/sorbps) ,
and somet i
mes in data packet s persecond ordat a packet s perti
me sl ot
.Thi s
measur eshow soont hereceiveri sabletogetacer tai
namountofdat asendbyt he
sender.Itisdeter
minedast her atioofthetotaldatareceivedtotheendt oenddel ay
.
Throughputi sanimpor t
antfactorwhi chdi
rectl
yimpactsthenet workperf
ormance.

Delay
Del
ayi stheti
meel apsedwhi leapackett ravel
sf r
om onepointe.g.,source
premiseornetworkingresstodestinat
ionpremiseornetwor kdegr
ees.Thelargerthe
value ofdelay,the more di
f f
icul
titi sfortransportlayerprot
ocolsto mai nt
ain
highbandwi
dths.Wewi l
lcal
culateendtoenddelay

QueueLengt h
Aqueuingsy st
em i nnetworkscanbedescr i
bedaspacketsarr
ivi
ngf orservi
ce,
waiti
ngf orservi
ceifitisnotimmediate,andifhavi
ngwait
edforservi
ce,leavi
ngthe
system afterbeing served.Thusqueue lengt
hi sv er
yimport
antcharacter
ist
icto
determinet hathow wel ltheacti
vequeuemanagementoft hecongestioncontrol
al
gor i
thm hasbeenwor ki
ng.

Congest
ioncontr
olAlgori
thms
Sl
ow-star
tisusedinconjunctionwi
thot heralgori
thmst oavoidsendi
ngmor edata
thant
henetworkiscapabl
eoft ransmi
tt
ing,thatis,t
oav oidcausi
ngnetworkcongest
ion.
Theadditi
veincr
ease/multi
pli
cati
vedecrease( AIMD)al gori
thm i
saf eedbackcontrol
algori
thm.AIMDcombinesl
ineargr
owt hofthecongest
ionwindowwi
thanexponent
ial
reducti
onwhenacongesti
ontakesplace.Mult
ipl
efl
owsusingAIMDcongest
ioncont
rol
willev
entual
l
yconver
ge
36

t
ouseequalamount
sofacontendedl
ink.FastRetr
ansmiti
sanenhancementt
oTCP
t
hatr
educesthet
imeasenderwait
sbeforeret
ransmit
ti
ngalostsegment
.

POSTLABVI
VAQUESTI ONS:
1.Whati
stheuseofat rf i
l
e?
2.Whatdoes$1,$2,
..
..
.indi
cat
eintheawkf
il
e?
3.Howdowei ncreasethethr
oughput
?
4.Whati
sanode?
5.Whati
spointtopointli
nk?

Resul
t:
ThuswehaveStudi
edNet
wor
ksi
mul
ator(
NS)andSi
mul
ati
onofCongest
ion
Contr
olAl
gori
thmsusi
ngNS.
37

Ex.
No:7 St
udyofTCP/
UDPper
for
manceusi
ngSi
mul
ati
ont
ool
.

AI
M:

Tosi
mul
atet
heper
for
manceofTCP/
UDPusi
ngNS2.

THEORY:

TheTransmi
ssi
onCont
rol
Prot
ocol
(TCP)i
soneoft
hemai
npr
otocol
soft
he
I
nter
net
prot
ocolsui
te.I
tori
ginat
edi
nthei
nit
ial
net
wor
kimpl
ement
ati
oni
nwhi
chi
t
complementedthe
I
nter
netPr
otocol
(IP)
.Ther
efor
e,t
heent
ir
esui
tei
scommonl
yref
err
edt
oasTCP/
IP.
TCP
provi
desrel
i
abl
e,or
der
ed,
ander
ror
-checkeddel
i
ver
yofast
ream ofoct
ets(
byt
es)
between
appl
i
cat
ionsrunni
ngonhost
scommuni
cat
ingbyanI
Pnet
wor
k.Maj
orI
nter
net
appl
i
cat
ionssuch
ast
heWor
ld Wi
de Web,emai
l
,remot
eadmi
nist
rat
ion,
andf
il
etr
ansf
err
elyon TCP.
Appli
cati
onsthatdonotr
equi
rer
eli
abl
edat
ast
ream ser
vicemayuset
heUser
Datagr
am Protocol
(
UDP) ,whi
chpr
ovi
desaconnect
ionl
essdat
agr
am ser
vicet
hatemphasi
zesr
educed
l
atencyover
r
eli
abi
l
ity
.

PRELABVI
VAQUESTI
ONS:

1.WhatisTCP?
2.Expl
ainthethr
eewayHandshakeprocess?
3.Whichlayeri
sclosertoauser
?
4.Expl
ainhowTCPav oi
dsanetwor
kmeltdown?
5.Whatisthediff
erencebet
weenfl
owcontrolandEr
rorcont
rol
?

TCPPer
for
mance

1. Al
gor
it
hm:
2. Cr
eat
eaSi
mul
atorobj
ect
.
3. Setr
out
ingasdy
nami
c.
4. Opent
het
raceandnam t
racef
il
es.
5. Def
inet
hef
ini
shpr
ocedur
e.
6. Cr
eat
enodesandt
hel
i
nksbet
weent
hem.
7. Cr
eat
etheagent
sandat
tacht
hem t
othenodes.
8. Cr
eat
etheappl
i
cat
ionsandat
tacht
hem t
othet
cpagent
.
9. Connectt
cpandt
cpsi
nk.
10.Runt
hesi
mul
ati
on.
38

PROGRAM:

setns[
newSi
mul
ator
]
$nscol
or0Bl
ue
$nscol
or1Red
$nscol
or2Yel
l
ow
setn0[
$nsnode]
setn1[
$nsnode]
setn2[
$nsnode]
setn3[
$nsnode]
setf[
opent
cpout
.t
rw]
$nst
race-
all
$f
setnf[
opent
cpout
.nam w]
$nsnamt
race-
all
$nf
$nsdupl
ex-
li
nk$n0$n25Mb2msDr
opTai
l
$nsdupl
ex-
li
nk$n1$n25Mb2msDr
opTai
l
$nsdupl
ex-
li
nk$n2$n31.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk-
op$n0$n2or
ientr
ight
-up
$nsdupl
ex-
li
nk-
op$n1$n2or
ientr
ight
-down
$nsdupl
ex-
li
nk-
op$n2$n3or
ientr
ight
$nsdupl
ex-
li
nk-
op$n2$n3queuePos0.
5
sett
cp[
newAgent
/TCP]
$t
cpsetcl
ass_1
setsi
nk[
newAgent
/TCPSi
nk]
$nsat
tach-
agent$n1$t
cp
$nsat
tach-
agent$n3$si
nk
$nsconnect$t
cp$si
nk
setf
tp[
newAppl
i
cat
ion/
FTP]
$f
tpat
tach-
agent$t
cp
$nsat1.
2"$f
tpst
art
"
$nsat1.
35"
$nsdet
ach-
agent$n1$t
cp;
$nsdet
ach-
agent$n3$si
nk"
$nsat3.
0"f
ini
sh"
pr
ocf
ini
sh{
}{
gl
obal
nsfnf
$nsf
lush-
tr
ace
39

cl
ose$f
cl
ose$nf
put
s"Runni
ngnam.
."
execxgr
apht
cpout
.t
r-geomet
ry600x800&
execnam t
cpout
.nam &
exi
t0
}
$nsr
un

Out
put

UDPPer
for
mance

ALGORI
THM :

1.CreateaSi mulat
orobject
.
2.Setroutingasdynamic.
3.Opent hetraceandnam tracef
il
es.
4.Defi
net hefini
shprocedure.
40

5.Creat
enodesandt heli
nksbetweenthem.
6.Creat
etheagentsandattachthem t
othenodes.
7.Creat
etheappli
cat
ionsandat t
achthem t
otheUDPagent
.
8.Connectudpandnullagents.
9.Runthesimul
ati
on.

PROGRAM:
setns[
newSi
mul
ator
]
$nscol
or0Bl
ue
$nscol
or1Red
$nscol
or2Yel
l
ow
setn0[
$nsnode]
setn1[
$nsnode]
setn2[
$nsnode]
setn3[
$nsnode]
setf[
openudpout
.t
rw]
$nst
race-
all
$f
setnf[
openudpout
.nam w]
$nsnamt
race-
all
$nf
$nsdupl
ex-
li
nk$n0$n25Mb2msDr
opTai
l
$nsdupl
ex-
li
nk$n1$n25Mb2msDr
opTai
l
$nsdupl
ex-
li
nk$n2$n31.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk-
op$n0$n2or
ientr
ight
-up
$nsdupl
ex-
li
nk-
op$n1$n2or
ientr
ight
-down
$nsdupl
ex-
li
nk-
op$n2$n3or
ientr
ight
$nsdupl
ex-
li
nk-
op$n2$n3queuePos0.
5
setudp0[
newAgent
/UDP]
$nsat
tach-
agent$n0$udp0
setcbr
0[newAppl
i
cat
ion/
Traf
fi
c/CBR]
$cbr
0at
tach-
agent$udp0
setudp1[
newAgent
/UDP]
$nsat
tach-
agent$n3$udp1
$udp1setcl
ass_0
setcbr
1[newAppl
i
cat
ion/
Traf
fi
c/CBR]
$cbr
1at
tach-
agent$udp1
setnul
l
0[newAgent
/Nul
l
]
$nsat
tach-
agent$n1$nul
l
0
41

setnul
l
1[newAgent
/Nul
l
]
$nsat
tach-
agent$n1$nul
l
1
$nsconnect$udp0$nul
l
0
$nsconnect$udp1$nul
l
1
$nsat1.
0"$cbr
0st
art
"
$nsat1.
1"$cbr
1st
art
"
put
s[$cbr
0setpacket
Size_
]
put
s[$cbr
0seti
nter
val
_]
$nsat3.
0"f
ini
sh"
pr
ocf
ini
sh{
}{
gl
obal
nsfnf
$nsf
lush-
tr
ace
cl
ose$f
cl
ose$nf
put
s"Runni
ngnam.
."
execnam udpout
.nam &
exi
t0
}
$nsr
un

Out
put
:

RESULT:

Thust
hest
udyofTCP/
UDPper
for
mancei
sdonesuccessf
ull
y.
42

Ex.
No:8 Si
mul
ati
onofDi
stanceVect
or/Li
nkSt
ateRout
ingal
gor
it
hm.

AI
M:

Tosi
mul
atet
heDi
stancev
ect
orandl
i
nkst
ater
out
ingpr
otocol
susi
ngNS2.

THEORY:
LINKSTATEROUTI NG
Rout ingi st hepr ocessofsel ectingbestpat hsi nanet wor k.Int hepast ,thet er m
rout i
ngwasal sousedt omeanf or war dingnet wor kt raf ficamongnet wor ks.Howev er
thisl atterf unct i
oni smuchbet t
erdescr ibedassi mpl yf orwar di ng.Rout i
ngi sper f
or med
formany ki nds ofnet wor ks,i ncludi ng t he t el ephone net wor k( circuitswi tchi ng),
elect ronicdat anet wor ks( suchast heI nt ernet ),and t ranspor tati
onnet works.Thi s
articlei sconcer nedpr imar i
lywi thr out ingi nel ect roni cdat anet wor ksusi ngpacket
swi tchingt echnol ogy .
Inpacketswi t
chi ngnet wor ks,r out i
ngdi rect spacketf or war ding( thet ransi tof
l
ogi cal l
yaddr essednet wor kpacket sf rom t hei rsour cet owar dt heirul ti
mat edest inat i
on)
throughi nt ermedi at enodes.I nt ermedi at enodesar et ypi cal lynet wor khar dwar edev ices
suchasr outer s,br idges,gat eway s,f irewal ls,orswi tches.Gener al-
pur posecomput ers
canal sof orwar dpacket sandper formr out ing, thought heyar enotspeci alizedhar dwar e
and may suf ferf r
om l imited per for mance.The r out ing pr ocess usual l
y di rect s
forwar dingont hebasi sofr out i
ngt abl eswhi chmai nt ainar ecor doft her out est o
variousnet wor kdest i
nat i
ons.Thus,const r uct ingr out ingt abl es,whi char ehel di nt he
rout er'smemor y,isv eryi mpor tantf oref ficientr out ing.Mostr out ingal gorithmsuse
onlyonenet wor kpat hatat ime.Mul ti
pat hrout ingt echni quesenabl et heuseofmul tiple
alternat ivepat hs.
Incaseofov erl
appi ng/ equalr out es,t hef ol lowi ngel ement sar econsi der edi n
ordert odeci dewhi chr outesgeti nst all
edi nt ot her out ingt abl e( sor t
edbypr i
ori
t y)
:
1.Pr efi
x- Lengt h:wher el ongersubnetmasksar epr ef erred( i
ndependentofwhet her
itiswi t hinar outingpr ot ocol orov erdi ff erentr out i
ngpr otocol )
2.Met r
ic:wher eal owermet ric/costi spr ef erred( onl yv alidwi thinoneandt he
samer out ingpr ot ocol)
3.Admi nist rativedi stance:wher eal owerdi st ancei spr efer red( onl yv alidbet ween
differentr out i
ngpr otocol s)
Rout ing,i namor enar rowsenseoft het erm,i sof tencont rast edwi thbr idgingi n
i
tsassumpt i
ont hatnet workaddr essesar est ruct ur edandt hatsi mi l
araddr essesi mpl y
proxi mi tywi thi nt henet wor k.St ruct uredaddr essesal lowasi ngl er out i
ngt ableent ryt o
repr esentt her outet oagr oupofdev ices.I nl ar genet wor ks,st r
uct ur edaddr essi ng
(rout i
ng,i nthenar rowsense)out per f
or msunst ruct ur edaddr essi ng( bridging).Rout ing
hasbecomet hedomi nantf or m ofaddr essi ngont heI nt er net .Br i
dgi ngi sst il
lwi del y
usedwi
thi
nlocal
i
zedenv
ironment
s.
43

b.Flooding
Fl
oodi ngi sasi mpl er outingal gorit
hm inwhi chev eryi ncomi ngpacketi ssent
throughev eryout goingl inkexceptt heonei tarr
ivedon.Fl oodingi susedi nbr i
dgingand
i
nsy stemssuchasUsenetandpeer -
to-peerf i
leshar ingandaspar tofsomer outing
protocols,i ncludingOSPF,DVMRP,andt hoseusedi nad- hocwi r
elessnet works.Ther e
aregener allyt wot ypesoff loodingav ail
able,Uncont r
ol l
edFl oodingandCont r
olled
Flooding.Uncont r
ol l
edFl oodi ngi sthef atallawoff loodi ng.Al lnodeshav enei ghbour s
andr outepacket si ndefinitel
y.Mor ethant wonei ghbour scr eatesabr oadcastst orm.
Cont roll
ed Fl ooding has i ts own t wo algorithms t o make i treliabl
e,SNCF
(SequenceNumberCont r oll
edFl ooding)andRPF( Rev ersePat hFloodi ng).I
nSNCF, the
nodeat t
achesi t
sownaddr essandsequencenumbert ot hepacket ,sinceev erynode
hasamemor yofaddr essesandsequencenumber s.Ifitrecei vesapacketi nmemor y ,i
t
dropsi timmedi atelywhi lei nRPF,t henodewi l
lonlysendt hepacketf orward.I fitis
receivedfrom t henextnode, i
tsendsi tbackt othesender .

c.Di stancev ect or


In comput ercommuni cati
on t heoryr elati
ng to packet -swi t
ched net wor ks,a
dist
ance- vect orr out i
ngpr otocolisoneoft het womaj orcl assesofr outingpr otocol s,
theot hermaj orcl assbei ngt helink-stat
epr otocol.Distance- vectorr outingpr otocols
uset heBel lman–For dal gor i
thm,For d–Ful kersonal gori
thm,orDUALFSM ( inthecase
ofCiscoSy stems' spr otocol s)t ocalculatepat hs.
Adi st ance- vectorr outingpr otocolrequi r
est hatar out erinformsi t
snei ghborsof
topologychangesper i
odical l
y.Compar edt ol i
nk-stateprot ocols,whi chr equi rear outer
toinf orm al lthenodesi nanet wor koft opologychanges,di stance-vect orr outing
protocolshav elesscomput ationalcompl exityandmessageov er head.
Thet erm di stancev ectorreferst othef actt hatt
hepr otocolmani pul atesv ectors
(arr
ay s)ofdi stancest oot hernodesi nthenet work.Thev ectordi stanceal gorit
hm was
theor iginalARPANETr out i
ngal gorithm andwasal sousedi nt hei nternetundert he
name ofRI P( Rout i
ng I nformation Pr otocol )
.Examples ofdi st
ance- vect orr outing
protocolsi ncl udeRI Pv1andRI Pv2andI GRP.

Method
Rout ersusi ngdistance-vectorprotocoldonothaveknowl edgeoftheent i
repat htoa
destination.Insteadt heyuset womet hods:
1.Di rectioninwhi chrouterorexitinter
faceapacketshouldbef or
war ded.
2.Di stancef r
om i tsdesti
nation
Distance-vectorprotocolsar ebasedoncalcul
ati
ngt hedirect
ionanddi st
ancet o
anyl i
nk
i
nanet wor k."Direction"usuallymeanst henexthopaddr essandt heexitinterface.
"Di
stance"i sameasur eoft hecostt or eachacertai
nnode.Thel eastcostr out
e
betweenanyt wonodesi st her outewi t
hmi ni
mum distance.Eachnodemai ntainsa
vector( t
abl e)ofmi ni
mum di stancet o
44

ev er
ynode.Thecostofr eachi ngadest i
nationiscal culatedusi ngv ariousr outemet ri
cs.
RIP usest hehopcountoft hedest i
nationwher easI GRP t akesi ntoaccountot her
i
nf ormationsuchasnodedel ayandav ail
ablebandwi dth.
Updat esar eper formedper i
odicall
yinadi stance- vectorpr otocolwher eallorpar t
ofar outer'sr out i
ngt abl eissentt oallit
snei ghbor st hatareconf iguredt ouset hesame
distance-vect orr outingpr otocol.RIPsuppor t
scr oss-platform di stancev ectorrouting
wher easI GRPi saCi scoSy stemspr opri
etarydi stancev ectorr outingpr otocol.Oncea
routerhast hisi nformat i
oni tisablet oamendi tsownr outingt ablet or efl
ectt he
changes and t hen i nform i ts neighbors oft he changes.Thi s pr ocess has been
descr i
bedas‗ r outingbyr umor ‘becauser out ersar erelyingont hei nformationt hey
receivefrom ot herr out ersandcannotdet ermi nei fthei nformat i
oni sact uall
yvalidand
true.Ther ear eanumberoff eat
ureswhi chcanbeusedt ohel pwi thinstabili
tyand
i
naccur ater outingi nfor mat i
on.
EGPandBGPar enotpur edi
stance-vectorr out i
ngpr ot ocolsbecauseadi stance-
vectorpr otocolcal culatesr outesbasedonl yonl inkcost swher easinBGP, f
orexampl e,
thelocal routepr eferencev aluetakespriori
tyov ert hel i
nkcost .

Count -
to-
infi
nityprobl em
TheBellman–For dalgorit
hm doesnotpr ev entrouti
ngloopsf r
om happeni ngand
suffersfr
om thecount -t
o-infi
nit
ypr oblem.Thecor eofthecount -to-i
nfi
nit
ypr oblem is
thatifAtellsBt hatithasapat hsomewher e,ther eisnowayf orBt oknowi fthepat h
hasBasapar tofi t.Toseet hepr oblem clear l
y,imagineasubnetconnect edlike
A–B–C–D–E–F,andl ett hemet ri
cbet weent her outersbe" numberofj umps" .Now
supposet hatAi stakenof fli
ne.Inthev ector-
updat e-
processBnot i
cest hatther out
et o
A,whi chwasdi stance1,i sdown–Bdoesnotr eceivet hevectorupdat efrom A.The
problem i
s,Bal soget sanupdat efrom C,andCi ssti
llnotawar eoft hefactt hatAi s
down–soi ttell
sBt hatAi sonlytwoj umpsf rom C( Ct oBt oA) ,whichisf alse.This
slowlypropagat est hr ought henet wor kunt i
li treachesi nfi
nit
y( i
nwhi chcaset he
algori
thm corr
ect si
tsel f,duetother el
axat i
onpr opertyofBellman–For d).

PRELABVIVAQUESTI ONS:
1.Expl
ainRI P.
2.Describetheprocessofr
outingpackets.
3.Whatar esomeoft hemerit
susedbyr outingprot
ocol
s?
4.Whar eisrout
ingtabl
eismaintai
ned?Al soStat
etheofmai
ntai
ningar
out
ing
t
abl
e.
5.Dist
inguishbetweenbri
dgesandr out
ers

ALGORI
THM:

1.CreateaSimul
atorobj
ect.
2.Setrout
ingasdynamic.
3.Openthetr
aceandnam tr
acef
il
es.
4.Defi
nethefi
nishpr
ocedur
e.
45

5.Creat
enodesandt helinksbetweenthem.
6.Creat
etheagentsandat tachthem t
othenodes.
7.Creat
etheappli
cat
ionsandat t
achthem t
otheudpagent
.
8.Connectudpandnul l
..
9.At1sectheli
nkbet weennode1and2i sbroken.
10.
At2sectheli
nkisupagai n.
11.
Runthesimul
ati
on.

LI
NKSTATEROUTI
NGPROTOCOL

PROGRAM
setns[
newSi
mul
ator
]
$nsr
tpr
otoLS
setnf[
openl
i
nkst
ate.
nam w]
$nsnamt
race-
all
$nf
setf
0[openl
i
nkst
ate.
trw]
$nst
race-
all
$f0
pr
ocf
ini
sh{
}{
gl
obal
nsf
0nf
$nsf
lush-
tr
ace
cl
ose$f
0
cl
ose$nf
execnam l
i
nkst
ate.
nam &
exi
t0
}
f
or{
seti
0}{
$i<7}{
incri
}{
setn(
$i)[
$nsnode]
}
f
or{
seti
0}{
$i<7}{
incri
}{
$nsdupl
ex-
li
nk$n(
$i)$n(
[expr(
$i+1)
%7]
)1Mb10msDr
opTai
l
}
setudp0[
newAgent
/UDP]
$nsat
tach-
agent$n(
0)$udp0
setcbr
0[newAppl
i
cat
ion/
Traf
fi
c/CBR]
$cbr
0setpacket
Size_500
$cbr
0seti
nter
val
_0.
005
$cbr
0at
tach-
agent$udp0
46

setnul
l
0[newAgent
/Nul
l
]
$nsat
tach-
agent$n(
3)$nul
l
0
$nsconnect$udp0$nul
l
0
$nsat0.
5"$cbr
0st
art
"
$nsr
tmodel
-at1.
0down$n(
1)$n(
2)
$nsr
tmodel
-at2.
0up$n(
1)$n(
2)
$nsat4.
5"$cbr
0st
op"
$nsat5.
0"f
ini
sh"
$nsr
un

Out
put
47

DI
STANCEVECTORROUTI
NGALGORI
THM

ALGORITHM:
1.Cr eateasi mul at orobj ect
2.Setr outingpr ot ocol toDi stanceVectorrouti
ng
3.Tr acepacket sonal l l
inksont oNAM traceandt exttr
acefi
le
4.Def inefinishpr ocedur etocl osefi
les,f
lushtraci
ngandrunNAM
5.Cr eateei ghtnodes
6.Speci fythel inkchar act eristi
csbetweennodes
7.Descr ibet heirl ay outt opol ogyasaoct agon
8.AddUDPagentf ornoden1
9.Cr eateCBRt raff i
cont opofUDPandsett raf
f i
cparameter
s.
10.Addasi nkagentt onoden4
11.Connectsour ceandt hesi nk
12.Schedul eev ent sasf ollows:
a.St arttraf fi
cf lowat0. 5
b.Downt hel i
nkn3- n4at1.0
c.Upt hel inkn3- n4at2. 0
d.St opt raff i
cat3. 0
e.Cal lfi
ni shpr ocedur eat5.0
13.Startt
heschedul er
14.Observ et hetr afficr out ewhenl inkisupanddown
48

15.Vi ewt hesi mul atedev entsandt r


acefil
eanal
yzei
t
16.St op
PROGRAM
#Distancev ectorr out i
ngpr ot
ocol–di stvect
.t
cl
#Createasi mul atorobject
setns[ newSi mul at or]
#Usedi st ancev ectorrouting
$nsrtprot oDV
#Opent henam t r
acef il
e
setnf[openout .nam w]
$nsnamt race-all$nf
#Opent racef il
e
setnt[opent r
ace. trw]
$nstrace- all$nt
#Define' fini
sh' procedur e
procfinish{ }
{
global nsnf
$nsf lush- t
race
#Cl oset het racefil
e
close$nf
#Execut enam ont hetracefil
e
execnam - aout .
nam &
exi t0
}
#Create 8
nodes 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]set
n8[$nsnode]
#Speci fyl i
nkchar acteresti
cs
$nsdupl ex- li
nk$n1$n21Mb10msDr opTai l
$nsdupl ex- li
nk$n2$n31Mb10msDr opTai l
$nsdupl ex- li
nk$n3$n41Mb10msDr opTai l
$nsdupl
ex-
li
nk$n4$n51Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n5$n61Mb10msDr
opTai
l
49

$nsduplex- li
nk$n6$n71Mb10msDr opTai l
$nsduplex- li
nk$n7$n81Mb10msDr opTai l
$nsduplex- li
nk$n8$n11Mb10msDr opTai l
#specifylay outasaoct agon
$nsduplex- li
nk- op$n1$n2or ientleft-
up
$nsduplex- li
nk- op$n2$n3or ientup
$nsduplex- li
nk- op$n3$n4or ientright-up
$nsduplex- li
nk- op$n4$n5or ientright
$nsduplex- li
nk- op$n5$n6or ientright-down
$nsduplex- li
nk- op$n6$n7or ientdown
$nsduplex- li
nk- op$n7$n8or ientleft-
down
$nsduplex- li
nk- op$n8$n1or ientleft
#CreateaUDPagentandat t
achi ttonoden1
setudp0[ newAgent /UDP]
$nsattach- agent$n1$udp0
#CreateaCBRt rafficsourceandat tachi tto
udp0setcbr 0[ newAppl icati
on/ Traff
ic/CBR]
$cbr0setpacket Size_500
$cbr0seti nterv al_0.005
$cbr0attach- agent$udp0
#CreateaNul lagent( atraffi
csi nk)andat tachitt
onoden4
setnul
l0[ newAgent /Null
]
$nsattach- agent$n4$nul l0
#Connectt het r affi
csour cewi ththet raffi
csi nk
$nsconnect$udp0$nul l0
#Scheduleev ent sfort heCBRagentandt henetwork
dynamics$nsat0. 0" $n1label Source"
$nsat0.0" $n4l abel Dest i
nation"
$nsat0.5" $cbr 0st art"
$nsrtmodel -
at1. 0down$n3$n4
$nsrtmodel -
at2. 0up$n3$n4
$nsat4.5" $cbr 0st op"
#Callt
hef inishpr ocedur eafter5secondsofsi mulat
iont
ime
$nsat5.0" fi
nish"
#Runthesi mul ation
$nsrun
50

OUTPUT
$nsdist
vect
.t
c
l
51

POSTLABVI
VAQUESTI
ONS:

1.Whatdoy oumeanbyt heterm“no.ofhops”?


2.Li
stthebasicfuncti
onsofr out
ers.
3.Expl
ainmulti
castrouti
ng.
4.Expl
aint
hedi f
ferencebetweeninter
iorandexter
iornei
ghborgat
eway
s.

RESULT:

Thusthesimul
ati
onf
orDi
stancev
ect
orandl
i
nkst
ater
out
ingpr
otocol
swas
doneusing
NS2.
52

Ex.
No:
9 Per
for
manceev
aluat
ionofRout
ingpr
otocol
susi
ngSi
mul
ati
ont
ool
.

AI
M:
Tost
udyt
hel
i
nkst
ater
out
ing.

LINKSTATEROUTI NG
a.Li nkSt at er out ing
Rout ingi st hepr ocessofsel ectingbestpat hsi nanet wor k.Int hepast ,thet erm
rout ing
wasal sousedt omeanf or war di ngnet wor kt raf ficamongnet wor ks.Howev erthi sl atter
funct i
oni smuchbet t
erdescr ibedassi mpl yf or war ding.Rout ingi sper formedf ormany
kindsofnet wor ks,i ncludi ngt het elephonenet wor k( ci r
cui tswi t
chi ng),el ect r
oni cdat a
net wor ks( suchast heI nter net ),andt ranspor tat i
onnet wor ks.Thi sar ti
clei sconcer ned
primar ilywi thr out ingi nel ect roni cdat anet wor ksusi ngpacketswi tchingt echnol ogy .
Inpacketswi tchi ngnet wor ks,r out i
ngdi rect spacketf or war ding( thet ransi tof
l
ogi cal l
yaddr essednet wor kpacket sfrom t hei rsour cet owar dt heirul ti
mat edest inat i
on)
throughi nt er medi atenodes.I nt ermedi at enodesar et ypical l
ynet wor khar dwar edev ices
suchasr out er s,br i
dges,gat eway s,firewal ls,orswi tches.Gener al-
pur posecomput ers
canal sof orwar dpacket sandper formr outing, thought heyar enotspeci alizedhar dwar e
and may suf ferf rom l imi ted per f
or mance.The r out i
ng pr ocess usual l
y di rect s
forwar di ngont hebasi sofr out i
ngt abl eswhi chmai ntainar ecor doft her out est o
variousnet wor kdest inat i
ons.Thus,const r uct ingr out ingt ables,whi char ehel di nt he
rout er'
smemor y,i sv eryi mpor tantf oref ficientr out ing.Mostr out ingal gor i
thmsuse
onlyonenet wor kpat hatat i
me.Mul ti
pat hr out ingt echni quesenabl et heuseofmul tiple
alternat ivepat hs.
Incaseofov er l
appi ng/ equalr out es,t hef ol lowi ngel ement sar econsi der edi n
ordert odeci dewhi chr out esgeti nstalledi nt ot her out ingt abl e( sortedbypr ior
ity):
4.Pr efix- Lengt h:wher elongersubnetmasksar epr eferred( i
ndependentofwhet her
i
ti swi t hinar out ingpr ot ocol orov erdi ff erentr out ingpr otocol )
5.Met ric:wher eal owermet ri
c/ costi spr ef erred( onl yv ali
dwi thinoneandt he
samer out ingpr ot ocol )
6.Admi nist rativedi stance:wher eal owerdi st ancei spr ef erred( onl yv alidbet ween
differ entr out ingpr otocol s)
Rout ing, i
namor enar rowsenseoft het er m, isof t
encont rastedwi thbr i
dgi ngi n
i
ts
assumpt iont hatnet wor kaddr essesar est r
uct ur edandt hatsi mi l
araddr essesi mpl y
proxi mi tywi thi nt henet wor k.St ruct uredaddr essesal lowasi ngl er out i
ngt ableent ryt o
representt her out et oagr oupofdev ices.I nl ar genet wor ks,st r
uct ur edaddr essi ng
(rout i
ng,i nt henar rowsense)out per formsunst ruct uredaddr essi ng( bridgi ng).Rout ing
hasbecomet hedomi nantf or m ofaddr essi ngont heI nternet .Br i
dgi ngi sst illwi del y
usedwi thinl ocal izedenv i
ronment s.
b.Fl oodi ng
Fl
ooding i
sasimpl
er out
ingalgor
ithm inwhicheveryi
ncomi
ngpacketissent
thr
oughever
youtgoi
ngl
i
nkexcepttheoneitarr
ivedon.Fl
oodi
ngi
susedinbr
idgi
ngandin
syst
emssuch
53

asUsenetandpeer -
to-peerf i
lesharingandaspar tofsomer outingprotocols,i
ncluding
OSPF,DVMRP,andt hoseusedi nad- hocwi r
elessnet wor ks.Therear egener al
lytwo
typesoff l
oodingav ail
able,Uncont r
ol l
edFl oodi
ngandCont rolledFlooding.Uncont rol
led
Floodingist hef atallaw off l
ooding.Al lnodeshav enei ghbour sandr outepacket s
i
ndef i
nitel
y.Mor ethant wonei ghbour screatesabr oadcastst orm.
Cont r
oll
ed Fl ooding has its own t wo algori
thms t o make i treliabl
e,SNCF
(SequenceNumberCont rol
ledFloodi ng)andRPF( ReversePat hFlooding).I
nSNCF, the
nodeat tachesi t
sownaddr essandsequencenumbert othepacket ,sinceev erynode
hasamemor yofaddr essesandsequencenumber s.I
fitreceiv esapacketi nmemor y,i
t
dropsi timmedi atel
ywhi l
ei nRPF,t henodewi llonlysendt hepacketf orward.Ifitis
recei
vedf rom thenextnode, i
tsendsi tbacktothesender .

Algorit
hm
Therear esev er
alvari
antsoffloodi ngalgorit
hm.Mostwor kroughlyasf ol
lows:
1.Eachnodeact sasbothat ransmi t
terandar eceiver.
2.Eachnodet r
iestoforwar dev er
ymessaget oev eryoneofi tsneighbour sex cept
the
sour cenode.
Thisr esultsineverymessageev entuall
ybeingdeliveredt oallreachablepar t
soft he
network.
Algorithms may need t o be mor e complex than t his,si nce,in some case,
precautionshav etobetakent oav oidwast eddupl i
catedel i
veri
esandi nfinit
eloops, and
toal l
ow messagest oev ent
uallyexpi refrom thesy stem.Av ariantoff loodingcal l
ed
selecti
vef loodingparti
all
yaddr essest heseissuesbyonl ysendingpacket storout er
sin
thesamedi recti
on.Inselecti
vef loodingt heroutersdon' tsendev er
yincomi ngpacket
onev erylinebutonl yonthosel ineswhi char egoi
ngappr oxi
mat elyinther i
ghtdirecti
on.

Adv
ant
ages

Sincefl
oodingnat
ural
lyut
il
izesever
ypat
hthrought
henet
wor
k,i
twi
l
lal
souse
theshort
estpath.

Thisal
gorit
hm isver
ysimpletoimpl
ement.
54

Di
sadv
ant
ages

Fl
oodingcanbecostl
yintermsofwastedbandwidth.Whil
eamessagemayonly
haveonedest
inat
ioni
thast obesentt
oeveryhost.Inthecaseofapi
ngf
loodor
adenialofservi
ceattack,itcanbeharmfultot her el
i
abil
i
tyofacomputer
net
wor k.

Messagescanbecomedupl i
cat
edinthenetworkf
urt
herincreasi
ngtheloadon
the networks bandwidt
h as wel
las r equi
ri
ng an i
ncrease in pr
ocessi
ng
complexit
ytodisregar
ddupl
icat
emessages.

Dupl
i
cat
epacket
smayci
rcul
atef
orev
er,
unl
esscer
tai
npr
ecaut
ionsar
etaken:

Useahopcountorati
metoli
v ecountandi
ncl
udeitwi
theachpacket
.Thi
sval
ue
shoul
dtakeint
oaccountt
henumberofnodest hatapacketmayhav et
opass
thr
oughonthewaytoit
sdest
inati
on.

Hav
eeachnodekeept
rackofev
erypacketseenandonl
yfor
war
deachpacketonce

Enf
orceanet
wor
ktopol
ogywi
thoutl
oops

d.Di stancev ect or


Incomput ercommuni cationt heor yr elati
ngt opacket -
swi t
chednet works, a
distance-
vectorr out i
ngpr ot ocoli soneoft het womaj orclassesofr outi
ngpr otocols,theot her
majorcl assbei ngt hel i
nk-st atepr ot ocol.Di stance-vectorr outingpr otocolsuset he
Bell
man–For dal gor i
thm, For d–Ful ker sonal gori
thm,orDUALFSM ( int hecaseofCi sco
Systems' spr otocol s)t ocalculatepat hs.
Adi stance- vectorrout ingpr otocolr equirest hatar out erinformsi t
snei ghborsof
topologychangesper iodi
cally.Compar edt ol i
nk-stateprot ocols,whi chr equirear outer
toinf orm al lthenodesi nanet wor koft opologychanges,di stance-vectorr outing
protocol shav elesscomput at ionalcompl exityandmessageov erhead.
Thet erm di stancev ect orr eferst ot hef actthatthepr otocolmani pulatesv ectors
(arr
ay s)ofdi stancest oothernodesi nt henet wor k.Thev ectordi stanceal gorit
hm was
theor iginalARPANETr outingal gorithm andwasal sousedi nt hei nternetundert he
name ofRI P( Rout ing Infor mat i
on Pr otocol).
Exampl es ofdi st
ance- vectorr outing
protocol sincludeRI Pv1andRI Pv2andI GRP.

Method
Routersusingdi stance-vectorprotocoldonothaveknowl edgeoftheent i
repathtoa
desti
nation.Insteadt heyuset womet hods:
3.Di recti
oni nwhi chrouterorexitinter
faceapacketshouldbef or
war ded.
4.Di stancef r
om i tsdesti
nation
Distance-vectorprotocolsarebasedoncal cul
ati
ngt hedirect
ionanddi st
anceto
anyl i
nk
i
nanet wor k."Direction"usuallymeanst henexthopaddr essandt heexitinter
face.
"Di
stance"i sameasur eoft hecostt or eachacertai
nnode.Thel eastcostr out
e
betweenanyt wonodesisther outewit
hmi ni
mum distance.Eachnodemaintai
nsa
vector(t
abl
e)ofminimum di
stancetoeverynode.Thecostofreachi
ngadest
inati
oni
s
calcul
atedusi
ngvari
ousrout
emet ri
cs.RI
Puses
55

thehopcountoft hedest i
nationwher easI GRPt akesi ntoaccountot herinf ormat ion
suchasnodedel ayandav ail
abl ebandwi dth.
Updat esar eper formedper i
odicall
yinadi stance-vectorpr otocolwher eal lorpar t
ofar outer'sr out i
ngt abl eissentt oallit
snei ghbor sthatareconf iguredtouset hesame
distance-vect orr outingpr otocol .RIPsuppor t
scr oss-
platform di stancev ectorr outing
wher easI GRPi saCi scoSy stemspr opri
etarydi stancev ectorr outingpr otocol.Oncea
routerhast hisi nformat i
oni tisabl et oamendi tsownr outi
ngt ablet or efl
ectt he
changes and t hen i nform i ts nei ghbors oft he changes.Thi s process has been
descr i
bedas‗ r outingbyr umor ‘becauser out ersar erelyingont heinformat i
ont hey
receivefrom ot herr out ersandcannotdet ermi nei ftheinformat ioni sactuallyv ali
dand
true.Ther ear eanumberoff eatureswhi chcanbeusedt ohel pwi t
hi nstabilit
yand
i
naccur ater outingi nfor mat i
on.
EGPandBGPar enotpur edistance-vectorr outi
ngpr ot ocolsbecauseadi stance-
vectorpr otocolcal culatesr outesbasedonl yonl inkcostswher easi nBGP, forexampl e,
thelocal routepr eferencev aluet akespriorit
yov ert heli
nkcost .

Count -
to-
infi
nityprobl em
TheBellman–For dalgorit
hm doesnotpr ev entrouti
ngloopsf r
om happeni ngand
suffersfr
om thecount -t
o-infi
nit
ypr oblem.Thecor eofthecount -to-i
nfi
nit
ypr oblem is
thatifAtellsBt hatithasapat hsomewher e,ther eisnowayf orBt oknowi fthepat h
hasBasapar tofi t.Toseet hepr oblem clear l
y,imagineasubnetconnect edlike
A–B–C–D–E–F,andl ett hemet ri
cbet weent her outersbe" numberofj umps" .Now
supposet hatAi stakenof fli
ne.Inthev ector-
updat e-
processBnot i
cest hatther out
et o
A,whi chwasdi stance1,i sdown–Bdoesnotr eceivet hevectorupdat efrom A.The
problem i
s,Bal soget sanupdat efrom C,andCi ssti
llnotawar eoft hefactt hatAi s
down–soi ttell
sBt hatAi sonlytwoj umpsf rom C( Ct oBt oA) ,whichisf alse.This
slowlypropagat est hr ought henet wor kunt i
li treachesi nfi
nit
y( i
nwhi chcaset he
algori
thm corr
ect si
tsel f,duetother el
axat i
onpr opertyofBellman–For d).
56

(a)UNI CASTROUTI NGPROTOCOL


AIM:
Towr i
teans2pr ogram fori mplement i
nguni castr out i
ngpr otocol.
THEORY:
Whenadev icehasmul tipl
epat hst or eachadest ination,i talway ssel ectsone
pathbypr eferri
ngi tov erothers.Thi sselectionpr ocessi stermedasRout ing.Rout i
ngi s
donebyspeci alnet wor kdevicescal ledrout ersori tcanbedonebymeansofsof t
war e
processes. Thesof twar ebasedr outershav el i
mi tedf unct i
onal it
yandl i
mi tedscope. A
routeri sal waysconf iguredwi thsomedef aultr oute.Adef aul troutet ell
st her outer
wher et of orwardapacketi ft herei snor out efoundf orspeci ficdestination.I ncase
therear emul ti
plepat hexisti
ngt or eacht hesamedest i
nation, rout ercanmakedeci sion
basedont hef ol
lowi ngi nfor
mat i
on.Rout escanbest ati
cal l
yconf iguredordy nami call
y
l
ear nt.Oner outecanbeconf i
gur edt obepr eferredov erot her s.Mostoft het raf
ficon
thei nter
netandi ntranet sknownasuni castdat aoruni castt rafficissentwi t
hspeci f
ied
dest i
nation.Rout inguni castdat aov ert hei nterneti scal leduni castrout i
ng.I tist he
simpl estfor m ofr outingbecauset hedest i
nat i
oni sal readyknown.Hencet her outer
j
usthast ol ookupt her outi
ngt ableandf orwar dthepackett onexthop

PRELABVIVAQUESTI ONS:
1.Whatt y
peofpr otocolisBGP?
2.Whatt y
peofpr otocolisOSPF?
3.WhatisDi st
anceVect orRouti
ng.
4.Whatisf l
ooding.
5.Descri
bet hediff
erencebetweenstati
canddynamicrout
ing/
6.Defi
neanaut onomoussy st
em.
7.Whatar etheadaptiverouti
ngalgor
it
hms.
8.Dint
inguishbetweenadapt i
veandnonadapti
verouti
ngalgor
it
hms.
9.Whatisr out
ing

ALGORITHM:
1.St artthepr ogram.
2.Decl ar etheglobal variablesnsforcreatinganewsi mul ator.
3.Sett hecol orforpacket s.
4.Opent henetwor kani matorfil
einthenameoff i
l
e2int hewr it
emode.
5.Opent hetracef i
leinthenameoff i
l
e1i nt hewritemode.
6.Sett heuni castr outingprotocoltotransferthepacketsi nnetwor
k.
7.Cr eatet herequi r
ednoofnodes.
8.Cr eatet hedupl ex-l
inkbet weenthenodesi ncludingthedel ay
ti
me, bandwi dthanddr oppingqueuemechani sm.
9.Gi vet heposi t
ionf orthelinksbetweent henodes.
10.Setat cprenoconnect ionforsourcenode.
57

11.
Setthedest i
nationnodeusi ngtcpsink.
12.
Setupaf t
pconnect i
onov erthetcpconnection.
13.
Downt heconnect ionbetweenanynodesatapar t
icul
arti
me.
14.
Reconnectt hedownedconnect i
onatapar ti
cularti
me.
15.
Definethefinishprocedure.
16.
Inthedefinit
ionoft hefi
nishproceduredeclaretheglobalv
ari
abl
esns,fi
l
e1,
and
fi
le2.
17.
Closethet r
acef il
eandnamef il
eandexecut ethenetworkani
mationf
il
e.
18.
Attheparticularti
mecal lthefi
nishprocedure.
19.
Stopthepr ogram.

PROGRAM:
setns[ newSi mul ator]
#Definedi fferentcol or
sfordat
afl
ows(forNAM)
$nscol or1Bl ue
$nscol or2Red
#Opent heTr acef il
e
setfi
le1[ openout .trw]
$nstrace- all$fil
e1
#Opent heNAM t r
acef i
le
setfi
le2[ openout .nam w]
$nsnamt race- all
$f i
le2
#Definea' f
inish'procedure
procfinish{ }
{
global nsf il
e1f il
e2
$nsf lush- tr
ace
close$f i
le1
close$f i
le2
execnam out .nam &
exit3
}
#Nextl ineshoul dbecomment edoutt
ohav et
hest
ati
c
rout
ing$nsr t
pr otoDV
#Create six
nodes set n0
[$ns node]set
n1 [$ns node]
setn2[ $nsnode]
setn4[ $nsnode]
setn4[ $nsnode]
setn5[ $nsnode]
58

#Creat
elinksbet
weenthenodes
$nsduplex-l
i
nk$n0$n10.3Mb10msDr
opTai
l
$nsduplex-l
i
nk$n1$n20.3Mb10msDr
opTai
l
$nsduplex-l
i
nk$n2$n30.3Mb10msDr
opTai
l
$nsduplex-l
i
nk$n1$n40.3Mb10msDr
opTai
l
$nsduplex-l
i
nk$n3$n50.5Mb10msDr
opTai
l
$nsduplex-l
i
nk$n4$n50.5Mb10msDr
opTai
l

#Giv
enodeposit
ion(
forNAM)
$nsdupl
ex-
li
nk-
op$n0$n1ori
entri
ght
$nsdupl
ex-
li
nk-
op$n1$n2ori
entri
ght
$nsdupl
ex-
li
nk-
op$n2$n3ori
entup
$nsdupl
ex-
li
nk-
op$n1$n4ori
entup-l
eft
$nsdupl
ex-
li
nk-
op$n3$n5ori
entl
eft-
up
$nsdupl
ex-
li
nk-
op$n4$n5ori
entri
ght-
up

#SetupaTCPconnect ion
settcp[newAgent /TCP/ Newr
eno]
$nsat t
ach-agent$n0$t cp
setsink[newAgent /TCPSink/
DelAck]
$nsat t
ach-agent$n5$si nk
$nsconnect$t cp$sink
$tcpsetfid_1

#SetupaFTPov erTCPconnect
ion
setft
p[newApplicati
on/
FTP]
$ft
pattach-
agent$tcp
$ft
psettype_FTP

$nsrtmodel-
at1.0down$n1$n4
$nsrtmodel-
at4.5up$n1$n4
$nsat0.1"$ft
pstart
"
$nsat6.0"fi
nish"
$nsrun
59
60

(
b)MULTI
CASTI
NGROUTI
NGPROTOCOL

AI
M:
Towr
it
eans2pr
ogr
am f
ori
mpl
ement
ingmul
ti
cast
ingr
out
ingpr
otocol
.

ALGORITHM:
1.St artthepr ogr am.
2.Decl ar ethegl obal v ariabl
esnsf orcreatinganewsi mul ator.
3.Sett hecol orf orpacket s.
4.Opent henet wor kani matorf i
leinthenameoff i
le2int hewr it
emode.
5.Opent het r
acef il
eint henameoff i
le1int hewr itemode.
6.Sett hemul t
icastr out ingpr ot
ocol totransfert hepacket si nnet work.
7.Cr eatet hemul ticastcapabl enoofnodes.
8.Cr eatet hedupl ex-l
inkbet weent henodesi ncludingthedel ay
ti
me, bandwi dthanddr oppingqueuemechani sm.
9.Gi vet heposi ti
onf ort helinksbet weent henodes.
10.Setaudpconnect i
onf orsour cenode.
11.Setthedest inat ionnode, por tandr andom f alsef orthesour ceanddest i
nat
ion
fi
les.
12.Setupat rafficgener atorCBRf orthesour ceanddest i
nationf iles.
13.Downt heconnect i
onbet weenanynodesatapar ti
culartime.
14.Createt her ecei v eagentf orjoini
ngandl eavingift henodesi nt hegroup.
15.Definet hef i
ni shpr ocedur e.
16.I
nt hedef initionoft hef i
nishpr oceduredecl arethegl obal v ariables.
17.Closet het racef il
eandnamef il
eandexecut et henet wor kani mat i
onfil
e.
18.Atthepar ti
cul art imecal lthef i
nishprocedur e.
19.Stopt hepr ogr am.

PROGRAM:
#Creat escheduler
#Createanev entschedulerwitmul
ti
cast
tur
nedonsetns[ newSi mulat
or-mul
ti
caston]
#$nsmul ticast
#TurnonTr acing
settf[openout put.t
rw]
$nstrace-all$tf
#Turnonnam Tr acing
setfd[openmcast .nam
w]$nsnamt race-all$f
d
61

#Cr eat
enodes
setn0[$ns
node]setn1
[$nsnode]set
n2[$nsnode]
setn3[$ns
node]setn4
[$nsnode]set
n5[$nsnode]
setn6[$ns
node]setn7
[$nsnode]

#Creat
eli
nks
$nsdupl
ex-
li
nk$n0$n21.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n1$n21.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n2$n31.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n3$n41.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n3$n71.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n4$n51.
5Mb10msDr
opTai
l
$nsdupl
ex-
li
nk$n4$n61.
5Mb10msDr
opTai
l

#Routi
ngprotocol:saydist
ance
vect
or#Prot
ocol s:Ctr
Mcast,DM,
ST,BSTsetmpr otoDM
setmrt
handle[$nsmr tpr
oto$mprot
o{}
]

#All
ocat
egroupaddresses
setgr
oup1[
Nodeallocaddr
]
setgr
oup2[
Nodeallocaddr
]

#UDPTr ansportagentforthetr
aff
ic
sourcesetudp0[ newAgent /UDP]
$nsat tach-agent$n0
$udp0$udp0set
dst_addr _$group1$udp0
setdst _port_0
setcbr 1[new
Applicati
on/Traffi
c/CBR]$cbr1
att
ach- agent$udp0
#Transportagentf
orthetr
aff
icsour
ce
setudp1[newAgent/UDP]
$nsattach-
agent$n1$udp1
$udp1setdst_addr
_$group2
62

$udp1setdst
_port
_0
setcbr
2[newApplicat
ion/
Traf
fi
c/CBR]
$cbr2at
tach-
agent$udp1

#Createrecei
ver
setr
cvr1[newAgent /Null
]
$nsatt
ach-agent$n5$r cvr
1
$nsat1.0"$n5join-
group$rcvr
1$group1"
setr
cvr2[newAgent /Null
]
$nsatt
ach-agent$n6$r cvr
2
$nsat1.5"$n6join-
group$rcvr
2$group1"
setr
cvr3[newAgent /Null
]
$nsatt
ach-agent$n7$r cvr
3
$nsat2.0"$n7join-
group$rcvr
3$group1"
setr
cvr4[newAgent /Null
]
$nsatt
ach-agent$n5$r cvr
1
$nsat2.5"$n5join-
group$rcvr
4$group2"
setr
cvr5[newAgent /Null
]
$nsatt
ach-agent$n6$r cvr
2
$nsat3.0"$n6join-
group$rcvr
5$group2"
setr
cvr6[newAgent /Null
]
$nsatt
ach-agent$n7$r cvr
3
$nsat3.5"$n7join-
group$rcvr
6$group2"
$nsat4.0"$n5leave-gr
oup$rcvr1$gr
oup1"
$nsat4.5"$n6leave-gr
oup$rcvr2$gr
oup1"
$nsat5.0"$n7leave-gr
oup$rcvr3$gr
oup1"
$nsat5.5"$n5leave-gr
oup$rcvr4$gr
oup2"
$nsat6.0"$n6leave-gr
oup$rcvr5$gr
oup2"
$nsat6.5"$n7leave-gr
oup$rcvr6$gr
oup2"

#Schedul
eevents
$nsat0.
5"$cbr
1start
"
$nsat9.
5"$cbr
1stop"
$nsat0.
5"$cbr
2start
"
$nsat9.
5"$cbr
2stop"

#post
-pr
ocessi
ng
$nsat10.0"
fi
nish"
procf
ini
sh{}
{
63

globalnstf
$nsf l
ush-
tr
ace
cl
ose$t f
execnam mcast.
nam &
exit0
}

#Fornam
#Col
orsforpacketsf
rom t
womcastgr
oups
$nscol
or10red
$nscol
or11gr een
$nscol
or30pur pl
e
$nscol
or31gr een

#Manuall
ayout:
orderoft
heli
nkissigni
fi
cant
!
#$nsdupl
ex-
li
nk-op$n0$n1ori
entri
ght
#$nsdupl
ex-
li
nk-op$n0$n2ori
entri
ght-
up
#$nsdupl
ex-
li
nk-op$n0$n3ori
entri
ght-
down
#Showqueueonsi mpl
exli
nkn0->n1
#$nsdupl
ex-
li
nk-op$n2$n3queuePos0.5

#Group 0
sour
ce $udp0
setfi
d_10$n0
col
orred
$n0label
"Sour
ce1"

#Group1sour ce
$udp1setfi
d_11
$n1colorgreen
$n1label"
Source2"
$n5label"
Receiver1"
$n5colorbl
ue
$n6label"
Receiver2"
$n6colorbl
ue
$n7label"
Receiver3"
$n7colorbl
ue

#$n2add-
markm0r
ed
#$n2del
ete-
mar
km0"
64

#Animati
onrat
e
$nsset
-ani
mati
on-
rat
e3.
0ms
$nsrun
65
66

(
c)DI
STANCEVECTORROUTI
NGPROTOCOL

AI
M:
Tosi
mul
ateal
i
nkf
ail
ureandt
oobser
vedi
stancev
ect
orr
out
ingpr
otocol
inact
ion.

ALGORI THM:
1.Cr eat easi mul atorobj ect
2.Setr out i
ngpr ot ocol toDi stanceVectorrouti
ng
3.Tr acepacket sonal l l
inksont oNAM traceandt exttr
acefi
le
4.Def inef i
nishpr ocedur etocl osefil
es,f
lushtraci
ngandrunNAM
5.Cr eat eei ghtnodes
6.Speci fythel i
nkchar act eristi
csbetweennodes
7.Descr i
bet hei rlay outt opol ogyasaoct agon
8.AddUDPagentf ornoden1
9.Cr eat eCBRt raf fi
cont opofUDPandsett raf
f i
cparameter
s.
10.Addasi nkagentt onoden4
11.Connectsour ceandt hesi nk
12.Schedul eev ent sasf ollows:
a.St arttraf fi
cf lowat0. 5
b.Downt hel i
nkn3- n4at1.0
c.Upt hel inkn3- n4at2. 0
d.St opt raf fi
cat3. 0
e.Cal lfinishpr ocedur eat5.0
13.St ar ttheschedul er
14.Obser vet het raf f
icr out ewhenl inkisupanddown
15.Vi ewt hesi mul atedev ent sandt racefi
l
eanaly zeit
16.St op
PROGRAM
#Distancev ectorr out ingpr ot ocol –distvect
.t
cl
#Createasi mul atorobj ect
setns[ newSi mul ator ]
#Usedi st ancev ect orr out i
ng
$nsrtprot oDV
#Opent henam t racef il
e
setnf[openout .nam w]
$nsnamt race-all $nf
#Opent racef i
le
setnt[opent race. t
rw]
$nstrace- al l$nt
#Define' finish'pr ocedur e
67

procfini
sh{ }
{
global nsnf
$nsf l
ush- t
race
#Closet het r
acefil
e
close$nf
#Execut enam ont hetracefi
le
execnam - aout .
nam &
exit0
}
#Create 8
nodes 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]set
n8[$nsnode]
#Speci f
ylinkchar acter
esti
cs
$nsdupl ex-l
ink$n1$n21Mb10msDr opTai
l
$nsdupl ex-l
ink$n2$n31Mb10msDr opTai
l
$nsdupl ex-l
ink$n3$n41Mb10msDr opTai
l
$nsdupl ex-l
ink$n4$n51Mb10msDr opTai
l
$nsdupl ex-l
ink$n5$n61Mb10msDr opTai
l
$nsdupl ex-l
ink$n6$n71Mb10msDr opTai
l
$nsdupl ex-l
ink$n7$n81Mb10msDr opTai
l
$nsdupl ex-l
ink$n8$n11Mb10msDr opTai
l
#speci f
ylay outasaoct agon
$nsdupl ex-l
ink-op$n1$n2or i
entleft-
up
$nsdupl ex-l
ink-op$n2$n3or i
entup
$nsdupl ex-l
ink-op$n3$n4or i
entright-
up
$nsdupl ex-l
ink-op$n4$n5or i
entright
$nsdupl ex-l
ink-op$n5$n6or i
entright-
down
$nsdupl ex-l
ink-op$n6$n7or i
entdown
$nsdupl ex-l
ink-op$n7$n8or i
entleft-
down
$nsdupl ex-l
ink-op$n8$n1or i
entleft
#CreateaUDPagentandat t
achittonoden1
setudp0[newAgent/UDP]
$nsattach-
agent$n1$udp0
68

#CreateaCBRt rafficsourceandat t
achitto
udp0setcbr 0[ newAppl icati
on/ Traf
fi
c/CBR]
$cbr0setpacket Size_500
$cbr0seti nterv al_0.005
$cbr0attach- agent$udp0
#CreateaNul lagent( atraffi
csi nk)andattachitt
onoden4
setnul
l0[ newAgent /Null
]
$nsattach- agent$n4$nul l0
#Connectt het r affi
csour cewi ththetraf
fi
csi nk
$nsconnect$udp0$nul l0
#Scheduleev ent sfort heCBRagentandt henetwork
dynamics$nsat0. 0" $n1label Source"
$nsat0.0" $n4l abel Dest i
nation"
$nsat0.5" $cbr 0st art"
$nsrtmodel -
at1. 0down$n3$n4
$nsrtmodel -
at2. 0up$n3$n4
$nsat4.5" $cbr 0st op"
#Callt
hef inishpr ocedur eafter5secondsofsi mulat
iont
ime
$nsat5.0" fi
nish"
#Runthesi mul ation
$nsrun

OUTPUT
$nsdist
vect
.t
c
l
69
70

POSTLABVI
VAQUESTI
ONS:

1.Whatdoy oumeanbyt heterm“no.ofhops” ?


2.Listthebasi cfunctionsofr out
ers.
3.Explainmul ti
castr outi
ng.
4.Explaint hedif
ferencebet weeninteri
orandext eri
orneighborgateway
s.
5.ExplainRI P.
6.Descr ibetheprocessofr outi
ngpackets.
7.Whatar esomeoft hemer i
tsusedbyr outi
ngpr ot
ocols?
8.Whar eisrouti
ngt ableismai nt
ained?AlsoStatetheofmai ntai
ningarout
ing
table.
9.Distinguishbetweenbr i
dgesandr outers

RESULT:
Thusthecasestudyaboutt
hediff
erentr
outi
ngalgori
thmstosel
ectt
henet
wor
k
pat
hwithit
soptimum andeconomical
duringdatat
ransferi
sdone.
71

Ex.
No:
10 Si
mul
ati
onofEr
rorCor
rect
ionCode(
li
keCRC)

AI
M:
Toi
mpl
ementer
rorchecki
ngcodeusi
ngj
ava.
THEORY:

Thecy cl
i
credundancycheck,orCRC,isatechni
quefordet
ect
inger
ror
sindigi
tal
data,butnotformaki
ngcor r
ect
ionswhenerrorsar
edetect
ed.Iti
susedpri
mari
lyi
ndata
tr
ansmi ssi
on.

I
ntheCRCmet
hod,acer
tai
nnumberofcheckbi
ts,of
tencal
l
edachecksum,ar
e
appendedt
othemessagebei
ngt
ransmi
tt
ed.Ther
ecei
vercandet
ermi
newhet
herornott
he
checkbi
tsagr
eewi
tht
hedat
a,t
oascer
tai
nwi
thacer
tai
ndegr
eeofpr
obabi
l
itywhet
heror
notaner
roroccur
redi
ntr
ansmi
ssi
on.

I
tdoeser r
orchecki
ngviapoly
nomialdi
vi
sion.I
ngener
al,
abi
tst
ri
ng
bb b…bbb
n-1 n- 2 n- 3 2 1 0
As
bn-1Xn-
1+bn- 2Xn-2+bn-3Xn-3+…b2X2 +b1 X1 +b0
Ex:-
10001000000100001As
X16+X12+X5+1
Allcomputat
ionsar
edonei nmodulo2

PRELABVI
VAQUESTI
ONS:

1.Whatisflowcontrol
?
2.Whatismeantbyer rorcontrol
?
3.WhichisoperatedintheDat aLinkandtheNet
wor
klay
er?
4.St
atethepurposeofl ayeri
ng.
5.Whatar ethetwot y
pesofl i
neconf i
gur
ati
on?

ALGORI
THM:

1.Startt
heProgram
2.Givenabitstr
ing,
append0St ot
heendofi t(thenumberof0si st
hesameasthe
degreeofthegenerat
orpoly
nomial
)letB(x)bet hepol
ynomialcor
respondi
ngt
o
B.
3.Divi
deB(x)bysomeagr eedonpoly
nomi alG(x)(gener
atorpol
ynomial
)and
det
ermi
net
her
emai
nderR(
x).Thi
sdi
vi
sioni
stobedoneusi
ngModul
o2Di
vi
sion.
72

4.Def i
neT( x)=B( x)–R( x)
5.(T(x)/G(x)=>r emai nder0)
6.Transmi tT, t
hebi tstri
ngcorrespondingtoT(x) .
7.LetT’r epresentt he bitstr
eam t he recei
v ergets and T’
(x)t he associ
ated
polynomi al.Ther eceiv
erdividesT1( x)byG( x)
.Iftherei
sa0r emainder
,the
receiverconcludesT=T’ andnoer r
oroccur r
edot her
wise,t
her eceiverconcl
udes
aner roroccurredandr equi
resaretransmission
8.Stopt hePr ogram

PROGRAM:

i
mpor tjav a.i
o.* ;
cl
asscr c_gen
{
publicst aticv oidmai n(Str
ingar gs[])throwsI OException{
BufferedReaderbr =newBuf feredReader (newI nputStreamReader (Sy
stem.
in)
);
i
nt[]dat a;
i
nt[]div ;
i
nt[]div i
sor ;
i
nt[]rem;
i
nt[]crc;
i
ntdat a_ bits,div i
sor _bi
ts,tot_lengt h;
System. out .println("
Enternumberofdat abits: ");
data_bi ts=I nteger .parseInt(
br .
readLi ne());data=newi nt[data_
bits]
;
System. out .println("
Enterdat abi t
s: ");f
or (
inti=0;
i
<dat a_ bits; i
++)
data[i]
=I nt eger.par seInt(br
.readLi ne( )
);
System. out .println("
Enternumberofbi t
si ndivisor
:");
di
visor _bi ts=Int eger.parseInt(br.readLine());divisor
=new
i
nt[divisor _ bit
s] ;System. out.println("
EnterDi vi
sorbi t
s: ");f
or(i
nti=0;
i
<divisor _ bits;i++)

divi
sor[i
]=Integer.parseInt(br.
readLine()
);
Sy stem.out .
pri
nt ("
Dat abitsar e:");
for(i
nti=0; i
<dat a_bit
s; i
++)
System. out.pri
nt(data[i
]);
System. out.pri
ntln()
;
System. out.pri
nt("di
visorbi t
sar e:");
for(i
nti=0; i
<divisor_bits;i++)
System. out.pri
nt(divi
sor [
i]
);
System. out.pri
ntln()
;
* /
tot_l
engt h=data_bits+divisor_bit
s-1;
div=newi nt[tot
_length];
73

rem=newi nt[tot _lengt h];


crc=newi nt[tot_ lengt h];
/*--
--
---
--
---
--
----CRCGENERATI ON--
--
--
--
--
--
--
--
--
--
--
-*/
for(
inti=0;i
<dat a.lengt h;i
++)
div[i
]=data[i];
System. out.print ("Dividend(af
terappendi
ng0's)are:
");
for
(i
nti
=0;
i<di
v.
lengt
h;i
++)
System. out.print (div[
i]);
System. out.print l
n( );
for(
intj=0;j<div .length; j++)
{
rem[j]=div[j];
}
rem=di vi
de(di v, divisor ,
rem);
for(i
nti=0;i<div .length; i
++)
{

/
/appenddi
vi
dendandr
emai
nder

crc[i
]=(
div[i
]^rem[ i
])
;
}
Sy stem.out.pr i
ntl
n()
;
System. out.
pr int
ln(
"CRCcode:
");
for(i
nti=0;i
<cr c.l
ength;
i++)
System. out.
pr int
(cr
c[i]
);

/*--
--
---
---
---
--
---
-ERRORDETECTI ON---
--
--
--
--
--
--
--
--
--*
/
System. out.print
ln();
System. out.print
ln("
Ent erCRCcodeof" +tot_
length+"bi
ts:
");
for
(i
nti
=0;
i<cr
c.l
engt
h;i
++)
crc[i
]=Integer.
par seInt(
br .
readLi
ne()
);
System. out.print
("crcbitsar e:"
);
for(i
nti=0; i
<cr c.l
ength; i
++)
System. out.print
(crc[i
])
;
System. out.print
ln();
for(i
ntj=0; j
<cr c.
length;j++){
rem[ j
]=cr c[j
];
}
rem=di vi
de( crc,divi
sor, r
em) ;
for(i
nti=0; i
<r em. l
ength; i
++)
{
i
f(rem[ i
]!
=0)
{
System. out.print
ln("
Er r
or "
);
break;
}
i
f(i==rem. l
engt h-
1)
74

Syst em.out .
pri
ntl
n("NoEr ror")
;
}
Syst em.out .
pri
ntl
n("THANKYOU. .
..:
)")
;
}
staticint[
]divide(i
ntdiv[]
,i
ntdivisor [
],
intr
em[
])
{
i
ntcur =0;
whi l
e(true)
{
for(i
nti=0;i<divi
sor.
length;
i++)
rem[ cur+i]
=(rem[cur+i]
^divisor[
i]
);
whi l
e(rem[cur ]
==0&&cur !
=r em.length-1)
cur++;
i
f((rem. l
ength-cur)
<divisor.
length)
break;
}
returnrem;
}
}
OUTPUT:
run:

Ent
ernumberofdat
abi
ts:

Ent
erdat
abi
ts:
1
0
1
1
0
0
1

Ent
ernumberofbi
tsi
ndi
vi
sor:
3

EnterDi
vi
sorbit
s:
1
0
1
Div
idend(af
terappendi
ng0'
s)ar
e:101100100
CRCcode:
101100111
EnterCRCcodeof9bi t
s:
75

1
0
1
1
0
0
1
0
1
cr
cbitsar
e:101100101
Er
ror
THANKYOU...
.:)
BUILDSUCCESSFUL(tot
alt
ime:
1mi
nut
e34seconds)

POSTLABVI
VAQUESTI
ONS:

1.Whatar eheadersandt r
ail
ersandhowdot heygetaddedandr
emov
ed?
2.Whatar eprotocols?
3.8.
Whi choneoft hef ol
lowingcondi
tionisusedtot
ransmitt
wo
packetsoveramedi um atthesamet i
me?
• Cont ention
• Col l
isi
on
• Sy nchronous
4.Whatar etheresponsibil
iti
esofdatali
nklayer
?
5.Whatar ethefunctionsofMAC?

RESULT:
Thust
heabov
epr
ogr
am f
orer
rorchecki
ngcodeusi
ngwasexecut
edsuccessf
ull
y.
76

Ex.
no.
11
TOPI
CBEYONDSYLLABUS

a.UDPCHATSERVERANDCLI
ENT
AI
M:
ToDev
elopaCl
i
ent
/Ser
verAppl
i
cat
ionf
orachatsessi
onusi
ngUDP.
THEORY:
UserDat agr am Pr otocol( UDP)i soneoft hecor emember soft heI nternet
protocolsui te.Thepr otocolwasdesi gnedbyDav idP.Reedi n1980andf ormal l
y
definedi nRFC768.Wi t
hUDP,comput erappli
cati
onscansendmessages,i nt hiscase
referredt oasdat agrams,t oot herhostsonanI nternetPr ot
ocol( I
P)net wor k.Prior
communi cati
onsar enotr equiredi nordertosetudpcommuni cati
onchannel sordat a
paths.UDPusesasi mpleconnect i
onl
esscommuni cationmodelwi thami nimum of
protocolmechani sm.UDPpr ovideschecksumsf ordat aint egri
ty,andportnumber sf or
addr essingdifferentf unctionsatt hesour ceanddest i
nationoft hedatagram.I thasno
handshaki ngdialogues,andt husexposest heuser'
spr ogr am toanyunr eliabil
i
t yoft he
under ly
ingnet wor k; Thereisnoguar ant
eeofdeliv
ery,order i
ng, ordupli
catepr ot
ect i
on.

PRELABVI VAQUESTI ONS:


1.WhatisCSMA?
2.Whatismeantbynon-persi
stentCSMA?
3.Whatismeantbyp-persi
stentCSMA?
4.WhatumeantbyExponat onalBackOFF?
5.Def
ineColl
isi
on?
6.Whatistheaccessmethodusedbywi r
elessLAN?

ALGORITHM:
Server
1.Createanewsocket .
2.Bindthenewlycreatedsocket(Assignl
ocalpr
otocol
addr
ess)
.
3.Serverreadyt
oreceivedatafrom cl
ient
4.Receivedatafr
om thecli
entandRepl y(CHAT)
.
Cli
ent
1.Createanewsocket .
2.Startt
osendmessagest otheserver
3.Receivethemessagessentbyt heserver.
4.Closetheconnecti
on.
77

PROGRAM:
SERVER:
#incl
ude<st di
o.h>
#incl
ude<st ri
ng.h>
#incl
ude<sy s/socket .
h>
#incl
ude<sy s/types. h>
#incl
ude<sy s/ti
mes. h>
#incl
ude<ar pa/i
net .h>
#incl
ude<net i
net /in.h>
#defineSAst ructsockaddr
voiddgecho( i
ntsockf d, SA* pcli
addr ,
socklen_ tcl
ilen)
{
i
ntn,i,
n1;
socklen_tlen;
charmsg[ 500] ,
msg1[ 500],msg2[ ]
={'
b',
'y'
,'
e',
'\
0'};
for(
;;
)
{
l
en=cl i
len;
n=recvf rom( sockf d,msg, 500,0,pcli
addr ,
&l en)
;
pri
nt f
("\nCLI ENT" );
i
f((msg[ 0] =='b' )&&( msg[ 1]=='y'
)&&(msg[ 2]=='
e')
)
{
print f("by e\ n");
print f("\nCl ientt ermi nated")
;
retur n;
}
for(i
=0;i<n; i++)
print f("%c" ,msg[ i])
;
pri
nt f
("\nSERVER: ");
fgets(msg1, 500, stdin);
sendto( sockf d, msg1, strlen(msg1) ,0,pcli
addr,l
en);
i
f((msg[ 0] =='b' )&&( msg[ 1]=='y'
)&&(msg[ 2]=='
e')
)
exit(0) ;
}
}
i
ntmai n(i
ntagr c,char* argv )
{
i
ntsockf d;
str
uctsockaddr _inser vaddr,cliaddr;
sockfd=socket ( AF_ INET, SOCK_ DGRAM, 0);
78

bzero(&servaddr,
sizeof(ser vaddr));
servaddr.si
n_famil
y =AF_INET;
servaddr.si
n_port
=ht ons(9003) ;
servaddr.si
n_addr.s_addr =htonl(I
NADDR_ ANY);
bind(sockfd,
(SA*)&servaddr ,
siz
eof (
servaddr)
);
print
f("
\nSERVERconnect ed\n"
) ;
dgecho( sockf
d,(
SA* )&cliaddr ,
sizeof(
cli
addr))
;
}

CLIENT:
#incl
ude<st dio. h>
#incl
ude<sy s/ socket .
h>
#incl
ude<sy s/ types. h>
#incl
ude<ar pa/ inet .
h>
#incl
ude<net i
net / in.h>
#incl
ude<st ring. h>
#incl
ude<uni st d.h>
#incl
ude<sy s/ times. h>
#defineSAst ructsockaddr
voiddgcli
(FILE* fp, i
ntsockf d,constSA* pserv
addr ,socklen_tservl
en)
{
i
ntn,n1;
charsendl ine[ 500] ,recv l
ine[500],
msg[ ]
={'
b',
'y
',
'e','
\0'
};
for(
;;
)
{
printf("\ nCLI ENT: ");
sendl ine[ 0]='\0';
fget s(sendl ine, 500,stdin);
sendt o( sockf d, sendl i
ne,str
len(sendline),
0,pserv addr,
servl
en);
i
f((sendl i
ne[ 0]==' b'
)&&( sendline[1]
=='y'
)&&( sendline[
2]=='
e')
)
ret ur n;
recv li
ne[ 0]='\0';
n=r ecv from( sockf d,
r ecvl
ine,500,0,NULL,NULL) ;
recv li
ne[ n]=0;
i
f((recv l
ine[ 0]==' b')
&&( recvl
ine[1]=='y'
)&&(r ecvl
ine[2]
=='e'
))
ret ur n;
recv li
ne[ n]=0;
printf("\ nSERVER" );
fput s(recv l
ine, stdout );
printf("\ n" )
;
79

}
}
i
ntmain(intar gc, char* argv[
])
{
i
ntsockf d;
str
uctsockaddr _inser v
addr ;
bzero( &ser vaddr ,
sizeof(ser vaddr)
);
servaddr .sin_ family=AF_ INET;
servaddr .sin_ port=htons( 9003);
i
net_pt on( AF_ INET, argv[1],
&servaddr.
sin_addr)
;
sockf d=socket (
AF_ INET,SOCK_ DGRAM, 0);
pri
ntf("\nCl ientconnect edt o..
.%s\n",
argv[1]
);
dgcli
( stdi
n, sockf d,(SA*)&ser vaddr,
si
zeof(serv
addr
));
exi
t(0) ;
}

OUTPUT:
ServerSi
de:
SERVERconnect ed
CLIENT:hai
SERVER:hel l
o
CLIENT:howar eu
SERVER:fine..
you?
CLIENT:fi
ne
SERVER:okt akecar e.
.by
e.
CLIENT:bye
Cli
entter
mi nated[i
t5003@veci
tit
5003]
$

Cli
entSide:
Cli
entconnect edto.
..172.
16.
0.5
CLIENT: hai
SERVERhel lo
CLIENT: howar eu
SERVERf ine..
you?
CLIENT: fi
ne
SERVERokt akecare..
bye.
CLIENT: bye
[
it
5003@v eci
tit5003]$
80

b.
CARRI
ERSENSEMULTI
PLEACCESS
AI
M:
Towr
it
eans2pr
ogr
am f
ori
mpl
ement
ingcar
ri
ersensemul
ti
pleaccess.

THEORY:
Carri
erSensedMul t
ipleAccess( CSMA):CSMA i sanet wor kaccessmet hod
usedonshar ednet wor kt opol ogi essuchasEt hernettocont rolaccesst ot henet wor k.
Devicesat tachedt othenet wor kcabl el i
sten( carri
ersense)bef oret ransmi t
ting.I ft he
channeli sinuse, deviceswai tbef oretransmi tti
ng.MA( Mul t
ipleAccess)i ndi catest hat
manydev i
cescanconnectt oandshar et hesamenet wor k.Alldev i
ceshav eequal
accesst ouset henet wor kwheni tisclear .I
not herwor ds,ast ationt hatwant st o
communi cate" listen"f irstont hemedi acommuni cat
ionandawai tsa" si l
ence"ofa
presett i
me( calledt heDi stribut edI nterFrameSpaceorDI FS) .Afterthiscompul sor y
peri
od,t hest ationst ar tsacount downf orar andom per i
odconsi der ed.Themaxi mum
durationoft hiscount downi scal l
edt hecol l
isionwi ndow( WindowCol l
i
sion,CW) .Ifno
equipmentspeaksbef or et heendoft hecount down,t hest ati
onsi mpl ydel iveri ts
package.Howev er,ifi ti s ov er taken byanot herstation,i tst ops i mmedi atelyi ts
count downandwai tsf ort henextsi lence.Shet hencont inuedhi saccountcount down
wher ei tleftof f.Thi si ssummar i
zedi nFi gure.Thewai t
ingt imer andom hast he
advant ageofal lowi ngast atistical l
yequi t
abledi stri
buti
onofspeaki ngt i
mebet weent he
vari
ousnet wor kequi pment ,whi lemaki ngl i
ttleunlikel
y( butnoti mpossi bl e)t hatbot h
devicesspeakexact l
yt hesamet ime.Thecount downsy stem pr event sast ati
onwai ting
tool ongbef or ei ssuingi tspackage.I t'
sabi twhatpl acei nameet ingr oom whenno
mast ersessi on( andal ltheWor ld'
spol it
e)expect edasi l
ence,t henaf ew moment s
beforespeaki ng,t oal low timef orsomeoneel setospeak.Thet i
mei sandr andoml y
assigned, t
hati st osay ,mor eorl essequal ly.

ALGORITHM:
1.St artthepr ogr am.
2.Decl ar ethegl obal variabl
esnsf orcreati
nganewsi mulator.
3.Sett hecol orforpacket s.
4.Opent henet wor kanimat orf i
leinthewr i
temode.
5.Opent hetracef i
leandt hewi nf il
einthewr i
temode.
6.Tr ansf erthepacket sinnet wor k.
7.Cr eatet hecapabl enoofnodes.
8.Cr eatet hedupl ex-l
inkbetweent henodesi ncludi
ngthedelay
ti
me, bandwi dthanddr oppingqueuemechani sm.
9.Gi vet heposi ti
onf orthelinksbet weenthenodes.
10.Setat cpconnect i
onf orsour cenode.
11.Setthedest i
nat ionnodeusi ngt cpsink.
12.Setthewi ndowsi zeandt hepacketsi zeforthetcp.
13.
Setupt
hef
tpov
ert
het
cpconnect
ion.
81

14.
Settheudpandt cpconnectionforthesour ceanddesti
nati
on.
15.
Createthet r
affi
cgeneratorCBRf orthesour ceanddest
inati
onfi
les.
16.
Definetheplotwindowandf i
nishprocedure.
17.
Inthedefinit
ionofthefini
shprocedur edeclarethegl
obalvari
abl
es.
18.
Closethet r
acef i
leandnamef i
leandexecut et henet
workanimati
onfil
e.
19.
Attheparticulart
imecal l
thefi
nishpr ocedure.
20.
Stopthepr ogram.

PROGRAM:
setns[ newSi mul at
or]
$nscol or1bl ue
$nscol or2r ed
setfi1[openout .trw]
setwinf i
le[ openWi nFil
ew]
$nst r
ace- all$fi1
setfi2[openout .nam w]
$nsnamt race- al
l$fi2
procfinish{ }
{
global nsfi1fi
2
$nsf lush-t
race
close$f i1
close$f i2
execnam out .
nam &
exit0
}
setn0[ $nsnode]
setn1[ $nsnode]
setn2[ $nsnode]
setn3[ $nsnode]
setn4[ $nsnode]
setn5[ $nsnode]
$n1col orr ed
$n1shapebox
$nsdupl ex- li
nk$n0$n22Mb10msDr opTai
l
$nsdupl ex- li
nk$n1$n22Mb10msDr opTai
l
$nssi mplex- li
nk$n2$n30. 3Mb100msDr opTai
l
$nssi mplex- li
nk$n3$n20. 3Mb100msDr opTai
l
setlan[$nsnewLan" $n3$n4$n5"0.
5Mb40msLLQueue/
DropTai
lMAC/
Csma/
Cd
Channel ]sett cp[newAgent /
TCP/Newreno]
82

$nsat t
ach- agent$n0$t cp
setsink[ newAgent /TCPSi nk/DelAck]
$nsat t
ach- agent$n4$si nk
$nsconnect$t cp$si nk
$tcpsetf id_1
$tcpsetwi ndow_8000
$tcpsetpacket si ze_552
setft
p[ newAppl icat i
on/ FTP]
$ftpattach- agent$t cp
$ftpsett ype_FTP
setudp[ newAgent /UDP]
$nsat t
ach- agent$n1$udp
setnull[newAgent /Null]
$nsat t
ach- agent$n5$nul l
$nsconnect$udp$nul l
$udpsetf i
d_2
setcbr[ newAppl ication/Tr aff
ic/CBR]
$cbrattach- agent$udp
$cbrsett ype_CBR
$cbrsetpacket _size_1000
$cbrsetr ate_0. 01mb
$cbrsetr andom_f alse
$nsat0. 1" $cbrst art"
$nsat1. 0" $f t
pst art"
$nsat24. 0" $ftpst op"
$nsat24. 5" $cbrst op"
procplot window{t cpSour cefile}
{
global ns
sett ime0. 1
setnow[ $nsnow]
setcwnd[ $t cpSour cesetcwnd_ ]
setwnd[ $t cpSour cesetwi ndow_]
put s$f ile" $now$cwnd"
$nsat[ expr$now+$t i
me]" pl
otwi
ndow$t
cpSour
ce$f
il
e"
}
$nsat1. 0" plot wi ndow$t cp$wi nfil
e"
$nsat5" $nst race- annot at e\"packetdr
op\"
"
$nsat125. 0" finish"
$nsrun
83

OUTPUT:
84
85

POSTLABVIVAQUESTI ONS:
1.WhatisCSMA/ CD?
2.Defi
netheterm Medium Accesscontrol
Mechnism?
3.WhatisColl
isi
onDet ect
ion?
4.Menti
ondiffer
entrandom accessTechniques/
5.WhatisALOHAPr otocol.
6.Whatdoy ouunderstandCSMAPr otocol
.

RESULT

ThustheUDPchatser
verandcl
i
entappli
cat
ionandcarr
iersense
mul
ti
pleaccessar
eimpl
ementedandexecut
edsuccessf
ull
y.

You might also like