Kalau yang ini contoh script jaringan wired + wireless, di buat saat pelatihan network simulator tahun 2009 silam.
# Copyright (c) 2009 Regents of the research.conf ’06
# Switching Technique Laboratory
# wireless.tcl
# simulation of a wired+wireless topology running with mobile nodes
# ======================================================================
# Define options
# ======================================================================
set opt(chan) Channel/WirelessChannel ;# channel type
set opt(prop) Propagation/TwoRayGround ;# radio-propagation model
set opt(netif) Phy/WirelessPhy ;# network interface type
set opt(mac) Mac/802_11 ;# MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type
set opt(ll) LL ;# link layer type
set opt(ant) Antenna/OmniAntenna ;# antenna model
set opt(ifqlen) 50 ;# max packet in ifq
set opt(nn) 4 ;# number of mobilenodes
set opt(adhocRouting) DSDV ;# routing protocol
set opt(cp) “” ;# cp file not used
set opt(sc) “” ;# node movement file.
set opt(x) 1000 ;# x coordinate of topology
set opt(y) 1000 ;# y coordinate of topology
set opt(seed) 0.0 ;# random seed
set opt(stop) 250 ;# time to stop simulation
set opt(ftp1-start) 100.0
set num_wired_nodes 2
set num_bs_nodes 2 ;# number of base nodes
# ======================================================================
# check for boundary parameters and random seed
if { $opt(x) == 0 || $opt(y) == 0 } {
puts “No X-Y boundary values given for wireless topology\n”
}
if {$opt(seed) > 0} {
puts “Seeding Random number generator with $opt(seed)\n”
ns-random $opt(seed)
}
# create simulator instance
set ns_ [new Simulator]
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 3 ;# number of domains
lappend cluster_num 1 1 1 ;# number of clusters in each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 2 3 3 ;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# of each domain
set tracefd [open wireless.tr w]
set namtrace [open wireless.nam w]
$ns_ use-newtrace
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
# Create topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $opt(x) $opt(y)
# create God
# 2 for AP1 dan AP2
create-god [expr $opt(nn) + $num_bs_nodes]
#create wired nodes
set temp {0.0.0 0.0.1} ;# hierarchical addresses
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns_ node [lindex $temp $i]]
}
# Configure for AP1 &AP2
$ns_ node-config -mobileIP OFF \
-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 \
-wiredRouting ON \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF
# Create AP1 and AP2
set AP1 [$ns_ node 1.0.0]
set AP2 [$ns_ node 2.0.0]
$AP1 random-motion 0
$AP2 random-motion 0
$AP1 color blue
$AP2 color red
$AP1 label “AP kharis”
$AP2 label “AP dodyst”
# Position (fixed) for base-station nodes (AP1 & AP2).
$AP1 set X_ 600.000000000000
$AP1 set Y_ 600.000000000000
$AP1 set Z_ 0.000000000000
$AP2 set X_ 650.000000000000
$AP2 set Y_ 600.000000000000
$AP2 set Z_ 0.000000000000
# create a mobilenode that would be moving between AP1 and AP2.
# note address of revient indicates its in the same domain as AP1.
$ns_ node-config -wiredRouting OFF
set revient [$ns_ node 1.0.1]
set node_(0) $revient
$node_(0) base-station [AddrParams addr2id [$AP1 node-addr]]
$revient label “revient”
#baru topek
set topek [$ns_ node 1.0.2]
set node_(1) $topek
$node_(1) base-station [AddrParams addr2id [$AP1 node-addr]]
$topek label “topek”
#baru satya
set satya [$ns_ node 2.0.1]
set node_(2) $satya
$node_(2) base-station [AddrParams addr2id [$AP2 node-addr]]
$satya label “satya”
#baru arief
set arief [$ns_ node 2.0.2]
set node_(3) $arief
$node_(3) base-station [AddrParams addr2id [$AP2 node-addr]]
$arief label “arief”
#letak topek
$topek set Z_ 0.000000000000
$topek set Y_ 500.000000000000
$topek set X_ 400.000000000000
# letak revient
$revient set Z_ 0.000000000000
$revient set Y_ 600.000000000000
$revient set X_ 400.000000000000
#letak satya
$satya set Z_ 0.000000000000
$satya set Y_ 700.000000000000
$satya set X_ 400.000000000000
#letak arief
$arief set Z_ 0.000000000000
$arief set Y_ 800.000000000000
$arief set X_ 400.000000000000
# goes back to HA
$ns_ at 50.000000000000 “$revient setdest 600.000000000000 700.000000000000 20.000000000000″
$ns_ at 50.000000000000 “$topek setdest 500.000000000000 700.000000000000 20.000000000000″
$ns_ at 50.000000000000 “$satya setdest 700.000000000000 700.000000000000 20.000000000000″
$ns_ at 50.000000000000 “$arief setdest 800.000000000000 700.000000000000 20.000000000000″
$ns_ at 100.000000000000 “$topek setdest 990.000000000000 500.000000000000 20.000000000000″
$ns_ at 100.000000000000 “$revient setdest 990.000000000000 600.000000000000 20.000000000000″
$ns_ at 100.000000000000 “$satya setdest 990.000000000000 700.000000000000 20.000000000000″
$ns_ at 100.000000000000 “$arief setdest 990.000000000000 800.000000000000 20.000000000000″
$ns_ at 150.000000000000 “$topek setdest 500.000000000000 500.000000000000 20.000000000000″
$ns_ at 150.000000000000 “$revient setdest 600.000000000000 500.000000000000 20.000000000000″
$ns_ at 150.000000000000 “$satya setdest 700.000000000000 500.000000000000 20.000000000000″
$ns_ at 150.000000000000 “$arief setdest 800.000000000000 500.000000000000 20.000000000000″
$ns_ at 200.000000000000 “$topek setdest 400.000000000000 500.000000000000 20.000000000000″
$ns_ at 200.000000000000 “$revient setdest 400.000000000000 600.000000000000 20.000000000000″
$ns_ at 200.000000000000 “$satya setdest 400.000000000000 700.000000000000 20.000000000000″
$ns_ at 200.000000000000 “$arief setdest 400.000000000000 800.000000000000 20.000000000000″
# create links between wired and BaseStation nodes
$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DRR
$ns_ duplex-link $W(1) $AP1 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $AP2 5Mb 2ms DropTail
$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $AP1 orient left-down
$ns_ duplex-link-op $W(1) $AP2 orient right-down
# setup TCP connections between a wired node and the MobileHost
#warna-warna
$ns_ color 0 blue
$ns_ color 1 red
$ns_ color 2 green
$ns_ color 3 magenta
$W(0) label “Server FTP”
$W(1) label “Router”
set tcp1 [new Agent/TCP]
$tcp1 set class_ 0
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp1
$ns_ attach-agent $revient $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at 3.0 “$ftp1 start”
set tcp2 [new Agent/TCP]
$tcp2 set class_ 1
set sink2 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp2
$ns_ attach-agent $topek $sink2
$ns_ connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns_ at 3.0 “$ftp2 start”
set tcp3 [new Agent/TCP]
$tcp3 set class_ 2
set sink3 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp3
$ns_ attach-agent $arief $sink3
$ns_ connect $tcp3 $sink3
set ftp3 [new Application/FTP]
$ftp3 attach-agent $tcp3
$ns_ at 3.0 “$ftp3 start”
set tcp4 [new Agent/TCP]
$tcp4 set class_ 3
set sink4 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp4
$ns_ attach-agent $satya $sink4
$ns_ connect $tcp4 $sink4
set ftp4 [new Application/FTP]
$ftp4 attach-agent $tcp4
#$ns_ at $opt(ftp2-start) “$ftp2 start”
$ns_ at 3.0 “$ftp4 start”
# source connection-pattern and node-movement scripts
if { $opt(cp) == “” } {
puts “*** NOTE: no connection pattern specified.”
set opt(cp) “none”
} else {
puts “Loading connection pattern…”
source $opt(cp)
}
if { $opt(sc) == “” } {
puts “*** NOTE: no scenario file specified.”
set opt(sc) “none”
} else {
puts “Loading scenario file…”
source $opt(sc)
puts “Load complete…”
}
# Define initial node position in nam
for {set i 0} {$i < $opt(nn)} {incr i} {
# 20 defines the node size in nam, must adjust it according to your
# scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 20
}
# Tell all nodes when the siulation ends
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).0 “$node_($i) reset”;
}
$ns_ at $opt(stop).0 “$AP1 reset”;
$ns_ at $opt(stop).0 “$AP2 reset”;
$ns_ at $opt(stop).0002 “puts \”NS EXITING…\” ; $ns_ halt”
$ns_ at $opt(stop).0001 “stop”
proc stop {} {
global ns_ tracefd namtrace
close $tracefd
close $namtrace
exec nam wireless.nam &
exec awk -f delay.awk wireless.tr &
exec awk -f packetloss.awk wireless.tr &
exec awk -f throughput.awk wireless.tr &
exec awk -f jitter.awk wireless.tr &
exec xgraph delay.tr -geometry 400×800 &
exit 0
}
# some useful headers for tracefile
puts $tracefd “M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \
$opt(adhocRouting)”
puts $tracefd “M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)”
puts $tracefd “M 0.0 prop $opt(prop) ant $opt(ant)”
puts “Starting Simulation…”
$ns_ run
#=======================================================================
Animasi yang keluar:

Gambar animasi jaringan wired+wireless