src/internet/model/ipv4-l3-protocol.h
changeset 10440 1e48ff9185f1
parent 9915 d4c2228d3c30
child 10495 e877c029ed3e
equal deleted inserted replaced
10439:73bc9e55f9bd 10440:1e48ff9185f1
    75  * attack.
    75  * attack.
    76  */
    76  */
    77 class Ipv4L3Protocol : public Ipv4
    77 class Ipv4L3Protocol : public Ipv4
    78 {
    78 {
    79 public:
    79 public:
       
    80   /**
       
    81    * \brief Get the type ID.
       
    82    * \return the object TypeId
       
    83    */
    80   static TypeId GetTypeId (void);
    84   static TypeId GetTypeId (void);
    81   static const uint16_t PROT_NUMBER;
    85   static const uint16_t PROT_NUMBER; //!< Protocol number (0x0800)
    82 
    86 
    83   Ipv4L3Protocol();
    87   Ipv4L3Protocol();
    84   virtual ~Ipv4L3Protocol ();
    88   virtual ~Ipv4L3Protocol ();
    85 
    89 
    86   /**
    90   /**
    95     DROP_INTERFACE_DOWN,   /**< Interface is down so can not send packet */
    99     DROP_INTERFACE_DOWN,   /**< Interface is down so can not send packet */
    96     DROP_ROUTE_ERROR,   /**< Route error */
   100     DROP_ROUTE_ERROR,   /**< Route error */
    97     DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */
   101     DROP_FRAGMENT_TIMEOUT /**< Fragment timeout exceeded */
    98   };
   102   };
    99 
   103 
       
   104   /**
       
   105    * \brief Set node associated with this stack.
       
   106    * \param node node to set
       
   107    */
   100   void SetNode (Ptr<Node> node);
   108   void SetNode (Ptr<Node> node);
   101 
   109 
   102   // functions defined in base class Ipv4
   110   // functions defined in base class Ipv4
   103 
   111 
   104   void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol);
   112   void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol);
   180    * (Intend to be used with IpHeaderInclude attribute.)
   188    * (Intend to be used with IpHeaderInclude attribute.)
   181    */
   189    */
   182   void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
   190   void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
   183 
   191 
   184   uint32_t AddInterface (Ptr<NetDevice> device);
   192   uint32_t AddInterface (Ptr<NetDevice> device);
       
   193   /**
       
   194    * \brief Get an interface.
       
   195    * \param i interface index
       
   196    * \return IPv4 interface pointer
       
   197    */
   185   Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
   198   Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
   186   uint32_t GetNInterfaces (void) const;
   199   uint32_t GetNInterfaces (void) const;
   187 
   200 
   188   int32_t GetInterfaceForAddress (Ipv4Address addr) const;
   201   int32_t GetInterfaceForAddress (Ipv4Address addr) const;
   189   int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
   202   int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
   218    * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
   231    * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
   219    */
   232    */
   220   virtual void NotifyNewAggregate ();
   233   virtual void NotifyNewAggregate ();
   221 private:
   234 private:
   222   friend class Ipv4L3ProtocolTestCase;
   235   friend class Ipv4L3ProtocolTestCase;
       
   236 
       
   237   /**
       
   238    * \brief Copy constructor.
       
   239    *
       
   240    * Defined but not implemented to avoid misuse
       
   241    */
   223   Ipv4L3Protocol(const Ipv4L3Protocol &);
   242   Ipv4L3Protocol(const Ipv4L3Protocol &);
       
   243 
       
   244   /**
       
   245    * \brief Copy constructor.
       
   246    *
       
   247    * Defined but not implemented to avoid misuse
       
   248    * \returns the copied object
       
   249    */
   224   Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
   250   Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
   225 
   251 
   226   // class Ipv4 attributes
   252   // class Ipv4 attributes
   227   virtual void SetIpForward (bool forward);
   253   virtual void SetIpForward (bool forward);
   228   virtual bool GetIpForward (void) const;
   254   virtual bool GetIpForward (void) const;
   229   virtual void SetWeakEsModel (bool model);
   255   virtual void SetWeakEsModel (bool model);
   230   virtual bool GetWeakEsModel (void) const;
   256   virtual bool GetWeakEsModel (void) const;
   231 
   257 
       
   258   /**
       
   259    * \brief Construct an IPv4 header.
       
   260    * \param source source IPv4 address
       
   261    * \param destination destination IPv4 address
       
   262    * \param protocol L4 protocol
       
   263    * \param payloadSize payload size
       
   264    * \param ttl Time to Live
       
   265    * \param tos Type of Service
       
   266    * \param mayFragment true if the packet can be fragmented
       
   267    * \return newly created IPv4 header
       
   268    */
   232   Ipv4Header BuildHeader (
   269   Ipv4Header BuildHeader (
   233     Ipv4Address source,
   270     Ipv4Address source,
   234     Ipv4Address destination,
   271     Ipv4Address destination,
   235     uint8_t protocol,
   272     uint8_t protocol,
   236     uint16_t payloadSize,
   273     uint16_t payloadSize,
   237     uint8_t ttl,
   274     uint8_t ttl,
   238     uint8_t tos,
   275     uint8_t tos,
   239     bool mayFragment);
   276     bool mayFragment);
   240 
   277 
       
   278   /**
       
   279    * \brief Send packet with route.
       
   280    * \param route route
       
   281    * \param packet packet to send
       
   282    * \param ipHeader IPv4 header to add to the packet
       
   283    */
   241   void
   284   void
   242   SendRealOut (Ptr<Ipv4Route> route,
   285   SendRealOut (Ptr<Ipv4Route> route,
   243                Ptr<Packet> packet,
   286                Ptr<Packet> packet,
   244                Ipv4Header const &ipHeader);
   287                Ipv4Header const &ipHeader);
   245 
   288 
       
   289   /**
       
   290    * \brief Forward a packet.
       
   291    * \param rtentry route
       
   292    * \param p packet to forward
       
   293    * \param header IPv4 header to add to the packet
       
   294    */
   246   void 
   295   void 
   247   IpForward (Ptr<Ipv4Route> rtentry, 
   296   IpForward (Ptr<Ipv4Route> rtentry, 
   248              Ptr<const Packet> p, 
   297              Ptr<const Packet> p, 
   249              const Ipv4Header &header);
   298              const Ipv4Header &header);
   250 
   299 
       
   300   /**
       
   301    * \brief Forward a multicast packet.
       
   302    * \param mrtentry route
       
   303    * \param p packet to forward
       
   304    * \param header IPv6 header to add to the packet
       
   305    */
   251   void
   306   void
   252   IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, 
   307   IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, 
   253                       Ptr<const Packet> p, 
   308                       Ptr<const Packet> p, 
   254                       const Ipv4Header &header);
   309                       const Ipv4Header &header);
   255 
   310 
       
   311   /**
       
   312    * \brief Deliver a packet.
       
   313    * \param p packet delivered
       
   314    * \param ip IPv4 header
       
   315    * \param iif input interface packet was received
       
   316    */
   256   void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
   317   void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
       
   318 
       
   319   /**
       
   320    * \brief Fallback when no route is found.
       
   321    * \param p packet
       
   322    * \param ipHeader IPv4 header
       
   323    * \param sockErrno error number
       
   324    */
   257   void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno);
   325   void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno);
   258 
   326 
       
   327   /**
       
   328    * \brief Add an IPv4 interface to the stack.
       
   329    * \param interface interface to add
       
   330    * \return index of newly added interface
       
   331    */
   259   uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
   332   uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
       
   333 
       
   334   /**
       
   335    * \brief Setup loopback interface.
       
   336    */
   260   void SetupLoopback (void);
   337   void SetupLoopback (void);
   261 
   338 
   262   /**
   339   /**
   263    * \brief Get ICMPv4 protocol.
   340    * \brief Get ICMPv4 protocol.
   264    * \return Icmpv4L4Protocol pointer
   341    * \return Icmpv4L4Protocol pointer
   265    */
   342    */
   266   Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
   343   Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
       
   344 
       
   345   /**
       
   346    * \brief Check if an IPv4 address is unicast.
       
   347    * \param ad address
       
   348    * \param interfaceMask the network mask
       
   349    * \return true if the address is unicast
       
   350    */
   267   bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
   351   bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
   268 
   352 
   269   /**
   353   /**
   270    * \brief Fragment a packet
   354    * \brief Fragment a packet
   271    * \param packet the packet
   355    * \param packet the packet
   275   void DoFragmentation (Ptr<Packet> packet, uint32_t outIfaceMtu, std::list<Ptr<Packet> >& listFragments);
   359   void DoFragmentation (Ptr<Packet> packet, uint32_t outIfaceMtu, std::list<Ptr<Packet> >& listFragments);
   276 
   360 
   277   /**
   361   /**
   278    * \brief Process a packet fragment
   362    * \brief Process a packet fragment
   279    * \param packet the packet
   363    * \param packet the packet
   280    * \param fragmentSize the size of the fragment
   364    * \param ipHeader the IP header
   281    * \param iif Input Interface
   365    * \param iif Input Interface
   282    * \return true is the fragment completed the packet
   366    * \return true is the fragment completed the packet
   283    */
   367    */
   284   bool ProcessFragment (Ptr<Packet>& packet, Ipv4Header & ipHeader, uint32_t iif);
   368   bool ProcessFragment (Ptr<Packet>& packet, Ipv4Header & ipHeader, uint32_t iif);
   285 
   369 
   289    * \param ipHeader the IP header of the original packet
   373    * \param ipHeader the IP header of the original packet
   290    * \param iif Input Interface
   374    * \param iif Input Interface
   291    */
   375    */
   292   void HandleFragmentsTimeout ( std::pair<uint64_t, uint32_t> key, Ipv4Header & ipHeader, uint32_t iif);
   376   void HandleFragmentsTimeout ( std::pair<uint64_t, uint32_t> key, Ipv4Header & ipHeader, uint32_t iif);
   293 
   377 
       
   378   /**
       
   379    * \brief Container of the IPv4 Interfaces.
       
   380    */
   294   typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
   381   typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
       
   382   /**
       
   383    * \brief Container of the IPv4 Raw Sockets.
       
   384    */
   295   typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
   385   typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
   296   typedef std::list<Ptr<IpL4Protocol> > L4List_t;
   386   /**
   297 
   387    * \brief Container of the IPv4 L4 instances.
   298   bool m_ipForward;
   388    */
   299   bool m_weakEsModel;
   389    typedef std::list<Ptr<IpL4Protocol> > L4List_t;
   300   L4List_t m_protocols;
   390 
   301   Ipv4InterfaceList m_interfaces;
   391   bool m_ipForward;      //!< Forwarding packets (i.e. router mode) state.
   302   uint8_t m_defaultTos;
   392   bool m_weakEsModel;    //!< Weak ES model state
   303   uint8_t m_defaultTtl;
   393   L4List_t m_protocols;  //!< List of transport protocol.
   304   uint16_t m_identification;
   394   Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces.
   305   Ptr<Node> m_node;
   395   uint8_t m_defaultTos;  //!< Default TOS
   306 
   396   uint8_t m_defaultTtl;  //!< Default TTL
       
   397   uint16_t m_identification; //!< Identification
       
   398   Ptr<Node> m_node; //!< Node attached to stack.
       
   399 
       
   400   /// Trace of sent packets
   307   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
   401   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
       
   402   /// Trace of unicast forwarded packets
   308   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
   403   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
       
   404   /// Trace of locally delivered packets
   309   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
   405   TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
   310 
   406 
   311   // The following two traces pass a packet with an IP header
   407   // The following two traces pass a packet with an IP header
       
   408   /// Trace of transmitted packets
   312   TracedCallback<Ptr<const Packet>, Ptr<Ipv4>,  uint32_t> m_txTrace;
   409   TracedCallback<Ptr<const Packet>, Ptr<Ipv4>,  uint32_t> m_txTrace;
       
   410   /// Trace of received packets
   313   TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace;
   411   TracedCallback<Ptr<const Packet>, Ptr<Ipv4>, uint32_t> m_rxTrace;
   314   // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
   412   // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
       
   413   /// Trace of dropped packets
   315   TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, uint32_t> m_dropTrace;
   414   TracedCallback<const Ipv4Header &, Ptr<const Packet>, DropReason, Ptr<Ipv4>, uint32_t> m_dropTrace;
   316 
   415 
   317   Ptr<Ipv4RoutingProtocol> m_routingProtocol;
   416   Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< Routing protocol associated with the stack
   318 
   417 
   319   SocketList m_sockets;
   418   SocketList m_sockets; //!< List of IPv4 raw sockets.
   320 
   419 
   321   /**
   420   /**
   322    * \class Fragments
   421    * \class Fragments
   323    * \brief A Set of Fragment belonging to the same packet (src, dst, identification and proto)
   422    * \brief A Set of Fragment belonging to the same packet (src, dst, identification and proto)
   324    */
   423    */
   372      */
   471      */
   373     std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments;
   472     std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments;
   374 
   473 
   375   };
   474   };
   376 
   475 
       
   476   /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment
   377   typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments_t;
   477   typedef std::map< std::pair<uint64_t, uint32_t>, Ptr<Fragments> > MapFragments_t;
       
   478   /// Container of fragment timeout event, stored as pairs(src+dst addr, src+dst port) / EventId
   378   typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_t;
   479   typedef std::map< std::pair<uint64_t, uint32_t>, EventId > MapFragmentsTimers_t;
   379 
   480 
   380   /**
   481   MapFragments_t       m_fragments; //!< Fragmented packets.
   381    * \brief The hash of fragmented packets.
   482   Time                 m_fragmentExpirationTimeout; //!< Expiration timeout
   382    */
   483   MapFragmentsTimers_t m_fragmentsTimers; //!< Expiration events.
   383   MapFragments_t       m_fragments;
       
   384   Time                 m_fragmentExpirationTimeout;
       
   385   MapFragmentsTimers_t m_fragmentsTimers;
       
   386 
   484 
   387 };
   485 };
   388 
   486 
   389 } // Namespace ns3
   487 } // Namespace ns3
   390 
   488