From 3d32a4d0d20417d78b61c46bdd3806dfd50d33ad Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 12 Feb 2007 22:44:41 +0100 Subject: [PATCH] add routing table output function --- SConstruct | 2 +- samples/main-simple-p2p.cc | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 55d9dd59c..a487f95cf 100644 --- a/SConstruct +++ b/SConstruct @@ -193,7 +193,6 @@ node.add_headers ([ 'l3-protocol.h', 'ipv4-l4-demux.h', 'net-device-list.h', - 'ipv4-route.h', 'llc-snap-header.h', 'header-utils.h', ]) @@ -209,6 +208,7 @@ node.add_inst_headers ([ 'ipv4-interface.h', 'mac-address.h', 'ipv4.h', + 'ipv4-route.h', ]) diff --git a/samples/main-simple-p2p.cc b/samples/main-simple-p2p.cc index 6f396e572..d53352d0f 100644 --- a/samples/main-simple-p2p.cc +++ b/samples/main-simple-p2p.cc @@ -1,4 +1,5 @@ #include +#include #include "ns3/internet-node.h" #include "ns3/simulator.h" @@ -8,6 +9,7 @@ #include "ns3/p2p-net-device.h" #include "ns3/ipv4.h" #include "ns3/arp-ipv4-interface.h" +#include "ns3/ipv4-route.h" using namespace ns3; @@ -41,7 +43,20 @@ DestroyP2PNetDevice (P2PNetDevice *dev) delete dev; } -void +static void +PrintRoutingTable (InternetNode *a, std::string name) +{ + Ipv4 *ipv4 = a->GetIpv4 (); + std::cout << "routing table start node=" << name << std::endl; + for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++) + { + Ipv4Route *route = ipv4->GetRoute (i); + std::cout << (*route) << std::endl; + } + std::cout << "routing table end" << std::endl; +} + +static void AddP2PLink (InternetNode *a, InternetNode *b) { P2PChannel * channel = new P2PChannel (MilliSeconds (20), 1000); @@ -55,6 +70,8 @@ AddP2PLink (InternetNode *a, InternetNode *b) Ipv4Address ipb = Ipv4Address ("192.168.0.3"); a->GetIpv4 ()->AddHostRouteTo (ipb, indexA); b->GetIpv4 ()->AddHostRouteTo (ipa, indexB); + PrintRoutingTable (a, "a"); + PrintRoutingTable (b, "b"); } int main (int argc, char *argv[]) @@ -68,7 +85,7 @@ int main (int argc, char *argv[]) UdpSocket *sink = new UdpSocket (a); sink->Bind (80); UdpSocket *source = new UdpSocket (b); - source->SetDefaultDestination (Ipv4Address::GetLoopback (), 80); + source->SetDefaultDestination (Ipv4Address ("192.168.0.2"), 80); GenerateTraffic (source, 500); PrintTraffic (sink);