Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applications and transport agent API 695430050 許庭瑋.

Similar presentations


Presentation on theme: "Applications and transport agent API 695430050 許庭瑋."— Presentation transcript:

1 Applications and transport agent API 695430050 許庭瑋

2 Outline Application in NS Class Application Attaching applications Class TrafficGenerator Simulated Applications

3 Application in NS On top of transport agents Two basic types  Traffic generators  Simulated applications

4 Application in NS

5 Class Application class Application : public TclObject { public: Application(); virtual void send(int nbytes); virtual void recv(int nbytes); virtual void resume(); protected: int command(int argc, const char*const* argv); virtual void start(); virtual void stop(); Agent *agent_; int enableRecv_; // call OTcl recv or not int enableResume_; // call OTcl resume or not }; *see trafgen.cc/.h

6 Attaching transport agent set src [new Agent/TCP/FullTcp] set sink [new Agent/TCP/FullTcp] $ns_ attach-agent $node_(s1) $src $ns_ attach-agent $node_(k1) $sink $ns_ connect $src $sink

7 Attaching applications Use attach-agent function set ftp1 [new Application/FTP] $ftp1 attach-agent $src  Set agent_  Call attachApp()[agent.cc] An alternative Set ftp1 [$src attach-app FTP]

8 System calls to use transport agent send(int nbytes)  send nbytes of data to peer  if nbytes==-1, infinite send sendmsg(int nbytes, const char* flags = 0)  Identical to send(int bytes)  Additional string flags MSG_EOF

9 System calls to use transport agent close()  Requests the agent to close the connection (only applicable for TCP) listen()  Requests the agent to listen for new connections (only applicable for Full TCP) set_pkttype(int pkttype)  This function sets the type_ variable in the agent to pkttype.

10 Agent upcalls to application In NS, no actual data transfering between applications Agents upcalls application to notify events  Incoming number of bytes of data Two types of upcalls  recv(int nbytes)  resume()

11 Done()  All data has been transferred, and ACKed  Done does nothing by default An example set myagent [new Agent/TCP/FullTcp] $myagent proc done... code you want...

12 Example for FTP set src [new Agent/TCP/FullTcp] set sink [new Agent/TCP/FullTcp] $ns_ attach-agent $node_(s1) $src $ns_ attach-agent $node_(k1) $sink $ns_ connect $src $sink # set up TCP-level connections $sink listen; $src set window_ 100 set ftp1 [new Application/FTP] $ftp1 attach-agent $src $ns_ at 0.0 "$ftp1 start"

13 Class TrafficGenerator class TrafficGenerator : public Application { public: TrafficGenerator(); virtual double next_interval(int &) = 0; virtual void init() {} virtual double interval() { return 0; } virtual int on() { return 0; } virtual void timeout(); virtual void recv() {} virtual void resume() {} protected: virtual void start(); virtual void stop(); double nextPkttime_; int size_; int running_; TrafficTimer timer_; };

14 Class TrafficGenerator Four classes derived from TrafficGenerator  EXPOO_Traffic Exponential on/off duration Fixed rate,packet size  POO_Traffic Pareto on/off distribution  CBR_Traffic  TrafficTrace Generates traffic according to trace file

15 Exponential distribution

16 Exponential On/Off packetSize_  the constant size of the packets generated burst_time_  the average “on” time for the generator idle_time_  the average “off” time for the generator rate_  the sending rate during “on” times Next_packet_time=tr_time+idle _time Example: set e [new Application/Traffic/Expon ential] $e set packetSize_ 210 $e set burst_time_ 500ms $e set idle_time_ 500ms $e set rate_ 100k

17 Pareto Distribution α,β>0 Shape in NS is β

18 Pareto On/Off packetSize_  the constant size of the packets generated burst_time_  the average "on" time for the generator idle_time_  the average "off" time for the generator rate_  the sending rate during "on" times shape_  the "shape" parameter used by the pareto distribution Example: set p [new Application/Traffic/Pareto] $p set packetSize_ 210 $p set burst_time_ 500ms $p set idle_time_ 500ms $p set rate_ 200k $p set shape_ 1.5

19 CBR rate_  the sending rate interval_ (Optional)  interval between packets packetSize_  the constant size of the packets generated random_ flag  indicating whether or not to introduce random “noise” in the scheduled departure times (default isoff) maxpkts_  the maximum number of packets to send (default is (228) Example: set e [new Application/Traffic/CB R] $e set packetSize_ 48 $e set rate_ 64Kb $e set random_ 1

20 Traffic Trace Enable multiple Traffic/Trace associated with one trace file 2 32-bit fields in trace file  Next packet generates time (ms)  Length of next packet (bytes) Example: set tfile [new Tracefile] $tfile filename example- trace set t1 [new Application/Traffic/Trace] $t1 attach-tracefile $tfile set t2 [new Application/Traffic/Trace] $t2 attach-tracefile $tfile

21 Random variable in NS Pareto Distribution Constant Distribution Uniform Distribution Exponential Distribution HyperExponential Distribution

22 Pareto Distribution # Pareto 分佈,柏拉圖分佈 set r1 [new RandomVariable/Pareto] $r1 use-rng $rng $r1 set avg_ 10.0 $r1 set shape_ 1.2 for {set i 1} {$i<=3} {incr i} { puts [$r1 value] }

23 Constant Distribution set r2 [new RandomVariable/Constant] $r2 use-rng $rng $r2 set avg_ 5 for {set i 1} {$i<=3} {incr i} { puts [$r2 value] }

24 Uniform Distribution Set min & max set r3 [new RandomVariable/Uniform] $r3 use-rng $rng $r3 set min_ 0.0 $r3 set max_ 10.0 for {set i 1} {$i<=3} {incr i} { puts [$r3 value] }

25 Exponential Distribution set r4 [new RandomVariable/Exponential] $r4 use-rng $rng $r4 set avg_ 5.0 for {set i 1} {$i<=3} {incr i} { puts [$r4 value] }

26 Example-Exponential traffic set src [new Agent/UDP] set sink [new Agent/UDP] $ns_ attach-agent $node_(s1) $src $ns_ attach-agent $node_(k1) $sink $ns_ connect $src $sink set e [new Application/Traffic/Exponential] $e attach-agent $src $e set packetSize_ 210 $e set burst_time_ 500ms $e set idle_time_ 500ms $e set rate_ 100k $ns_ at 0.0 "$e start"

27 Simulated applications Two simulated applications : FTP & Telnet FTP methods: attach-agent start stop produce n producemore n send n

28 Simulated applications Telnet Packet inter-packet time:  Chose from exponential distribution, with average=interval_ ; (if interval not zero)  Chose according tcplib distribution (see ns- 2.28\tcp\tcplib-telnet.cc)

29 Example CBR + FTP Node 1 CBR Node 2 FTP


Download ppt "Applications and transport agent API 695430050 許庭瑋."

Similar presentations


Ads by Google