# HG changeset patch # User Fabian Mauchle # Date 1256201897 -7200 # Node ID f5e6f524b7874c39c9469f2160ad7e767b62fd37 # Parent 2abe024e7099d8dc848d00f738af7b21f4e0b815 IPv6 over PPP diff -r 2abe024e7099 -r f5e6f524b787 src/devices/point-to-point/point-to-point-net-device.cc --- a/src/devices/point-to-point/point-to-point-net-device.cc Wed Oct 21 17:19:03 2009 -0700 +++ b/src/devices/point-to-point/point-to-point-net-device.cc Thu Oct 22 10:58:17 2009 +0200 @@ -173,8 +173,8 @@ PointToPointNetDevice::AddHeader(Ptr p, uint16_t protocolNumber) { NS_LOG_FUNCTION_NOARGS (); - NS_ASSERT_MSG (protocolNumber == 0x800, "PointToPointNetDevice::AddHeader(): protocolNumber must be 0x800"); PppHeader ppp; + ppp.SetProtocol(ETHERtoPPP(protocolNumber)); p->AddHeader (ppp); } @@ -184,7 +184,7 @@ NS_LOG_FUNCTION_NOARGS (); PppHeader ppp; p->RemoveHeader (ppp); - param = 0x800; + param = PPPtoETHER(ppp.GetProtocol()); return true; } @@ -655,5 +655,29 @@ return m_mtu; } + uint16_t +PointToPointNetDevice::PPPtoETHER(uint16_t proto) +{ + switch(proto) + { + case 0x0021: return 0x0800; //IPv4 + case 0x0057: return 0x86DD; //IPv6 + default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!"); + } + return 0; +} + + uint16_t +PointToPointNetDevice::ETHERtoPPP(uint16_t proto) +{ + switch(proto) + { + case 0x0800: return 0x0021; //IPv4 + case 0x86DD: return 0x0057; //IPv6 + default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!"); + } + return 0; +} + } // namespace ns3 diff -r 2abe024e7099 -r f5e6f524b787 src/devices/point-to-point/point-to-point-net-device.h --- a/src/devices/point-to-point/point-to-point-net-device.h Wed Oct 21 17:19:03 2009 -0700 +++ b/src/devices/point-to-point/point-to-point-net-device.h Thu Oct 22 10:58:17 2009 +0200 @@ -548,6 +548,15 @@ uint32_t m_mtu; Ptr m_currentPkt; + + /** + * PPP to Ethernet protocol number mapping + */ + static uint16_t PPPtoETHER(uint16_t); + /** + * Ethernet to PPP protocol number mapping + */ + static uint16_t ETHERtoPPP(uint16_t); }; } // namespace ns3 diff -r 2abe024e7099 -r f5e6f524b787 src/devices/point-to-point/ppp-header.cc --- a/src/devices/point-to-point/ppp-header.cc Wed Oct 21 17:19:03 2009 -0700 +++ b/src/devices/point-to-point/ppp-header.cc Thu Oct 22 10:58:17 2009 +0200 @@ -56,7 +56,7 @@ void PppHeader::Print (std::ostream &os) const { - os << "Point-to-Point Protocol: IP (0x0021)"; + os << "Point-to-Point Protocol: " << m_protocol; } uint32_t @@ -68,15 +68,27 @@ void PppHeader::Serialize (Buffer::Iterator start) const { - start.WriteHtonU16 (0x0021); + start.WriteHtonU16 (m_protocol); } uint32_t PppHeader::Deserialize (Buffer::Iterator start) { - uint16_t data = start.ReadNtohU16 (); - NS_ABORT_MSG_UNLESS (data == 0x0021, "MyHeader::Deserialize(): expected protocol 0x0021"); - return 2; + m_protocol = start.ReadNtohU16 (); + return GetSerializedSize(); } + void +PppHeader::SetProtocol (uint16_t protocol) +{ + m_protocol=protocol; +} + + uint16_t +PppHeader::GetProtocol (void) +{ + return m_protocol; +} + + } // namespace ns3 diff -r 2abe024e7099 -r f5e6f524b787 src/devices/point-to-point/ppp-header.h --- a/src/devices/point-to-point/ppp-header.h Wed Oct 21 17:19:03 2009 -0700 +++ b/src/devices/point-to-point/ppp-header.h Thu Oct 22 10:58:17 2009 +0200 @@ -28,9 +28,9 @@ * * This class can be used to add a header to PPP packet. Currently we do not * implement any of the state machine in RFC 1661, we just encapsulate the - * inbound packet as an IP version 4 type and send it on. The goal here is - * not really to implement the point-to-point protocol, but to encapsulate our - * packets in a known protocol so packet sniffers can parse them. + * inbound packet send it on. The goal here is not really to implement the + * point-to-point protocol, but to encapsulate our packets in a known protocol + * so packet sniffers can parse them. * * if PPP is transmitted over a serial link, it will typically be framed in * some way derivative of IBM SDLC (HDLC) with all that that entails. @@ -41,20 +41,20 @@ * teach the PcapWriter about the appropriate data link type (DLT_PPP = 9), * and we need to add a PPP header to each packet. Since we are not using * framed PPP, this just means prepending the sixteen bit PPP protocol number - * (0x0021) to the packet. The ns-3 way to do this is via a class that - * inherits from class Header. + * to the packet. The ns-3 way to do this is via a class that inherits from + * class Header. */ class PppHeader : public Header { public: /** - * \brief Construct an IP version 4 PPP header. + * \brief Construct a PPP header. */ PppHeader (); /** - * \brief Destroy an IP version 4 PPP header. + * \brief Destroy a PPP header. */ virtual ~PppHeader (); @@ -64,6 +64,27 @@ virtual void Serialize (Buffer::Iterator start) const; virtual uint32_t Deserialize (Buffer::Iterator start); virtual uint32_t GetSerializedSize (void) const; + + /** + * \brief Set the protocol type carried by this PPP packet + * + * The type numbers to be used are defined in RFC3818 + * + * \param protocol the protocol type being carried + */ + void SetProtocol(uint16_t protocol); + + /** + * \brief Get the protocol type carried by this PPP packet + * + * The type numbers to be used are defined in RFC3818 + * + * \return the protocol type being carried + */ + uint16_t GetProtocol(void); + +private: + uint16_t m_protocol; }; }; // namespace ns3