A Discrete-Event Network Simulator
API
llc-snap-header.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 INRIA
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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "llc-snap-header.h"
21 
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 
25 #include <string>
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("LlcSnalHeader");
31 
32 NS_OBJECT_ENSURE_REGISTERED(LlcSnapHeader);
33 
35 {
36  NS_LOG_FUNCTION(this);
37 }
38 
39 void
41 {
42  NS_LOG_FUNCTION(this);
43  m_etherType = type;
44 }
45 
46 uint16_t
48 {
49  NS_LOG_FUNCTION(this);
50  return m_etherType;
51 }
52 
53 uint32_t
55 {
56  NS_LOG_FUNCTION(this);
58 }
59 
60 TypeId
62 {
63  static TypeId tid = TypeId("ns3::LlcSnapHeader")
64  .SetParent<Header>()
65  .SetGroupName("Network")
66  .AddConstructor<LlcSnapHeader>();
67  return tid;
68 }
69 
70 TypeId
72 {
73  return GetTypeId();
74 }
75 
76 void
77 LlcSnapHeader::Print(std::ostream& os) const
78 {
79  NS_LOG_FUNCTION(this << &os);
80  os << "type 0x";
81  os.setf(std::ios::hex, std::ios::basefield);
82  os << m_etherType;
83  os.setf(std::ios::dec, std::ios::basefield);
84 }
85 
86 void
88 {
89  NS_LOG_FUNCTION(this << &start);
91  uint8_t buf[] = {0xaa, 0xaa, 0x03, 0, 0, 0};
92  i.Write(buf, 6);
94 }
95 
96 uint32_t
98 {
99  NS_LOG_FUNCTION(this << &start);
101  i.Next(5 + 1);
102  m_etherType = i.ReadNtohU16();
103  return GetSerializedSize();
104 }
105 
106 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void Write(const uint8_t *buffer, uint32_t size)
Definition: buffer.cc:948
void WriteHtonU16(uint16_t data)
Definition: buffer.h:915
uint16_t ReadNtohU16()
Definition: buffer.h:954
void Next()
go forward by one byte
Definition: buffer.h:853
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Header for the LLC/SNAP encapsulation.
uint16_t m_etherType
the Ethertype
void Print(std::ostream &os) const override
static TypeId GetTypeId()
Get the type ID.
uint16_t GetType()
Return the Ethertype.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t GetSerializedSize() const override
void Serialize(Buffer::Iterator start) const override
void SetType(uint16_t type)
Set the Ethertype.
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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.
static const uint16_t LLC_SNAP_HEADER_LENGTH
The length in octets of the LLC/SNAP header.