Home > Mobile >  setKind() not taken into account
setKind() not taken into account

Time:01-03

I'm trying to Identify a message by using the getKind() function, I've previously defined my own DATA_KIND for sending:

DataM *data = new DataM();
data ->setKind(DATA_KIND);
data ->setSrc(this->getParentModule()->getIndex());
socket.sendTo(data, destAddr, destPort);

for receiving which it bypasses but is received as as a UDP_I_DATA bypasses this:

else if (msg->getKind() == DATA_KIND) {
    // process incoming packet;
}

and uses this:

else if (msg->getKind() == UDP_I_DATA) {
    // process incoming packet;
}

Please help!

I have tried adding the DATA_KIND value to the .h files and to the .cc files, I thought it was about the scope, it didn't work

CodePudding user response:

You cannot use setKind()/getKind() to carry out own information across the whole network in INET. Kind is a metadata that is used mainly between modules inside a device - to inform about the status of a packet. Therefore UDP layer always sets the value of kind for received packets (e.g.UDP_I_DATA, UDP_I_ERROR).

I suggest introducing own packet with the field that will determine the type, e.g. 1 - MY_DATA, 2 - MY_CONTROL, etc. An example:

packet DataM {
  int myType;    // own type
  // other data
  int otherData;
  
}

Then in your code you may use:

// somewhere in *.h 
#define MY_DATA    1
#define MY_CONTROL 2


// in *.cc - sending 
DataM *data = new DataM();
data->setMyType(MY_DATA);

// in *.cc - receiving
DataM *data2 = dynamic_cast<DataM*>(msg);
if (data2 != nullptr) {
  if (data2->getMyType == MY_DATA) {
      // MY_DATA - do something
  }
}

Reference:

  1. OMNeT Simulation Manula - 6 Message Definitions
  2. TicToc Tutorial - 4.4 Defining our message class
  • Related