This commit is contained in:
Sebastien Vincent
2009-10-18 18:20:10 +02:00
parent 69e94e521d
commit d33666ce23
8 changed files with 71 additions and 43 deletions

View File

@@ -49,6 +49,8 @@ NS_LOG_COMPONENT_DEFINE ("LooseRoutingIpv6Example");
int main (int argc, char **argv)
{
LogComponentEnable("Ipv6ExtensionLooseRouting", LOG_LEVEL_ALL);
LogComponentEnable("Ipv6Extension", LOG_LEVEL_ALL);
#if 0
LogComponentEnable("Ipv6EndPointDemux", LOG_LEVEL_ALL);
LogComponentEnable("Udp6Socket", LOG_LEVEL_ALL);
@@ -137,58 +139,33 @@ int main (int argc, char **argv)
Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
i6.SetRouter (0, true);
i6.SetRouter (1, true);
#if 0
/**
* Network Configuration :
* - h0 : client
* - rX : router
* - h1 : UDP server (port 7)
*/
NS_LOG_INFO ("Create Applications.");
UdpEcho6ServerHelper server (7);
ApplicationContainer apps = server.Install (h1);
apps.Start (Seconds (1.0));
apps.Stop (Seconds (15.0));
/**
* UDP Echo from h0 to h1 port 7
* ICMPv6 Echo from h0 to h1 port 7
*/
uint32_t packetSize = 1024;
uint32_t maxPacketCount = 1;
Time interPacketInterval = Seconds (1.);
UdpEcho6ClientHelper client (i2.GetAddress (0), 7);
std::vector<Ipv6Address> routersAddress;
routersAddress.push_back (i3.GetAddress (1, 1));
routersAddress.push_back (i4.GetAddress (1, 1));
routersAddress.push_back (i5.GetAddress (1, 1));
routersAddress.push_back (i6.GetAddress (1, 1));
routersAddress.push_back (i2.GetAddress (0, 1));
Ping6Helper client;
client.SetRemote (i2.GetAddress (0, 1));
client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client.SetAttribute ("Interval", TimeValue(interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (packetSize));
apps = client.Install (h0);
client.SetRoutersAddress (routersAddress);
ApplicationContainer apps = client.Install (h0);
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
/**
* UDP Echo from h0 to h1 port 7 with loose routing
*/
std::vector<Ipv6Address> routersAddress;
routersAddress.push_back (i3.GetAddress (1));
routersAddress.push_back (i4.GetAddress (1));
routersAddress.push_back (i5.GetAddress (1));
routersAddress.push_back (i6.GetAddress (1));
routersAddress.push_back (i2.GetAddress (0));
UdpEcho6ClientHelper client2 (i1.GetAddress (1), 7);
packetSize = 10000;
client2.SetLocal (i1.GetAddress (0));
client2.SetLooseRouting (true);
client2.SetRoutersAddress (routersAddress);
client2.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
client2.SetAttribute ("Interval", TimeValue(interPacketInterval));
client2.SetAttribute ("PacketSize", UintegerValue (packetSize));
apps = client2.Install (h0);
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
#endif
std::ofstream ascii;
ascii.open ("loose-routing-ipv6.tr");
CsmaHelper::EnablePcapAll ("loose-routing-ipv6", true);

View File

@@ -31,6 +31,7 @@
#include "ns3/icmpv6-header.h"
#include "ns3/ipv6-raw-socket-factory.h"
#include "ns3/ipv6-header.h"
#include "ns3/ipv6-extension-header.h"
#include "ping6.h"
@@ -109,7 +110,7 @@ void Ping6::StartApplication ()
m_socket->Bind (Inet6SocketAddress (m_localAddress, 0));
m_socket->Connect (Inet6SocketAddress (m_peerAddress, 0));
m_socket->SetAttribute ("Protocol", UintegerValue (58)); /* ICMPv6 */
m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
m_socket->SetRecvCallback (MakeCallback (&Ping6::HandleRead, this));
}
@@ -151,6 +152,11 @@ void Ping6::ScheduleTransmit (Time dt)
m_sendEvent = Simulator::Schedule (dt, &Ping6::Send, this);
}
void Ping6::SetRouters (std::vector<Ipv6Address> routersAddress)
{
m_routersAddress = routersAddress;
}
void Ping6::Send ()
{
NS_LOG_FUNCTION_NOARGS ();
@@ -172,7 +178,7 @@ void Ping6::Send ()
src = m_localAddress;
}
NS_ASSERT_MSG(m_size >= 4, "ICMPv6 echo request payload size must be >= 4");
NS_ASSERT_MSG (m_size >= 4, "ICMPv6 echo request payload size must be >= 4");
data[0] = 0xDE;
data[1] = 0xAD;
data[2] = 0xBE;
@@ -192,6 +198,20 @@ void Ping6::Send ()
p->AddHeader (req);
m_socket->Bind (Inet6SocketAddress (src, 0));
/* use routing type 0 */
if (m_routersAddress.size ())
{
Ipv6ExtensionLooseRoutingHeader routingHeader;
routingHeader.SetNextHeader (Ipv6Header::IPV6_ICMPV6);
routingHeader.SetLength (m_routersAddress.size () * 16 + 8);
routingHeader.SetTypeRouting (0);
routingHeader.SetSegmentsLeft (m_routersAddress.size ());
routingHeader.SetRoutersAddress (m_routersAddress);
p->AddHeader (routingHeader);
m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_EXT_ROUTING));
}
m_socket->Send (p, 0);
++m_sent;

View File

@@ -81,6 +81,12 @@ class Ping6 : public Application
*/
void SetIfIndex (uint32_t ifIndex);
/**
* \brief Set routers for routing type 0 (loose routing).
* \param routers routers
*/
void SetRouters(std::vector<Ipv6Address> routersAddress);
protected:
/**
* \brief Dispose this object;
@@ -169,6 +175,11 @@ class Ping6 : public Application
* \brief Out interface (i.e. for link-local communication).
*/
uint32_t m_ifIndex;
/**
* \brief Routers addresses for routing type 0.
*/
std::vector<Ipv6Address> m_routersAddress;
};
} /* namespace ns3 */

View File

@@ -57,6 +57,7 @@ ApplicationContainer Ping6Helper::Install (NodeContainer c)
client->SetLocal (m_localIp);
client->SetRemote (m_remoteIp);
client->SetIfIndex (m_ifIndex);
client->SetRouters (m_routers);
node->AddApplication (client);
apps.Add (client);
}
@@ -68,5 +69,10 @@ void Ping6Helper::SetIfIndex (uint32_t ifIndex)
m_ifIndex = ifIndex;
}
void Ping6Helper::SetRoutersAddress (std::vector<Ipv6Address> routers)
{
m_routers = routers;
}
} /* namespace ns3 */

View File

@@ -77,6 +77,13 @@ class Ping6Helper
*/
void SetIfIndex (uint32_t ifIndex);
/**
* \brief Set routers addresses for routing type 0.
* \param routers routers addresses
*/
void SetRoutersAddress(std::vector<Ipv6Address> routers);
private:
/**
* \brief An object factory.
@@ -97,6 +104,11 @@ class Ping6Helper
* \brief Out interface index.
*/
uint32_t m_ifIndex;
/**
* \brief Routers addresses.
*/
std::vector<Ipv6Address> m_routers;
};
} /* namespace ns3 */

View File

@@ -952,8 +952,9 @@ uint8_t Ipv6ExtensionLooseRouting::Process (Ptr<Packet>& packet, uint8_t offset,
{
ipv6->Lookup (ipv6header, p, MakeCallback (&Ipv6L3Protocol::SendRealOut, PeekPointer (ipv6)));
}
*/
isDropped = true;
*/
return routingHeader.GetSerializedSize ();
}

View File

@@ -129,6 +129,7 @@ def build(bld):
'icmpv6-header.h',
'ipv4-l3-protocol.h',
'ipv6-l3-protocol.h',
'ipv6-extension-header.h',
'arp-l3-protocol.h',
'udp-l4-protocol.h',
'tcp-l4-protocol.h',

View File

@@ -529,8 +529,8 @@ bool Ipv6StaticRouting::RouteInput (Ptr<const Packet> p, const Ipv6Header &heade
{
NS_LOG_LOGIC ("Multicast destination");
Ptr<Ipv6MulticastRoute> mrtentry = LookupStatic (header.GetSourceAddress (),
header.GetDestinationAddress ()
, m_ipv6->GetInterfaceForDevice (idev));
header.GetDestinationAddress (),
m_ipv6->GetInterfaceForDevice (idev));
if (mrtentry)
{