[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] add a new prop model?
Hello,
I am trying to add a new propagation model in NS-2.1b6. Here is the
sample:
LOS.cc
**************************************************
#include <math.h>
#include <delay.h>
#include <packet.h>
#include <packet-stamp.h>
#include <antenna.h>
#include <mobilenode.h>
#include <propagation.h>
#include <wireless-phy.h>
#include <LOS.h>
static class LOSClass: public TclClass {
public:
LOSClass() : TclClass("Propagation/LOS") {}
TclObject* create(int, const char*const*) {
return (new LOS);
}
} class_los;
LOS::LOS()
{
last_hr= 0.0;
}
static double
LO(double Pt, double A, double hr, double d)
{
/* LOS multipah model.
*
* Pt * A* (hr^2)
* Pr = ----------------------------
* PI*(d^4)
*/
return Pt * A* (hr * hr)/ PI*(d * d * d * d);
}
double
LOS::Pr(PacketStamp *t, PacketStamp *r, double L)
{
double rX, rY, rZ; // loc of receiver
double tX, tY, tZ; // loc of xmitter
double d; // the straight-line speration
double hr; //vertical height between recv and xmit
double Pr;
r->getNode()->getLoc(&rX, &rY, &rZ);
t->getNode()->getLoc(&tX, &tY, &tZ);
d = sqrt((rX - tX) * (rX - tX)
+ (rY - tY) * (rY - tY)
+ (rZ - tZ) * (rZ - tZ));
hr = tZ-rZ;
Pr = LO (t->getTxPr(),0.5,hr, d);
printf("LOS %e\n",Pr);
return Pr;
}
***************************************************************
LOS.h
*************************************************************
#ifndef __LOS_h__
#define __LOS_h__
#include <packet-stamp.h>
#include <wireless-phy.h>
#include <propagation.h>
class LOS : public Propagation {
public:
LOS();
virtual double Pr(PacketStamp *tx, PacketStamp *rx, WirelessPhy *ifp)
{return Pr(tx, rx, ifp->getL());}
protected:
virtual double Pr(PacketStamp *tx, PacketStamp *rx, double L);
double last_hr;
};
#endif /* __LOS_h__ */
*****************************************************************
Then I put LOS.o in Makefile in $HOME\ns-2.1b6\
Then : make
Everything seems all right. But when I was trying to use:
set val(prop) Propagation/LOS
in my tcl file, I got the error information as follows:
***************************************
invalid command name "Propagation/LOS"
while executing
"Propagation/LOS create _o12 "
invoked from within
"catch "$className create $o $args" msg"
(procedure "new" line 3)
invoked from within
"new $propType_"
(procedure "_o3" line 28)
(Simulator node-config line 28)
invoked from within
"$ns_ node-config -adhocRouting $val(adhocRouting) \
-llType $val(ll) \
-macType $val(mac) \
-ifqTyp..."
(file "wireless1.tcl" line 95)
**************************************8
Any information will be very helpful and I am looking forward to your
reply. Many thanks.
Ziran