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.

yr applic<strong>at</strong>ion in the <strong>ns</strong> context. <strong>The</strong> few lines describe the changes/additio<strong>ns</strong> you need to make for yr diffusion applic<strong>at</strong>ionto work in <strong>ns</strong> environment.We will co<strong>ns</strong>ider onePhasePullFilter object (under diffusion3/filters/misc/log.*) as an example. As a first step you need tocre<strong>at</strong>e a split object out of the applic<strong>at</strong>ion class object, presumably defined as a pure c++ object. A split object is one th<strong>at</strong> iscre<strong>at</strong>ed by the user in the interpretor (in OTcl space) <strong>and</strong> which is also has a shadow object in the compiled hierarchy (in c++space). In <strong>ns</strong>, a split object is derived from class TclClass as shown below:#ifdef NS_DIFFUSIONst<strong>at</strong>ic class LogFilterClass : public TclClasspublic:LogFilterClass() : TclClass("Applic<strong>at</strong>ion/DiffApp/LogFilter")TclObject * cre<strong>at</strong>e(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv)return(new LogFilter());class_log_filter;#endif //DIFFUSIONNote th<strong>at</strong> all filter objects specifically have a h<strong>and</strong>le to the DiffAppAgent (the diffusion routing object) passed in the co<strong>ns</strong>tructorcall. Filter objects get cre<strong>at</strong>ed from function cre<strong>at</strong>e-diffusionApp-agent diffFilters defined in <strong>ns</strong>-diffusion.tcl. Usersneed not specifically call the OTcl function cre<strong>at</strong>e-diffusionApp-agent as it is called during node cre<strong>at</strong>ion based on the nodeconfigur<strong>at</strong>ionparameters. See how filters are defined in node-config under comm<strong>and</strong>s <strong>at</strong> a glance section. However applic<strong>at</strong>ionobjects which are not filter objects (like ping_sender, push_receiver etc) are cre<strong>at</strong>ed by users directly from user scripts. Andin th<strong>at</strong> case the h<strong>and</strong>le to DiffAppAgent is passed using $<strong>ns</strong> <strong>at</strong>tach-diffapp $node $app where the applic<strong>at</strong>ion$app is <strong>at</strong>tached to the node object $node.So for the reaso<strong>ns</strong> explained above the co<strong>ns</strong>tructors are different in non NS_DIFFUSION context as shown below.#ifdef NS_DIFFUSIONLogFilter::LogFilter()#elseLogFilter::LogFilter(int argc, char **argv)#endif // NS_DIFFUSION// Cre<strong>at</strong>e Diffusion Routing class#ifndef NS_DIFFUSIONparseComm<strong>and</strong>Line(argc, argv);dr_ = NR::cre<strong>at</strong>eNR(diffusion_port_);#endif // !NS_DIFFUSIONfilter_callback_ = new LogFilterReceive(this);#ifndef NS_DIFFUSION// Set up the filterfilter_h<strong>and</strong>le_ = setupFilter();......#endif // !NS_DIFFUSION198

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

Saved successfully!

Ooh no, something went wrong!