【正文】
llType LL \ macType Mac/802_11 \ ifqType Queue/DropTail/PriQueue \ ifqLen 50 \ antType Antenna/OmniAntenna \ propType Propagation/TwoRayGround \ phyType Phy/WirelessPhy \ channelType Channel/WirelessChannel \ topoInstance $topo \ wiredRouting ON \ agentTrace ON \ routerTrace OFF \ macTrace OFF Create Home Agent and Foreign Agent set HA [$ns_ node ] set FA [$ns_ node ] $HA set X_ $HA set Y_ $HA set Z_ $FA set X_ $FA set Y_ $FA set Z_ create links between wired and BaseStation nodes $ns_ duplexlink $W(0) $W(1) 5Mb 2ms DropTail $ns_ duplexlink $W(1) $HA 5Mb 2ms DropTail $ns_ duplexlink $W(1) $FA 5Mb 2ms DropTail $ns_ duplexlinkop $W(0) $W(1) orient down $ns_ duplexlinkop $W(1) $HA orient leftdown $ns_ duplexlinkop $W(1) $FA orient rightdown create a mobilenode (in the domain of the HA) that is moving between HA and FA. $ns_ nodeconfig wiredRouting OFF set MH [$ns_ node ] set HAaddress [AddrParams addr2id [$HA nodeaddr]] [$MH set regagent_] set home_agent_ $HAaddress $MH set Z_ $MH set Y_ $MH set X_ MH starts to move towards FA $ns_ at $MH setdest goes back to HA $ns_ at $MH setdest Define initial node position in nam $ns_ initial_node_pos $MH 20 set tcp1 [new Agent/TCP] $tcp1 set class_ 2 set sink1 [new Agent/TCPSink] $ns_ attachagent $W(0) $tcp1 $ns_ attachagent $MH $sink1 $ns_ connect $tcp1 $sink1 set ftp1 [new Application/FTP] $ftp1 attachagent $tcp1 $ns_ at $opt(ftp1start) $ftp1 start $ns_ at $opt(stop).0 $MH reset。 flow_id = $8。 只把接收時間大於傳送時間的記錄列出來 if ( start end ) printf(%f %f\n, start, packet_duration)。 int seqno_。 agent_get_pkttype() != PT_TFRC) agent_set_pkttype(PT_CBR)。 } void TrafficTimer::expire(Event *) { tgen_timeout()。t usually have one. void UdpAgent::sendmsg(int nbytes, AppData* data, const char* flags) { Packet *p。 hdr_cmn::access(p)timestamp() = (u_int32_t)(SAMPLERATE*local_time)。 psetdata(data)。 sendmsg(atoi(argv[2]), data)。 } } class_mudp_agent。 } …………………………………………………………………. psetdata(data)。 while (n 0) { ……………………………………………………………………………….. hdr_cmn::access(p)sendtime_ = local_time。 FILE *BWFile。 (%s process_data %d {%s}, name(), iph Address::instance().NodeShift_[1], datadata())。 hdr_cmn::access(p)timestamp() = (u_int32_t)(SAMPLERATE*local_time)。 hdr_cmn::access(p)size() = size_。size_)。 /* send a packet */ send(size_)。maxpkts_)。 void init()。 packet_id = highest_packet_id。 from = $3。 number of domains lappend cluster_num 2 1 1 。 if ((!qib_ amp。 printf(DropTail(enque) size:%d iphprio:%d\n, cmhsize(), iphprio())。 x coordinate of topology set opt(y) 670 。 highest_packet_id = 0。 action != d ) { if ( action == r ) { end_time[packet_id] = time。)。 bind(packetSize_, amp。 if (++seqno_ maxpkts_) return(t)。 endif include include include include include static class UdpAgentClass : public TclClass { public: UdpAgentClass() : TclClass(Agent/UDP) {} TclObject* create(int, const char*const*) { return (new UdpAgent())。 return。 hdr_rtp* rh = hdr_rtp::access(p)。 hdr_ip* iph = hdr_ip::access(pkt)。 virtual int mand(int argc, const char*const* argv)。 if (nbytes == 1) { printf(Error: sendmsg() for UDP should not be 1\n)。 if (n 0) { …………………………………………………………………………….. hdr_cmn::access(p)sendtime_ = local_time。 UdpAgent::UdpAgent()。 strcpy((char*)datadata(), argv[3])。 } void UdpAgent::recv(Packet* pkt, Handler*) { if (app_ ) { // If an application is attached, pass the data to the app hdr_cmn* h = hdr_cmn::access(pkt)。 (0 ==strcmp(flags, NEW_BURST))) rhflags() |= RTP_M。 n = nbytes / size_。 virtual void sendmsg(int nbytes, const char *flags = 0) { sendmsg(nbytes, NULL, flags)。 timeout()。 static class CBRTrafficClass : public TclClass { public: CBRTrafficClass() : TclClass(Application/Traffic/CBR) {} TclObject* create(int, const char*const*) { return (new CBR_Traffic())。 Schedule Record after $time interval sec } proc finish {} { global ns nf nd f0 f1 f2 $ns flushtrace close $nf close $nd close $f0 close $f1 close $f2 Plot Recorded Statistics exec xgraph geometry 800x400 amp。 seq_no = $11。 $ns_ at $opt(stop).0002 puts \NS EXITING...\ 。 } else { drop(p)。Network Simulation and AnalysisUsing NS2 ChihHeng Ke (柯志亨 ) Webpage: Email: MSN: Methods for work research ? Analytical – Model – General expression or close form ? Emulation – Network testbed – Lab environment – Real code ? Simulation – Virtual work testbed Why Simulation ? Study of implemented protocols and algorithms – Behavior – Performance ? Test of unimplemented new protocols and algorithms ? Comparison of results across research efforts Simulation Advantage ? Inexpensive, Flexible and Reconfigurable ? Network phenomena interested can be reproduced ? Opportunity to study largescale work ? Easier parison of results across research efforts Simulation Disadvantage ? Important work details may be missed ? Protocols or algorithms must be “added” before simulation can be d