View | Details | Raw Unified | Return to bug 729
Collapse All | Expand All

(-)a/src/devices/point-to-point/point-to-point-net-device.cc (-2 / +26 lines)
 Lines 173-180    Link Here 
173
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
173
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
174
{
174
{
175
  NS_LOG_FUNCTION_NOARGS ();
175
  NS_LOG_FUNCTION_NOARGS ();
176
  NS_ASSERT_MSG (protocolNumber == 0x800, "PointToPointNetDevice::AddHeader(): protocolNumber must be 0x800");
177
  PppHeader ppp;
176
  PppHeader ppp;
177
  ppp.SetProtocol(ETHERtoPPP(protocolNumber));
178
  p->AddHeader (ppp);
178
  p->AddHeader (ppp);
179
}
179
}
180
180
 Lines 184-190    Link Here 
184
  NS_LOG_FUNCTION_NOARGS ();
184
  NS_LOG_FUNCTION_NOARGS ();
185
  PppHeader ppp;
185
  PppHeader ppp;
186
  p->RemoveHeader (ppp);
186
  p->RemoveHeader (ppp);
187
  param = 0x800;
187
  param = PPPtoETHER(ppp.GetProtocol());
188
  return true;
188
  return true;
189
}
189
}
190
190
 Lines 655-659    Link Here 
655
  return m_mtu;
655
  return m_mtu;
656
}
656
}
657
657
658
  uint16_t
659
PointToPointNetDevice::PPPtoETHER(uint16_t proto)
660
{
661
  switch(proto)
662
    {
663
      case 0x0021: return 0x0800; //IPv4
664
      case 0x0057: return 0x86DD; //IPv6
665
      default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
666
    }
667
  return 0;
668
}
669
670
  uint16_t
671
PointToPointNetDevice::ETHERtoPPP(uint16_t proto)
672
{
673
  switch(proto)
674
    {
675
      case 0x0800: return 0x0021; //IPv4
676
      case 0x86DD: return 0x0057; //IPv6
677
      default: NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
678
    }
679
  return 0;
680
}
681
658
682
659
} // namespace ns3
683
} // namespace ns3
(-)a/src/devices/point-to-point/point-to-point-net-device.h (+9 lines)
 Lines 548-553    Link Here 
548
  uint32_t m_mtu;
548
  uint32_t m_mtu;
549
549
550
  Ptr<Packet> m_currentPkt;
550
  Ptr<Packet> m_currentPkt;
551
552
  /**
553
   * PPP to Ethernet protocol number mapping
554
   */
555
  static uint16_t PPPtoETHER(uint16_t);
556
  /**
557
   * Ethernet to PPP protocol number mapping
558
   */
559
  static uint16_t ETHERtoPPP(uint16_t);
551
};
560
};
552
561
553
} // namespace ns3
562
} // namespace ns3
(-)a/src/devices/point-to-point/ppp-header.cc (-5 / +17 lines)
 Lines 56-62    Link Here 
56
void 
56
void 
57
PppHeader::Print (std::ostream &os) const
57
PppHeader::Print (std::ostream &os) const
58
{
58
{
59
  os << "Point-to-Point Protocol: IP (0x0021)";
59
  os << "Point-to-Point Protocol: " << m_protocol;
60
}
60
}
61
61
62
  uint32_t
62
  uint32_t
 Lines 68-82    Link Here 
68
  void
68
  void
69
PppHeader::Serialize (Buffer::Iterator start) const
69
PppHeader::Serialize (Buffer::Iterator start) const
70
{
70
{
71
  start.WriteHtonU16 (0x0021);
71
  start.WriteHtonU16 (m_protocol);
72
}
72
}
73
73
74
  uint32_t
74
  uint32_t
75
PppHeader::Deserialize (Buffer::Iterator start)
75
PppHeader::Deserialize (Buffer::Iterator start)
76
{
76
{
77
  uint16_t data = start.ReadNtohU16 ();
77
  m_protocol = start.ReadNtohU16 ();
78
  NS_ABORT_MSG_UNLESS (data == 0x0021, "MyHeader::Deserialize(): expected protocol 0x0021");
78
  return GetSerializedSize();
79
  return 2;
80
}
79
}
81
80
81
  void
82
PppHeader::SetProtocol (uint16_t protocol)
83
{
84
  m_protocol=protocol;
85
}
86
87
  uint16_t
88
PppHeader::GetProtocol (void)
89
{
90
  return m_protocol;
91
}
92
93
82
} // namespace ns3
94
} // namespace ns3
(-)a/src/devices/point-to-point/ppp-header.h (-7 / +28 lines)
 Lines 28-36    Link Here 
28
 *
28
 *
29
 * This class can be used to add a header to PPP packet.  Currently we do not
29
 * This class can be used to add a header to PPP packet.  Currently we do not
30
 * implement any of the state machine in RFC 1661, we just encapsulate the
30
 * implement any of the state machine in RFC 1661, we just encapsulate the
31
 * inbound packet as an IP version 4 type and send it on.  The goal here is
31
 * inbound packet send it on.  The goal here is not really to implement the
32
 * not really to implement the point-to-point protocol, but to encapsulate our
32
 * point-to-point protocol, but to encapsulate our packets in a known protocol
33
 * packets in a known protocol so packet sniffers can parse them.
33
 * so packet sniffers can parse them.
34
 *
34
 *
35
 * if PPP is transmitted over a serial link, it will typically be framed in
35
 * if PPP is transmitted over a serial link, it will typically be framed in
36
 * some way derivative of IBM SDLC (HDLC) with all that that entails.
36
 * some way derivative of IBM SDLC (HDLC) with all that that entails.
 Lines 41-60    Link Here 
41
 * teach the PcapWriter about the appropriate data link type (DLT_PPP = 9),
41
 * teach the PcapWriter about the appropriate data link type (DLT_PPP = 9),
42
 * and we need to add a PPP header to each packet.  Since we are not using
42
 * and we need to add a PPP header to each packet.  Since we are not using
43
 * framed PPP, this just means prepending the sixteen bit PPP protocol number
43
 * framed PPP, this just means prepending the sixteen bit PPP protocol number
44
 * (0x0021) to the packet.  The ns-3 way to do this is via a class that 
44
 * to the packet.  The ns-3 way to do this is via a class that inherits from
45
 * inherits from class Header.
45
 * class Header.
46
 */
46
 */
47
class PppHeader : public Header 
47
class PppHeader : public Header 
48
{
48
{
49
public:
49
public:
50
50
51
  /**
51
  /**
52
   * \brief Construct an IP version 4 PPP header.
52
   * \brief Construct a PPP header.
53
   */
53
   */
54
  PppHeader ();
54
  PppHeader ();
55
55
56
  /**
56
  /**
57
   * \brief Destroy an IP version 4 PPP header.
57
   * \brief Destroy a PPP header.
58
   */
58
   */
59
  virtual ~PppHeader ();
59
  virtual ~PppHeader ();
60
60
 Lines 64-69    Link Here 
64
  virtual void Serialize (Buffer::Iterator start) const;
64
  virtual void Serialize (Buffer::Iterator start) const;
65
  virtual uint32_t Deserialize (Buffer::Iterator start);
65
  virtual uint32_t Deserialize (Buffer::Iterator start);
66
  virtual uint32_t GetSerializedSize (void) const;
66
  virtual uint32_t GetSerializedSize (void) const;
67
68
  /**
69
   * \brief Set the protocol type carried by this PPP packet
70
   *
71
   * The type numbers to be used are defined in RFC3818
72
   *
73
   * \param protocol the protocol type being carried
74
   */
75
  void SetProtocol(uint16_t protocol);
76
77
  /**
78
   * \brief Get the protocol type carried by this PPP packet
79
   *
80
   * The type numbers to be used are defined in RFC3818
81
   *
82
   * \return the protocol type being carried
83
   */
84
  uint16_t GetProtocol(void);
85
86
private:
87
  uint16_t m_protocol;
67
};
88
};
68
89
69
}; // namespace ns3
90
}; // namespace ns3

Return to bug 729