bettyn
bettyn

Reputation: 25

How to include a vector (container class) in a message file in OMNeT++

I am struggling on how message from a node which is a Cluster head in VANET to contain list of cluster members. I tried to add a vector to contain a cluster table in a message file but am getting errors (see my codes of message file and error below). Can anyone help on how can I go about this?

cplusplus {{
#include <vector>
#include <iostream>
#include "veins/modules/application/traci/MyClusterApp.h"
typedef std::vector<Neighbour> NeighbourEntrySet;

}}

import veins.base.utils.Coord;
import veins.modules.messages.BaseFrame1609_4;
import veins.base.utils.SimpleAddress;

namespace veins;



packet DemoSafetyMessage extends BaseFrame1609_4 {
    Coord senderPos;
    Coord senderSpeed;
    int clusterHead;                    // The cluster head of this node.
    int neighbourCount;                 // Number of neighbours this node has.
    int clusterSize;                    // If CH, this is the number of nodes in its cluster.
    NeighbourEntrySet clusterTable;     // Cluster Member table.
    
}

Error:

veins/modules/messages/DemoSafetyMessage.msg:59: Error: unknown type 'NeighbourEntrySet' for field 'clusterTable' in 'DemoSafetyMessage'
make[1]: Leaving directory '/home/veins/src/veins/src'
make[1]: *** [Makefile:234: veins/modules/messages/DemoSafetyMessage_m.h] Error 1
make: *** [Makefile:36: all] Error 2
"make MODE=release -j2 all" terminated with exit code 2. Build might be incomplete.

Upvotes: 1

Views: 489

Answers (1)

Pritom
Pritom

Reputation: 525

What you are looking is provided in the omnetpp simulation manual chapter 6.8 : https://doc.omnetpp.org/omnetpp/manual/#sec:msg-defs:cplusplus-blocks

instead of adding a vector container you can add a variable with a class container.So, basically a vector container can be placed inside a class. same thing! If this solves your problem then you can try the following approach:

  1. create a header file which contains your class(container) the class can have the vector container you want.
  2. create a .msg file which which includes the the header file in 1. example content :
cplusplus {{
#include "Hearer_File_you_created.h"
}}

namespace veins;
class Class_name_given_in_header_file
{
    @existingClass;
    @opaque;
}
  1. create another .msg file that is your message file and import the message file created in step 2. example content:
import <.msg file name created in step 2>;
namespace veins;

packet DemoSafetyMessage extends BaseFrame1609_4 {
   
   class_name_you_created_inThe_header_file mwc;
}

mwc -> is your container variable name.

Upvotes: 1

Related Questions