A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ppp-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ppp-header.h"
8
9#include "ns3/abort.h"
10#include "ns3/assert.h"
11#include "ns3/header.h"
12#include "ns3/log.h"
13
14#include <iostream>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("PppHeader");
20
22
26
30
33{
34 static TypeId tid = TypeId("ns3::PppHeader")
36 .SetGroupName("PointToPoint")
37 .AddConstructor<PppHeader>();
38 return tid;
39}
40
43{
44 return GetTypeId();
45}
46
47void
48PppHeader::Print(std::ostream& os) const
49{
50 std::string proto;
51
52 switch (m_protocol)
53 {
54 case 0x0021: /* IPv4 */
55 proto = "IP (0x0021)";
56 break;
57 case 0x0057: /* IPv6 */
58 proto = "IPv6 (0x0057)";
59 break;
60 default:
61 NS_ASSERT_MSG(false, "PPP Protocol number not defined!");
62 }
63 os << "Point-to-Point Protocol: " << proto;
64}
65
68{
69 return 2;
70}
71
72void
74{
75 start.WriteHtonU16(m_protocol);
76}
77
80{
81 m_protocol = start.ReadNtohU16();
82 return GetSerializedSize();
83}
84
85void
86PppHeader::SetProtocol(uint16_t protocol)
87{
88 m_protocol = protocol;
89}
90
91uint16_t
93{
94 return m_protocol;
95}
96
97} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
Packet header for PPP.
Definition ppp-header.h:38
uint16_t m_protocol
The PPP protocol type of the payload packet.
Definition ppp-header.h:91
void SetProtocol(uint16_t protocol)
Set the protocol type carried by this PPP packet.
Definition ppp-header.cc:86
uint32_t Deserialize(Buffer::Iterator start) override
Definition ppp-header.cc:79
TypeId GetInstanceTypeId() const override
Get the TypeId of the instance.
Definition ppp-header.cc:42
static TypeId GetTypeId()
Get the TypeId.
Definition ppp-header.cc:32
~PppHeader() override
Destroy a PPP header.
Definition ppp-header.cc:27
uint32_t GetSerializedSize() const override
Definition ppp-header.cc:67
void Serialize(Buffer::Iterator start) const override
Definition ppp-header.cc:73
uint16_t GetProtocol() const
Get the protocol type carried by this PPP packet.
Definition ppp-header.cc:92
PppHeader()
Construct a PPP header.
Definition ppp-header.cc:23
void Print(std::ostream &os) const override
Definition ppp-header.cc:48
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.