Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

X.CreatingWiredcumWirelessandMobileIP
Simulationsinns
[Previoussection][Nextsection][Backtotheindex]
IMPORTANT:ThistutorialchapterusesnewnodeAPIswhicharenotavailableinthens2.1b5version.So
pleasedownloadthedailysnapshotunlessareleaseismadeforversionns2.1b6orhigher.Thecurrentsnapshot
versionisupdateddaily,sopleasecheckthevalidationtestresultsforthatdaybeforedownloading,asthese
snapshotscansometimesbeunstableduetoongoingchangesmadebynsdevelopers.
X.1.Creatingasimplewiredcumwirelessscenario
ThewirelesssimulationdescribedinsectionIX,supportsmultihopadhocnetworksorwirelessLANs.Butwe
mayneedtosimulateatopologyofmultipleLANsconnectedthroughwirednodes,orinotherwordsweneedto
createawiredcumwirelesstopology.
InthissectionwearegoingtoextendthesimplewirelesstopologycreatedinsectionIXtocreateamixed
scenarioconsistingofawirelessandawireddomain,wheredataisexchangedbetweenthemobileandnon
mobilenodes.Wearegoingtomakemodificationstothetclscriptcalledwireless1.tclcreatedinsectionIX.2
andnametheresultingwiredcumwirelessscenariofilewireless2.tcl.
Forthemixedscenario,wearegoingtohave2wirednodes,W(0)andW(1),connectedtoourwirelessdomain
consistingof3mobilenodes(nodes0,1&2)viaabasestationnode,BS.Basestationnodesarelikegateways
betweenwirelessandwireddomainsandallowpacketstobeexchangedbetweenthetwotypesofnodes.For
detailsonbasestationnodepleaseseesection2(wiredcumwirelessnetworking)ofchapter15ofnsnotes&doc
(nowrenamedasnsManual).Fig1.showsthetopologyforthisexampledescribedabove.

http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

1/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

Letusbeginbycheckingwhatchangesneedtobemadetothelistofvariablesdefinedatthebeginningof
wireless1.tcl.
TheAdhocroutingprotocolischangedtoDSDV.Also,wedefineTCPandCBRconnectionsbetweenthewired
andwirelessnodesinthescriptitself.Sowewon'tneedtousetheconnectionpatternfileusedinearlier
simulation.Alsochangethesimulationstoptime.Noteherethatweusearrayopt()insteadofval()simplyto
illustratethatthisisnolongeraglobalarrayvariableanditsscopeisdefinedonlyinthetestscript.
setopt(adhocRouting)DSDV
setopt(cp)
"";#cpfilenotused
setopt(stop)
300;#timetostopsimulation

WedefinethestarttimesforTCPflowshere:
setopt(ftp1start)160.0
setopt(ftp2start)170.0

Alsoaddthefollowinglinetodefinenumberofwiredandbasestationnodes:
setnum_wired_nodes2
setnum_bs_nodes1

Nowwemovetothemainpartoftheprogram.Formixedsimulationsweneedtousehierarchicalroutingin
ordertoroutepacketsbetweenwirelessandwireddomains.Asexplainedinsection15.2.1ofnsManual,inns,
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

2/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

theroutinginformationforwirednodesarebasedonconnectivityofthetopology,i.ehowarenodesconnected
tooneanotherthroughLinks.Thisconnectivityinformationisusedtopopulatetheforwardingtablesineach
wirednode.Howeverwirelessnodeshavenoconceptof"links".Packetsareroutedinawirelesstopologyusing
theiradhocroutingprotocolswhichbuildforwardingtablesbyexchangingroutingqueriesamongits
neighbours.Soinordertoexchangepktsamongthesewiredandwirelessnodes,weusebasestationswhichact
asgatewaysbetweenthetwodomains.Weseggregatewiredandwirelessnodesbyplacingthemindifferent
domains.Domainsandsubdomains(orclustersastheyarecalledhere)aredefinedbymeansofhierarchical
topologystructureasshownbelow.Afterline"setns[newSimulator]",addthefollowinglines:
$ns_nodeconfigaddressTypehierarchical
AddrParamssetdomain_num_2;#numberofdomains
lappendcluster_num21;#numberofclustersineach
;#domain
AddrParamssetcluster_num_$cluster_num
lappendeilastlevel114;#numberofnodesineachcluster
AddrParamssetnodes_num_$eilastlevel;#foreachdomain

IntheabovelineswefirstconfigurethenodeobjecttohaveaddresstypeasHierarchical.Nextthetopology
hierarchyisdefined.Numberofdomainsinthistopologyis2(oneforthewirednodesandoneforthewireless).
Numberofclustersineachofthesedomainsisdefinedas"21"whichindicatesthefirstdomain(wired)tohave
2clustersandthesecond(wireless)tohave1cluster.Thenextlinedefinesthenumberofnodesineachofthese
clusterswhichis"114"i.eonenodeineachofthefirst2clusters(inwireddomain)and4nodesinthecluster
inthewirelessdomain.Sothetopologyisdefinedintoa3levelhierarchy(seethetopologyfigureabove).
Nextwesetuptracingforthesimulation.Noteherethatforwiredcumwirelesssimulationtracesmaybe
generatedforbothwiredandwirelessdomains.Boththetracesarewrittenintothesameoutputfiledefinedhere
aswireless2out.tr.Inordertodifferentiatewirelesstracesfromwiredones,allwirelesstracesbeginwith"WL".
Wealsosetupnamtraces.Asmentionedearliernamtracesforwirelessnodescurrentlyshownodemovements
only.
settracefd[openwireless2out.trw]
setnamtrace[openwireless2out.namw]
$ns_traceall$tracefd
$ns_namtraceallwireless$namtrace$opt(x)$opt(y)

Nextweneedtocreatethewired,wirelessandbasestationnodes.Noteherethatforallnodecreations,you
havetopassthehierarchicaladdressofthenode.Soafterline"creategod$opt(nn)",addthefollowinglinesfor
creatingwirednodes:
#createwirednodes
settemp{0.0.00.1.0};#hierarchicaladdressestobeused
for{seti0}{$i<$num_wired_nodes}{incri}{
setW($i)[$ns_node[lindex$temp$i]]
}

Inordertocreatebasestationnode,weneedtoconfigurethenodestructureasshownbelow.Thisispartofthe
newnodeAPIwhichconsistsoffirstconfiguringandthencreatingnodes.RefertonodeAPIinchapterIXfor
detailsaboutthenewnodeAPI.Sincebasestationnodesaregatewaysbetweenwiredandwirelessdomains
theyneedtohavewiredroutingmechanismturnedonwhichisdonebysettingnodeconfigoption
wiredRoutingON.Aftercreatingthebasestationnodewereconfigureforwirelessnodeandsoturn
wiredRoutingOFF.Allothernodeconfigoptionsusedforbasestationremainsthesameformobilenode.Also
theBS(0)nodeisassignedasthebasestationnodeforallthemobilenodesinthewirelessdomain,sothatall
pktsoriginatingfrommobilenodesanddestinedoutsidethewirelessdomain,willbeforwardedbymobilenodes
towardstheirassignedbasestation.
Notethatitisimportantforthebasestationnodetobeinthesamedomainasthewirelessnodes.Thisissothat
allpktsoriginatingfromthewireddomain,anddestinedforawirelessnodewillreachthebasestationwhich
thenusesitsadhocroutingprotocoltoroutethepkttoitscorrectdestination.Thusinamixedsimulation
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

3/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

involvingwiredandwirelessnodesitsnecessary:
1)toturnonhierarchicalrouting
2)tocreateseparatedomainsforwiredandwirelessnodes.Theremaybemultiplewiredandwirelessdomains
tosimulatemultiplenetworks.
3)tohaveonebasestationnodeineverywirelessdomain,thruwhichthewirelessnodesmaycommunicate
withnodesoutsidetheirdomain.
Letusgostepbystepforthisexampletoseehowthehierarchyiscreated.Herewehavetwodomains,domain0
,forwiredanddomain1,forwireless.Thetwowirednodesareplacedin2separateclusters,0and1thustheir
addresseslooklike0(domain0).0(cluster0).0(onlynode)and0(samedomain0).1(cluster1).0(againonly
node).
Asforthewirelessnodes,theyareindomain1wehavedefinedonecluster(0),soallnodesareinthiscluster.
Hencetheaddressesare:
Basestation:1(seconddomain,1).0(cluster0).0(firstnodeincluster)
WLnode#1:1.0.1(secondnodeincluster)
WLnode#2:1.0.2(thirdnode)
WLnode#3:1.0.3(fourthnode)
Wecouldhaveplacedthetwowirednodesinthesameclusterinwireddomain0.Alsowecouldhaveplaced
otherwirelessnodesindifferentclustersinwirelessdomain1.Alsodependingonourtopologywemayhave
gotridofclustersaltogether,andsimplyhavehad2layersofhierarchy,thedomainsandthenodes.
#configureforbasestationnode
$ns_nodeconfigadhocRouting$opt(adhocRouting)\
llType$opt(ll)\
macType$opt(mac)\
ifqType$opt(ifq)\
ifqLen$opt(ifqlen)\
antType$opt(ant)\
propType$opt(prop)\
phyType$opt(netif)\
channelType$opt(chan)\

topoInstance$topo\
wiredRoutingON\

agentTraceON\
routerTraceOFF\
macTraceOFF
#createbasestationnode
settemp{1.0.01.0.11.0.21.0.3};#hieraddresstobeusedfor
;#wirelessdomain
setBS(0)[$ns_node[lindex$temp0]]
$BS(0)randommotion0;#disablerandommotion
#providesomecoordinates(fixed)tobasestationnode
$BS(0)setX_1.0
$BS(0)setY_2.0
$BS(0)setZ_0.0
#createmobilenodesinthesamedomainasBS(0)
#notethepositionandmovementofmobilenodesisasdefined
#in$opt(sc)
#NotetherehasbeenachangeoftheearlierAddrParams
#function'sethieraddr'to'addr2id'.
#configureformobilenodes
$ns_nodeconfigwiredRoutingOFF
#nowcreatemobilenodes
for{setj0}{$j<$opt(nn)}{incrj}{
setnode_($j)[$ns_node[lindex$temp\
[expr$j+1]]]
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

4/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

$node_($j)basestation[AddrParamsaddr2id\
[$BS(0)nodeaddr]];#provideeachmobilenodewith
;#hieraddressofitsbasestation
}

NextconnectwirednodesandBSandsetupTCPtrafficbetweenwirelessnode,node_(0)andwirednodeW(0),
andbetweenW(1)andnode_(2),asshownbelow:
#createlinksbetweenwiredandBSnodes
$ns_duplexlink$W(0)$W(1)5Mb2msDropTail
$ns_duplexlink$W(1)$BS(0)5Mb2msDropTail
$ns_duplexlinkop$W(0)$W(1)orientdown
$ns_duplexlinkop$W(1)$BS(0)orientleftdown
#setupTCPconnections
settcp1[newAgent/TCP]
$tcp1setclass_2
setsink1[newAgent/TCPSink]
$ns_attachagent$node_(0)$tcp1
$ns_attachagent$W(0)$sink1
$ns_connect$tcp1$sink1
setftp1[newApplication/FTP]
$ftp1attachagent$tcp1
$ns_at$opt(ftp1start)"$ftp1start"
settcp2[newAgent/TCP]
$tcp2setclass_2
setsink2[newAgent/TCPSink]
$ns_attachagent$W(1)$tcp2
$ns_attachagent$node_(2)$sink2
$ns_connect$tcp2$sink2
setftp2[newApplication/FTP]
$ftp2attachagent$tcp2
$ns_at$opt(ftp2start)"$ftp2start"

Thiswouldbefollowedbytheremaininglinesfromwireless1.tcl(sourcingcpandscfiles,tellingmobilenodes
whentostopandfinallyrunningns).Itispossiblethatsomelinesofcodeinwireless2.tclhavenotbeen
discussedhere.Foracompletecopyofscriptwireless2.tcl,downloadfromhere.
Runthescript.Thensandnamtracefilesaregeneratedattheendofsimulationrun.Runningwireless2out.nam
showsthemovementofmobilenodesandtrafficinthewireddomain.Asmentionedearlier,trafficflowfor
mobilenodesisnotasyetsupportedinnam.Intracefilewireless2out.trweseetracesforbothwireddomain
andwirelessdomain(preceedingwith"WL"forwireless).At160.0s,aTCPconnectionissetupbetween_3_,
(whichisnode_(0))and0,(whichisW(0)).Notethatthenodeidsarecreatedinternallybythesimulatorandare
assignedintheorderofnodecreation.At170s,anotherTCPconnectionissetupintheoppositedirection,from
thewiredtothewirelessdomain.FordetailsonCMUTracesseechapter15ofnsdocumentation.
X.2.RunningMobileIPinasimplewiredcumwirelesstopology
Sofarwehavecreatedawiredcumwirelesstopologyandhaveexchangedpktsbetweenawiredandwireless
domainviaabasestation.Butamobilenodemayroamoutsidethedomainofitsbasestationandshouldstill
continuetoreceivepacketsdestinedtoit.InotherwordsitwouldbeinterestingtoextendmobileIPsupportin
thewiredcumwirelessscenariowecreatedinsectionX.1.
Forthisexamplewehavethesamewireddomainconsistingof2wirednodes,W0andW1.Wehave2base
stationnodesandcallthemHomeAgent(HA)andForeignAgent(FA)respectively.ThewirednodeW1is
connectedtoHAandFAasshowninthefigurebelow.ThereisaroamingmobilenodecalledMobileHost(MH)
thatmovesbetweenitshomeagentandforeignagents.WewillsetupaTCPflowbetweenW0andMH.AsMH
movesoutfromthedomainofitsHA,intothedomainofFA,wewillobservehowpktsdestinedforMHis
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

5/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

redirectedbyitsHAtotheFAaspermobileIPprotocoldefinitions.Seefig2belowforthetopologydescribed
above.

Weshalleditwireless2.tclcreatedinsectionX.1tocreatethewirelessmipscriptcalledwireless3.tcl.Itmaybe
possiblethatthewholeofwireless3.tclisnotdiscussedhere.Soforconvinience,youmaydownloadacopyof
wireless3.tclfromhere.
Changenumberofmobilenodesandtimeofsimulation,
setopt(nn)1;#justoneMH
setopt(stop)250

InthisexamplewewillsetuptheTCPconnectionaswellasdefinemovementoftheMHinthescriptitself.
Hencewearenotgoingtousethecpandscfiles.
setopt(cp)""
setopt(sc)""

DefinetheTCPflowstarttime,
setopt(ftp1start)100.0

Changenumberofwired,basestationandmobilenodes.Howevernotethatthevariablenum_bs_nodesisnot
reallyusedinthisscript.Thebasestationnodes,HAandFA,areindividuallycreatedandhandled.
setnum_wired_nodes2

Afterthe2linescreatingnsinstanceandsettingaddressformattohierarchical,addthefollowinglinestodefine
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

6/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

thetopologicalhierarchy.Itisquitesimilartothatofwireless2.tclexceptthatnowwehaveathirddomainfor
theFA.Changetheclusterandnodeparametersaccordingly.
AddrParamssetdomain_num_3;#numberofdomains
lappendcluster_num211;#numberofclustersineachdomain
AddrParamssetcluster_num_$cluster_num
lappendeilastlevel1121;#numberofnodesineachcluster
AddrParamssetnodes_num_$eilastlevel;#ofeachdomain

Nextsetupnstraceandnamfilesforwirelessmip,
settracefd[openwireless3out.trw]
setnamtrace[openwireless3out.namw]
$ns_traceall$tracefd
$ns_namtraceallwireless$namtrace$opt(x)$opt(y)

Sointhistopologywehaveonewireddomain(denotedby0)and2wirelessdomains(denotedby1&2
respectively).HenceasdescribedinsectionX.1,thewirednodeaddressesremainthesame,0.0.0and0.1.0.In
thefirstwirelessdomain(domain1)wehavebasestation,HAandmobilenode,MH,inthesamesinglecluster.
Theiraddressesare1.0.0and1.0.1respectively.Forthesecondwirelessdomain(domain2)wehaveabase
station,FAwithanaddressof2.0.0.Howeverinthecourseofthesimulation,theMHwillmoveintothedomain
ofFAandweshallseehowpktsoriginatingfromawireddomainanddestinedtoMHwillreachitasaresultof
theMobileIPprotocol.
Wirednodeswillbecreatedasearlier.Howeverinplaceofasinglebasestationnode,aHAandFAwillbe
created.NoteherethattoturnthemobileIPflagonwehaveconfigurethenodestructureaccordinglyusing
optionmobileIPON.
#ConfigureforForeignAgentandHomeAgentnodes
$ns_nodeconfigmobileIPON\
adhocRouting$opt(adhocRouting)\
llType$opt(ll)\
macType$opt(mac)\
ifqType$opt(ifq)\
ifqLen$opt(ifqlen)\
antType$opt(ant)\
propType$opt(prop)\
phyType$opt(netif)\
channelType$opt(chan)\

topoInstance$topo\
wiredRoutingON\

agentTraceON\
routerTraceOFF\
macTraceOFF
#CreateHAandFA
setHA[$ns_node1.0.0]
setFA[$ns_node2.0.0]
$HArandommotion0
$FArandommotion0
#providesomecoord(fixed)tothesebasestationnodes.
$HAsetX_1.000000000000
$HAsetY_2.000000000000
$HAsetZ_0.000000000000
$FAsetX_650.000000000000
$FAsetY_600.000000000000
$FAsetZ_0.000000000000

Nextcreatethemobilehostasfollows.NoteasbeforewehavetoturnofftheoptionwiredRouting(usedfor
creationofbasestationnodes)beforecreatingmobilenodes.AlsotheHAissetupasthehomeagentforthe
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

7/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

mobilehost.TheMHhasanaddresscalledthecareofaddress(COA).Basedontheregistration/beacons
exchangedbetweentheMHandthebasestationnode(ofthedomaintheMHiscurrentlyin),thebasestation's
addressisassignedastheMH'sCOA.Thusinthissimulation,addressofHAisassignedinitiallyastheCOAof
MH.AsMHmovesintothedomainofFA,itsCOAchangestothatoftheFA.FordetailsonMobileIP
implementationinns,readsection15.2.2of(inwirelessnetworkingchapter)nsdocumentation.Alsoseefiles
mip.{cc,h},mipreg.{cc,h},tcl/lib/{nsmip.tcl,nswirelessmip.tcl}.
#configureformobilehost
$ns_nodeconfigwiredRoutingOFF
#createmobilehostthatwouldbemovingbetweenHAandFA.
#noteaddressofMHindicatesitsinthesamedomainasHA.
setMH[$ns_node1.0.1]
setnode_(0)$MH
setHAaddress[AddrParamssethieraddr[$HAnodeaddr]]
[$MHsetregagent_]sethome_agent_$HAaddress
#movementoftheMH
$MHsetZ_0.000000000000
$MHsetY_2.000000000000
$MHsetX_2.000000000000
#MHstartstomovetowardsFA(640,610)ataspeedof20m/s
$ns_at100.000000000000"$MHsetdest640.000000000000610.000000000000
20.000000000000"
#andgoesbacktoHA(2,2)ataspeedof20m/s
$ns_at200.000000000000"$MHsetdest2.0000000000002.000000000000
20.000000000000"

CreatelinksbetweenWirednodesandHA/FAandsetupTCPconnection:
#createlinksbetweenwiredandBaseStationnodes
$ns_duplexlink$W(0)$W(1)5Mb2msDropTail
$ns_duplexlink$W(1)$HA5Mb2msDropTail
$ns_duplexlink$W(1)$FA5Mb2msDropTail
$ns_duplexlinkop$W(0)$W(1)orientdown
$ns_duplexlinkop$W(1)$HAorientleftdown
$ns_duplexlinkop$W(1)$FAorientrightdown
#setupTCPconnectionsbetweenawirednodeandtheMobileHost
settcp1[newAgent/TCP]
$tcp1setclass_2
setsink1[newAgent/TCPSink]
$ns_attachagent$W(0)$tcp1
$ns_attachagent$MH$sink1
$ns_connect$tcp1$sink1
setftp1[newApplication/FTP]
$ftp1attachagent$tcp1
$ns_at$opt(ftp1start)"$ftp1start"

Therestofthescriptremainsunchanged(i.etellmobilenodeswhenthesimulationstops).Saveandrunthe
script.Clickhereforacopyofthefilewireless3.tcl.
Whilerunningthescript,youmayseewarningslike"warning:Routetobase_stnnotknown:droppingpkt".
ThismeansthatastheMHmovesfromthedomainofonebasestationintodomainofanothertheremaybe
interimperiodswhenitisnotregisteredtoanybasestationandthusdoesnotknowwhomtoforwardpkts
destinedoutsideitsdomain.Oncompletionoftherun,nsandnamtraceoutputfiles"wireless3out.tr"and
"wireless3out.nam"arecreated.Thenamoutputshowsthemovementofthemobilehostandtrafficflowinthe
wireddomain.Thenstraceoutputshowstracesforboththewirednodesaswellasthewirelessdomain.Wesee
http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

8/9

6/26/2016

TutorialfortheUCB/LBNL/VINTNetworkSimulator"ns"

routinebeaconbroadcast/solicitationssentoutbyHA/FAandtheMH.InitiallytheTCPpktsarehandeddown
toMHdirectlybyitsHA.AsMHmovesawayfromHAdomainintothedomainoftheFA,wefindthepkts
destinedforMH,beingencapsulatedandforwardedtotheFAwhichthenstripsoffordecapsulatesthepktand
handsitovertotheMH.
[Previoussection][Nextsection][Backtotheindex]
VINT
nsusers@isi.edu

http://www.isi.edu/nsnam/ns/tutorial/nsscript6.html

9/9

You might also like