12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Otherwise, ErrorModel just marks the error_ flag of the packet’s common header, thereby, allowing agents to h<strong>and</strong>lethe loss. <strong>The</strong> ErrorModel also defines additional Tcl method unit to specify the unit of error <strong>and</strong> ranvar to specify ther<strong>and</strong>om variable for gener<strong>at</strong>ing errors. If not specified, the unit of error will be in packets, <strong>and</strong> the r<strong>and</strong>om variable will beuniform distributed from 0 to 1. Below is a simple example of cre<strong>at</strong>ing an error model with the packet error r<strong>at</strong>e of 1 percent(0.01):# cre<strong>at</strong>e a loss_module <strong>and</strong> set its packet error r<strong>at</strong>e to 1 percentset loss_module [new ErrorModel]$loss_module set r<strong>at</strong>e_ 0.01# optional: set the unit <strong>and</strong> r<strong>and</strong>om variable$loss_module unit pkt$loss_module ranvar [new R<strong>and</strong>omVariable/Uniform];# error unit: packets (the default)# set target for dropped packets$loss_module drop-target [new Agent/Null]In C++, the ErrorModel contai<strong>ns</strong> both the mechanism <strong>and</strong> policy for dropping packets. <strong>The</strong> packet dropping mechanismis h<strong>and</strong>led by the recv method, <strong>and</strong> packet corrupting policy is h<strong>and</strong>led by the corrupt method.enum ErrorUnit { EU_PKT=0, EU_BIT, EU_TIME };class ErrorModel : public Connector {public:ErrorModel();void recv(Packet*, H<strong>and</strong>ler*);virtual int corrupt(Packet*);inline double r<strong>at</strong>e() { return r<strong>at</strong>e_; }protected:int comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv);ErrorUnit eu_; /* error unit in pkt, bit, or time */R<strong>and</strong>omVariable* ranvar_;double r<strong>at</strong>e_;};<strong>The</strong> ErrorModel only implements a simple policy based on a single error r<strong>at</strong>e, either in packets of bits. More sophistic<strong>at</strong>eddropping policy can be implemented in C++ by deriving from ErrorModel <strong>and</strong> redefining its corrupt method.13.2 Configur<strong>at</strong>ion<strong>The</strong> previous section talked about error model, in this section we discuss how to use error models in <strong>ns</strong> over either wirednetworks or wireless ones.To use an error model for wired networks, <strong>at</strong> first it has to be i<strong>ns</strong>erted into a SimpleLink object. Because a SimpleLink is acomposite object (Chapter 6), an error model can be i<strong>ns</strong>erted to many places. Currently we provide the following methods toi<strong>ns</strong>ert an error module into three different places.• I<strong>ns</strong>ert an error module in a SimpleLink BEFORE the queue module. This is provided by the following two OTclmethods:127

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!