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/iana-ppp-numbers.h"
13#include "ns3/log.h"
14
15#include <iostream>
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("PppHeader");
21
23
27
31
34{
35 static TypeId tid = TypeId("ns3::PppHeader")
37 .SetGroupName("PointToPoint")
38 .AddConstructor<PppHeader>();
39 return tid;
40}
41
44{
45 return GetTypeId();
46}
47
48void
49PppHeader::Print(std::ostream& os) const
50{
51 std::string proto;
52
53 switch (m_protocol)
54 {
56 proto = "IP (0x0021)";
57 break;
59 proto = "IPv6 (0x0057)";
60 break;
61 default:
62 NS_ASSERT_MSG(false, "PPP DLL Protocol number not defined!");
63 }
64 os << "Point-to-Point Protocol: " << proto;
65}
66
69{
70 return 2;
71}
72
73void
75{
76 start.WriteHtonU16(m_protocol);
77}
78
81{
82 m_protocol = start.ReadNtohU16();
83 return GetSerializedSize();
84}
85
86void
87PppHeader::SetProtocol(uint16_t protocol)
88{
89 m_protocol = protocol;
90}
91
92uint16_t
94{
95 return m_protocol;
96}
97
98} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:109
Protocol header serialization and deserialization.
Definition header.h:36
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:87
uint32_t Deserialize(Buffer::Iterator start) override
Definition ppp-header.cc:80
TypeId GetInstanceTypeId() const override
Get the TypeId of the instance.
Definition ppp-header.cc:43
static TypeId GetTypeId()
Get the TypeId.
Definition ppp-header.cc:33
~PppHeader() override
Destroy a PPP header.
Definition ppp-header.cc:28
uint32_t GetSerializedSize() const override
Definition ppp-header.cc:68
void Serialize(Buffer::Iterator start) const override
Definition ppp-header.cc:74
uint16_t GetProtocol() const
Get the protocol type carried by this PPP packet.
Definition ppp-header.cc:93
PppHeader()
Construct a PPP header.
Definition ppp-header.cc:24
void Print(std::ostream &os) const override
Definition ppp-header.cc:49
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
#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:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
constexpr uint16_t IPV4_DLL
IPv4 PPP protocol number.
constexpr uint16_t IPV6_DLL
IPv6 PPP protocol number.
Every class exported by the ns3 library is enclosed in the ns3 namespace.