Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(867)

Unified Diff: src/mpls-stack/mpls/ipv4-to-mpls-routing-protocol.cc

Issue 850045: MPLS implementation
Patch Set: Created 13 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/mpls-stack/mpls/ipv4-to-mpls-routing-protocol.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/mpls-stack/mpls/ipv4-to-mpls-routing-protocol.cc
@@ -0,0 +1,169 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Andrey Churin
+ *
+ * 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
+ *
+ * Author: Andrey Churin <aachurin@gmail.com>
+ */
+
+#include "ns3/log.h"
+#include "ns3/assert.h"
+
+#include "ipv4-to-mpls-routing-protocol.h"
+
+NS_LOG_COMPONENT_DEFINE ("Ipv4ToMplsRoutingProtocol");
+
+namespace ns3 {
+namespace mpls {
+
+NS_OBJECT_ENSURE_REGISTERED (Ipv4ToMplsRoutingProtocol);
+
+Ipv4ToMplsRoutingProtocol::Ipv4ToMplsRoutingProtocol ()
+ : m_ipv4 (0),
+ m_mpls (0)
+{
+ NS_LOG_FUNCTION (this);
+}
+
+Ipv4ToMplsRoutingProtocol::~Ipv4ToMplsRoutingProtocol ()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+TypeId
+Ipv4ToMplsRoutingProtocol::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::mpls::Ipv4ToMplsRoutingProtocol")
+ .SetParent<Ipv4RoutingProtocol> ()
+ .AddConstructor<Ipv4ToMplsRoutingProtocol> ()
+ ;
+ return tid;
+}
+
+void
+Ipv4ToMplsRoutingProtocol::DoDispose (void)
+{
+ m_ipv4 = 0;
+ m_mpls = 0;
+ m_routingProtocol = 0;
+ Ipv4RoutingProtocol::DoDispose ();
+}
+
+Ptr<Ipv4Route>
+Ipv4ToMplsRoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr)
+{
+ NS_LOG_FUNCTION (this << &oif << p << header);
+
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::RouteOutput ():"
+ "Need a Ipv4 routing protocol to process packets");
+
+ return m_routingProtocol->RouteOutput (p, header, oif, sockerr);
+}
+
+bool
+Ipv4ToMplsRoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
+ UnicastForwardCallback ucb, MulticastForwardCallback mcb,
+ LocalDeliverCallback lcb, ErrorCallback ecb)
+{
+ NS_LOG_FUNCTION (this << &idev << p << header);
+ NS_ASSERT_MSG (m_mpls, "Ipv4ToMplsRoutingProtocol::RouteInput ():"
+ "Need a MplsRoutingProtocol object to process packets");
+
+ MplsRoutingProtocol::MplsRoutingErrno result = m_mpls->RouteInput (p, header, idev);
+
+ switch (result)
+ {
+ case MplsRoutingProtocol::ERROR_IPROUTING:
Tom Henderson 2010/05/22 06:12:44 It may be a bit misleading to call this an error;
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::RouteInput ():"
+ "Need a Ipv4 routing protocol to process packets");
+ return m_routingProtocol->RouteInput (p, header, idev, ucb, mcb, lcb, ecb);
+
+ case MplsRoutingProtocol::ERROR_NOLIBENTRY:
+ ecb (p, header, Socket::ERROR_NOROUTETOHOST);
+ return false;
+
+ case MplsRoutingProtocol::ERROR_NOTERROR:
+ break;
+ }
+
+ return true;
+}
+
+void
+Ipv4ToMplsRoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
+{
+ NS_LOG_FUNCTION (this << ipv4);
+ NS_ASSERT_MSG (m_ipv4 == 0, "Ipv4ToMplsRoutingProtocol::SetIpv4 (): m_ipv4 != 0");
+ NS_ASSERT (ipv4 != 0);
+ m_ipv4 = ipv4;
+}
+
+void
+Ipv4ToMplsRoutingProtocol::SetMpls (Ptr<MplsRoutingProtocol> mpls)
+{
+ NS_LOG_FUNCTION (this << mpls);
+ NS_ASSERT_MSG (m_mpls == 0, "Ipv4ToMplsRoutingProtocol::SetMpls (): m_mpls != 0");
+ NS_ASSERT (mpls != 0);
+ m_mpls = mpls;
+}
+
+void
+Ipv4ToMplsRoutingProtocol::NotifyInterfaceUp (uint32_t interface)
+{
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::NotifyInterfaceUp (): "
+ "Need a Ipv4 routing protocol to process InterfaceUp notification");
+ m_routingProtocol->NotifyInterfaceUp (interface);
+}
+
+void
+Ipv4ToMplsRoutingProtocol::NotifyInterfaceDown (uint32_t interface)
+{
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::NotifyInterfaceUp (): "
+ "Need a Ipv4 routing protocol to process InterfaceDown notification");
+ m_routingProtocol->NotifyInterfaceDown (interface);
+}
+
+void
+Ipv4ToMplsRoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
+{
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::NotifyInterfaceUp (): "
+ "Need a Ipv4 routing protocol to process AddAddress notification");
+ m_routingProtocol->NotifyAddAddress (interface, address);
+}
+
+void
+Ipv4ToMplsRoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
+{
+ NS_ASSERT_MSG (m_routingProtocol != 0, "Ipv4ToMplsRoutingProtocol::NotifyInterfaceUp (): "
+ "Need a Ipv4 routing protocol to process RemoveAddress notification");
+ m_routingProtocol->NotifyRemoveAddress (interface, address);
+}
+
+void
+Ipv4ToMplsRoutingProtocol::SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol)
+{
+ NS_LOG_FUNCTION (this << routingProtocol);
+ m_routingProtocol = routingProtocol;
+ m_routingProtocol->SetIpv4 (m_ipv4);
+}
+
+Ptr<Ipv4RoutingProtocol>
+Ipv4ToMplsRoutingProtocol::GetRoutingProtocol (void) const
+{
+ return m_routingProtocol;
+}
+
+} // namespace mpls
+} // namespace ns3

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b