[Ns-developers] Bug in shadowing.cc
baldo at dei.unipd.it
Wed Jan 30 11:15:08 PST 2008
Hi Marcello & everybody,
Marcello Caleffi wrote:
> In the function Shadowing::Pr() the avg_db is calculated as
> -10.0 * pathLossExp_ * log10(dist/dis0)
> without checking if dist is equal to 0, as happens if the send and the
> recv node have the same position. If so, an arithmetic exception happens.
> What about adding a check as the following:
> if (dist == 0)
> dist = 1e-23;
> before the avg_db computation?
this fixes the arithmetic exception, but in my opinion is not the
correct way to do it because it leads to unrealistic simulations in some
Suppose that we have one transmitter TX1 at distance 0.0m from the
receiver, and another transmitter TX2 at 1.0m.
Using the default values dist0_ = 1.0m and pathlossExp_ = 2.0,
you will get an avg_db equal to 0 for TX2. For TX1, applying the fix you
proposed (if (dist == 0) dist = 1e-23;), avg_db will be 460.
Consequently, whenever TX1 and TX2 happen simultaneously, ns2 will
result in TX1 always being captured, while in real life you will just
get a collision (transmitters are only 1.0m apart!).
The issue is actually more general, in fact it applies not only to the
case of dist == 0 but to all cases in which dist < dist0_. In these
cases, it is not realistic to have a gain in the average received power
instead of an attenuation, as currently implemented.
Unfortunately dist < dist0_ means we are dealing with near field
propagation, so I really don't think we can come up with an accurate
expression for avg_db. Anyway, I think that a practical solution which
would not mess simulation results too much could be this one:
if (dist > dist0_)
avg_db = -10.0 * pathlossExp_ * log10(dist/dist0_);
avg_db = 0.0;
that is, limiting the average received power to the value at the
More information about the Ns-developers