'Network'에 해당되는 글 204건
- 2009.01.18 http://web.syr.edu/~dchen02/FAQ.txt [ns2] 802.11b
- 2009.01.18 Tutorial for the Network Simulator "ns" : X. Creating Wired-cum-Wireles and MobileIP Simulations in ns.
- 2009.01.17 정답이 없는 node-config
- 2009.01.17 [ns2] b-50 CWmin-CWmax 8,16,32~16,32,64,128,1024 802.11b between wired and wireless network
- 2009.01.17 NS-2.28 with DYMO ad-hoc routing protocol support
- 2009.01.17 First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄-
- 2009.01.17 ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING
- 2009.01.17 ns2 새로운 어플리케이션 추가LionHeart
- 2009.01.17 AP의 설정
- 2009.01.17 mac의 transmit
내용을 보시려면 비밀번호를 입력하세요.
Tutorial for the Network Simulator "ns" : X. Creating Wired-cum-Wireles and MobileIP Simulations in ns.
| 2009. 1. 18. 02:48내용을 보시려면 비밀번호를 입력하세요.
-adhocRouting AODV \bs
-llType LL \bs
-macType Mac/802_11 \bs
-ifqType Queue/DropTail/PriQueue \bs
-ifqLen 50 \bs
-antType Antenna/OmniAntenna \bs
-propType Propagation/TwoRayGround \bs
-phyType Phy/WirelessPhy \bs
-topologyInstance \$topo \bs
-channel Channel/WirelessChannel \bs
-agentTrace ON \bs
-routerTrace ON \bs
-macTrace OFF \bs
-movementTrace OFF
# DSDV DSR TORA AODV
$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/$qm \
-ifqLen $buf(wlan_complex) \
-propType "Propagation/TwoRayGround" \
-antType "Antenna/OmniAntenna" \
-phyType "Phy/WirelessPhy" \
-wiredRouting ON \
-channel [new "Channel/WirelessChannel"] \
-agentTrace ON \
-routerTrace OFF \
-topoInstance $topo \
-macTrace OFF \
-movementTrace OFF
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $val(chan) \
-topoInstance $topo \
-agentTrace OFF \
-routerTrace OFF \
-macTrace ON \
-movementTrace OFF
'Network > Ns2_source' 카테고리의 다른 글
[ns2] b-50 CWmin-CWmax 8,16,32~16,32,64,128,1024 802.11b between wired and wireless network
| Network/Ns2_source 2009. 1. 17. 17:46'Network > Ns2_source' 카테고리의 다른 글
Tutorial for the Network Simulator "ns" : X. Creating Wired-cum-Wireles and MobileIP Simulations in ns. (0) | 2009.01.18 |
---|---|
정답이 없는 node-config (0) | 2009.01.17 |
NS-2.28 with DYMO ad-hoc routing protocol support (0) | 2009.01.17 |
First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄- (0) | 2009.01.17 |
ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING (0) | 2009.01.17 |
This HOWTO covers installation on Ubuntu Linux.
[소스 다운 받기]
$ tar xzf ns-allinone-2.28.tar.gz
[GDB debugger를 위한 수정]
1. install 파일 수정
$ vim install
1.1 408번 줄에 더하기 --enable-synbols
./configure --enable-gcc --disable-shared --prefix=$CUR_PATH || die "tcl8.3.2 configuration failed! Exiting ..." becomes,
./configure --enable-symbols --enable-gcc --disable-shared --prefix=$CUR_PATH || die "tcl8.3.2 configuration failed! Exiting ..."
1.2 498번 줄에 더하기 –enable-debug
./configure || die "tclcl-$TCLCLVER configuration failed! Exiting ..." becomes,
./configure --enable-debug || die "tclcl-$TCLCLVER configuration failed! Exiting ..."
2. ns의 Makefile.in수정하기
$ vim Makefile.in
82번째 줄에 더하기 -g
3. 필요 패키지 설치하기
3.1 X11/Intrinsic.h 는 otcl1-9 설치시 필요하므로
3.2 /usr/X11R6/include/X11/Xmu/WinUtil.h는 nam-1.1에 필요함
확인 : /usr/include/X11/Xmu/WinUtil.h 에 파일 생성 안되면 아래 링크 이용 http://www.koders.com/cpp/fid8242d90801 ··· 7d0.aspx
4. xgraph Makefile수정하기
$ ./configure
$ vim Makefile
4.1 85번째 줄에 더하기 -L/usr/X11R6/lib
xgraph_LDADD = $(ADDITIONAL_LIBS) $(X_LIBS) $(X_PRE_LIBS) $(X_EXTRA_LIBS) -lX11 -lm becomes,
xgraph_LDADD = $(ADDITIONAL_LIBS) $(X_LIBS) $(X_PRE_LIBS) $(X_EXTRA_LIBS) -L/usr/X11R6/lib -lX11 -lm
5. gt-itm 은 sgb2ns에 필요함
5.1 sgb설치를 위한 apt수정
deb-src http://au.archive.ubuntu.com/ubuntu hoary main restricted deb http://au.archive.ubuntu.com/ubuntu hoary-updates main restricted deb-src http://au.archive.ubuntu.com/ubuntu hoary-updates main restricted deb http://au.archive.ubuntu.com/ubuntu hoary universe deb-src http://au.archive.ubuntu.com/ubuntu hoary universe deb http://security.ubuntu.com/ubuntu hoary-security main restricted deb-src http://security.ubuntu.com/ubuntu hoary-security main restricted deb http://security.ubuntu.com/ubuntu hoary-security universe deb-src http://security.ubuntu.com/ubuntu hoary-security universe deb http://archive.ubuntu.com/ubuntu hoary multiverse deb-src http://archive.ubuntu.com/ubuntu hoary multiverse deb http://archive.ubuntu.com/ubuntu hoary-backports main universe multiverse restricted
5.2 sgb 다운 받기
6. eval 파일 수정
$ vim eval.c
162번째 둘줄로 나누어져 있는 아래 내용을 한줄로 수정
7. gt-itm관련 작업
gt-itm 하부에 bin 디렉토리 없으면 생성
$ mkdir bin
$ cd ./gt-itm/src
$ make
8. gt-itm 와 sgb2ns 필요로 하는 라이브러리 링크 하기
$ mkdir lib
$ ln -s /usr/lib/libgb.a /root/ns-allinone-2.28/gt-itm/lib
9. 발생 가능 에러 해결
9.1 tcl 컴파일 에러
에러 메시지:syntax error near unexpected token `)' ./configure: line 7068: ` OSF*)'
해결 : http://mailman.isi.edu/pipermail/ns-users/2006-September/057322.html
- apt-get install autoconf
- rm configure (이전 설정파일 삭제)
./autoconf
./configure
9.2 make: *** [queue/cbq.o] ## 에러 해결 하기
88 #define POWEROFTWO 16
89
90 class CBQueue; <-- 추가된 부분
91
92 class CBQClass : public Connector
46 LINK_DN = 0x0002, // downstream
47 LINK_UN = 0x0004, // undirected
48 };
49
50 class toraAgent; <-- 추가된 부분
51
52 class TORANeighbor {
53 friend class TORADest;
54 friend class toraAgent;
103 typedef list NeighborList;
104 typedef list HashList;
105 typedef list BlackList;
106
107 class DiffRoutingAgent; <-- 추가된 부분
108
109 class DiffusionCoreAgent {
110 public:
111 #ifdef NS_DIFFUSION
112 friend class DiffRoutingAgent;
[ * dymo 기능 추가 하기 ]
-소스 다운 받기 ( http://sourceforge.net/projects/dymoum/ )
cd /root/ns-allinone-2.28/ns-2.28
wget http://jaist.dl.sourceforge.net/sourcef ··· -0.3.tgz
tar zvfx dymoum-0.3.tgz
-링크 걸기
cd /root/ns-allinone-2.28/ns-2.28
ln -s ./dymoum-0.3 ./dymoum
-패치 하기
patch -p1 < dymoum/dymoum_ns-2.28_v0.1.patch
If you haven't installed ns2 yet, then do the following:
$ cd ..
$ ./install
On the other hand, if you are installing DYMOUM on a running installation of ns2:
$ ./configure
$ make distclean
$ ./configure
$ make
10. ns컴파일 하기
$ ./install &> compile.out
9.1 install 스크립트로 한번데 되면 좋은데 ...안될경우 각 패키지 별로 설치하며 확인하기
11. Environmental variables.
#!/bin/sh
# LD_LIBRARY_PATH OTCL_LIB=/home/lucsp/ns-allinone-2.28/otcl-1.9 NS2_LIB=/home/lucsp/ns-allinone-2.28/lib X11_LIB=/usr/X11R6/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:/usr/local/lib
# TCL_LIBRARY export TCL_LIBRARY=/home/lucsp/ns-allinone-2.28/tcl8.4.5/library:/usr/lib
# PATH XGRAPH=/home/lucsp/ns-allinone-2.28/bin:/home/lucsp/ns-allinone-2.28/tcl8.4.5/unix:/home/lucsp/ns-allinone-2.28/tk8.4.5/unix
PATH=$PATH:$XGRAPH:/home/lucsp/ns-allinone-2.28/ns-2.28/
OTCL_LIB=/root/ns-allinone-2.28/otcl-1.9 NS2_LIB=/root/ns-allinone-2.28/lib X11_LIB=/usr/X11R6/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:/usr/local/lib # TCL_LIBRARY export TCL_LIBRARY=/root/ns-allinone-2.28/tcl8.4.5/library:/usr/lib # PATH XGRAPH=/root/ns-allinone-2.28/bin:/root/ns-allinone-2.28/tcl8.4.5/unix:/root/ns-allinone-2.28/tk8.4.5/unix export PATH=$PATH:$XGRAPH:/root/ns-allinone-2.28/bin:/root/ns-allinone-2.28/tcl8.4.5/unix:/root/ns-allinone-2.28/tk8.4.5/unix
gcc 에러 보고 되고 있음 : http://blog.naver.com/etenallove/100016553174
[패치방법] /root/ns-allinone-2.28 patch -p1 < ../ns-allinone-2.28/ns228-gcc40.patch
작성 : 2006.6.07 by 임헌정
http://www.4ellene.net
참고http://www.ics.mq.edu.au/~phillipl/documents/NS-2.28AllInOne_HOWTO.html
출처: http://www.4ellene.net/tt/category/Network
'Network > Ns2_source' 카테고리의 다른 글
정답이 없는 node-config (0) | 2009.01.17 |
---|---|
[ns2] b-50 CWmin-CWmax 8,16,32~16,32,64,128,1024 802.11b between wired and wireless network (0) | 2009.01.17 |
First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄- (0) | 2009.01.17 |
ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING (0) | 2009.01.17 |
ns2 새로운 어플리케이션 추가LionHeart (0) | 2009.01.17 |
First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄-
| Network/Ns2_source 2009. 1. 17. 17:42# Test file for wimax - Based on the sample script written by Rouil
# Simulation time - 25 seconds
# Topology - 1100 x 1100
#check input parameters
if {$argc != 0} {
puts ""
puts "Wrong Number of Arguments! No arguments in this topology"
puts ""
exit (1)
}
# set global variables
set nb_mn 1 ;# max number of mobile node
set packet_size 1500 ;# packet size in bytes at CBR applications
set output_dir .
set gap_size 1 ;#compute gap size between packets
puts "gap size=$gap_size"
set traffic_start 100
set traffic_stop 200
set simulation_stop 210
#define debug values
Mac/802_16 set debug_ 1
Mac/802_16 set rtg_ 20
Mac/802_16 set ttg_ 20
Mac/802_16 set frame_duration_ 0.004
Mac/802_16 set client_timeout_ 110 ;#to avoid BS disconnecting the SS since the traffic starts a 100s
Phy/WirelessPhy/OFDM set g_ 0.25
#define coverage area for base station: 20m coverage
Phy/WirelessPhy set Pt_ 0.025
#Phy/WirelessPhy set freq_ 2412e+6
#Phy/WirelessPhy set RXThresh_ 2.90781e-09
Phy/WirelessPhy set RXThresh_ 2.025e-12 ;#500m radius
Phy/WirelessPhy set CSThresh_ [expr 0.9*[Phy/WirelessPhy set RXThresh_]]
# Parameter for wireless nodes
set opt(chan) Channel/WirelessChannel ;# channel type
set opt(prop) Propagation/TwoRayGround ;# radio-propagation model
set opt(netif) Phy/WirelessPhy/OFDM ;# network interface type
set opt(mac) Mac/802_16/BS ;# 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(adhocRouting) DSDV ;# routing protocol
set opt(x) 1100 ;# X dimension of the topography
set opt(y) 1100 ;# Y dimension of the topography
Mac/802_11 set basicRate_ 11Mb
Mac/802_11 set dataRate_ 11Mb
Mac/802_11 set bandwidth_ 11Mb
#defines function for flushing and closing files
proc finish {} {
global ns tf output_dir nb_mn nf
$ns flush-trace
close $tf
close $nf
exec nam wimax1.nam &
exit 0
}
#create the simulator
set ns [new Simulator]
set nf [open wimax1.nam w]
$ns namtrace-all $nf
$ns use-newtrace
#create the topography
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
puts "Topology created"
#open file for trace
set tf [open $output_dir/out.res w]
$ns trace-all $tf
puts "Output file configured"
# set up for hierarchical routing (needed for routing over a basestation)
puts "start hierarchical addressing"
$ns node-config -addressType hierarchical
AddrParams set domain_num_ 2 ;# domain number
lappend cluster_num 1 1 ;# cluster number for each domain
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 [expr ($nb_mn+1)] ;# number of nodes for each cluster (1 for sink and one for mobile nodes + base station
AddrParams set nodes_num_ $eilastlevel
puts "Configuration of hierarchical addressing done"
# Create God
create-god [expr ($nb_mn + 2)] ;# nb_mn + 2 (base station and sink node)
puts "God node created"
#creates the sink node in first addressing space.
set sinkNode [$ns node 0.0.0]
#provide some co-ord (fixed) to base station node
$sinkNode set X_ 50.0
$sinkNode set Y_ 50.0
$sinkNode set Z_ 0.0
puts "sink node created"
#creates the Access Point (Base station)
$ns node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType Mac/802_16/BS \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF
puts "Configuration of base station"
set bstation [$ns node 1.0.0]
$bstation random-motion 0
puts "Base-Station node created"
#provide some co-ord (fixed) to base station node
$bstation set X_ 550.0
$bstation set Y_ 550.0
$bstation set Z_ 0.0
[$bstation set mac_(0)] set-channel 0
# creation of the mobile nodes
$ns node-config -macType Mac/802_16/SS \
-wiredRouting OFF \
-macTrace ON ;# Mobile nodes cannot do routing.
for {set i 0} {$i < $nb_mn} {incr i} {
set wl_node_($i) [$ns node 1.0.[expr $i + 1]] ;# create the node with given @.
$wl_node_($i) random-motion 0 ;# disable random motion
$wl_node_($i) base-station [AddrParams addr2id [$bstation node-addr]] ;#attach mn to basestation
#compute position of the node
$wl_node_($i) set X_ [expr 340.0]
$wl_node_($i) set Y_ 550.0
$wl_node_($i) set Z_ 0.0
$ns at 0 "$wl_node_($i) setdest 1060.0 550.0 1.0"
puts "wireless node $i created ..." ;# debug info
[$wl_node_($i) set mac_(0)] set-channel 0
[$wl_node_($i) set mac_(0)] set-diuc 7 ;# Change the node profile here (7=64QAM_3_4)
#create source traffic
#Create a UDP agent and attach it to node n0
set udp_($i) [new Agent/UDP]
$udp_($i) set packetSize_ 1500
$ns attach-agent $wl_node_($i) $udp_($i)
# Create a CBR traffic source and attach it to udp0
set cbr_($i) [new Application/Traffic/CBR]
$cbr_($i) set packetSize_ $packet_size
$cbr_($i) set interval_ $gap_size
$cbr_($i) attach-agent $udp_($i)
#create an sink into the sink node
# Create the Null agent to sink traffic
set null_($i) [new Agent/Null]
$ns attach-agent $sinkNode $null_($i)
# Attach the 2 agents
$ns connect $udp_($i) $null_($i)
}
# create the link between sink node and base station
$ns duplex-link $sinkNode $bstation 100Mb 1ms DropTail
# Traffic scenario: if all the nodes start talking at the same
# time, we may see packet loss due to bandwidth request collision
set diff 0.0
for {set i 0} {$i < $nb_mn} {incr i} {
$ns at [expr $traffic_start+$i*$diff] "$cbr_($i) start"
$ns at [expr $traffic_stop+$i*$diff] "$cbr_($i) stop"
}
$ns at $simulation_stop "finish"
#$ns at $simulation_stop "$ns halt"
# Run the simulation
puts "Running simulation for $nb_mn mobile nodes..."
$ns run
puts "Simulation done."
'Network > Ns2_source' 카테고리의 다른 글
[ns2] b-50 CWmin-CWmax 8,16,32~16,32,64,128,1024 802.11b between wired and wireless network (0) | 2009.01.17 |
---|---|
NS-2.28 with DYMO ad-hoc routing protocol support (0) | 2009.01.17 |
ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING (0) | 2009.01.17 |
ns2 새로운 어플리케이션 추가LionHeart (0) | 2009.01.17 |
AP의 설정 (0) | 2009.01.17 |
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
#open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#open the Trace file
set tf [open out.tr w]
set windowVsTime2 [open WindowVsTimeNReno w]
$ns trace-all $tf
#Define a 'finish' procedure
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam out.nam &
exit 0
}
#create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns at 0.1 "$n1 label \"CBR\""
$ns at 0.1 "$n0 label \"FTP\""
# 노드 구분을 하기 위한 표식
#create links beween the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.07Mb 20ms DropTail
$ns simplex-link $n3 $n2 0.07Mb 20ms DropTail
#set Queue size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10 #node n2 와 n3 사이의 큐 사이즈
#monitor the queue for link (n2-n3). (for NAM)
$ns simplex-link-op $n2 $n3 queuePos 0.5
#nam 에서 큐가 쌓이는 각도를 설정 할수 있습니다. 0~2 값
#set error model on link n3 to n2
set loss_module [new ErrorModel]
$loss_module set rate_ 0.2
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n2 $n3
#손실률을 설정합니다.
#setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#setup a udp connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packetSize_ 1000
$cbr set rate_ 0.01Mb
$cbr set random_ false
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 624.0 "$ftp stop"
$ns at 624.5 "$cbr stop"
#printing the window size
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file"
}
$ns at 1.1 "plotWindow $tcp $windowVsTime2"
#sample the bottlenect queue every 0.1 sec. store the trace in qm.out
set qmon [$ns monitor-queue $n2 $n3 [open qm.out w] 0.1];
#monitor-queue는 4개의 속성을 가집니다. 첫번째와 두번째는 시작과 끝 노드, 세번째는# output trace file, 네번째는 빈도를 의미 합니다.
[$ns link $n2 $n3] queue-sample-timeout; # [$ns link $n2 $n3] start-tracing
#detach tcp and sink agents (now really necessary)
$ns at 624.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
# 노드에 연결했던 tcp와 sink를 분리합니다.
$ns at 625.0 "finish"
$ns run
xls 자료
'Network > Ns2_source' 카테고리의 다른 글
NS-2.28 with DYMO ad-hoc routing protocol support (0) | 2009.01.17 |
---|---|
First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄- (0) | 2009.01.17 |
ns2 새로운 어플리케이션 추가LionHeart (0) | 2009.01.17 |
AP의 설정 (0) | 2009.01.17 |
mac의 transmit (0) | 2009.01.17 |
==================================================================================
[참고 : Marc Greis's Tutorial의 "VII. A new protocol fo ns" ]
본 내용은 위 사이트의 NS by Example의 내용을 학습하면서 정리한 것입니다.
여기서 정리된 내용으로 인해 발생 할 수 있는 문제에 대해서는 책임을 지지 않습니다.
USE AT YOUR OWN RISK!
==================================================================================
■ 본 예제는 Marc Greis's Tutorial의 ping 예제를 추가하는 부분을 정리한 것임. 최근 NS 버전에는
ping이 작성되어 있으므로 NS에 새로운 Application을 추가하는 방법을 학습하기 위한 예제로 이름만
수정하여 작성하였음.
■ 따라서 소스 자체에 대한 의미보다는 NS에 새로운 어플리케이션을 추가하는 방법적인면에 중점을 두고 이해 바람.
■ 실습을 위해 "ping" 이라는 명칭 대신 "hoya"라는 예제명으로 고쳐 작성.
■ OTcl과 C++ 링크에 대한 부분은 본 블로그의 [OTcl & C++ Linkage]를 참조하거나 기타 다른 NS2 관련 사이트를 참조.
■ hoya.h
========================================================================================
/* This is a ping example included in the ns2 */
/* I modified the ping.h and ping.cc as hoya */
#ifndef ns_hoya_h
#define ns_hoya_h
#include "agent.h"
#include "tclcl.h"
#include "packet.h"
#include "address.h"
#include "ip.h"
// "hoya"라는 새로운 프로토콜에 대한 패킷 헤더 구조를 정의
// ret | send_time 두 개의 필드로 "hoya"의 패킷 헤더를 정의
struct hdr_hoya {
// 0: sender -> the node, 1: sender <- the node
// 즉, 0이면 ping_request, 1이면 ping_reply가 될 것임
char ret;
// timestamp when this packet is sent.
// 나중에 RTT(round_trip_time)를 계산하기 위함
double send_time;
// Header access methods
// 패킷으로 부터 "hoya" 패킷에 접근하기 위한 방법을 정의하는 매크로
static int offset_; // required by PacketHeaderManager
inline static int& offset() { return offset_; }
inline static hdr_hoya* access(const Packet* p) {
return (hdr_hoya*) p->access(offset_);
}
};
// declare "HoyaAgent" as a subclass of "Agent"
// 나중에 이 클래스에 대한 객체를 생성하기 위해
// TclClass를 상속합든 HoyaClass를 정의해야함
class HoyaAgent : public Agent {
public:
HoyaAgent();
virtual int command(int argc, const char*const* argv);
virtual void recv(Packet*, Handler*);
};
#endif // ns_hoya_h
========================================================================================
■ hoya.cc
========================================================================================
/* This is a ping example included in the ns2 */
/* I modified the ping.h and ping.cc as hoya */
#include "hoya.h"
int hdr_hoya::offset_;
static class HoyaHeaderClass : public PacketHeaderClass {
public:
HoyaHeaderClass() : PacketHeaderClass("PacketHeader/Hoya", sizeof(hdr_hoya))
{
bind_offset(&hdr_hoya::offset_);
}
} class_hoyahdr;
// HoyaAgent 객체를 생성하기 위해 TclClass 상속받는 HoyaClass 생성
// C++ (HoyaAgent)와 Tcl (Agent/Hoya)를 링크하게 됨.
// NS 실행시 static vairable를 실행하여 HoyaClass의 인스턴스가 생성됨
// 따라서 Tcl에서 "new Agent/Hoya" 명령어를 통해 HoyaAgent::create()가 호출됨
static class HoyaClass : public TclClass {
public:
HoyaClass() : TclClass("Agent/Hoya") {}
TclObject* create(int, const char*const*)
{
return (new HoyaAgent());
}
} class_hoya;
// constructor : Tcl과 C++에서 접근되는 변수들을 binding
// '_'로 끝나는 변수들은 local object scope를 가짐
HoyaAgent::HoyaAgent() : Agent(PT_HOYA) // PT_HOYA : packet.h에 추가될 프로토콜 이름
{
// Tcl 인스턴스 변수 "packetSize_ " 와 C++ 변수 "size_" 바인딩
// bind()는 클래스의 생성자에 있어야 함
// Tcl 변수는 ns-default.tcl 에 등록하거나 시뮬레이션 스크립트에서 정의 가능.
bind("packetSize_", &size_);
}
// HoyaAgent 클래스에 대한 Tcl 명령어가 호출될 때 실행되는 메소드
int HoyaAgent::command(int argc, const char*const* argv)
{
if (argc == 2) {
// 즉,
// set hoyaagent [new Agent/Hoya]
// $hoyaagent start
// 명령어 실행에 대한 command() 의 처리 코드
if (strcmp(argv[1], "start") == 0) {
// Create a new packet
Packet* pkt = allocpkt();
// Access the Hoya header for the new packet:
hdr_hoya* hdr = hdr_hoya::access(pkt);
// Set the 'ret' field to 0, so the receiving node
// knows that it has to generate an echo packet
hdr->ret = 0;
// Store the current time in the 'send_time' field
hdr->send_time = Scheduler::instance().clock();
// Send the packet
send(pkt, 0);
// return TCL_OK, so the calling function knows that
// the command has been processed
return (TCL_OK);
}
}
// If the command hasn't been processed by HoyaAgent()::command,
// call the command() function for the base class
return (Agent::command(argc, argv));
}
// 수신 패킷에 대한 처리를 위한 코드를 작성
void HoyaAgent::recv(Packet* pkt, Handler*)
{
// Access the IP header for the received packet:
hdr_ip* hdrip = hdr_ip::access(pkt);
// Access the Hoya header for the received packet:
hdr_hoya* hdr = hdr_hoya::access(pkt);
// Is the 'ret' field = 0 (i.e. the receiving node is being hoyaed)?
if (hdr->ret == 0) {
// Send an 'echo'. First save the old packet's send_time
double stime = hdr->send_time;
// Discard the packet
Packet::free(pkt);
// Create a new packet
Packet* pktret = allocpkt();
// Access the Hoya header for the new packet:
hdr_hoya* hdrret = hdr_hoya::access(pktret);
// Set the 'ret' field to 1, so the receiver won't send
// another echo
hdrret->ret = 1;
// Set the send_time field to the correct value
hdrret->send_time = stime;
// Send the packet
send(pktret, 0);
} else {
// A packet was received. Use tcl.eval to call the Tcl
// interpreter with the hoya results.
// Note: In the Tcl code, a procedure
// 'Agent/Hoya recv {from rtt}' has to be defined which
// allows the user to react to the hoya result.
char out[100];
// Prepare the output to the Tcl interpreter. Calculate the
// round trip time
sprintf(out, "%s recv %d %3.1f", name(),
hdrip->src_.addr_ >> Address::instance().NodeShift_[1],
(Scheduler::instance().clock()-hdr->send_time) * 1000);
Tcl& tcl = Tcl::instance();
tcl.eval(out);
// Discard the packet
Packet::free(pkt);
}
}
========================================================================================
■ hoya.tcl
========================================================================================
#Create a simulator object
set ns [new Simulator]
#Open a trace file
set nf [open hoya_out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam hoya_out.nam &
exit 0
}
#Create three nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
#Define a 'recv' function for the class 'Agent/Hoya'
Agent/Hoya instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received hoya answer from \
$from with round-trip-time $rtt ms."
}
#Create two hoya agents and attach them to the nodes n0 and n2
set p0 [new Agent/Hoya]
$ns attach-agent $n0 $p0
set p1 [new Agent/Hoya]
$ns attach-agent $n2 $p1
#Connect the two agents
$ns connect $p0 $p1
#Schedule events
$ns at 0.2 "$p0 start"
$ns at 0.4 "$p1 start"
$ns at 0.6 "$p0 start"
$ns at 0.6 "$p1 start"
$ns at 1.0 "finish"
#Run the simulation
$ns run
========================================================================================
■ NS 수정사항
1. 일단 hoya.h와 hoya.cc 소스 코드를 ns-2.xx 폴더내에 작성합니다
(이 폴더내에 따로 hoya라는 폴더를 만들어서 이 폴더에서 코드를 저장해도 무방함).
2. packet.h의 enum packet_t { 부분에 "PT_HOYA"를 추가하고, class p_info { 의 p_info()내에
name_[PT_HOYA] = "Hoya"를 추가합니다. (아마도 common 디렉토리에 있을 것)
3. tcl/lib/ns-default.tcl 파일에 "Agent/Hoya set packetSize_ 64"를 추가
4. tcl/lib/ns-packet.tcl 파일에 foreach proto { 부분에 "Hoya" 추가 (위치는 그다지 중요하지 않은것 같음)
5. Makefile에 "OBJ_CC" 부분에 "hoya/hoya.o \" 라고 추가(hoya 폴더를 따로 만들어 작성한경우임).
6. 컴파일 : make depend; make
7. hoya.tcl 실행해보기.
[출처] [NS2] 새로운 어플리케이션 추가 (ex. Ping)|작성자 호야다
'Network > Ns2_source' 카테고리의 다른 글
First wimax simulation script - wimax1.tcl 11Mb에 대한 실험 - 논문에 실제 참조해봄- (0) | 2009.01.17 |
---|---|
ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING (0) | 2009.01.17 |
AP의 설정 (0) | 2009.01.17 |
mac의 transmit (0) | 2009.01.17 |
awk script- delay 계산 (0) | 2009.01.17 |
set BS(0) [$ns_node [lindex $temp 0]]
for{set j 0} {$j <$opt(nn)} {incr j}{
set node_($j) [$ns_node [lindex $temp [expr $j+1]] ]
$node($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}
'Network > Ns2_source' 카테고리의 다른 글
ns2 - TCP OVER NOISY LINKS AND QUEUE MONITORING (0) | 2009.01.17 |
---|---|
ns2 새로운 어플리케이션 추가LionHeart (0) | 2009.01.17 |
mac의 transmit (0) | 2009.01.17 |
awk script- delay 계산 (0) | 2009.01.17 |
awk script- delay 계산 및 IP 주소 C 상에서 얻어오기 (0) | 2009.01.17 |
{
hdr_tcp *tcph = hdr_tcp::access(p);
printf("\noffset type %d %d\n",tcph->flags(),addr());
}
'Network > Ns2_source' 카테고리의 다른 글
ns2 새로운 어플리케이션 추가LionHeart (0) | 2009.01.17 |
---|---|
AP의 설정 (0) | 2009.01.17 |
awk script- delay 계산 (0) | 2009.01.17 |
awk script- delay 계산 및 IP 주소 C 상에서 얻어오기 (0) | 2009.01.17 |
멈춰!! 움직이지마!! 움직여!! 빨리 달려!! 달리라고!!!! (0) | 2009.01.17 |