A Discrete-Event Network Simulator
API
sll-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Université Pierre et Marie Curie
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Matthieu Coudron <matthieu.coudron@lip6.fr>
19  */
20 #include "sll-header.h"
21 #include "ns3/log.h"
22 
23 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("SllHeader");
27 
28 NS_OBJECT_ENSURE_REGISTERED (SllHeader);
29 
31  : m_packetType (UNICAST_FROM_PEER_TO_ME),
32  m_arphdType (0),
33  m_addressLength (0),
34  m_address (0),
35  m_protocolType (0)
36 {
37  NS_LOG_FUNCTION (this);
38 }
39 
41 {
42  NS_LOG_FUNCTION (this);
43 }
44 
45 
46 TypeId
48 {
49  static TypeId tid = TypeId ("ns3::SllHeader")
50  .SetParent<Header> ()
51  .SetGroupName ("Network")
52  .AddConstructor<SllHeader> ()
53  ;
54  return tid;
55 }
56 
57 TypeId
59 {
60  return GetTypeId ();
61 }
62 
63 uint16_t
65 {
66  return m_arphdType;
67 }
68 
69 void
70 SllHeader::SetArpType (uint16_t arphdType)
71 {
72  NS_LOG_FUNCTION (arphdType);
73  m_arphdType = arphdType;
74 }
75 
78 {
79  return m_packetType;
80 }
81 
82 void
84 {
85  NS_LOG_FUNCTION (type);
86  m_packetType = type;
87 }
88 
89 void
90 SllHeader::Print (std::ostream &os) const
91 {
92  os << "SLLHeader packetType=" << m_packetType << " protocol=" << m_protocolType;
93 }
94 
95 uint32_t
97 {
98  return 2 + 2 + 2 + 8 + 2;
99 }
100 
101 void
103 {
110 }
111 
112 uint32_t
114 {
116  m_packetType = static_cast<PacketType> (i.ReadNtohU16 ());
117  m_arphdType = i.ReadNtohU16 ();
119  m_address = i.ReadNtohU64 ();
121 
122  return GetSerializedSize ();
123 }
124 
125 }
Protocol header serialization and deserialization.
Definition: header.h:42
void WriteHtonU64(uint64_t data)
Definition: buffer.cc:940
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t m_protocolType
protocol type
Definition: sll-header.h:124
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint64_t m_address
Address.
Definition: sll-header.h:123
uint16_t m_arphdType
ARP protocol hardware identifier.
Definition: sll-header.h:121
def start()
Definition: core.py:1844
void SetPacketType(PacketType type)
Definition: sll-header.cc:83
uint64_t ReadNtohU64(void)
Definition: buffer.cc:1043
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
iterator in a Buffer instance
Definition: buffer.h:98
PacketType
Type of the packet.
Definition: sll-header.h:71
static TypeId GetTypeId(void)
Get the type ID.
Definition: sll-header.cc:47
Protocol header serialization and deserialization.
Definition: sll-header.h:64
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
uint16_t m_addressLength
Address length.
Definition: sll-header.h:122
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: sll-header.cc:113
PacketType m_packetType
Packet type.
Definition: sll-header.h:120
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetArpType(uint16_t arphdType)
Definition: sll-header.cc:70
virtual uint32_t GetSerializedSize(void) const
Definition: sll-header.cc:96
uint16_t GetArpType() const
Definition: sll-header.cc:64
virtual void Print(std::ostream &os) const
Definition: sll-header.cc:90
virtual ~SllHeader()
Definition: sll-header.cc:40
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: sll-header.cc:58
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
virtual void Serialize(Buffer::Iterator start) const
Definition: sll-header.cc:102
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
enum PacketType GetPacketType() const
Definition: sll-header.cc:77