Veins' AirFrame message ids are not what you might think they are

Every cMessage object in OMNeT++ has a unique id. However, if you try to access that id via cMessage::getId() as the manual says, you might be surprised.

Veins' AirFrame messages contain a field named id and the getter of this, AirFrame::getId(), shadows the method of cMessage. So what you get is a custom id that is managed by the phy layer, not OMNeT++ itself. The id is most probably not unique per clone. Instead, it is the same for all copies of the message. This is what you would expect of a tree Id but not the message Id.

So, how to get the original (OMNeT++ cMessage) id from an AirFrame? Just a pointer is not enough, as polymorphism will still find the override from AirFrame. So you need a reference to cMessage instead:

// assume there is some AirFrame* frame
const omnetpp::cMessage& msgRef = *frame;
std::cout << "Air Frame Id " << frame->getId();
std::cout << "Unique Message Id " << msgRef.getId();

Now if you clone that message, both the originial and the clone should keep the same airframe id (and tree id). But they will have different message ids, which can be obtained as shown above.