add routing table output function
This commit is contained in:
@@ -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',
|
||||
])
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user