mini ns2

download mini ns2

of 8

Transcript of mini ns2

  • 8/16/2019 mini ns2

    1/8

    Sample Projects in ns2 withsource code for replica nodeattack:set conversation_holder 3

    set replica(0) 1

    set replica(1) 2

    set replica(2) 4

    for { set k 0 } { $k < 3} { incr k } {

    set udp1 [ne !"ent#%&' $ns_ attacha"ent $node_($replica($k))

    $udp1

    set cr1 [ne !pplication#*raffic#+,-' $cr1 set packet.i/e_ 12

    $cr1 set interval_ 0

    $cr1 attacha"ent $udp1

    set null1 [ne !"ent#ull' $ns_ attacha"ent

    $node_($conversation_holder) $null1

    $ns_ connect $udp1 $null1

    $ns_ at [epr $no ' $cr1 start5

    $ns_ at [epr $no 6 10' $cr1 stop5

    }

    $ns_ at $no $ns_ traceannotate 75!ttacker &retends like 8ultiple

    vehicle and send 8essa"e to conversation holder755

    Benefits of using computer networks:

  • 8/16/2019 mini ns2

    2/8

    • 9t enales 8ultiple users to share a sin"le hardare device like aprinter or scanner

    • :ake infor8ation easier to access and 8aintain a8on" netorkusers

    •  !llo for sharin" of softare or operatin" pro"ra8s on re8otes;ste8s

    • acilitate co88unication via e8ail= video conferencin"= instant8essa"in"

    • >nale file sharin" across the netork

    Characteristics of computer network:

    • ?et co8puters of the netork use the 8achines availale overthe netork

    • +reate files and store the8 in one co8puter= access those filesfro8 the other co8puters connected over the netork

    • .hare resources fro8= one co8puter to anotherSample code for computer networks:

    *his is the tcl code for @os ased routin" protocolA "et dela; esti8atestclevalf (Bs "etdela;esti8ates5= na8e())C 

    A initiali/e routin"routin"_init(this)C Aco8pute @os routesA 9D:> do e need to do this no e" hen onde8and co8putationroutin"_co8puteEF.-outes()C Aset ?._read;_ 9D:> dont kno h; its heretclevalf(Bs set ?._read;5= na8e())C

    charG token H strtok(tclresult()= 5 7t7n5)Cif (token HH ??)?._read;_ H 0Celse?._read;_ H atoi(token)C ## u""; 

  • 8/16/2019 mini ns2

    3/8

     Types of P2P architecture

    • nstructured &2&o +entrali/ed &2&o &ure &2&o I;rid &2&• .tructured &2&o %I*asedo I;rid &2&

    Sample code for p2p

    network – NS2Simulation Projectcode:

    ro8 this code e "ot the detail of ho to create seed= create trackerand unifor8 start offset for peers

    A create tracker (&ara8etersJ ile .i/e [,'= +hunk .i/e [,')set "o [ne ,it*orrent*racker#lolevel $._ $._+' $"o tracefile$p2ptraceA unifor8 start offset for peersset t_offset_rn" [ne -K' set t_offset [ne-ando8Lariale#nifor8' $t_offset set 8in_ 0$t_offset set 8a_ [,it*orrent!pp set chokin"_interval' $t_offset usern" $t_offset_rn"

    A +reate .eedsfor {set i 0} {$i < $_&} {

  • 8/16/2019 mini ns2

    4/8

    incr i} {

    Platforms requiredto NS2 SimulationSource Code:

    ni and ni like s;ste8s• ?inu (se edora or untu versions)• ree ,.%• .unF.#.olaris• Mindos N#NO#*#2000#D&

    Sample NS2 simulationSource code:

    Tcl programming basics:

    • %efinin" the a"ents and their applications• 9nitiali/ation and ter8ination aspects of netork si8ulator• etork !ni8ator(!:)• %efinin" the netork nodes=links=@ueues and topolo"; as ell

    Sample ns2 simulation source code:

    .a8ple code for handlin" as a ottleneck link (link eteen node 1and node 2)= a differentiated droppin" sche8e

    $ns duplelink $n(1) $n(2) P00Q 28s ->%#8;-9F$ns duplelinkop $n(1) $n(2) orient ri"htEueue#->%#8;-9F set "entle_ trueEueue#->%#8;-9F set thresh_ 1Eueue#->%#8;-9F set 8athresh_ 1

  • 8/16/2019 mini ns2

    5/8

    Eueue#->%#8;-9F set ei"ht_ 10Eueue#->%#8;-9F set setit_ falseset red@ [[$ns link $n(1) $n(2)' @ueue' $red@ set @_ei"ht_ [epr10#2' $red@ set linter8_ [epr 40' $ns @ueueli8it $n(1) $n(0) 30

    Categories of intrusion detection system:

    • etork ased s;ste8 Ls hostased s;ste8• :isuse detection Ls ano8al; detection• &assive s;ste8 Ls reactive s;ste8

     

    Sample code for AODroutin! protocol in NS2:*his is code for !F%L link failure condition checkin"void

     !F%LJJhandle_link_failure(nsaddr_t id) {

     aodv_rt_entr; Grt= GrtnC&acket Grerr H &acketJJalloc()Cstruct hdr_aodv_error Gre H I%-_!F%L_>--F-(rerr)CreR%est+ount H 0Cfor(rt H rtalehead()C rtC rt H rtn) {## for each rt entr;rtn H rtRrt_linkle_netCif ((rtRrt_hops SH 999*T2) UU (rtRrt_nethop HH id) ) {assert (rtRrt_fla"s HH -*_&)Cassert((rtRrt_se@noB2) HH 0)CrtRrt_se@no66CreRunreachale_dst[reR%est+ount' H rtRrt_dstCreRunreachale_dst_se@no[reR%est+ount' H rtRrt_se@noCAifdef %>,K

  • 8/16/2019 mini ns2

    6/8

    fprintf(stderr= Bs(Bf)J Bd7t(Bd7tBu7tBd)7n5= __+*9F__=+-->*_*9:>=inde= reRunreachale_dst[reR%est+ount'=reRunreachale_dst_se@no[reR%est+ount'= rtRrt_nethop)C

    Aendif ## %>,KreR%est+ount 6H 1Crt_don(rt)C}

    Properties of AO!:• 9t utili/es routin" tales to store routin" infor8ation 9t 8aintains

    oth unicast and 8ulticast router tale• -outer tale 8aintain infor8ation of destination address= net

    hop address= destination se@uence nu8er and life ti8e of the node• or each destination= a node should 8aintain a list of precursor

    nodes to route throu"h the8• ?ifeti8e updated ever; ti8e the route is used

    Types of computer networks:•

    • >nterprise private netork• +a8pus netorks• ,ackone netorks• Kloal area netorks• :etropolitan area netorks• &ersonal area netorks• Io8e area netorks• Milde area netork• ?ocal area netork

    Sample code for computer network projects:

    *his co8puter netork proVects 8ain ai8 is to achieve Eo. in routin"Ainclude @ospfh5Ainclude

  • 8/16/2019 mini ns2

    7/8

    na8espace EF.& {## a "loal variale?s:essa"e+enter ?s:essa"e+enterJJ8s"ctr_Cint EF.-outin"JJ8s".i/es[?._:>..!K>_*T&>.'C

    static class init-outin" {pulicJinit-outin"() {EF.-outin"JJ8s".i/es[?._:.K_?.!' H ?._?.!_:>..!K>_.9W>CEF.-outin"JJ8s".i/es[?._:.K_*&:' H?._*F&F_:>..!K>_.9W>CEF.-outin"JJ8s".i/es[?._:.K_?.!!+Q' H?._!+Q_:>..!K>_.9W>C

    EF.-outin"JJ8s".i/es[?._:.K_*&:!+Q' H?._!+Q_:>..!K>_.9W>C}} @os-outin"9nitiali/erC

    Steps in"ol"ed in DS#routin! Networkin!Projects:

    -oute discover;• -oute 8aintenance

    "eatures of S#:

    • +achin" overheard routin" infor8ation•  !uto8atic route shortenin"• Eueued packets destined over a roken link• -oute re@uest hop li8its

  • 8/16/2019 mini ns2

    8/8

    • &acket salva"in"• 9ncreased spreadin" of route error 8essa"e• -epl;in" to route re@uest usin" cached routes

     

    Sample code for DSR networking projects:int -oute+acheJJco88and(int ar"c= const charGconstG ar"v){if(ar"c HH 2){if(strcasec8p(ar"v[1'= startdsr5) HH 0){Aifdef %.-_+!+I>_.*!*.

    8hstart()CAendif return *+?_FQC}}else if(ar"c HH 3){if (strcasec8p(ar"v[1'= ipaddr5) HH 0) {net_id H 9%(atoi(ar"v[2')= JJ9&)C

    return *+?_FQC}else if(strcasec8p(ar"v[1'= 8acaddr5) HH 0) {:!+_id H 9%(atoi(ar"v[2')= JJ:!+)Creturn *+?_FQC}