Bug #729 IPv6 over PPP.
authorSebastien Vincent <vincent@clarinet.u-strasbg.fr>
Wed Nov 11 16:21:18 2009 +0100 (3 months ago)
changeset 5503c305c6e122c9
parent 5502 04acce3f7133
child 5504 2cc780c07f5e
child 5505 c0ac392289c3
child 5803 56b5e7ff673a
Bug #729 IPv6 over PPP.
src/devices/point-to-point/point-to-point-net-device.cc
src/devices/point-to-point/point-to-point-net-device.h
src/devices/point-to-point/ppp-header.cc
src/devices/point-to-point/ppp-header.h
     1.1 --- a/src/devices/point-to-point/point-to-point-net-device.cc	Wed Nov 11 12:44:09 2009 +0100
     1.2 +++ b/src/devices/point-to-point/point-to-point-net-device.cc	Wed Nov 11 16:21:18 2009 +0100
     1.3 @@ -173,8 +173,8 @@
     1.4  PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
     1.5  {
     1.6    NS_LOG_FUNCTION_NOARGS ();
     1.7 -  NS_ASSERT_MSG (protocolNumber == 0x800, "PointToPointNetDevice::AddHeader(): protocolNumber must be 0x800");
     1.8    PppHeader ppp;
     1.9 +  ppp.SetProtocol(EtherToPpp(protocolNumber));
    1.10    p->AddHeader (ppp);
    1.11  }
    1.12  
    1.13 @@ -184,7 +184,7 @@
    1.14    NS_LOG_FUNCTION_NOARGS ();
    1.15    PppHeader ppp;
    1.16    p->RemoveHeader (ppp);
    1.17 -  param = 0x800;
    1.18 +  param = PppToEther(ppp.GetProtocol());
    1.19    return true;
    1.20  }
    1.21  
    1.22 @@ -655,5 +655,29 @@
    1.23    return m_mtu;
    1.24  }
    1.25  
    1.26 +  uint16_t
    1.27 +PointToPointNetDevice::PppToEther(uint16_t proto)
    1.28 +{
    1.29 +  switch(proto)
    1.30 +    {
    1.31 +      case 0x0021: return 0x0800; //IPv4
    1.32 +      case 0x0057: return 0x86DD; //IPv6
    1.33 +      default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
    1.34 +    }
    1.35 +  return 0;
    1.36 +}
    1.37 +
    1.38 +  uint16_t
    1.39 +PointToPointNetDevice::EtherToPpp(uint16_t proto)
    1.40 +{
    1.41 +  switch(proto)
    1.42 +    {
    1.43 +      case 0x0800: return 0x0021; //IPv4
    1.44 +      case 0x86DD: return 0x0057; //IPv6
    1.45 +      default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
    1.46 +    }
    1.47 +  return 0;
    1.48 +}
    1.49 +
    1.50  
    1.51  } // namespace ns3
     2.1 --- a/src/devices/point-to-point/point-to-point-net-device.h	Wed Nov 11 12:44:09 2009 +0100
     2.2 +++ b/src/devices/point-to-point/point-to-point-net-device.h	Wed Nov 11 16:21:18 2009 +0100
     2.3 @@ -548,6 +548,20 @@
     2.4    uint32_t m_mtu;
     2.5  
     2.6    Ptr<Packet> m_currentPkt;
     2.7 +
     2.8 +  /**
     2.9 +   * \brief PPP to Ethernet protocol number mapping
    2.10 +   * \param protocol A PPP protocol number
    2.11 +   * \return The corresponding Ethernet protocol number
    2.12 +   */
    2.13 +  static uint16_t PppToEther(uint16_t protocol);
    2.14 +
    2.15 +  /**
    2.16 +   * \brief Ethernet to PPP protocol number mapping
    2.17 +   * \param protocol An Ethernet protocol number
    2.18 +   * \return The corresponding PPP protocol number
    2.19 +   */
    2.20 +  static uint16_t EtherToPpp(uint16_t protocol);
    2.21  };
    2.22  
    2.23  } // namespace ns3
     3.1 --- a/src/devices/point-to-point/ppp-header.cc	Wed Nov 11 12:44:09 2009 +0100
     3.2 +++ b/src/devices/point-to-point/ppp-header.cc	Wed Nov 11 16:21:18 2009 +0100
     3.3 @@ -56,7 +56,7 @@
     3.4  void 
     3.5  PppHeader::Print (std::ostream &os) const
     3.6  {
     3.7 -  os << "Point-to-Point Protocol: IP (0x0021)";
     3.8 +  os << "Point-to-Point Protocol: " << m_protocol;
     3.9  }
    3.10  
    3.11    uint32_t
    3.12 @@ -68,15 +68,27 @@
    3.13    void
    3.14  PppHeader::Serialize (Buffer::Iterator start) const
    3.15  {
    3.16 -  start.WriteHtonU16 (0x0021);
    3.17 +  start.WriteHtonU16 (m_protocol);
    3.18  }
    3.19  
    3.20    uint32_t
    3.21  PppHeader::Deserialize (Buffer::Iterator start)
    3.22  {
    3.23 -  uint16_t data = start.ReadNtohU16 ();
    3.24 -  NS_ABORT_MSG_UNLESS (data == 0x0021, "MyHeader::Deserialize(): expected protocol 0x0021");
    3.25 -  return 2;
    3.26 +  m_protocol = start.ReadNtohU16 ();
    3.27 +  return GetSerializedSize();
    3.28  }
    3.29  
    3.30 +  void
    3.31 +PppHeader::SetProtocol (uint16_t protocol)
    3.32 +{
    3.33 +  m_protocol=protocol;
    3.34 +}
    3.35 +
    3.36 +  uint16_t
    3.37 +PppHeader::GetProtocol (void)
    3.38 +{
    3.39 +  return m_protocol;
    3.40 +}
    3.41 +
    3.42 +
    3.43  } // namespace ns3
     4.1 --- a/src/devices/point-to-point/ppp-header.h	Wed Nov 11 12:44:09 2009 +0100
     4.2 +++ b/src/devices/point-to-point/ppp-header.h	Wed Nov 11 16:21:18 2009 +0100
     4.3 @@ -28,9 +28,9 @@
     4.4   *
     4.5   * This class can be used to add a header to PPP packet.  Currently we do not
     4.6   * implement any of the state machine in RFC 1661, we just encapsulate the
     4.7 - * inbound packet as an IP version 4 type and send it on.  The goal here is
     4.8 - * not really to implement the point-to-point protocol, but to encapsulate our
     4.9 - * packets in a known protocol so packet sniffers can parse them.
    4.10 + * inbound packet send it on.  The goal here is not really to implement the
    4.11 + * point-to-point protocol, but to encapsulate our packets in a known protocol
    4.12 + * so packet sniffers can parse them.
    4.13   *
    4.14   * if PPP is transmitted over a serial link, it will typically be framed in
    4.15   * some way derivative of IBM SDLC (HDLC) with all that that entails.
    4.16 @@ -41,20 +41,20 @@
    4.17   * teach the PcapWriter about the appropriate data link type (DLT_PPP = 9),
    4.18   * and we need to add a PPP header to each packet.  Since we are not using
    4.19   * framed PPP, this just means prepending the sixteen bit PPP protocol number
    4.20 - * (0x0021) to the packet.  The ns-3 way to do this is via a class that 
    4.21 - * inherits from class Header.
    4.22 + * to the packet.  The ns-3 way to do this is via a class that inherits from
    4.23 + * class Header.
    4.24   */
    4.25  class PppHeader : public Header 
    4.26  {
    4.27  public:
    4.28  
    4.29    /**
    4.30 -   * \brief Construct an IP version 4 PPP header.
    4.31 +   * \brief Construct a PPP header.
    4.32     */
    4.33    PppHeader ();
    4.34  
    4.35    /**
    4.36 -   * \brief Destroy an IP version 4 PPP header.
    4.37 +   * \brief Destroy a PPP header.
    4.38     */
    4.39    virtual ~PppHeader ();
    4.40  
    4.41 @@ -64,6 +64,31 @@
    4.42    virtual void Serialize (Buffer::Iterator start) const;
    4.43    virtual uint32_t Deserialize (Buffer::Iterator start);
    4.44    virtual uint32_t GetSerializedSize (void) const;
    4.45 +
    4.46 +  /**
    4.47 +   * \brief Set the protocol type carried by this PPP packet
    4.48 +   *
    4.49 +   * The type numbers to be used are defined in RFC3818
    4.50 +   *
    4.51 +   * \param protocol the protocol type being carried
    4.52 +   */
    4.53 +  void SetProtocol(uint16_t protocol);
    4.54 +
    4.55 +  /**
    4.56 +   * \brief Get the protocol type carried by this PPP packet
    4.57 +   *
    4.58 +   * The type numbers to be used are defined in RFC3818
    4.59 +   *
    4.60 +   * \return the protocol type being carried
    4.61 +   */
    4.62 +  uint16_t GetProtocol(void);
    4.63 +
    4.64 +private:
    4.65 +
    4.66 +  /**
    4.67 +   * \brief The PPP protocol type of the payload packet
    4.68 +   */
    4.69 +  uint16_t m_protocol;
    4.70  };
    4.71  
    4.72  }; // namespace ns3