Hi,

It's a segmentation fault since you create an uninitilized object 
"WirelessChannel *tifp" in your aodv class and after you call your function for 
this null object. Note that segmentation fault usually occurs when you call a 
function for a null object.

Thus, you should first initialize "WirelessChannel *tifp" to the "channel" 
object assicited to the aodv object.
See, you have a node where aodv is running and for this node you have an 
associated  physical layer and below the physical layer you have an associated 
channel.
I had a similar problem some time ago, where in application layer I wanted to 
access physical layer, so I used the code below:

        
        //To enable packet discard writing
        MobileNode* node_ = 
(MobileNode*)(Node::get_node_by_address(here_.addr_));
        WirelessPhyExt* physicalLayer = 
(WirelessPhyExt*)(node_->ifhead()).lh_first;
        physicalLayer->writePktDiscardToFile();

Note that I used "WirelessPhyExt" ( a variant of "WirelessPhy") in my program 
so in your case you should replace it with "WirelessPhy". 
Now in your case, you want to access the channel associated to the physical 
layer so as I saw in the ns2 library you need to get the "channel_" object of 
the physical layer and then call your function for it.

I think this code should work to get the node object in the network layer 
(i.e., aodv), if this does not work, in any case you should find a way to 
access to the associated channel object of your node when adov is running.

Hope this helps,
Best regards,
Behnaz


On Jul 11, 2014, at 1:39 PM, Alireza Shamsoshoara <a.shamsosho...@gmail.com> 
wrote:

> 
> Hello
> 
> I'm working on my MS thesis and I want to use some value from a variable in
> channel.cc , this variable return the Pr and Pt , power of receiver and
> power of transmitter respectively. so i defined a variable ("getvalue_")
> and a function (getvalue) in channel.h (channel header file) in this way:
> 
> [channel.h :]
> 
> class WirelessChannel : public Channel {
> ....
> public:
> ...
> WirelessChannel(void);
> double getvalue_;
> inline double getvalue() {return getvalue_;}
> ....
> }
> 
> and also in channel.cc ,call the variable and equal it to the function that
> desire to read   :
> 
> [channel.cc]
> 
> void
> WirelessChannel::calcHighestAntennaZ(Phy *tifp)
> {
> ...
> getvalue_ = wifp->getPt();
> printf("P_t____ = %f\n",getvalue_);
> ...
> }
> it's noticable that getvalue_ is printed in channel.cc
> but when call the function getvalue in AODV.CC
> [AODV.cc]
> {
> ....
> void
> AODV::recvRequest(Packet *p) {
> ...
> WirelessChannel *tifp;
> double x=tifp->gethighestAntennaZ();
> printf("x____ = %f\n",x);
> double y=tifp->getvalue();
> printf("y____ = %f\n",y);
> ...
>     }
> 
> the value of x is printed in terminal but
> but for the getvalue function segmentation fault occur.
> 
> what should i do to read a variable from other cc files? which part of
> above i was wrong that segmentation fault happened?
> 
> Thanks in advance for your help.
> 
> 
> 
> ______________________________________________________
> 
> Alireza Shamsoshoara, M.Sc.
> 
> Faculty of Electrical and Computer Engineering (ECE)
> 
> K.N.Toosi University of Technology
> 
> Tehran, IRAN.

Reply via email to