Print Routing Table

181 views
Skip to first unread message

netwo...@gmail.com

unread,
Feb 23, 2017, 6:39:13 AM2/23/17
to ns-3-users
Hi,
To gather more information, i want to print Routing Tables
Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
std::vector<RoutingTableEntry> entry = routing -> GetRoutingTableEntries();
//        std::cout << "Routing table for device: " << Names::FindName(node)<< std::endl;
std::cout << "Routing table for device: " << node->GetId() << std::endl;
std::cout << "DestinyAddress\t\tNextAddress\t\tInterface\t\tDistance\n";
for (std::vector < RoutingTableEntry, std::allocator<RoutingTableEntry>::iterator i = entry.begin(); i != entry.end(); i++)
{
std::cout << i->destAddr << "\t\t"
         << i->nextAddr << "\t\t"
         << i->interface << "\t\t"
         << i->distance << std::endl;
}
But when i try to run this codes it show

/scratch/final-multipath.cc: In function ‘int main(int, char**)’:
../scratch/final-multipath.cc:323:6: error: ‘RoutingProtocol’ was not declared in this scope
  Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
      ^
../scratch/final-multipath.cc:323:21: error: template argument 1 is invalid
  Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
                     ^
../scratch/final-multipath.cc:323:31: error: invalid type in declaration before ‘=’ token
  Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
                               ^
../scratch/final-multipath.cc:323:33: error: ‘node’ was not declared in this scope
  Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
                                 ^
../scratch/final-multipath.cc:323:68: error: expected primary-expression before ‘)’ token
  Ptr<RoutingProtocol> routing = node -> GetObject<RoutingProtocol>();
                                                                    ^
../scratch/final-multipath.cc:324:14: error: ‘RoutingTableEntry’ was not declared in this scope
  std::vector<RoutingTableEntry> entry = routing -> GetRoutingTableEntries();
              ^
../scratch/final-multipath.cc:324:31: error: template argument 1 is invalid
  std::vector<RoutingTableEntry> entry = routing -> GetRoutingTableEntries();
                               ^
../scratch/final-multipath.cc:324:31: error: template argument 2 is invalid
../scratch/final-multipath.cc:324:39: error: invalid type in declaration before ‘=’ token
  std::vector<RoutingTableEntry> entry = routing -> GetRoutingTableEntries();
                                       ^
../scratch/final-multipath.cc:324:49: error: base operand of ‘->’ is not a pointer
  std::vector<RoutingTableEntry> entry = routing -> GetRoutingTableEntries();
                                                 ^
../scratch/final-multipath.cc:328:72: error: type/value mismatch at argument 1 in template parameter list for ‘template<class> class std::allocator’
  for (std::vector < RoutingTableEntry, std::allocator<RoutingTableEntry>::iterator i = entry.begin(); i != entry.end(); i++)
                                                                        ^
../scratch/final-multipath.cc:328:72: error:   expected a type, got ‘RoutingTableEntry’
../scratch/final-multipath.cc:328:100: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
  for (std::vector < RoutingTableEntry, std::allocator<RoutingTableEntry>::iterator i = entry.begin(); i != entry.end(); i++)
                                                                                                    ^
../scratch/final-multipath.cc:328:100: error:   expected a type, got ‘RoutingTableEntry’
../scratch/final-multipath.cc:328:100: error: template argument 2 is invalid
../scratch/final-multipath.cc:328:103: error: name lookup of ‘i’ changed [-Werror]
  for (std::vector < RoutingTableEntry, std::allocator<RoutingTableEntry>::iterator i = entry.begin(); i != entry.end(); i++)
                                                                                                       ^
In file included from ../scratch/final-multipath.cc:6:0:
../scratch/../src/ospf/model/ipv4-ospf-routing.cc:27:5: error:   matches this ‘i’ under ISO standard rules [-Werror]
 int i,vs,vd,l,c,f1,f2;int npaths=7;
     ^
../scratch/final-multipath.cc:300:64: error:   matches this ‘i’ under old rules [-Werror]
  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); i++)
                                                                ^
../scratch/final-multipath.cc:328:114: error: request for member ‘end’ in ‘entry’, which is of non-class type ‘int’
  for (std::vector < RoutingTableEntry, std::allocator<RoutingTableEntry>::iterator i = entry.begin(); i != entry.end(); i++)
                                                                                                                  ^
../scratch/final-multipath.cc:330:17: error: base operand of ‘->’ is not a pointer
   std::cout << i->destAddr << "\t\t"
                 ^
../scratch/final-multipath.cc:331:17: error: base operand of ‘->’ is not a pointer
             << i->nextAddr << "\t\t"
                 ^
../scratch/final-multipath.cc:332:17: error: base operand of ‘->’ is not a pointer
             << i->interface << "\t\t"
                 ^
../scratch/final-multipath.cc:333:17: error: base operand of ‘->’ is not a pointer
             << i->distance << std::endl;
                 ^



what am i doing wrong,
a little point to right direction would be appreciated.

Thanks

PS. I have attached my code in which i want routing table output.

Regards
final-multipath.cc

Krishna Bharadwaj

unread,
Feb 24, 2017, 1:14:09 AM2/24/17
to ns-3-users
Hi,

Mention the protocol which you are using, Routing Protocol is the name given in olsr. To use that you must specify like this --
Ptr <ns3::olsr::RoutingProtocol>. If you're not using olsr then specify that particular routing protocol in the pointer definition. Of course I didn't find any such thing in your code.

Secondly don't use const_iterator i. Instead use and try this
for (std::map<FlowId, FlowMonitor::FlowStats>::iterator i = stats.begin (); i != stats.end (); i++)

Regards,
Krishna.

Konstantinos

unread,
Feb 24, 2017, 5:17:38 AM2/24/17
to ns-3-users
I would suggest to create a simpler PrintRoutingTable method in your routing protocol, as required by the abstract Ipv4RoutingProtocol class

netwo...@gmail.com

unread,
Feb 24, 2017, 10:48:02 PM2/24/17
to ns-3-users
Hi,

Thank you Mr. K and Mr. K.B
I will work on that and hopefully i will get what i want.

Regards
V
Reply all
Reply to author
Forward
0 new messages