Applications and transport agent API 695430050 許庭瑋.

29
Applications and transport agent API 695430050 許許許
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    283
  • download

    0

Transcript of Applications and transport agent API 695430050 許庭瑋.

Page 1: Applications and transport agent API 695430050 許庭瑋.

Applications and transport agent API

695430050

許庭瑋

Page 2: Applications and transport agent API 695430050 許庭瑋.

Outline

Application in NSClass ApplicationAttaching applicationsClass TrafficGeneratorSimulated Applications

Page 3: Applications and transport agent API 695430050 許庭瑋.

Application in NS

On top of transport agents Two basic types

Traffic generators Simulated applications

Page 4: Applications and transport agent API 695430050 許庭瑋.

Application in NS

Page 5: Applications and transport agent API 695430050 許庭瑋.

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 notint enableResume_; // call OTcl resume or not};

*see trafgen.cc/.h

Page 6: Applications and transport agent API 695430050 許庭瑋.

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

Page 7: Applications and transport agent API 695430050 許庭瑋.

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]

Page 8: Applications and transport agent API 695430050 許庭瑋.

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

Page 9: Applications and transport agent API 695430050 許庭瑋.

System calls to use transport agent

close() Requests the agent to close the connection (onl

y 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 agen

t to pkttype.

Page 10: Applications and transport agent API 695430050 許庭瑋.

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()

Page 11: Applications and transport agent API 695430050 許庭瑋.

Done() All data has been transferred, and ACKed Done does nothing by default

An exampleset myagent [new Agent/TCP/FullTcp]

$myagent proc done

... code you want ...

Page 12: Applications and transport agent API 695430050 許庭瑋.

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_ 100set ftp1 [new Application/FTP]$ftp1 attach-agent $src$ns_ at 0.0 "$ftp1 start"

Page 13: Applications and transport agent API 695430050 許庭瑋.

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_;};

Page 14: Applications and transport agent API 695430050 許庭瑋.

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

Page 15: Applications and transport agent API 695430050 許庭瑋.

Exponential distribution

Page 16: Applications and transport agent API 695430050 許庭瑋.

Exponential On/Off

packetSize_ the constant size of the p

ackets generated burst_time_

the average “on” time for the generator

idle_time_ the average “off” time for t

he generator rate_

the sending rate during “on” times

Next_packet_time=tr_time+idle_time

Example:set e [new Application/Traffi

c/Exponential]$e set packetSize_ 210$e set burst_time_ 500ms$e set idle_time_ 500ms$e set rate_ 100k

Page 17: Applications and transport agent API 695430050 許庭瑋.

Pareto Distribution

α,β>0 Shape in NS is β

Page 18: Applications and transport agent API 695430050 許庭瑋.

Pareto On/Off

packetSize_ the constant size of the packet

s generated burst_time_

the average "on" time for the generator

idle_time_ the average "off" time for the g

enerator rate_

the sending rate during "on" times

shape_ the "shape" parameter used b

y the pareto distribution

Example:set p [new Application/Traffic/Par

eto]$p set packetSize_ 210$p set burst_time_ 500ms$p set idle_time_ 500ms$p set rate_ 200k$p set shape_ 1.5

Page 19: Applications and transport agent API 695430050 許庭瑋.

CBR

rate_ the sending rate

interval_ (Optional) interval between packets

packetSize_ the constant size of the packet

s generated random_ flag

indicating whether or not to introduce random “noise” in the scheduled departure times (default isoff)

maxpkts_ the maximum number of pack

ets to send (default is (228)

Example: set e [new Application

/Traffic/CBR] $e set packetSize_ 48 $e set rate_ 64Kb $e set random_ 1

Page 20: Applications and transport agent API 695430050 許庭瑋.

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

Page 21: Applications and transport agent API 695430050 許庭瑋.

Random variable in NS

Pareto Distribution Constant Distribution Uniform Distribution Exponential Distribution HyperExponential Distribution

Page 22: Applications and transport agent API 695430050 許庭瑋.

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]  }

Page 23: Applications and transport agent API 695430050 許庭瑋.

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]  }

Page 24: Applications and transport agent API 695430050 許庭瑋.

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]  }

Page 25: Applications and transport agent API 695430050 許庭瑋.

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]  }

Page 26: Applications and transport agent API 695430050 許庭瑋.

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 $sinkset 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"

Page 27: Applications and transport agent API 695430050 許庭瑋.

Simulated applications

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

Page 28: Applications and transport agent API 695430050 許庭瑋.

Simulated applications

TelnetPacket 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)

Page 29: Applications and transport agent API 695430050 許庭瑋.

Example

CBR + FTP Node 1 CBR Node 2 FTP