Neighbor discovery

174 views
Skip to first unread message

retta

unread,
Feb 6, 2012, 6:50:18 PM2/6/12
to Castalia Simulator
Hello,

During my algorithm implementation, I got stack on collecting
neighbors' information from received packets.
My program is reading incorrect neighbors' id and location
information.
I couldn't see where its problem is,

Here is the set and the get to read there information:

void DetMAC::fromNetworkLayer(cPacket * pkt, int destination)
{
// Create a new MAC frame from the received packet and buffer it (if
possible)
DetPacket *macFrame = new DetPacket("BypassRouting packet",
MAC_LAYER_PACKET);
DetPacket_t temp_data;

temp_data.id = SELF_MAC_ADDRESS;
temp_data.x_coor = mobilityModule->getLocation().x;
temp_data.y_coor = mobilityModule->getLocation().y;

macFrame->setExtra(temp_data);
encapsulatePacket(macFrame, pkt);
bufferPacket(macFrame);
}

void DetMAC::fromRadioLayer(cPacket * pkt, double rssi, double lqi)
{
DetPacket *macPkt = dynamic_cast < DetPacket * >(pkt);
if (macPkt == NULL)
return;

if (macPkt->getDestination() == SELF_MAC_ADDRESS ||
macPkt->getDestination() == BROADCAST_MAC_ADDRESS)
{
trace() << "Received frame";
trace() << "Rx id: " << macPkt->getExtra().id;
trace() << "Rx x_coord: " << macPkt->getExtra().x_coor;
trace() << "Rx y_coord: " << macPkt->getExtra().y_coor;

/////////////////////// Store ID and location
supertile_neighbor[num_neighbors].id = macPkt->getExtra().id;
supertile_neighbor[num_neighbors].x = macPkt->getExtra().x_coor;
supertile_neighbor[num_neighbors].y = macPkt->getExtra().y_coor;
num_neighbors++;

toNetworkLayer(decapsulatePacket(macPkt));
}

}

For additional information here is the getExtra() and setExtra(...)
functions that i use:

void DetPacket::setExtra(const DetPacket_t& extra_var)
{
this->extra_var = extra_var;
}

DetPacket_t& DetPacket::getExtra()
{
return extra_var;
}

Thanks in advance for helping,
retta

Athanassios Boulis

unread,
Feb 6, 2012, 8:03:24 PM2/6/12
to castalia-...@googlegroups.com
Hi Retta,

Make sure you call encapsulatePacket before any protocol specific settings. 
Call it immediately after the creation of macFrame
We have discussed in other threads that this is important, because encapsulatePacket already sets some fields of the newly created macFrame with default values. In your case though, where you are setting your own structures, I am not sure it will make a difference.

I guess DetPacket_t is a struct used inside a DetPacket. Maybe you can give it a better name. If you call the field "extra" (again not the best name) then "extra_t" can be the type.

You do not really need to store the source ID in a separate custom field. The standard field "source" in a mac packet contains this information. It is set automatically in VirtualMac::encapsulatePacket()  and you can access it by 
makPacket->getSource()

You need to store the coordinates of the source in a custom way, as you do.

After setting the packet and before buffering it, you can check whether the fields in the "extra" struct are set appropriately.
trace << "x_coord: " << macFrame->getExtra().x_coor;


--
You received this message because you are subscribed to the Google Groups "Castalia Simulator" group.
To post to this group, send email to castalia-...@googlegroups.com.
To unsubscribe from this group, send email to castalia-simula...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castalia-simulator?hl=en.


retta

unread,
Feb 10, 2012, 5:40:28 AM2/10/12
to Castalia Simulator
Hello Athanassions,

Its working good now,
Thank you very much.

Retta

mohamed yehia

unread,
Feb 26, 2012, 4:46:45 PM2/26/12
to castalia-...@googlegroups.com
Hello
I am making a new algorithm and want to do a neighbor discovery at MAC startup
could you please tell me how to get the coordinates of the received
packet to my new algorithm?
i saw what a connectivity map example do and used the same sequence
but i need the x and y coordinate

another question please
should I use an application packet for this purpose or use another one?

thanks in advance

Best Regards
Mohamed Yehia

Athanassios Boulis

unread,
Feb 26, 2012, 5:34:32 PM2/26/12
to castalia-...@googlegroups.com
If you need extra information in the packet (e.g. coordinates of the sending node)
then you need to include them when you create the packet.


another question please
should I use an application packet for this purpose or use another one?

If this is a mac level algorithm as you suggest, then a mac packet has to contain this extra info. 

mohamed yehia

unread,
Feb 26, 2012, 5:55:55 PM2/26/12
to castalia-...@googlegroups.com
Dear Athanassios,
thanks for your fast replay and kind help
I'm making an application level algorithm.

does the cMessage struct contain these extra information?
if so i think I can get these information from the
virtualApplication.handlemessage () methode then pass it through the
fromNetworkLayer function to my application algorithm. right?

where can i find the cMessage dot h file?

thank you very much

Athanassios Boulis

unread,
Feb 26, 2012, 6:01:05 PM2/26/12
to castalia-...@googlegroups.com
cMessage is the basic omnet class that all messages (thus packets) inherit from.
You will have to create a new app packet including the extra info you want. The manual offers useful info on this. 
Reply all
Reply to author
Forward
0 new messages