0

I'm using Veins 5.0. Here is the code I've written:

NodeMsg.msg

cplusplus{{
    #import "veins/base/utils/Coord.h"
    #import "veins/modules/utility/Consts80211p.h"
    #include "veins/modules/messages/BaseFrame1609_4_m.h"
    #include "veins/base/utils/SimpleAddress.h"
}};

namespace veins;

class noncobject Coord;
class BaseFrame1609_4;
class noncobject LAddress::L2Type;

packet mR_SA extends BaseFrame1609_4
{
    int isWlan; // IEEE 80211p and LTE classification variables
    int mrsuId;
    int type;
    int status;
    int remainingCapacity;
    int neighborVehiclesCount;
    int checksum; 
    double direction;
    double velocity;
    double posX; // longitude
    double posY; // latitude
    simtime_t timestamp = 0;
    LAddress::L2Type macId; // MAC address
}

Node.h

#include "veins/modules/mac/ieee80211p/DemoBaseApplLayerToMac1609_4Interface.h"
...

class VEINS_API Node : public DemoBaseApplLayer
{
     ...
     public:
         LAddress::L2Type nodeMacId = 0;
}

Node.cc

...
else if(stage == 1)
{
     mac = FindModule<DemoBaseApplLayerToMac1609_4Interface*>::findSubModule(getParentModule());
     ASSERT(mac);

     nodeMacId = mac -> getMACAddress();
}

...

void Node::handleSelfMsg(cMessage* msg)
{
     ... 
     mR_SA* mr_sa = new mR_SA();
     ...
     mr_sa -> setMacId(nodeMacId);

     BaseFrame1609_4* wsm = new BaseFrame1609_4();
     wsm -> encapsulate(mr_sa);
     populateWSM(wsm);
     sendDelayedDown(wsm, uniform(0.01, 0.50));
}

AnotherNode.cc

...
mR_SA* mr_sa = new mR_SA();
LAddress::L2Type nodeMacId = mr_sa -> getMacId();

EV_TRACE << "MAC address: " << nodeMacId << std::endl;
...

The log is displayed as the MAC address value obtained from Node is 326. However, the MAC address value received from the message by another node is 0. Why does this happen?

There are no errors at all when running the current code in simulation form after building. I suspected that a different type was the cause, so I did a cast to a long type, but the result was the same.

Minwoo Kim
  • 497
  • 1
  • 5
  • 21

1 Answers1

2

AnotherNode.cc is creating a fresh mR_SA using new, but is expecting to find the sending node's mac address in there. This will not work. Rather, you would need to cast the received cMessage to this type and use member accessors to get the mac address.

Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35
  • Thanks for the advice. Knowing that the `new` keyword creates a new object, it was structurally misunderstood. I was able to fix it using `check_and_cast<>()`. – Minwoo Kim Apr 09 '21 at 17:41