📄 node551.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by: Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>39.5 An Example</TITLE><META NAME="description" CONTENT="39.5 An Example"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node552.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node552.html"><LINK REL="previous" HREF="node545.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node545.html"><LINK REL="up" HREF="node540.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node540.html"><LINK REL="next" HREF="node552.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node552.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html9868" HREF="node552.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node552.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html9862" HREF="node540.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node540.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html9856" HREF="node550.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node550.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html9864" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html9866" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html9869" HREF="node552.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node552.html">39.6 Commands at a</A><B> Up:</B> <A NAME="tex2html9863" HREF="node540.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node540.html">39. Emulation</A><B> Previous:</B> <A NAME="tex2html9857" HREF="node550.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node550.html">39.4.3 IP/UDP Network Objects</A>   <B> <A NAME="tex2html9865" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html9867" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H1><A NAME="SECTION09150000000000000000">39.5 An Example</A></H1><P>The following code illustrates a small but completesimulation script for setting up an emulation test using BPF andIP network objects.It was run on a multi-homed machine, and the simulator essentiallyprovides routing capability by reading frames from one interface,passing them through the simulated network, and writing themout via the raw IP network object:<P><PRE> set me "10.0.1.1" set ns [new Simulator] $ns use-scheduler RealTime # # we want the test machine to have ip forwarding disabled, so # check this (this is how to do so under FreeBSD at least) # set ipforw [exec sysctl -n net.inet.ip.forwarding] if { $ipforw } { puts "can not run with ip forwarding enabled" exit 1 } # # allocate a BPF type network object and a raw-IP object # set bpf0 [new Network/Pcap/Live] set bpf1 [new Network/Pcap/Live] $bpf0 set promisc_ true $bpf1 set promisc_ true set ipnet [new Network/IP] set nd0 [$bpf0 open readonly fxp0] set nd1 [$bpf1 open readonly fxp1] $ipnet open writeonly # # try to filter out weird stuff like netbios pkts, arp requests, dns, # also, don't catch stuff to/from myself or broadcasted # set notme "(not ip host $me)" set notbcast "(not ether broadcast)" set ftp "and port ftp-data" set f0len [$bpf0 filter "(ip dst host bit) and $notme and $notbcast"] set f1len [$bpf1 filter "(ip src host bit) and $notme and $notbcast"] puts "filter lengths: $f0len (bpf0), $f1len (bpf1)" puts "dev $nd0 has address [$bpf0 linkaddr]" puts "dev $nd1 has address [$bpf1 linkaddr]" set a0 [new Agent/Tap] set a1 [new Agent/Tap] set a2 [new Agent/Tap] puts "install nets into taps..." $a0 network $bpf0 $a1 network $bpf1 $a2 network $ipnet set node0 [$ns node] set node1 [$ns node] set node2 [$ns node] $ns simplex-link $node0 $node2 10Mb 10ms DropTail $ns simplex-link $node1 $node2 10Mb 10ms DropTail $ns attach-agent $node0 $a0 $ns attach-agent $node1 $a1 $ns attach-agent $node2 $a2 $ns connect $a0 $a2 $ns connect $a1 $a2 puts "okey" $ns run</PRE><P><BR><HR><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -