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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

However if we have a large <strong>and</strong> de<strong>ns</strong>e topology, there is a chance th<strong>at</strong> two or more nodes may select the same slot in themac contention window (the contention window size varies from 31 to 1023 for DSSS PHY MIB specific<strong>at</strong>io<strong>ns</strong>). Thus nowwe need to add some extra jitter <strong>at</strong> the higher applic<strong>at</strong>ion layer. Diffusion has a provision to do this by compiling <strong>ns</strong> withthe macro USE_BROADCAST_MAC. Wh<strong>at</strong> this does is it in addition to delaying certain messages (to avoid collisio<strong>ns</strong>),when run with a BROADCAST MAC layer, diffusion will use a different set of values for delays <strong>and</strong> jitters. <strong>The</strong>se differentdelay/jitter values are defined under diffusion3/lib/main/config.hh. Since this might increase the l<strong>at</strong>ency you might want tofine-tune the delay values by h<strong>and</strong>.20.4 APIs for using filters in diffusionAs described earlier (see figure 20.1), filters can be <strong>at</strong>tached to a diffusion node for various reaso<strong>ns</strong>. <strong>The</strong>re can be basic diffusionfilters providing two-phase-pull (GradientFilter) <strong>and</strong> one-phase-pull (OnePhasePullFilter) diffusion routing algorithms.<strong>The</strong>re is the GeoRoutingFilter or gear th<strong>at</strong> provides a certain loc<strong>at</strong>ion (co-ordin<strong>at</strong>e) based routing algorithm. <strong>The</strong>re is alsoother filters for RMST routing algorithm (RmstFilter), logging (LogFilter), source routing (SourceRouteFilter) <strong>and</strong> tagging(TagFilter). See Comm<strong>and</strong>s <strong>at</strong> a glance section for details on APIs for adding filters to a diffusion node.20.5 Ping: an example diffusion applic<strong>at</strong>ion implement<strong>at</strong>ion<strong>The</strong>re is a ping applic<strong>at</strong>ion implemented under diffusion3/apps/ping subdir. <strong>The</strong> applic<strong>at</strong>ion co<strong>ns</strong>ists of a ping sender <strong>and</strong>receiver. <strong>The</strong> receiver requests for d<strong>at</strong>a by sending out “interest”s in the network. <strong>The</strong> interests get diffused through thenetwork. <strong>The</strong> ping-sender on receiving m<strong>at</strong>ching interests, sends out d<strong>at</strong>a.20.5.1 Ping Applic<strong>at</strong>ion as implemented in C++<strong>The</strong> ping-sender <strong>and</strong> -receiver classes, namely PingSenderApp <strong>and</strong> PingReceiverApp both derive from DiffApp, the parentclass for all diffusion based applic<strong>at</strong>io<strong>ns</strong>. See diffusion3/lib/diffapp{.cc,.hh} for detailed implement<strong>at</strong>ion of the DiffApp class.<strong>The</strong> ping-sender uses MySenderReceive object th<strong>at</strong> h<strong>and</strong>les all callbacks for it. Also the ping-sender defines two functio<strong>ns</strong>setupSubscription() <strong>and</strong> setupPublic<strong>at</strong>ion(). <strong>The</strong> first function cre<strong>at</strong>es interest <strong>at</strong>tributes th<strong>at</strong> m<strong>at</strong>ches with d<strong>at</strong>a <strong>at</strong>tributes it(the sender) has to offer. Next it calls the dr-library function subscribe(). <strong>The</strong> subscription is used by the ping-sender to cre<strong>at</strong>ean internal st<strong>at</strong>e agai<strong>ns</strong>t which <strong>at</strong>tributes for interests received from the network are m<strong>at</strong>ched agai<strong>ns</strong>t. Incase of a m<strong>at</strong>ch, them<strong>at</strong>ching d<strong>at</strong>a is sent outinto the network. Function setupPublic<strong>at</strong>ion() cre<strong>at</strong>e <strong>at</strong>tributes for the d<strong>at</strong>a it has to offer <strong>and</strong> callsthe library function publish() which inturn retur<strong>ns</strong> a publish h<strong>and</strong>le. <strong>The</strong> ping-sender uses this h<strong>and</strong>le to periodically send outd<strong>at</strong>a which is forwarded by the gradient to core-diffusion to be sent out into the network only if it finds a m<strong>at</strong>ching interest.<strong>The</strong> ping-receiver object uses a similar callback object called MyReceiverReceive. And it defines a function setupSubscription()th<strong>at</strong> cre<strong>at</strong>es <strong>at</strong>tributes for the interest the receiver will be sending. Next it calls the dr library supported subscribe() whichsends the interest out into the network. <strong>The</strong> recv() function is used to recv m<strong>at</strong>ching d<strong>at</strong>a <strong>and</strong> the receiver then calcul<strong>at</strong>es thel<strong>at</strong>ency for each d<strong>at</strong>a packet received from the ping-sender. <strong>The</strong> ping sender can be found under ping_sender.cc,.h. Andthe ping_receiver is implemented under ping_receiver.cc,.h. Some common defines <strong>and</strong> <strong>at</strong>tribute factories for d<strong>at</strong>a/interest<strong>at</strong>tributes are defined in ping.hh <strong>and</strong> ping_common.cc.196

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

Saved successfully!

Ooh no, something went wrong!