[Ns-developers] [ns3] wrapper classes in the Attributes API
Gustavo Carneiro
gjcarneiro at gmail.com
Wed May 21 03:28:17 PDT 2008
On 21/05/2008, Raj Bhattacharjea <raj.b at gatech.edu> wrote:
>
> I'd like to apologize for the strong wording in the last message in
> this thread...it was an overly strong reaction to something that
> caught me off guard. No one's code is "an abomination" or an "ugly
> hack", and I'm deeply sorry for having said so.
Heh, that happens to me also, once in a while. You should see some of my
bug reports :D It is always difficult to react to bad surprises :-)
I would like to retract the tone of my message with deepest apologies
> to Mathieu and the development team. It'd be great if everyone could
> forgive me for flaming. It would be even better if I could completely
> wipe my last mail from your memories, and rephrase it in terms of the
> following questions/points:
>
> 1) It seems to me that the object of the current wrapper API is to
> have some way to pass a bunch of different types into the Attributes
> system in a consistent way, using the same methods to do so for
> various types of Attributes. The wrappers tell the Attributes system
> exactly which type of object is being passed in.
Ok, taking your earlier examples:
p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps"));
p2p.SetChannelParameter ("Delay", StringValue ("10ms"));
p2p.SetChannelParameter ("BitRate", DataRateValue (DataRate(100000)));
Regarding, DataRateValue (DataRate(100000)), I distinctly remember Mathieu
probing this list if it was OK to do that. I was personally in favor of
this approach because it improves consistency.
Before you had things like:
1. SetAttribute ("Foo", Vector (1, 2, 3))
2. SetAttribute ("Foo", IntegerValue (1))
That is, you have to use a wrapper class for some types (int in this
example) but not others (Vector in this example).
Now it's like:
1. SetAttribute ("Foo", VectorValue (Vector (1, 2, 3)))
2. SetAttribute ("Foo", IntegerValue (1))
So now you know, to set an attribute of type Xpto, you have to wrap it in a
XptoValue class. It's verbose but consistent and so requires less memory
effort.
Now, regarding:
p2p.SetChannelParameter ("BitRate", StringValue ("1500kbps"));
For this part I am just as clueless, I have to admit. Clearly the "BitRate"
parameter is of type DataRate, and it is very confusing to be passing a
StringValue for this. I would recommend to change StringValue, when used in
this context, to something like GenericValue or SerializedValue. Because,
if I'm not mistaken, this example code is passing a string to the attribute
system so that NS-3 tries to convert to the appropriate value type from a
string representation of such a value.
2) It also seems that the way in which attribute-helper.h defines
> macros is such that they automatically generate class definitions for
> wrappers in which a single find and replace on a typename suffices to
> differentiate the different classes.
>From past remarks, I suspect Mathieu hates macros as much as the next guy.
And truth is that NS-3 does its best to avoid macros already.
My opinion is that not using macros here would make the code more readable,
but very error prone and tedious to add new attribute types.
These two issues independently make me think of templates immediately,
> and it seems that using templates in both of these cases would work
> really well together.
I'm afraid you are being too vague. At least I can't comment without
specific API proposal examples...
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
More information about the Ns-developers
mailing list