GlobalRouting print routing table

757 views
Skip to first unread message

Slawek

unread,
Aug 9, 2010, 12:25:44 PM8/9/10
to ns-3-users
Hi,
I want to print routing table same node. I use GlobalRouting to
populate routing tables and I use following function to print it
(thanks to Antti):
void printRoutingTable (Ptr<Node> node) {
Ipv4StaticRoutingHelper helper;
Ptr<Ipv4> stack = node -> GetObject<Ipv4>();
Ptr<Ipv4StaticRouting> staticrouting = helper.GetStaticRouting
(stack);
uint32_t numroutes=staticrouting->GetNRoutes();
Ipv4RoutingTableEntry entry;
std::cout << "Routing table for device: " <<
Names::FindName(node) <<
"\n";
std::cout << "Destination\tMask\t\tGateway\t\tIface\n";

for (uint32_t i =0 ; i<numroutes;i++) {
entry =staticrouting->GetRoute(i);
std::cout << entry.GetDestNetwork() << "\t"
<< entry.GetDestNetworkMask() << "\t"
<< entry.GetGateway() << "\t\t"
<< entry.GetInterface() << "\n";
}
return;

}

It's work but gateway is always 0.0.0.0. So I recently try with this
code:
void printRoutingTable (Ptr<Node> node) {
Ptr<Ipv4> stack = node -> GetObject<Ipv4>();
Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
Ptr<Ipv4GlobalRouting> globalrouting = router-
>GetRoutingProtocol ();
uint32_t numroutes = globalrouting->GetNRoutes();
Ipv4RoutingTableEntry entry;
std::cout << "Routing table for device: " <<
Names::FindName(node) <<"\n";
std::cout << "Destination\tMask\t\tGateway\t\tIface\n";

for (uint32_t i =0 ; i<numroutes;i++) {
entry =globalrouting->GetRoute(i);
std::cout << entry.GetDestNetwork() << "\t"
<< entry.GetDestNetworkMask() << "\t"
<< entry.GetGateway() << "\t\t"
<< entry.GetInterface() << "\t"
<</*globalrouting->GetMetric(i)*/<<"\n";
}
return;

}
Unfortunately it's displays errors. I would be grateful if somebody
help me print correct routing tables.

Slawek

unread,
Aug 12, 2010, 11:00:09 AM8/12/10
to ns-3-users
Could this be due to the presence of switch? But in the topology I
have 2 routers and few others node, so there are three network
addresses (subnetwork). Should I set up the correct gateway (only for
printing because routing is correct) using Ipv4StaticRouting?

Быков Евгений

unread,
Aug 12, 2010, 11:12:17 AM8/12/10
to ns-3-...@googlegroups.com
Probably it will be a good idea to show log of errors and node topology.
0.0.0.0 gateway may not be as bad as it seems

2010/8/12 Slawek <slawm...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.


Slawek

unread,
Aug 12, 2010, 2:53:19 PM8/12/10
to ns-3-users
OK, thanks.
My node topology is like this:
n0 ========= n3
|
|
|
|
n1 ========= n2(switch)
// \\
// \\
n4 n5

When I use the first peace of code (using Ipv4StaticRoutingHelper),
there is no errors - but this 0.0.0.0 gateway.
So, I tried to prepare the following function (I hope than gateway
will be correct):

226 void printRoutingTable (Ptr<Node> node) {
227 //Ipv4GlobalRoutingHelper helper;
228 Ptr<Ipv4> stack = node -> GetObject<Ipv4>();
229 Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
230 Ptr<Ipv4GlobalRouting> globalrouting = router-
>GetRoutingProtocol ();
231 uint32_t numroutes = globalrouting->GetNRoutes();
232 Ipv4RoutingTableEntry entry;
233 std::cout << "Routing table for device: " <<
Names::FindName(node) <<"\n";
234 std::cout << "Destination\tMask\t\tGateway\t\tIface\n";
235
236 for (uint32_t i =0 ; i<numroutes;i++) {
237 entry =globalrouting->GetRoute(i);
238 std::cout << entry.GetDestNetwork() << "\t"
239 << entry.GetDestNetworkMask() <<
"\t"
240 << entry.GetGateway() << "\t\t"
241 << entry.GetInterface() << "\t"
242 <</*globalrouting->GetMetric(i)*/<<"\n";
243 }
244 return;
245
246 }

Unfortunately, there are errors:
../scratch/rys10Glob.cc: In function ‘void
printRoutingTable(ns3::Ptr<ns3::Node>)’:
../scratch/rys10Glob.cc:231: error: invalid use of incomplete type
‘struct ns3::Ipv4GlobalRouting’
debug/ns3/global-router-interface.h:40: error: forward declaration of
‘struct ns3::Ipv4GlobalRouting’
../scratch/rys10Glob.cc:237: error: invalid use of incomplete type
‘struct ns3::Ipv4GlobalRouting’
debug/ns3/global-router-interface.h:40: error: forward declaration of
‘struct ns3::Ipv4GlobalRouting’
../scratch/rys10Glob.cc:242: error: expected primary-expression before
‘<<’ token
debug/ns3/ptr.h: In destructor ‘ns3::Ptr<T>::~Ptr() [with T =
ns3::Ipv4GlobalRouting]’:
../scratch/rys10Glob.cc:230: instantiated from here
debug/ns3/ptr.h:441: error: invalid use of incomplete type ‘struct
ns3::Ipv4GlobalRouting’
debug/ns3/global-router-interface.h:40: error: forward declaration of
‘struct ns3::Ipv4GlobalRouting’
debug/ns3/ptr.h: In member function ‘void ns3::Ptr<T>::Acquire() const
[with T = ns3::Ipv4GlobalRouting]’:
debug/ns3/ptr.h:426: instantiated from ‘ns3::Ptr<T>::Ptr(const
ns3::Ptr<T>&) [with T = ns3::Ipv4GlobalRouting]’
../scratch/rys10Glob.cc:230: instantiated from here
debug/ns3/ptr.h:396: error: invalid use of incomplete type ‘struct
ns3::Ipv4GlobalRouting’
debug/ns3/global-router-interface.h:40: error: forward declaration of
‘struct ns3::Ipv4GlobalRouting’
Waf: Leaving directory `/home/slawek/repos2/ns-allinone-3.8/ns-3.8/
build'
Build failed: -> task failed (err #1):
{task: cxx rys10Glob.cc -> rys10Glob_1.o}

Thanks in advance for your help.

On 12 Sie, 17:12, Быков Евгений <bikov...@gmail.com> wrote:
> Probably it will be a good idea to show log of errors and node topology.
> 0.0.0.0 gateway may not be as bad as it seems
>
> 2010/8/12 Slawek <slawmac...@gmail.com>
> > ns-3-users+...@googlegroups.com<ns-3-users%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages