adding my own routing protocol

952 views
Skip to first unread message

Thomas Roberts

unread,
Feb 26, 2013, 7:14:02 AM2/26/13
to ns-3-...@googlegroups.com
Hi everyone I have my own routing protocol, and I need to add it to the simulation, I have set up the module with the create_module.py script, but the line:

listRoutingPtr->AddRoutingProtocol (myRoutingProto, -10);

I don't know what this means, how can I add my routing protocol to my simulation? What is a listRoutingPtr, and how do i initialise one, since I don't think it exists in my simulation.

Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
OlsrHelper olsr;
list.Add (staticRouting, 0);
InternetStackHelper internet;
internet.SetRoutingHelper (list);
internet.Install (wifiNodes);
Ptr<Ipv4FYPRouting> fyp = CreateObject<Ipv4FYPRouting> ();


So then what am I meant to do?
Thanks in advance!

Konstantinos

unread,
Feb 26, 2013, 7:30:22 AM2/26/13
to ns-3-...@googlegroups.com
Hi Thomas,

ListRouting is a 'type' of aggragator of different routing protocols with certain priority.

So for example you can have Static Routing, OLSR, AODV, Global Routing etc all together running on a single node but giving a priority to each one of them,
The protocol with the highest priority will try to find a route first. If it does not find, then the second etc.

So, if you add your routing protocol with priority -10 and there is another protocol with higher priority (I think the default is 0) then the other protocol will be accessed first and try to find a route.

Thomas Roberts

unread,
Feb 26, 2013, 7:41:42 AM2/26/13
to ns-3-...@googlegroups.com
Hi Konstantinos ,

Thanks for the reply! I understand this much from the ns3 documentation, however what I'm actually struggling with is how to actually ADD my routing protocol to this list? I can't find the ListRouting object anywhere to execute the AddRoutingProtocol method.

Thanks,
Thomas

Konstantinos

unread,
Feb 26, 2013, 7:45:28 AM2/26/13
to ns-3-...@googlegroups.com
From the code snipped you have:

Ipv4ListRoutingHelper list;
OlsrHelper olsr;
// put here your routing protocol. I would suggest to create a helper similar to OLSR/AODV etc
       MyRoutingHelper myrouting

       list.Add(myrouting, 10),  // note that the priority is higher than static routing.
list.Add (staticRouting, 0);
InternetStackHelper internet;
internet.SetRoutingHelper (list); // here it is installed using the install of List Routing
internet.Install (wifiNodes);
Ptr<Ipv4FYPRouting> fyp = CreateObject<Ipv4FYPRouting> (); // This does not do anything... Should be deleted

Thomas Roberts

unread,
Feb 26, 2013, 8:45:11 AM2/26/13
to ns-3-...@googlegroups.com
Thanks for the reply Konstantinos,

../scratch/fyp.cc: In function ‘int main(int, char**)’:
../scratch/fyp.cc:87:2: error: ‘FYPRoutingHelper’ was not declared in this scope
../scratch/fyp.cc:87:19: error: expected ‘;’ before ‘fyp’
../scratch/fyp.cc:89:11: error: ‘fyp’ was not declared in this scope

So I add #include "ns3/FYPRouting-helper.h"

and then this:

../scratch/fyp.cc: In function ‘int main(int, char**)’:
../scratch/fyp.cc:86:23: error: cannot declare variable ‘fyp’ to be of abstract type ‘ns3::Ipv4FYPRoutingHelper’
In file included from ./ns3/FYPRouting-module.h:10:0,
                 from ../scratch/fyp.cc:23:
./ns3/FYPRouting-helper.h:42:7: note:   because the following virtual functions are pure within ‘ns3::Ipv4FYPRoutingHelper’:
./ns3/FYPRouting-helper.h:57:33: note: virtual ns3::Ipv4FYPRoutingHelper* ns3::Ipv4FYPRoutingHelper::Copy() const
./ns3/FYPRouting-helper.h:63:36: note: virtual ns3::Ptr<ns3::Ipv4RoutingProtocol> ns3::Ipv4FYPRoutingHelper::Create(ns3::Ptr<ns3::Node>) const
../scratch/fyp.cc:88:17: error: no matching function for call to ‘ns3::Ipv4ListRoutingHelper::Add(ns3::Ipv4FYPRoutingHelper&, int)’
../scratch/fyp.cc:88:17: note: candidate is:
In file included from ./ns3/internet-module.h:34:0,
                 from ../scratch/fyp.cc:15:
./ns3/ipv4-list-routing-helper.h:75:8: note: void ns3::Ipv4ListRoutingHelper::Add(const ns3::Ipv4RoutingHelper&, int16_t)
./ns3/ipv4-list-routing-helper.h:75:8: note:   no known conversion for argument 1 from ‘ns3::Ipv4FYPRoutingHelper’ to ‘const ns3::Ipv4RoutingHelper&’

Here is my code snippet:

Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
OlsrHelper olsr;
Ipv4FYPRoutingHelper fyp;
list.Add (staticRouting, 0);
list.Add(fyp, 1);

Thanks,
Thomas.

Konstantinos

unread,
Feb 26, 2013, 9:22:17 AM2/26/13
to ns-3-...@googlegroups.com
Dear Thomas,

Which helper did you use as a basis of constructing your helper class?
Are you familiar with C++ inheritance polymorphism? if not have a look at this tutorial (http://www.cplusplus.com/doc/tutorial/polymorphism/)

If yes, then take a closer look at the compiler error and you have your answer. 

You have to implement the pure virtual methods in your helper class which should be inherited from the Ipv4RoutingHelper.

Thomas Roberts

unread,
Feb 26, 2013, 9:27:14 AM2/26/13
to ns-3-...@googlegroups.com
Dear Konstantinos, 

Thanks for your reply, I'll have a read of that tutorial.
Also, I used the Ipv4-routing helper class to make mine.
I also copied the class verbatim and changed the references to Ipv4Routing to Ipv4FYPRouting - I guess this is not a good thing to do?

Thanks, Thomas.

Konstantinos

unread,
Feb 26, 2013, 11:25:21 AM2/26/13
to ns-3-...@googlegroups.com
This was a good way to do it, however Ipv4-routing is a base class and has pure virtual methods that have to be implemented by the sub-classes (see the tutorial for more information on that).
I would suggest to look at other protocols as well (staticrouting, olsr, aodv etc) that inherit ipv4-routing.

Thomas Roberts

unread,
Feb 28, 2013, 3:44:34 AM2/28/13
to ns-3-...@googlegroups.com
Hi
Konstantinos,

So I did manage to get it all to compile, however I don't actually have any code in my helper constructor...

What should I put in there? Looking at the OLSR helper it has this: m_agentFactory.SetTypeId ("ns3::olsr::RoutingProtocol");

but when I add that to my code (without the olsr:: part) it says m_agentFactory is undefined.

Cheers, Thomas.

PS:
Do you know where I can find any "tutorial" on creating my own routing protocol as there seems to be a scarcity of material covering this.

Alessandro Russo

unread,
Feb 28, 2013, 3:55:09 AM2/28/13
to ns-3-...@googlegroups.com
Hi,

so, everything in your code is like the follow.
In the helper/my-helper.cc

 MyRpHelper::MyRpHelper ()
  {
    m_agentFactory.SetTypeId("ns3::myrp::MyRoutingProtocol");
  }


In the model/my-routing.cc

TypeId
MyRoutingProtocol::GetTypeId (void)
{
  static TypeId tid = TypeId ("ns3::myrp::MyRoutingProtocol")
    .SetParent<Ipv4RoutingProtocol> ()
    .AddConstructor<MyRoutingProtocol> ()
...
...
}


I've implemented PIM-DM, that is a multicast routing protocol,
starting from the AODV code.
What is your routing protocol TypeId?

 Alessandro  R.


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Thomas Roberts

unread,
Feb 28, 2013, 10:13:27 AM2/28/13
to ns-3-...@googlegroups.com
HI Alessandro,

Yeah, everything looks like that!

../src/FYPRouting/helper/FYPRouting-helper.cc: In constructor ‘ns3::Ipv4FYPRoutingHelper::Ipv4FYPRoutingHelper()’:
../src/FYPRouting/helper/FYPRouting-helper.cc:32:3: error: ‘m_agentFactory’ was not declared in this scope

That's the error I'm getting.

Attached are my files! Hope I haven't made any STUPID mistakes!
FYPRouting.cc
FYPRouting.h
FYPRouting-helper.cc
FYPRouting-helper.h

Alessandro Russo

unread,
Feb 28, 2013, 10:33:46 AM2/28/13
to ns-3-...@googlegroups.com
Hi,

well, it seems you didn't define any m_agentFactory...
I mean, I didn't find its declaration in FYPRouting-helper.h
Try to add this line, I guess it will work

ObjectFactory m_agentFactory;

Let me know,

 Alessandro  R.

Thomas Roberts

unread,
Feb 28, 2013, 1:03:17 PM2/28/13
to ns-3-...@googlegroups.com
Hi, so it's compiling now, but my constructor in FYPRouting.cc is never called for some reason... I see the constructor from FYPRouting-helper.cc is being called though so you fixed that ! Thanks!

I'm now getting this error when I try to assign the routing protocol to my Ipv4ListRoutingHelper

Waf: Leaving directory `/home/thomas/ns-allinone-3.16/ns-3.16/build'
'build' finished successfully (2.746s)
assert failed. cond="uid <= m_information.size () && uid != 0", file=../src/core/model/type-id.cc, line=128

Thanks,
Thomas

Thomas Roberts

unread,
Mar 1, 2013, 3:35:03 PM3/1/13
to ns-3-...@googlegroups.com
Well, Konstantinos and Alessandro,

Now it's saying: assert failed. cond="uid != 0", msg="Assert in TypeId::LookupByName: ns3::FYP::RoutingProtocol not found", file=../src/core/model/type-id.cc, line=419

but I copied it exactly like it is in OLSR and AODV ... and changed it to suit my protocol

Thanks, Thomas

Konstantinos

unread,
Mar 1, 2013, 4:16:23 PM3/1/13
to ns-3-...@googlegroups.com
it says that because you are trying to call an object with typeId "ns3::FYP::RoutingProtocol"
Do you have defined your routing protocol to have such typeId?

Thomas Roberts

unread,
Mar 1, 2013, 5:42:39 PM3/1/13
to ns-3-...@googlegroups.com
Hi Konstantinos, thanks for your reply

I think I do have this set, let me upload the new files I made. Sorry I changed my routing protocol names to make it easier to understand what was going on!
Do I have to register my class name with the TypeID class or something?

Thanks,
Thomas
FYP.cc
FYP.h
FYP-helper.cc
FYP-helper.h

Konstantinos

unread,
Mar 3, 2013, 6:28:55 PM3/3/13
to ns-3-...@googlegroups.com
Dear Thomas,

Problem solved with "registering" the routing protocol.
Just add this line in FYP.cc

NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);

I run a simple test and saw the "Boom" log you have in the constructor of the protocol.

Thomas Roberts

unread,
Mar 4, 2013, 4:36:21 AM3/4/13
to ns-3-...@googlegroups.com
Thanks Konstatinos! It is working now. Many thanks to yourself and Alessandro for helping me with this.

Thomas Roberts

unread,
Mar 4, 2013, 7:54:12 AM3/4/13
to ns-3-...@googlegroups.com
Ok, so, now I've tried to apply the routing protocol to only a single node in my topology, and the Boom message doesn't happen, only when I do apply it to all 3 nodes does it show up :(

        Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
OlsrHelper olsr;
FYPHelper fyp;
list.Add (staticRouting, 0);
InternetStackHelper internet;
internet.SetRoutingHelper (list);
internet.Install(gatewayNode);
list.Add(fyp, 1);
internet.Install (wifiNodes);

Thanks,
Thomas

Konstantinos

unread,
Mar 4, 2013, 8:06:09 AM3/4/13
to ns-3-...@googlegroups.com
What do you mean?
You want to install it to the gateway node only any you can't?
The way you have configure it now, it will won't be installed to any node.

After the list.Add(fyp,1); you have to "updated" the pointer to this list in the internet with another SetRoutingHelper. I would suggest before that to do a internet.Reset() to clear previous pointers. Then you can install it to the wifiNodes.

Thomas Roberts

unread,
Mar 4, 2013, 8:41:53 AM3/4/13
to ns-3-...@googlegroups.com
Ah ok, sorry about that! Yep it works now, although I'm now worried about this:

Sending a packet from 10.1.1.1 TO 1.1.1.3 header.GetDestination in RouteOutput says 10.1.1.1? I'm making the traffic with a UdpClient, and I'm sure this should not be happening? Additionally, header.GetSource() is 102.102.102.102


Thanks,
Thomas

Konstantinos

unread,
Mar 4, 2013, 9:02:26 AM3/4/13
to ns-3-...@googlegroups.com
This happens because you haven't configured the protocol to set the values correctly. Which header is this? 

Have a look at the documentation here (http://www.nsnam.org/docs/models/html/internet-stack.html#example-path-of-a-packet) to see when the RouteOutput is called. 

Thomas Roberts

unread,
Mar 4, 2013, 11:35:41 AM3/4/13
to ns-3-...@googlegroups.com
Hi Konstantinos!
Thanks for your reply.
It's the IPv4 Header, I'm sending from a UdpClient to the node with my protocol on it (there are no other protocols running on it I don't think, as per the snippet below)

        Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
Ipv4ListRoutingHelper list2;
FYPHelper fyp;
list.Add (staticRouting, 0);
InternetStackHelper internet;
internet.SetRoutingHelper (list);
internet.Install (wifiNodes);
internet.Reset();
list2.Add(fyp, 0);
internet.SetRoutingHelper(list2);
internet.Install(gatewayNode);

but on the gatewayNode, only RouteOutput is called, which is confusing as I was under the impression RouteInput would be called on the node that was receiving the packets, and the UdpClient is on the wifi nodes NOT the gateway!

here's my code if you wish to take a look. (fyp.cc is my simulation, and FYP.cc is my routing protocol, sorry for the confusing names..)

Thanks,
Thomas
fyp.cc
FYP.cc

Danilo J Calvachi

unread,
Aug 23, 2019, 2:30:48 PM8/23/19
to ns-3-users
hi i have a problem 
i have an error with the OLSRHELPER class 

the error is : undefined reference to `ns3::OlsrHelper::OlsrHelper()
 how cai i fix it?
Reply all
Reply to author
Forward
0 new messages