MAC 地址值无法被其他节点消息识别
The MAC address value isn't recognized by other node messages
我正在使用 Veins 5.0
。这是我写的代码:
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));
}
另一个Node.cc
...
mR_SA* mr_sa = new mR_SA();
LAddress::L2Type nodeMacId = mr_sa -> getMacId();
EV_TRACE << "MAC address: " << nodeMacId << std::endl;
...
日志显示为从Node
获取的MAC
地址值为326
。但是,另一个节点从消息中收到的MAC
地址值为0
。为什么会这样?
构建后运行当前代码模拟形式完全没有错误。我怀疑是不同类型的原因,所以我转换为 long
类型,但结果是一样的。
AnotherNode.cc
正在使用 new
创建新的 mR_SA
,但希望在其中找到发送节点的 mac 地址。这是行不通的。相反,您需要将收到的 cMessage
转换为这种类型并使用成员访问器来获取 mac 地址。
我正在使用 Veins 5.0
。这是我写的代码:
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));
}
另一个Node.cc
...
mR_SA* mr_sa = new mR_SA();
LAddress::L2Type nodeMacId = mr_sa -> getMacId();
EV_TRACE << "MAC address: " << nodeMacId << std::endl;
...
日志显示为从Node
获取的MAC
地址值为326
。但是,另一个节点从消息中收到的MAC
地址值为0
。为什么会这样?
构建后运行当前代码模拟形式完全没有错误。我怀疑是不同类型的原因,所以我转换为 long
类型,但结果是一样的。
AnotherNode.cc
正在使用 new
创建新的 mR_SA
,但希望在其中找到发送节点的 mac 地址。这是行不通的。相反,您需要将收到的 cMessage
转换为这种类型并使用成员访问器来获取 mac 地址。