Create new attribute!

50 views
Skip to first unread message

ns3.us...@gmail.com

unread,
May 27, 2015, 2:15:51 AM5/27/15
to ns-3-...@googlegroups.com
Hye!
I need help creating a new attribute of type std::set for a class created by me. How can I create an attribute like this?
What's the easiest way to transmit a std::set as a parameter?
Thank's in advance.

Konstantinos

unread,
May 27, 2015, 4:07:36 AM5/27/15
to ns-3-...@googlegroups.com, ns3.us...@gmail.com
Hi,

IMHO, the std::set is similar to the std::vector which has already been discussed in the list. 
std::vectors can not be 'set' as attributes (https://groups.google.com/d/msg/ns-3-users/yFri5ZbKDvU/jDAPJ1LqvzYJ

Now, when you refer to 'transmit' a set you mean in a packet? I do not know if this is the easiest, but this is the correct way: you need to iterate on each element of the set and write it onto the packet. You will also need one extra field in the packet to identify how many elements you need to read when you receive this packet.

ns3.us...@gmail.com

unread,
May 27, 2015, 4:46:37 AM5/27/15
to ns-3-...@googlegroups.com
Thank you for your answer, Konstantinos.
Now I understand why it wasn't working..

I have pairs like: pair<Ipv4Adress, string> used to represent nodes (to associate the IP adress and a string name). With these pairs I create a set of pairs. I need to transmit the set in the helper constructor and therefor to install the helper on the created nodes so that they could process the set of pairs representing neighbour nodes.
I will also need to send the set of pairs in the payload of the packets, although I don't know exactly how to do this..

Konstantinos

unread,
May 27, 2015, 5:39:43 AM5/27/15
to ns-3-...@googlegroups.com, ns3.us...@gmail.com
As I said, this issue is very similar to the 'std::vector'

The next is some guidelines/pseudocode:

Create your 'set';
Create your helper;
Set your 'set' in your helper; e.g. using the pass by reference.
Use the 'set' in the helper;

pdbarnes

unread,
May 27, 2015, 10:12:46 AM5/27/15
to ns-3-...@googlegroups.com
The only technical requirement to inventing a new Attribute type is that you can serialize/deserialize to/from a string. In principle a vector could be serialized as "value0|value1|..." assuming the elements themselves could be serialized. A set could be serialized the same way. The difficult bit will be the templates to serialize arbitrary elements.

> IMHO, the std::set is similar to the std::vector which has already been discussed
> in the list. Std::vectors can not be 'set' as attributes
> (https://groups.google.com/d/msg/ns-3-users/yFri5ZbKDvU/jDAPJ1LqvzYJ)

pdbarnes

unread,
May 27, 2015, 10:14:54 AM5/27/15
to ns-3-...@googlegroups.com
Take a look at EpidemicRouting, which has nodes exchange packets containing a vector of packet ids.
Peter

ns3.us...@gmail.com

unread,
May 27, 2015, 12:42:30 PM5/27/15
to ns-3-...@googlegroups.com
Thank's for replying!
I've tried to send std::set as a reference, but it gave me some errors when I tried processing the set.
I've also looked at the epidemic routing, but I still don't know how to solve my problem.
Reply all
Reply to author
Forward
0 new messages