在NS2中对齐彼此连接的节点

时间:2017-03-08 21:34:42

标签: ns2

我试图将我创建的节点与网络模拟器2中的图片对齐,但是我编写的代码出了问题。如何将节点放置在此图片中?

picture

代码:

set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail
$ns duplex-link $n1 $n4 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n2 $n4 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail

$ns duplex-link-op $n0 $n1 orient right-down
$ns duplex-link-op $n0 $n3 orient left-down
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n0 $n4 orient left-down
$ns duplex-link-op $n4 $n3 orient right-down
$ns duplex-link-op $n1 $n2 orient left-down
$ns duplex-link-op $n1 $n4 orient left
$ns duplex-link-op $n2 $n3 orient left
$ns duplex-link-op $n1 $n3 orient left-down
$ns duplex-link-op $n4 $n2 orient right-down

proc finish {} {
    global ns nf
    $ns flush-trace
    close $nf
    exec nam out.nam &
    exit 0
}

$ns at 1.0 "finish"
$ns run

2 个答案:

答案 0 :(得分:0)

您可以使用NSG2等场景生成器来创建自己的拓扑。下载NSG2表单here 请注意,在运行NSG2 .jar文件之前,必须在Linux机器上安装java。

答案 1 :(得分:0)

您上传的图像不可用。从您编写的代码中我可以理解,因此,如果您想要创建一个如所附屏幕截图中所示的网络拓扑,可以按如下所示编辑代码。

set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

# Create Links between nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n0 $n4 1Mb 10ms DropTail

$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail
$ns duplex-link $n1 $n4 1Mb 10ms DropTail

$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n2 $n4 1Mb 10ms DropTail

$ns duplex-link $n3 $n4 1Mb 10ms DropTail

# Orientation of Nodes in Topology
$ns duplex-link-op $n0 $n1 orient right-down
$ns duplex-link-op $n0 $n3 orient left-down
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n0 $n4 orient left-down



proc finish {} {
    global ns nf
    $ns flush-trace
    close $nf
    exec nam out.nam &
    exit 0
}

$ns at 1.0 "finish"
$ns run

Aligned_Network Topology_1 Aligned_Network_Topology_2