NS2.35在Fedora的安装

NS2安装

一、安装环境:

1.虚拟机下的Fedora 21。

安装镜像:Fedora-Live-Workstation-i686-21-5

更新系统程序:

$yum install yum-fastestmirror

$yum update

二、安装包

1.ns-allinone-2.35.tar

 

二、安装过程

1.安装必备软件包

# yum install autoconf automake gcc-c++ libX11-devel xorg-x11-proto-devel libXt-devel libXmu-devel

 

2.下载和安装 NS2要下载和安装的模块很多,最简单的方式就是下载 allinone 版本,所有模块都包括: 

$ tar zxvf ns-allinone-2.35.tar.gz

$ cd ns-allinone-2.35

$ ./install

三、安装问题及解决方案

1.NS模块编译错误

In file included from linkstate/ls.cc:67:0:

linkstate/ls.h: In instantiation of ‘void LsMap<Key, T>::eraseAll() [with Key = int; T = LsIdSeq]’:

linkstate/ls.cc:396:28:   required from here

linkstate/ls.h:137:58: 错误:‘erase’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

  void eraseAll() { erase(baseMap::begin(), baseMap::end()); }

                                                          ^

linkstate/ls.h:137:58: 附注:declarations in dependent base ‘std::map<int, LsIdSeq, std::less<int>, std::allocator<std::pair<const int, LsIdSeq> > >’ are not found by unqualified lookup

linkstate/ls.h:137:58: 附注:use ‘this->erase’ instead

Makefile:93: recipe for target 'linkstate/ls.o' failed

make: *** [linkstate/ls.o] Error 1

解决方案:

a.Go to ns-allinone-2.35/ns-2.35/linkstate/

b.Now edit ls.h
In line number 137, in place of void eraseAll() { erase(baseMap::begin(), baseMap::end()); }
make it void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }

四、添加环境变量

$ vi ~/.bashrc

# LD_LIBRARY_PATH

OTCL_LIB=/home/xyl/SourceFile/NS2/ns-allinone-2.35/otcl-1.14

NS2_LIB=/home/xyl/SourceFile/NS2/ns-allinone-2.35/lib

X11_LIB=/usr/X11R6/lib

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB

# TCL_LIBRARY

TCL_LIB=/home/xyl/SourceFile/NS2/ns-allinone-2.35/tcl8.5.10/library

export TCL_LIBRARY=$TCL_LIB

# PATH

PATH=$PATH:/home/xyl/SourceFile/NS2/ns-allinone-2.35/bin:/home/xyl/SourceFile/NS2/ns-allinone-2.35/tcl8.5.10/unix:/home/xyl/SourceFile/NS2/ns-allinone-2.35/tk8.5.10/unix

 

五、简单例程

#Create a simulator object
set ns [new Simulator]

#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red

#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
        #Close the NAM trace file
        close $nf
        #Execute NAM on the trace file
        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]

#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10

#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5


#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$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 packet_size_ 1000
$cbr set rate_ 1mb
$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 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"

#Print CBR packet size and interval
puts "CBR packet size = [$cbr set packet_size_]"
puts "CBR interval = [$cbr set interval_]"

#Run the simulation
$ns run

把以上代码保存为ns-simple.tcl(详见http://nile.wpi.edu/NS/),运行ns ns-simple.tcl

运行后界面如下:

 

posted on 2014-12-26 13:43  YanLe  阅读(822)  评论(0编辑  收藏  举报