A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ppp-header.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #include "ppp-header.h"
19 
20 #include "ns3/abort.h"
21 #include "ns3/assert.h"
22 #include "ns3/header.h"
23 #include "ns3/log.h"
24 
25 #include <iostream>
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("PppHeader");
31 
33 
35 {
36 }
37 
39 {
40 }
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::PppHeader")
46  .SetParent<Header>()
47  .SetGroupName("PointToPoint")
48  .AddConstructor<PppHeader>();
49  return tid;
50 }
51 
52 TypeId
54 {
55  return GetTypeId();
56 }
57 
58 void
59 PppHeader::Print(std::ostream& os) const
60 {
61  std::string proto;
62 
63  switch (m_protocol)
64  {
65  case 0x0021: /* IPv4 */
66  proto = "IP (0x0021)";
67  break;
68  case 0x0057: /* IPv6 */
69  proto = "IPv6 (0x0057)";
70  break;
71  default:
72  NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
73  }
74  os << "Point-to-Point Protocol: " << proto;
75 }
76 
77 uint32_t
79 {
80  return 2;
81 }
82 
83 void
85 {
86  start.WriteHtonU16(m_protocol);
87 }
88 
89 uint32_t
91 {
92  m_protocol = start.ReadNtohU16();
93  return GetSerializedSize();
94 }
95 
96 void
97 PppHeader::SetProtocol(uint16_t protocol)
98 {
99  m_protocol = protocol;
100 }
101 
102 uint16_t
104 {
105  return m_protocol;
106 }
107 
108 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Packet header for PPP.
Definition: ppp-header.h:49
uint16_t m_protocol
The PPP protocol type of the payload packet.
Definition: ppp-header.h:102
void SetProtocol(uint16_t protocol)
Set the protocol type carried by this PPP packet.
Definition: ppp-header.cc:97
TypeId GetInstanceTypeId() const override
Get the TypeId of the instance.
Definition: ppp-header.cc:53
static TypeId GetTypeId()
Get the TypeId.
Definition: ppp-header.cc:43
~PppHeader() override
Destroy a PPP header.
Definition: ppp-header.cc:38
uint32_t GetSerializedSize() const override
Definition: ppp-header.cc:78
void Serialize(Buffer::Iterator start) const override
Definition: ppp-header.cc:84
uint16_t GetProtocol() const
Get the protocol type carried by this PPP packet.
Definition: ppp-header.cc:103
PppHeader()
Construct a PPP header.
Definition: ppp-header.cc:34
void Print(std::ostream &os) const override
Definition: ppp-header.cc:59
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.