From d33666ce239e2ae35eae5e8b30caeff98cd41f9d Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Sun, 18 Oct 2009 18:20:10 +0200 Subject: [PATCH] Update. --- examples/ipv6/loose-routing-ipv6.cc | 53 ++++++------------- src/applications/ping6/ping6.cc | 24 ++++++++- src/applications/ping6/ping6.h | 11 ++++ src/helper/ping6-helper.cc | 6 +++ src/helper/ping6-helper.h | 12 +++++ src/internet-stack/ipv6-extension.cc | 3 +- src/internet-stack/wscript | 1 + .../static-routing/ipv6-static-routing.cc | 4 +- 8 files changed, 71 insertions(+), 43 deletions(-) diff --git a/examples/ipv6/loose-routing-ipv6.cc b/examples/ipv6/loose-routing-ipv6.cc index 295003e24..5c25073ba 100644 --- a/examples/ipv6/loose-routing-ipv6.cc +++ b/examples/ipv6/loose-routing-ipv6.cc @@ -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 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 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); diff --git a/src/applications/ping6/ping6.cc b/src/applications/ping6/ping6.cc index 21b33b6d9..3791548df 100644 --- a/src/applications/ping6/ping6.cc +++ b/src/applications/ping6/ping6.cc @@ -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 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; diff --git a/src/applications/ping6/ping6.h b/src/applications/ping6/ping6.h index f09c29922..71eb9d5de 100644 --- a/src/applications/ping6/ping6.h +++ b/src/applications/ping6/ping6.h @@ -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 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 m_routersAddress; }; } /* namespace ns3 */ diff --git a/src/helper/ping6-helper.cc b/src/helper/ping6-helper.cc index 8f4787c71..86b90c49b 100644 --- a/src/helper/ping6-helper.cc +++ b/src/helper/ping6-helper.cc @@ -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 routers) +{ + m_routers = routers; +} + } /* namespace ns3 */ diff --git a/src/helper/ping6-helper.h b/src/helper/ping6-helper.h index c1911b916..e6ebef17d 100644 --- a/src/helper/ping6-helper.h +++ b/src/helper/ping6-helper.h @@ -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 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 m_routers; }; } /* namespace ns3 */ diff --git a/src/internet-stack/ipv6-extension.cc b/src/internet-stack/ipv6-extension.cc index 26e51c679..397ab07a2 100644 --- a/src/internet-stack/ipv6-extension.cc +++ b/src/internet-stack/ipv6-extension.cc @@ -952,8 +952,9 @@ uint8_t Ipv6ExtensionLooseRouting::Process (Ptr& packet, uint8_t offset, { ipv6->Lookup (ipv6header, p, MakeCallback (&Ipv6L3Protocol::SendRealOut, PeekPointer (ipv6))); } -*/ + isDropped = true; +*/ return routingHeader.GetSerializedSize (); } diff --git a/src/internet-stack/wscript b/src/internet-stack/wscript index d9713d626..73e3dc943 100644 --- a/src/internet-stack/wscript +++ b/src/internet-stack/wscript @@ -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', diff --git a/src/routing/static-routing/ipv6-static-routing.cc b/src/routing/static-routing/ipv6-static-routing.cc index e3d3f5938..5706efe1c 100644 --- a/src/routing/static-routing/ipv6-static-routing.cc +++ b/src/routing/static-routing/ipv6-static-routing.cc @@ -529,8 +529,8 @@ bool Ipv6StaticRouting::RouteInput (Ptr p, const Ipv6Header &heade { NS_LOG_LOGIC ("Multicast destination"); Ptr mrtentry = LookupStatic (header.GetSourceAddress (), - header.GetDestinationAddress () - , m_ipv6->GetInterfaceForDevice (idev)); + header.GetDestinationAddress (), + m_ipv6->GetInterfaceForDevice (idev)); if (mrtentry) {