src/internet-stack/ipv4-l3-protocol.h
changeset 4472 e20a31541404
parent 4377 2a05a47dba22
child 4481 9250a25ee683
--- a/src/internet-stack/ipv4-l3-protocol.h	Thu May 28 20:16:56 2009 +0200
+++ b/src/internet-stack/ipv4-l3-protocol.h	Thu May 28 21:37:25 2009 -0700
@@ -29,7 +29,8 @@
 #include "ns3/ipv4.h"
 #include "ns3/traced-callback.h"
 #include "ns3/ipv4-header.h"
-#include "ipv4-static-routing.h"
+#include "ns3/ipv4-routing-protocol.h"
+#include "ipv4-static-routing-impl.h"
 
 namespace ns3 {
 
@@ -38,6 +39,7 @@
 class Ipv4Interface;
 class Ipv4Address;
 class Ipv4Header;
+class Ipv4RoutingTableEntry;
 class Ipv4Route;
 class Node;
 class Socket;
@@ -64,6 +66,10 @@
 
   void SetNode (Ptr<Node> node);
 
+  // functions defined in base class Ipv4
+  void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routing);
+  Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const;
+
   Ptr<Socket> CreateRawSocket (void);
   void DeleteRawSocket (Ptr<Socket> socket);
 
@@ -105,15 +111,6 @@
   void SetDefaultTtl (uint8_t ttl);
 
   /**
-   * \param device the device to match
-   * \returns the matching interface, zero if not found.
-   *
-   * Try to find an Ipv4Interface whose NetDevice is equal to
-   * the input NetDevice.
-   */
-  Ptr<Ipv4Interface> FindInterfaceForDevice (Ptr<const NetDevice> device);
-
-  /**
    * Lower layer calls this method after calling L3Demux::Lookup
    * The ARP subclass needs to know from which NetDevice this
    * packet is coming to:
@@ -128,64 +125,21 @@
    * \param source source address of packet
    * \param destination address of packet
    * \param protocol number of packet
+   * \param route route entry
    *
    * Higher-level layers call this method to send a packet
    * down the stack to the MAC and PHY layers.
    */
   void Send (Ptr<Packet> packet, Ipv4Address source, 
-	     Ipv4Address destination, uint8_t protocol);
-
-
-    
-  void AddHostRouteTo (Ipv4Address dest, 
-                       Ipv4Address nextHop, 
-                       uint32_t interface);
-  void AddHostRouteTo (Ipv4Address dest, 
-                       uint32_t interface);
-
-  void AddNetworkRouteTo (Ipv4Address network, 
-                          Ipv4Mask networkMask, 
-                          Ipv4Address nextHop, 
-                          uint32_t interface);
-  void AddNetworkRouteTo (Ipv4Address network, 
-                          Ipv4Mask networkMask, 
-                          uint32_t interface);
-  void SetDefaultRoute (Ipv4Address nextHop, 
-                        uint32_t interface);
-
-  void Lookup (Ipv4Header const &ipHeader,
-               Ptr<Packet> packet,
-               Ipv4RoutingProtocol::RouteReplyCallback routeReply);
-
-  uint32_t GetNRoutes (void);
-  Ipv4Route GetRoute (uint32_t i);
-  void RemoveRoute (uint32_t i);
-
-  void AddMulticastRoute (Ipv4Address origin,
-                          Ipv4Address group,
-                          uint32_t inputInterface,
-                          std::vector<uint32_t> outputInterfaces);
-
-  void SetDefaultMulticastRoute (uint32_t onputInterface);
-
-  uint32_t GetNMulticastRoutes (void) const;
-  Ipv4MulticastRoute GetMulticastRoute (uint32_t i) const;
-
-  void RemoveMulticastRoute (Ipv4Address origin,
-                             Ipv4Address group,
-                             uint32_t inputInterface);
-  void RemoveMulticastRoute (uint32_t i);
+	     Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
 
   uint32_t AddInterface (Ptr<NetDevice> device);
   Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
   uint32_t GetNInterfaces (void) const;
 
-  uint32_t FindInterfaceForAddr (Ipv4Address addr) const;
-  uint32_t FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const;
-  int32_t FindInterfaceForDevice (Ptr<NetDevice> device) const;
-  
-  void JoinMulticastGroup (Ipv4Address origin, Ipv4Address group);
-  void LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group);
+  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
+  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
+  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
 
   uint32_t AddAddress (uint32_t i, Ipv4InterfaceAddress address);
   Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
@@ -193,9 +147,6 @@
 
   void SetMetric (uint32_t i, uint16_t metric);
   uint16_t GetMetric (uint32_t i) const;
-  Ipv4Address GetSourceAddress (Ipv4Address destination) const;
-  bool GetInterfaceForDestination (Ipv4Address destination, 
-                                 uint32_t& interface) const;
   uint16_t GetMtu (uint32_t i) const;
   bool IsUp (uint32_t i) const;
   void SetUp (uint32_t i);
@@ -209,39 +160,52 @@
 protected:
 
   virtual void DoDispose (void);
-
+  /**
+   * This function will notify other components connected to the node that a new stack member is now connected
+   * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
+   */
+  virtual void NotifyNewAggregate ();
 private:
   Ipv4L3Protocol(const Ipv4L3Protocol &);
   Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
-  void Lookup (uint32_t interface,
-               Ipv4Header const &ipHeader,
-               Ptr<Packet> packet,
-               Ipv4RoutingProtocol::RouteReplyCallback routeReply);
+
+  virtual void SetIpForward (bool forward);
+  virtual bool GetIpForward (void) const;
+
+  Ipv4Header BuildHeader (
+            Ipv4Address source,
+            Ipv4Address destination,
+            uint8_t protocol,
+            uint16_t payloadSize,
+            uint8_t ttl,
+            bool mayFragment);
 
-  void SendRealOut (bool found,
-                    Ipv4Route const &route,
-                    Ptr<Packet> packet,
-                    Ipv4Header const &ipHeader);
-  bool Forwarding (uint32_t interface, 
-                   Ptr<Packet> packet, 
-                   Ipv4Header &ipHeader, 
-                   Ptr<NetDevice> device);
-  void ForwardUp (Ptr<Packet> p, Ipv4Header const&ip, Ptr<Ipv4Interface> incomingInterface);
+  void
+  SendRealOut (Ptr<Ipv4Route> route,
+               Ptr<Packet> packet,
+               Ipv4Header const &ipHeader);
+
+  void 
+  IpForward (Ptr<Ipv4Route> rtentry, 
+             Ptr<const Packet> p, 
+             const Ipv4Header &header);
+
+  void
+  IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, 
+                      Ptr<const Packet> p, 
+                      const Ipv4Header &header);
+
+  void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
   uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
   void SetupLoopback (void);
   Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
   bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
-  void DoForward (uint32_t interface, 
-                  Ptr<Packet> packet, 
-                  Ipv4Header ipHeader);
-
 
   typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
-  typedef std::list<std::pair<Ipv4Address, Ipv4Address> > Ipv4MulticastGroupList;
-  typedef std::list< std::pair< int, Ptr<Ipv4RoutingProtocol> > > Ipv4RoutingProtocolList;
   typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
   typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
 
+  bool m_ipForward;
   L4List_t m_protocols;
   Ipv4InterfaceList m_interfaces;
   uint32_t m_nInterfaces;
@@ -253,10 +217,8 @@
   TracedCallback<Ptr<const Packet>, uint32_t> m_rxTrace;
   TracedCallback<Ptr<const Packet> > m_dropTrace;
 
-  Ipv4RoutingProtocolList m_routingProtocols;
-
-  Ptr<Ipv4StaticRouting> m_staticRouting;
-  Ipv4MulticastGroupList m_multicastGroups;
+  Ptr<Ipv4RoutingProtocol> m_routingProtocol;
+  Ptr<Ipv4StaticRouting> GetStaticRouting (void) const;
 
   SocketList m_sockets;
 };