Move tests from the internet module to its test library
This commit is contained in:
@@ -2191,211 +2191,3 @@ GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <stdlib.h> // for rand()
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class GlobalRouteManagerImplTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
GlobalRouteManagerImplTestCase();
|
||||
virtual void DoRun(void);
|
||||
};
|
||||
|
||||
GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase()
|
||||
: TestCase("GlobalRouteManagerImplTestCase")
|
||||
{}
|
||||
void
|
||||
GlobalRouteManagerImplTestCase::DoRun(void)
|
||||
{
|
||||
CandidateQueue candidate;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
SPFVertex *v = new SPFVertex;
|
||||
v->SetDistanceFromRoot (rand () % 100);
|
||||
candidate.Push (v);
|
||||
}
|
||||
|
||||
uint32_t lastDistance = 0;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
SPFVertex *v = candidate.Pop ();
|
||||
if (v->GetDistanceFromRoot () < lastDistance)
|
||||
{
|
||||
// XXX does nothing.
|
||||
UpdateErrorStatus (false);
|
||||
}
|
||||
lastDistance = v->GetDistanceFromRoot ();
|
||||
delete v;
|
||||
v = 0;
|
||||
}
|
||||
|
||||
// Build fake link state database; four routers (0-3), 3 point-to-point
|
||||
// links
|
||||
//
|
||||
// n0
|
||||
// \ link 0
|
||||
// \ link 2
|
||||
// n2 -------------------------n3
|
||||
// /
|
||||
// / link 1
|
||||
// n1
|
||||
//
|
||||
// link0: 10.1.1.1/30, 10.1.1.2/30
|
||||
// link1: 10.1.2.1/30, 10.1.2.2/30
|
||||
// link2: 10.1.3.1/30, 10.1.3.2/30
|
||||
//
|
||||
// Router 0
|
||||
GlobalRoutingLinkRecord* lr0 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2", // router ID 0.0.0.2
|
||||
"10.1.1.1", // local ID
|
||||
1); // metric
|
||||
|
||||
GlobalRoutingLinkRecord* lr1 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.1.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa0 = new GlobalRoutingLSA ();
|
||||
lsa0->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa0->SetLinkStateId ("0.0.0.0");
|
||||
lsa0->SetAdvertisingRouter ("0.0.0.0");
|
||||
lsa0->AddLinkRecord (lr0);
|
||||
lsa0->AddLinkRecord (lr1);
|
||||
|
||||
// Router 1
|
||||
GlobalRoutingLinkRecord* lr2 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr3 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa1 = new GlobalRoutingLSA ();
|
||||
lsa1->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa1->SetLinkStateId ("0.0.0.1");
|
||||
lsa1->SetAdvertisingRouter ("0.0.0.1");
|
||||
lsa1->AddLinkRecord (lr2);
|
||||
lsa1->AddLinkRecord (lr3);
|
||||
|
||||
// Router 2
|
||||
GlobalRoutingLinkRecord* lr4 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.0",
|
||||
"10.1.1.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr5 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.1.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr6 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.1",
|
||||
"10.1.2.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr7 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr8 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.3",
|
||||
"10.1.3.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr9 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.3.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa2 = new GlobalRoutingLSA ();
|
||||
lsa2->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa2->SetLinkStateId ("0.0.0.2");
|
||||
lsa2->SetAdvertisingRouter ("0.0.0.2");
|
||||
lsa2->AddLinkRecord (lr4);
|
||||
lsa2->AddLinkRecord (lr5);
|
||||
lsa2->AddLinkRecord (lr6);
|
||||
lsa2->AddLinkRecord (lr7);
|
||||
lsa2->AddLinkRecord (lr8);
|
||||
lsa2->AddLinkRecord (lr9);
|
||||
|
||||
// Router 3
|
||||
GlobalRoutingLinkRecord* lr10 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr11 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa3 = new GlobalRoutingLSA ();
|
||||
lsa3->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa3->SetLinkStateId ("0.0.0.3");
|
||||
lsa3->SetAdvertisingRouter ("0.0.0.3");
|
||||
lsa3->AddLinkRecord (lr10);
|
||||
lsa3->AddLinkRecord (lr11);
|
||||
|
||||
// Test the database
|
||||
GlobalRouteManagerLSDB* srmlsdb = new GlobalRouteManagerLSDB ();
|
||||
srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0);
|
||||
srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1);
|
||||
srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2);
|
||||
srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3);
|
||||
NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ()));
|
||||
|
||||
// next, calculate routes based on the manually created LSDB
|
||||
GlobalRouteManagerImpl* srm = new GlobalRouteManagerImpl ();
|
||||
srm->DebugUseLsdb (srmlsdb); // manually add in an LSDB
|
||||
// Note-- this will succeed without any nodes in the topology
|
||||
// because the NodeList is empty
|
||||
srm->DebugSPFCalculate (lsa0->GetLinkStateId ()); // node n0
|
||||
|
||||
Simulator::Run ();
|
||||
|
||||
// XXX here we should do some verification of the routes built
|
||||
|
||||
Simulator::Destroy ();
|
||||
|
||||
// This delete clears the srm, which deletes the LSDB, which clears
|
||||
// all of the LSAs, which each destroys the attached LinkRecords.
|
||||
delete srm;
|
||||
|
||||
// XXX
|
||||
// No testing has actually been done other than making sure that this code
|
||||
// does not crash
|
||||
}
|
||||
|
||||
|
||||
static class GlobalRouteManagerImplTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
GlobalRouteManagerImplTestSuite()
|
||||
: TestSuite("global-route-manager-impl", UNIT)
|
||||
{
|
||||
AddTestCase(new GlobalRouteManagerImplTestCase());
|
||||
}
|
||||
} g_globalRoutingManagerImplTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -295,111 +295,3 @@ Ipv4ListRouting::Compare (const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingPr
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ipv4-list-routing.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4ARouting : public Ipv4RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void SetIpv4 (Ptr<Ipv4> ipv4) {}
|
||||
void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {}
|
||||
};
|
||||
|
||||
class Ipv4BRouting : public Ipv4RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void SetIpv4 (Ptr<Ipv4> ipv4) {}
|
||||
void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {}
|
||||
};
|
||||
|
||||
class Ipv4ListRoutingNegativeTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingNegativeTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase()
|
||||
: TestCase("Check negative priorities")
|
||||
{}
|
||||
void
|
||||
Ipv4ListRoutingNegativeTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
|
||||
// The Ipv4BRouting should be added with higher priority (larger integer value)
|
||||
lr->AddRoutingProtocol (aRouting, -10);
|
||||
lr->AddRoutingProtocol (bRouting, -5);
|
||||
int16_t first = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
class Ipv4ListRoutingPositiveTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingPositiveTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase()
|
||||
: TestCase("Check positive priorities")
|
||||
{}
|
||||
void
|
||||
Ipv4ListRoutingPositiveTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
|
||||
// The Ipv4ARouting should be added with higher priority (larger integer
|
||||
// value) and will be fetched first below
|
||||
lr->AddRoutingProtocol (aRouting, 10);
|
||||
lr->AddRoutingProtocol (bRouting, 5);
|
||||
int16_t first = 3;
|
||||
int16_t second = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
|
||||
NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
static class Ipv4ListRoutingTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingTestSuite()
|
||||
: TestSuite("ipv4-list-routing", UNIT)
|
||||
{
|
||||
AddTestCase(new Ipv4ListRoutingPositiveTestCase());
|
||||
AddTestCase(new Ipv4ListRoutingNegativeTestCase());
|
||||
}
|
||||
|
||||
} g_ipv4ListRoutingTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/test.h"
|
||||
#include "ipv4-packet-info-tag.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -139,187 +138,3 @@ Ipv4PacketInfoTag::Print (std::ostream &os) const
|
||||
}
|
||||
}//namespace ns3
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Unit tests
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/attribute.h"
|
||||
#include "ns3/simple-net-device.h"
|
||||
#include "ns3/object-factory.h"
|
||||
#include "ns3/socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/inet-socket-address.h"
|
||||
#include "ns3/ipv4-l3-protocol.h"
|
||||
#include "ns3/ipv4-raw-socket-factory.h"
|
||||
#include "ns3/ipv4-interface.h"
|
||||
#include "ns3/arp-l3-protocol.h"
|
||||
#include "ns3/icmpv4-l4-protocol.h"
|
||||
#include "ns3/ipv4-static-routing.h"
|
||||
#include "ns3/ipv4-list-routing.h"
|
||||
#include "ns3/udp-l4-protocol.h"
|
||||
#include "ns3/tcp-l4-protocol.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static void
|
||||
AddInternetStack (Ptr<Node> node)
|
||||
{
|
||||
//ARP
|
||||
Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
|
||||
node->AggregateObject(arp);
|
||||
//IPV4
|
||||
Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
|
||||
//Routing for Ipv4
|
||||
Ptr<Ipv4ListRouting> ipv4Routing = CreateObject<Ipv4ListRouting> ();
|
||||
ipv4->SetRoutingProtocol (ipv4Routing);
|
||||
Ptr<Ipv4StaticRouting> ipv4staticRouting = CreateObject<Ipv4StaticRouting> ();
|
||||
ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
|
||||
node->AggregateObject(ipv4);
|
||||
//ICMP
|
||||
Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol> ();
|
||||
node->AggregateObject(icmp);
|
||||
//UDP
|
||||
Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
|
||||
node->AggregateObject(udp);
|
||||
}
|
||||
|
||||
class Ipv4PacketInfoTagTest: public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4PacketInfoTagTest ();
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
void RxCb (Ptr<Socket> socket);
|
||||
void DoSendData (Ptr<Socket> socket, std::string to);
|
||||
};
|
||||
|
||||
Ipv4PacketInfoTagTest::Ipv4PacketInfoTagTest ()
|
||||
: TestCase ("Ipv4PacketInfoTagTest")
|
||||
{}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::RxCb (Ptr<Socket> socket)
|
||||
{
|
||||
uint32_t availableData;
|
||||
Ptr<Packet> m_receivedPacket;
|
||||
|
||||
availableData = socket->GetRxAvailable ();
|
||||
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
|
||||
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
|
||||
|
||||
Ipv4PacketInfoTag tag;
|
||||
bool found;
|
||||
found = m_receivedPacket->RemovePacketTag (tag);
|
||||
NS_ASSERT (found);
|
||||
tag.Print (std::cout);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
|
||||
{
|
||||
Address realTo = InetSocketAddress (Ipv4Address (to.c_str()), 200);
|
||||
if (DynamicCast<UdpSocket> (socket) != 0)
|
||||
{
|
||||
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
|
||||
123, "XXX");
|
||||
}
|
||||
// Should only Ipv4RawSock
|
||||
else
|
||||
{
|
||||
socket->SendTo (Create<Packet> (123), 0, realTo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::DoRun (void)
|
||||
{
|
||||
Ptr<Node> node0 = CreateObject<Node> ();
|
||||
Ptr<Node> node1 = CreateObject<Node> ();
|
||||
|
||||
Ptr<SimpleNetDevice> device = CreateObject<SimpleNetDevice> ();
|
||||
Ptr<SimpleNetDevice> device2 = CreateObject<SimpleNetDevice> ();
|
||||
|
||||
// For Node 0
|
||||
node0->AddDevice (device);
|
||||
AddInternetStack (node0);
|
||||
Ptr<Ipv4> ipv4 = node0->GetObject<Ipv4> ();
|
||||
|
||||
uint32_t index = ipv4->AddInterface (device);
|
||||
Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("10.1.1.1",
|
||||
"255.255.255.0");
|
||||
ipv4->AddAddress (index, ifaceAddr1);
|
||||
ipv4->SetMetric (index, 1);
|
||||
ipv4->SetUp (index);
|
||||
|
||||
// For Node 1
|
||||
node1->AddDevice (device2);
|
||||
AddInternetStack (node1);
|
||||
ipv4 = node1->GetObject<Ipv4> ();
|
||||
|
||||
index = ipv4->AddInterface (device2);
|
||||
Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("10.1.1.2",
|
||||
"255.255.255.0");
|
||||
ipv4->AddAddress (index, ifaceAddr2);
|
||||
ipv4->SetMetric (index, 1);
|
||||
ipv4->SetUp (index);
|
||||
|
||||
// IPv4 test
|
||||
Ptr<SocketFactory> factory = node0->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket = factory->CreateSocket ();
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 200);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
|
||||
Simulator::Run ();
|
||||
|
||||
Ptr<SocketFactory> factory2 = node1->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
|
||||
// ipv4 w rawsocket
|
||||
factory = node0->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
|
||||
socket = factory->CreateSocket ();
|
||||
local = InetSocketAddress (Ipv4Address::GetAny (), 0);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
|
||||
Simulator::Run ();
|
||||
|
||||
factory2 = node1->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
|
||||
socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
static class Ipv4PacketInfoTagTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv4PacketInfoTagTestSuite ();
|
||||
private:
|
||||
} g_packetinfotagTests;
|
||||
|
||||
Ipv4PacketInfoTagTestSuite::Ipv4PacketInfoTagTestSuite ()
|
||||
: TestSuite ("ipv4-packet-info-tag", UNIT)
|
||||
{
|
||||
AddTestCase (new Ipv4PacketInfoTagTest ());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define __IPV4_PACKET_INFO_TAG_H__
|
||||
|
||||
#include "ns3/tag.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
|
||||
@@ -333,114 +333,3 @@ Ipv6ListRouting::Compare (const Ipv6RoutingProtocolEntry& a, const Ipv6RoutingPr
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ipv6-list-routing.h"
|
||||
#include "ns3/ipv6-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv6ARouting : public Ipv6RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
|
||||
GetZero ()) {}
|
||||
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
|
||||
void SetIpv6 (Ptr<Ipv6> ipv6) {}
|
||||
};
|
||||
|
||||
class Ipv6BRouting : public Ipv6RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
|
||||
GetZero ()) {}
|
||||
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
|
||||
void SetIpv6 (Ptr<Ipv6> ipv6) {}
|
||||
};
|
||||
|
||||
class Ipv6ListRoutingNegativeTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingNegativeTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv6ListRoutingNegativeTestCase::Ipv6ListRoutingNegativeTestCase()
|
||||
: TestCase("Check negative priorities")
|
||||
{}
|
||||
void
|
||||
Ipv6ListRoutingNegativeTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
|
||||
// The Ipv6BRouting should be added with higher priority (larger integer value)
|
||||
lr->AddRoutingProtocol (aRouting, -10);
|
||||
lr->AddRoutingProtocol (bRouting, -5);
|
||||
int16_t first = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
class Ipv6ListRoutingPositiveTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingPositiveTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv6ListRoutingPositiveTestCase::Ipv6ListRoutingPositiveTestCase()
|
||||
: TestCase("Check positive priorities")
|
||||
{}
|
||||
void
|
||||
Ipv6ListRoutingPositiveTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
|
||||
// The Ipv6ARouting should be added with higher priority (larger integer
|
||||
// value) and will be fetched first below
|
||||
lr->AddRoutingProtocol (aRouting, 10);
|
||||
lr->AddRoutingProtocol (bRouting, 5);
|
||||
int16_t first = 3;
|
||||
int16_t second = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
|
||||
NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
static class Ipv6ListRoutingTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingTestSuite()
|
||||
: TestSuite("ipv6-list-routing", UNIT)
|
||||
{
|
||||
AddTestCase(new Ipv6ListRoutingPositiveTestCase());
|
||||
AddTestCase(new Ipv6ListRoutingNegativeTestCase());
|
||||
}
|
||||
|
||||
} g_ipv6ListRoutingTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/ipv6-address.h"
|
||||
#include "ns3/test.h"
|
||||
#include "ipv6-packet-info-tag.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -137,196 +136,3 @@ Ipv6PacketInfoTag::Print (std::ostream &os) const
|
||||
}
|
||||
}//namespace ns3
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Unit tests
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/attribute.h"
|
||||
#include "ns3/simple-net-device.h"
|
||||
#include "ns3/object-factory.h"
|
||||
#include "ns3/socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/ipv6-l3-protocol.h"
|
||||
#include "ns3/ipv6-raw-socket-factory.h"
|
||||
#include "ns3/ipv6-interface.h"
|
||||
#include "ns3/icmpv6-l4-protocol.h"
|
||||
#include "ns3/ipv6-static-routing.h"
|
||||
#include "ns3/ipv6-list-routing.h"
|
||||
#include "ns3/inet6-socket-address.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static void
|
||||
AddInternetStack (Ptr<Node> node)
|
||||
{
|
||||
Ptr<Ipv6L3Protocol> ipv6 = CreateObject<Ipv6L3Protocol> ();
|
||||
Ptr<Icmpv6L4Protocol> icmpv6 = CreateObject<Icmpv6L4Protocol> ();
|
||||
node->AggregateObject (ipv6);
|
||||
node->AggregateObject (icmpv6);
|
||||
ipv6->Insert (icmpv6);
|
||||
icmpv6->SetAttribute ("DAD", BooleanValue (false));
|
||||
|
||||
//Routing for Ipv6
|
||||
Ptr<Ipv6ListRouting> ipv6Routing = CreateObject<Ipv6ListRouting> ();
|
||||
ipv6->SetRoutingProtocol (ipv6Routing);
|
||||
Ptr<Ipv6StaticRouting> ipv6staticRouting = CreateObject<Ipv6StaticRouting> ();
|
||||
ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
|
||||
|
||||
/* register IPv6 extensions and options */
|
||||
ipv6->RegisterExtensions ();
|
||||
ipv6->RegisterOptions ();
|
||||
}
|
||||
|
||||
class Ipv6PacketInfoTagTest: public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6PacketInfoTagTest ();
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
void RxCb (Ptr<Socket> socket);
|
||||
void DoSendData (Ptr<Socket> socket, std::string to);
|
||||
};
|
||||
|
||||
Ipv6PacketInfoTagTest::Ipv6PacketInfoTagTest ()
|
||||
: TestCase ("Ipv6PacketInfoTagTest")
|
||||
{}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::RxCb (Ptr<Socket> socket)
|
||||
{
|
||||
uint32_t availableData;
|
||||
Ptr<Packet> m_receivedPacket;
|
||||
|
||||
availableData = socket->GetRxAvailable ();
|
||||
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
|
||||
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
|
||||
|
||||
Ipv6PacketInfoTag tag;
|
||||
bool found;
|
||||
found = m_receivedPacket->RemovePacketTag (tag);
|
||||
NS_ASSERT (found);
|
||||
tag.Print (std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
|
||||
{
|
||||
Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str()), 200);
|
||||
if (DynamicCast<UdpSocket> (socket) != 0)
|
||||
{
|
||||
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
|
||||
123, "XXX");
|
||||
}
|
||||
// Should only Ipv6RawSock
|
||||
else
|
||||
{
|
||||
socket->SendTo (Create<Packet> (123), 0, realTo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::DoRun (void)
|
||||
{
|
||||
Ptr<Node> node0 = CreateObject<Node> ();
|
||||
Ptr<Node> node1 = CreateObject<Node> ();
|
||||
|
||||
Ptr<SimpleNetDevice> device = CreateObject<SimpleNetDevice> ();
|
||||
Ptr<SimpleNetDevice> device2 = CreateObject<SimpleNetDevice> ();
|
||||
|
||||
// For Node 0
|
||||
node0->AddDevice (device);
|
||||
AddInternetStack (node0);
|
||||
Ptr<Ipv6> ipv6 = node0->GetObject<Ipv6> ();
|
||||
|
||||
uint32_t index = ipv6->AddInterface (device);
|
||||
Ipv6InterfaceAddress ifaceAddr1 = Ipv6InterfaceAddress (Ipv6Address("2000:1000:0:2000::1"),
|
||||
Ipv6Prefix(64));
|
||||
ipv6->AddAddress (index, ifaceAddr1);
|
||||
ipv6->SetMetric (index, 1);
|
||||
ipv6->SetUp (index);
|
||||
|
||||
// For Node 1
|
||||
node1->AddDevice (device2);
|
||||
AddInternetStack (node1);
|
||||
ipv6 = node1->GetObject<Ipv6> ();
|
||||
|
||||
index = ipv6->AddInterface (device2);
|
||||
Ipv6InterfaceAddress ifaceAddr2 = Ipv6InterfaceAddress (Ipv6Address("2000:1000:0:2000::2"),
|
||||
Ipv6Prefix(64));
|
||||
ipv6->AddAddress (index, ifaceAddr2);
|
||||
ipv6->SetMetric (index, 1);
|
||||
ipv6->SetUp (index);
|
||||
|
||||
// ipv6 w rawsocket
|
||||
Ptr<SocketFactory> factory = node0->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket = factory->CreateSocket ();
|
||||
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address::GetAny (), 0);
|
||||
socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
|
||||
Simulator::Run ();
|
||||
|
||||
Ptr<SocketFactory> factory2 = node1->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket2 = factory2->CreateSocket ();
|
||||
std::stringstream dst;
|
||||
dst << ifaceAddr1.GetAddress ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket,
|
||||
dst.str ());
|
||||
Simulator::Run ();
|
||||
|
||||
#ifdef UDP6_SUPPORTED
|
||||
// IPv6 test
|
||||
factory = node0->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
socket = factory->CreateSocket ();
|
||||
local = Inet6SocketAddress (Ipv6Address::GetAny (), 200);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
|
||||
Simulator::Run ();
|
||||
|
||||
factory2 = node1->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
|
||||
#endif // UDP6_SUPPORTED
|
||||
|
||||
Simulator::Destroy ();
|
||||
// IPv6 test
|
||||
}
|
||||
|
||||
static class Ipv6PacketInfoTagTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv6PacketInfoTagTestSuite ();
|
||||
private:
|
||||
} g_packetinfotagTests;
|
||||
|
||||
Ipv6PacketInfoTagTestSuite::Ipv6PacketInfoTagTestSuite ()
|
||||
: TestSuite ("ipv6-packet-info-tag", UNIT)
|
||||
{
|
||||
AddTestCase (new Ipv6PacketInfoTagTest ());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define __IPV6_PACKET_INFO_TAG_H__
|
||||
|
||||
#include "ns3/tag.h"
|
||||
#include "ns3/ipv6-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
|
||||
234
src/internet/test/global-route-manager-impl-test-suite.cc
Normal file
234
src/internet/test/global-route-manager-impl-test-suite.cc
Normal file
@@ -0,0 +1,234 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright 2007 University of Washington
|
||||
* Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors: Tom Henderson (tomhend@u.washington.edu)
|
||||
*
|
||||
* Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
|
||||
* of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
|
||||
*/
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/global-route-manager-impl.h"
|
||||
#include "ns3/candidate-queue.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <stdlib.h> // for rand()
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class GlobalRouteManagerImplTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
GlobalRouteManagerImplTestCase();
|
||||
virtual void DoRun(void);
|
||||
};
|
||||
|
||||
GlobalRouteManagerImplTestCase::GlobalRouteManagerImplTestCase()
|
||||
: TestCase("GlobalRouteManagerImplTestCase")
|
||||
{}
|
||||
void
|
||||
GlobalRouteManagerImplTestCase::DoRun(void)
|
||||
{
|
||||
CandidateQueue candidate;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
SPFVertex *v = new SPFVertex;
|
||||
v->SetDistanceFromRoot (rand () % 100);
|
||||
candidate.Push (v);
|
||||
}
|
||||
|
||||
uint32_t lastDistance = 0;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
SPFVertex *v = candidate.Pop ();
|
||||
if (v->GetDistanceFromRoot () < lastDistance)
|
||||
{
|
||||
// XXX does nothing.
|
||||
UpdateErrorStatus (false);
|
||||
}
|
||||
lastDistance = v->GetDistanceFromRoot ();
|
||||
delete v;
|
||||
v = 0;
|
||||
}
|
||||
|
||||
// Build fake link state database; four routers (0-3), 3 point-to-point
|
||||
// links
|
||||
//
|
||||
// n0
|
||||
// \ link 0
|
||||
// \ link 2
|
||||
// n2 -------------------------n3
|
||||
// /
|
||||
// / link 1
|
||||
// n1
|
||||
//
|
||||
// link0: 10.1.1.1/30, 10.1.1.2/30
|
||||
// link1: 10.1.2.1/30, 10.1.2.2/30
|
||||
// link2: 10.1.3.1/30, 10.1.3.2/30
|
||||
//
|
||||
// Router 0
|
||||
GlobalRoutingLinkRecord* lr0 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2", // router ID 0.0.0.2
|
||||
"10.1.1.1", // local ID
|
||||
1); // metric
|
||||
|
||||
GlobalRoutingLinkRecord* lr1 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.1.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa0 = new GlobalRoutingLSA ();
|
||||
lsa0->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa0->SetLinkStateId ("0.0.0.0");
|
||||
lsa0->SetAdvertisingRouter ("0.0.0.0");
|
||||
lsa0->AddLinkRecord (lr0);
|
||||
lsa0->AddLinkRecord (lr1);
|
||||
|
||||
// Router 1
|
||||
GlobalRoutingLinkRecord* lr2 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr3 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa1 = new GlobalRoutingLSA ();
|
||||
lsa1->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa1->SetLinkStateId ("0.0.0.1");
|
||||
lsa1->SetAdvertisingRouter ("0.0.0.1");
|
||||
lsa1->AddLinkRecord (lr2);
|
||||
lsa1->AddLinkRecord (lr3);
|
||||
|
||||
// Router 2
|
||||
GlobalRoutingLinkRecord* lr4 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.0",
|
||||
"10.1.1.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr5 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.1.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr6 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.1",
|
||||
"10.1.2.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr7 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr8 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.3",
|
||||
"10.1.3.2",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr9 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.3.2",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa2 = new GlobalRoutingLSA ();
|
||||
lsa2->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa2->SetLinkStateId ("0.0.0.2");
|
||||
lsa2->SetAdvertisingRouter ("0.0.0.2");
|
||||
lsa2->AddLinkRecord (lr4);
|
||||
lsa2->AddLinkRecord (lr5);
|
||||
lsa2->AddLinkRecord (lr6);
|
||||
lsa2->AddLinkRecord (lr7);
|
||||
lsa2->AddLinkRecord (lr8);
|
||||
lsa2->AddLinkRecord (lr9);
|
||||
|
||||
// Router 3
|
||||
GlobalRoutingLinkRecord* lr10 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::PointToPoint,
|
||||
"0.0.0.2",
|
||||
"10.1.2.1",
|
||||
1);
|
||||
|
||||
GlobalRoutingLinkRecord* lr11 = new GlobalRoutingLinkRecord (
|
||||
GlobalRoutingLinkRecord::StubNetwork,
|
||||
"10.1.2.1",
|
||||
"255.255.255.252",
|
||||
1);
|
||||
|
||||
GlobalRoutingLSA* lsa3 = new GlobalRoutingLSA ();
|
||||
lsa3->SetLSType (GlobalRoutingLSA::RouterLSA);
|
||||
lsa3->SetLinkStateId ("0.0.0.3");
|
||||
lsa3->SetAdvertisingRouter ("0.0.0.3");
|
||||
lsa3->AddLinkRecord (lr10);
|
||||
lsa3->AddLinkRecord (lr11);
|
||||
|
||||
// Test the database
|
||||
GlobalRouteManagerLSDB* srmlsdb = new GlobalRouteManagerLSDB ();
|
||||
srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0);
|
||||
srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1);
|
||||
srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2);
|
||||
srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3);
|
||||
NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ()));
|
||||
|
||||
// next, calculate routes based on the manually created LSDB
|
||||
GlobalRouteManagerImpl* srm = new GlobalRouteManagerImpl ();
|
||||
srm->DebugUseLsdb (srmlsdb); // manually add in an LSDB
|
||||
// Note-- this will succeed without any nodes in the topology
|
||||
// because the NodeList is empty
|
||||
srm->DebugSPFCalculate (lsa0->GetLinkStateId ()); // node n0
|
||||
|
||||
Simulator::Run ();
|
||||
|
||||
// XXX here we should do some verification of the routes built
|
||||
|
||||
Simulator::Destroy ();
|
||||
|
||||
// This delete clears the srm, which deletes the LSDB, which clears
|
||||
// all of the LSAs, which each destroys the attached LinkRecords.
|
||||
delete srm;
|
||||
|
||||
// XXX
|
||||
// No testing has actually been done other than making sure that this code
|
||||
// does not crash
|
||||
}
|
||||
|
||||
|
||||
static class GlobalRouteManagerImplTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
GlobalRouteManagerImplTestSuite()
|
||||
: TestSuite("global-route-manager-impl", UNIT)
|
||||
{
|
||||
AddTestCase(new GlobalRouteManagerImplTestCase());
|
||||
}
|
||||
} g_globalRoutingManagerImplTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
127
src/internet/test/ipv4-list-routing-test-suite.cc
Normal file
127
src/internet/test/ipv4-list-routing-test-suite.cc
Normal file
@@ -0,0 +1,127 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/ipv4-list-routing.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4ARouting : public Ipv4RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void SetIpv4 (Ptr<Ipv4> ipv4) {}
|
||||
void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {}
|
||||
};
|
||||
|
||||
class Ipv4BRouting : public Ipv4RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
|
||||
void SetIpv4 (Ptr<Ipv4> ipv4) {}
|
||||
void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const {}
|
||||
};
|
||||
|
||||
class Ipv4ListRoutingNegativeTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingNegativeTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv4ListRoutingNegativeTestCase::Ipv4ListRoutingNegativeTestCase()
|
||||
: TestCase("Check negative priorities")
|
||||
{}
|
||||
void
|
||||
Ipv4ListRoutingNegativeTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
|
||||
// The Ipv4BRouting should be added with higher priority (larger integer value)
|
||||
lr->AddRoutingProtocol (aRouting, -10);
|
||||
lr->AddRoutingProtocol (bRouting, -5);
|
||||
int16_t first = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
class Ipv4ListRoutingPositiveTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingPositiveTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv4ListRoutingPositiveTestCase::Ipv4ListRoutingPositiveTestCase()
|
||||
: TestCase("Check positive priorities")
|
||||
{}
|
||||
void
|
||||
Ipv4ListRoutingPositiveTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv4ListRouting> lr = CreateObject<Ipv4ListRouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> aRouting = CreateObject<Ipv4ARouting> ();
|
||||
Ptr<Ipv4RoutingProtocol> bRouting = CreateObject<Ipv4BRouting> ();
|
||||
// The Ipv4ARouting should be added with higher priority (larger integer
|
||||
// value) and will be fetched first below
|
||||
lr->AddRoutingProtocol (aRouting, 10);
|
||||
lr->AddRoutingProtocol (bRouting, 5);
|
||||
int16_t first = 3;
|
||||
int16_t second = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
|
||||
Ptr<Ipv4RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
|
||||
NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
static class Ipv4ListRoutingTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv4ListRoutingTestSuite()
|
||||
: TestSuite("ipv4-list-routing", UNIT)
|
||||
{
|
||||
AddTestCase(new Ipv4ListRoutingPositiveTestCase());
|
||||
AddTestCase(new Ipv4ListRoutingNegativeTestCase());
|
||||
}
|
||||
|
||||
} g_ipv4ListRoutingTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
209
src/internet/test/ipv4-packet-info-tag-test-suite.cc
Normal file
209
src/internet/test/ipv4-packet-info-tag-test-suite.cc
Normal file
@@ -0,0 +1,209 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2010 Hajime Tazaki
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Unit tests
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/ipv4-packet-info-tag.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/attribute.h"
|
||||
#include "ns3/simple-net-device.h"
|
||||
#include "ns3/object-factory.h"
|
||||
#include "ns3/socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/inet-socket-address.h"
|
||||
#include "ns3/ipv4-l3-protocol.h"
|
||||
#include "ns3/ipv4-raw-socket-factory.h"
|
||||
#include "ns3/ipv4-interface.h"
|
||||
#include "ns3/arp-l3-protocol.h"
|
||||
#include "ns3/icmpv4-l4-protocol.h"
|
||||
#include "ns3/ipv4-static-routing.h"
|
||||
#include "ns3/ipv4-list-routing.h"
|
||||
#include "ns3/udp-l4-protocol.h"
|
||||
#include "ns3/tcp-l4-protocol.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static void
|
||||
AddInternetStack (Ptr<Node> node)
|
||||
{
|
||||
//ARP
|
||||
Ptr<ArpL3Protocol> arp = CreateObject<ArpL3Protocol> ();
|
||||
node->AggregateObject(arp);
|
||||
//IPV4
|
||||
Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
|
||||
//Routing for Ipv4
|
||||
Ptr<Ipv4ListRouting> ipv4Routing = CreateObject<Ipv4ListRouting> ();
|
||||
ipv4->SetRoutingProtocol (ipv4Routing);
|
||||
Ptr<Ipv4StaticRouting> ipv4staticRouting = CreateObject<Ipv4StaticRouting> ();
|
||||
ipv4Routing->AddRoutingProtocol (ipv4staticRouting, 0);
|
||||
node->AggregateObject(ipv4);
|
||||
//ICMP
|
||||
Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol> ();
|
||||
node->AggregateObject(icmp);
|
||||
//UDP
|
||||
Ptr<UdpL4Protocol> udp = CreateObject<UdpL4Protocol> ();
|
||||
node->AggregateObject(udp);
|
||||
}
|
||||
|
||||
class Ipv4PacketInfoTagTest: public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv4PacketInfoTagTest ();
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
void RxCb (Ptr<Socket> socket);
|
||||
void DoSendData (Ptr<Socket> socket, std::string to);
|
||||
};
|
||||
|
||||
Ipv4PacketInfoTagTest::Ipv4PacketInfoTagTest ()
|
||||
: TestCase ("Ipv4PacketInfoTagTest")
|
||||
{}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::RxCb (Ptr<Socket> socket)
|
||||
{
|
||||
uint32_t availableData;
|
||||
Ptr<Packet> m_receivedPacket;
|
||||
|
||||
availableData = socket->GetRxAvailable ();
|
||||
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
|
||||
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
|
||||
|
||||
Ipv4PacketInfoTag tag;
|
||||
bool found;
|
||||
found = m_receivedPacket->RemovePacketTag (tag);
|
||||
NS_ASSERT (found);
|
||||
tag.Print (std::cout);
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
|
||||
{
|
||||
Address realTo = InetSocketAddress (Ipv4Address (to.c_str()), 200);
|
||||
if (DynamicCast<UdpSocket> (socket) != 0)
|
||||
{
|
||||
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
|
||||
123, "XXX");
|
||||
}
|
||||
// Should only Ipv4RawSock
|
||||
else
|
||||
{
|
||||
socket->SendTo (Create<Packet> (123), 0, realTo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4PacketInfoTagTest::DoRun (void)
|
||||
{
|
||||
Ptr<Node> node0 = CreateObject<Node> ();
|
||||
Ptr<Node> node1 = CreateObject<Node> ();
|
||||
|
||||
Ptr<SimpleNetDevice> device = CreateObject<SimpleNetDevice> ();
|
||||
Ptr<SimpleNetDevice> device2 = CreateObject<SimpleNetDevice> ();
|
||||
|
||||
// For Node 0
|
||||
node0->AddDevice (device);
|
||||
AddInternetStack (node0);
|
||||
Ptr<Ipv4> ipv4 = node0->GetObject<Ipv4> ();
|
||||
|
||||
uint32_t index = ipv4->AddInterface (device);
|
||||
Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("10.1.1.1",
|
||||
"255.255.255.0");
|
||||
ipv4->AddAddress (index, ifaceAddr1);
|
||||
ipv4->SetMetric (index, 1);
|
||||
ipv4->SetUp (index);
|
||||
|
||||
// For Node 1
|
||||
node1->AddDevice (device2);
|
||||
AddInternetStack (node1);
|
||||
ipv4 = node1->GetObject<Ipv4> ();
|
||||
|
||||
index = ipv4->AddInterface (device2);
|
||||
Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("10.1.1.2",
|
||||
"255.255.255.0");
|
||||
ipv4->AddAddress (index, ifaceAddr2);
|
||||
ipv4->SetMetric (index, 1);
|
||||
ipv4->SetUp (index);
|
||||
|
||||
// IPv4 test
|
||||
Ptr<SocketFactory> factory = node0->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket = factory->CreateSocket ();
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 200);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
|
||||
Simulator::Run ();
|
||||
|
||||
Ptr<SocketFactory> factory2 = node1->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
|
||||
// ipv4 w rawsocket
|
||||
factory = node0->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
|
||||
socket = factory->CreateSocket ();
|
||||
local = InetSocketAddress (Ipv4Address::GetAny (), 0);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv4PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "127.0.0.1");
|
||||
Simulator::Run ();
|
||||
|
||||
factory2 = node1->GetObject<SocketFactory> (Ipv4RawSocketFactory::GetTypeId ());
|
||||
socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv4PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
|
||||
static class Ipv4PacketInfoTagTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv4PacketInfoTagTestSuite ();
|
||||
private:
|
||||
} g_packetinfotagTests;
|
||||
|
||||
Ipv4PacketInfoTagTestSuite::Ipv4PacketInfoTagTestSuite ()
|
||||
: TestSuite ("ipv4-packet-info-tag", UNIT)
|
||||
{
|
||||
AddTestCase (new Ipv4PacketInfoTagTest ());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
130
src/internet/test/ipv6-list-routing-test-suite.cc
Normal file
130
src/internet/test/ipv6-list-routing-test-suite.cc
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/ipv6-list-routing.h"
|
||||
#include "ns3/ipv6-route.h"
|
||||
#include "ns3/ipv6-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv6ARouting : public Ipv6RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
|
||||
GetZero ()) {}
|
||||
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
|
||||
void SetIpv6 (Ptr<Ipv6> ipv6) {}
|
||||
};
|
||||
|
||||
class Ipv6BRouting : public Ipv6RoutingProtocol {
|
||||
public:
|
||||
Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) { return 0;}
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) {return false;}
|
||||
void NotifyInterfaceUp (uint32_t interface) {}
|
||||
void NotifyInterfaceDown (uint32_t interface) {}
|
||||
void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) {}
|
||||
void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::
|
||||
GetZero ()) {}
|
||||
void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse) {}
|
||||
void SetIpv6 (Ptr<Ipv6> ipv6) {}
|
||||
};
|
||||
|
||||
class Ipv6ListRoutingNegativeTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingNegativeTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv6ListRoutingNegativeTestCase::Ipv6ListRoutingNegativeTestCase()
|
||||
: TestCase("Check negative priorities")
|
||||
{}
|
||||
void
|
||||
Ipv6ListRoutingNegativeTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
|
||||
// The Ipv6BRouting should be added with higher priority (larger integer value)
|
||||
lr->AddRoutingProtocol (aRouting, -10);
|
||||
lr->AddRoutingProtocol (bRouting, -5);
|
||||
int16_t first = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (-5, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
class Ipv6ListRoutingPositiveTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingPositiveTestCase();
|
||||
virtual void DoRun (void);
|
||||
};
|
||||
|
||||
Ipv6ListRoutingPositiveTestCase::Ipv6ListRoutingPositiveTestCase()
|
||||
: TestCase("Check positive priorities")
|
||||
{}
|
||||
void
|
||||
Ipv6ListRoutingPositiveTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<Ipv6ListRouting> lr = CreateObject<Ipv6ListRouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> aRouting = CreateObject<Ipv6ARouting> ();
|
||||
Ptr<Ipv6RoutingProtocol> bRouting = CreateObject<Ipv6BRouting> ();
|
||||
// The Ipv6ARouting should be added with higher priority (larger integer
|
||||
// value) and will be fetched first below
|
||||
lr->AddRoutingProtocol (aRouting, 10);
|
||||
lr->AddRoutingProtocol (bRouting, 5);
|
||||
int16_t first = 3;
|
||||
int16_t second = 3;
|
||||
uint32_t num = lr->GetNRoutingProtocols ();
|
||||
NS_TEST_ASSERT_MSG_EQ (num, 2, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> firstRp = lr->GetRoutingProtocol (0, first);
|
||||
NS_TEST_ASSERT_MSG_EQ (10, first, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (firstRp, aRouting, "XXX");
|
||||
Ptr<Ipv6RoutingProtocol> secondRp = lr->GetRoutingProtocol (1, second);
|
||||
NS_TEST_ASSERT_MSG_EQ (5, second, "XXX");
|
||||
NS_TEST_ASSERT_MSG_EQ (secondRp, bRouting, "XXX");
|
||||
}
|
||||
|
||||
static class Ipv6ListRoutingTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv6ListRoutingTestSuite()
|
||||
: TestSuite("ipv6-list-routing", UNIT)
|
||||
{
|
||||
AddTestCase(new Ipv6ListRoutingPositiveTestCase());
|
||||
AddTestCase(new Ipv6ListRoutingNegativeTestCase());
|
||||
}
|
||||
|
||||
} g_ipv6ListRoutingTestSuite;
|
||||
|
||||
} // namespace ns3
|
||||
216
src/internet/test/ipv6-packet-info-tag-test-suite.cc
Normal file
216
src/internet/test/ipv6-packet-info-tag-test-suite.cc
Normal file
@@ -0,0 +1,216 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2010 Hajime Tazaki
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Unit tests
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/ipv6-address.h"
|
||||
#include "ns3/ipv6-packet-info-tag.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/attribute.h"
|
||||
#include "ns3/simple-net-device.h"
|
||||
#include "ns3/object-factory.h"
|
||||
#include "ns3/socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "ns3/udp-socket.h"
|
||||
#include "ns3/ipv6-l3-protocol.h"
|
||||
#include "ns3/ipv6-raw-socket-factory.h"
|
||||
#include "ns3/ipv6-interface.h"
|
||||
#include "ns3/icmpv6-l4-protocol.h"
|
||||
#include "ns3/ipv6-static-routing.h"
|
||||
#include "ns3/ipv6-list-routing.h"
|
||||
#include "ns3/inet6-socket-address.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static void
|
||||
AddInternetStack (Ptr<Node> node)
|
||||
{
|
||||
Ptr<Ipv6L3Protocol> ipv6 = CreateObject<Ipv6L3Protocol> ();
|
||||
Ptr<Icmpv6L4Protocol> icmpv6 = CreateObject<Icmpv6L4Protocol> ();
|
||||
node->AggregateObject (ipv6);
|
||||
node->AggregateObject (icmpv6);
|
||||
ipv6->Insert (icmpv6);
|
||||
icmpv6->SetAttribute ("DAD", BooleanValue (false));
|
||||
|
||||
//Routing for Ipv6
|
||||
Ptr<Ipv6ListRouting> ipv6Routing = CreateObject<Ipv6ListRouting> ();
|
||||
ipv6->SetRoutingProtocol (ipv6Routing);
|
||||
Ptr<Ipv6StaticRouting> ipv6staticRouting = CreateObject<Ipv6StaticRouting> ();
|
||||
ipv6Routing->AddRoutingProtocol (ipv6staticRouting, 0);
|
||||
|
||||
/* register IPv6 extensions and options */
|
||||
ipv6->RegisterExtensions ();
|
||||
ipv6->RegisterOptions ();
|
||||
}
|
||||
|
||||
class Ipv6PacketInfoTagTest: public TestCase
|
||||
{
|
||||
public:
|
||||
Ipv6PacketInfoTagTest ();
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
void RxCb (Ptr<Socket> socket);
|
||||
void DoSendData (Ptr<Socket> socket, std::string to);
|
||||
};
|
||||
|
||||
Ipv6PacketInfoTagTest::Ipv6PacketInfoTagTest ()
|
||||
: TestCase ("Ipv6PacketInfoTagTest")
|
||||
{}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::RxCb (Ptr<Socket> socket)
|
||||
{
|
||||
uint32_t availableData;
|
||||
Ptr<Packet> m_receivedPacket;
|
||||
|
||||
availableData = socket->GetRxAvailable ();
|
||||
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
|
||||
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
|
||||
|
||||
Ipv6PacketInfoTag tag;
|
||||
bool found;
|
||||
found = m_receivedPacket->RemovePacketTag (tag);
|
||||
NS_ASSERT (found);
|
||||
tag.Print (std::cout);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::DoSendData (Ptr<Socket> socket, std::string to)
|
||||
{
|
||||
Address realTo = Inet6SocketAddress (Ipv6Address (to.c_str()), 200);
|
||||
if (DynamicCast<UdpSocket> (socket) != 0)
|
||||
{
|
||||
NS_TEST_EXPECT_MSG_EQ (socket->SendTo (Create<Packet> (123), 0, realTo),
|
||||
123, "XXX");
|
||||
}
|
||||
// Should only Ipv6RawSock
|
||||
else
|
||||
{
|
||||
socket->SendTo (Create<Packet> (123), 0, realTo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Ipv6PacketInfoTagTest::DoRun (void)
|
||||
{
|
||||
Ptr<Node> node0 = CreateObject<Node> ();
|
||||
Ptr<Node> node1 = CreateObject<Node> ();
|
||||
|
||||
Ptr<SimpleNetDevice> device = CreateObject<SimpleNetDevice> ();
|
||||
Ptr<SimpleNetDevice> device2 = CreateObject<SimpleNetDevice> ();
|
||||
|
||||
// For Node 0
|
||||
node0->AddDevice (device);
|
||||
AddInternetStack (node0);
|
||||
Ptr<Ipv6> ipv6 = node0->GetObject<Ipv6> ();
|
||||
|
||||
uint32_t index = ipv6->AddInterface (device);
|
||||
Ipv6InterfaceAddress ifaceAddr1 = Ipv6InterfaceAddress (Ipv6Address("2000:1000:0:2000::1"),
|
||||
Ipv6Prefix(64));
|
||||
ipv6->AddAddress (index, ifaceAddr1);
|
||||
ipv6->SetMetric (index, 1);
|
||||
ipv6->SetUp (index);
|
||||
|
||||
// For Node 1
|
||||
node1->AddDevice (device2);
|
||||
AddInternetStack (node1);
|
||||
ipv6 = node1->GetObject<Ipv6> ();
|
||||
|
||||
index = ipv6->AddInterface (device2);
|
||||
Ipv6InterfaceAddress ifaceAddr2 = Ipv6InterfaceAddress (Ipv6Address("2000:1000:0:2000::2"),
|
||||
Ipv6Prefix(64));
|
||||
ipv6->AddAddress (index, ifaceAddr2);
|
||||
ipv6->SetMetric (index, 1);
|
||||
ipv6->SetUp (index);
|
||||
|
||||
// ipv6 w rawsocket
|
||||
Ptr<SocketFactory> factory = node0->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket = factory->CreateSocket ();
|
||||
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address::GetAny (), 0);
|
||||
socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
|
||||
Simulator::Run ();
|
||||
|
||||
Ptr<SocketFactory> factory2 = node1->GetObject<SocketFactory> (Ipv6RawSocketFactory::GetTypeId ());
|
||||
Ptr<Socket> socket2 = factory2->CreateSocket ();
|
||||
std::stringstream dst;
|
||||
dst << ifaceAddr1.GetAddress ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket,
|
||||
dst.str ());
|
||||
Simulator::Run ();
|
||||
|
||||
#ifdef UDP6_SUPPORTED
|
||||
// IPv6 test
|
||||
factory = node0->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
socket = factory->CreateSocket ();
|
||||
local = Inet6SocketAddress (Ipv6Address::GetAny (), 200);
|
||||
socket->Bind (local);
|
||||
socket->SetRecvPktInfo (true);
|
||||
socket->SetRecvCallback (MakeCallback (&ns3::Ipv6PacketInfoTagTest::RxCb, this));
|
||||
|
||||
// receive on loopback
|
||||
Simulator::ScheduleWithContext (socket->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "::1");
|
||||
Simulator::Run ();
|
||||
|
||||
factory2 = node1->GetObject<SocketFactory> (UdpSocketFactory::GetTypeId ());
|
||||
socket2 = factory2->CreateSocket ();
|
||||
Simulator::ScheduleWithContext (socket2->GetNode ()->GetId (), Seconds (0),
|
||||
&Ipv6PacketInfoTagTest::DoSendData, this, socket, "10.1.1.1");
|
||||
Simulator::Run ();
|
||||
|
||||
#endif // UDP6_SUPPORTED
|
||||
|
||||
Simulator::Destroy ();
|
||||
// IPv6 test
|
||||
}
|
||||
|
||||
static class Ipv6PacketInfoTagTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
Ipv6PacketInfoTagTestSuite ();
|
||||
private:
|
||||
} g_packetinfotagTests;
|
||||
|
||||
Ipv6PacketInfoTagTestSuite::Ipv6PacketInfoTagTestSuite ()
|
||||
: TestSuite ("ipv6-packet-info-tag", UNIT)
|
||||
{
|
||||
AddTestCase (new Ipv6PacketInfoTagTest ());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -187,9 +187,14 @@ def build(bld):
|
||||
|
||||
internet_test = bld.create_ns3_module_test_library('internet')
|
||||
internet_test.source = [
|
||||
'test/global-route-manager-impl-test-suite.cc',
|
||||
'test/ipv4-list-routing-test-suite.cc',
|
||||
'test/ipv4-packet-info-tag-test-suite.cc',
|
||||
'test/ipv4-raw-test.cc',
|
||||
'test/ipv4-test.cc',
|
||||
'test/ipv6-extension-header-test-suite.cc',
|
||||
'test/ipv6-list-routing-test-suite.cc',
|
||||
'test/ipv6-packet-info-tag-test-suite.cc',
|
||||
'test/ipv6-test.cc',
|
||||
'test/tcp-test.cc',
|
||||
'test/udp-test.cc',
|
||||
@@ -253,6 +258,8 @@ def build(bld):
|
||||
'helper/ipv6-static-routing-helper.h',
|
||||
'model/global-router-interface.h',
|
||||
'model/global-route-manager.h',
|
||||
'model/global-route-manager-impl.h',
|
||||
'model/candidate-queue.h',
|
||||
'model/ipv4-global-routing.h',
|
||||
'helper/ipv4-global-routing-helper.h',
|
||||
'helper/internet-stack-helper.h',
|
||||
|
||||
Reference in New Issue
Block a user