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
SllHeader()30 SllHeader::SllHeader ()
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
~SllHeader()40 SllHeader::~SllHeader ()
41 {
42 NS_LOG_FUNCTION (this);
43 }
44
45
46 TypeId
GetTypeId(void)47 SllHeader::GetTypeId (void)
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
GetInstanceTypeId(void) const58 SllHeader::GetInstanceTypeId (void) const
59 {
60 return GetTypeId ();
61 }
62
63 uint16_t
GetArpType() const64 SllHeader::GetArpType () const
65 {
66 return m_arphdType;
67 }
68
69 void
SetArpType(uint16_t arphdType)70 SllHeader::SetArpType (uint16_t arphdType)
71 {
72 NS_LOG_FUNCTION (arphdType);
73 m_arphdType = arphdType;
74 }
75
76 SllHeader::PacketType
GetPacketType(void) const77 SllHeader::GetPacketType (void) const
78 {
79 return m_packetType;
80 }
81
82 void
SetPacketType(PacketType type)83 SllHeader::SetPacketType (PacketType type)
84 {
85 NS_LOG_FUNCTION (type);
86 m_packetType = type;
87 }
88
89 void
Print(std::ostream & os) const90 SllHeader::Print (std::ostream &os) const
91 {
92 os << "SLLHeader packetType=" << m_packetType << " protocol=" << m_protocolType;
93 }
94
95 uint32_t
GetSerializedSize(void) const96 SllHeader::GetSerializedSize (void) const
97 {
98 return 2 + 2 + 2 + 8 + 2;
99 }
100
101 void
Serialize(Buffer::Iterator start) const102 SllHeader::Serialize (Buffer::Iterator start) const
103 {
104 Buffer::Iterator i = start;
105 i.WriteHtonU16 (m_packetType);
106 i.WriteHtonU16 (m_arphdType);
107 i.WriteHtonU16 (m_addressLength);
108 i.WriteHtonU64 (m_address);
109 i.WriteHtonU16 (m_protocolType);
110 }
111
112 uint32_t
Deserialize(Buffer::Iterator start)113 SllHeader::Deserialize (Buffer::Iterator start)
114 {
115 Buffer::Iterator i = start;
116 m_packetType = static_cast<PacketType> (i.ReadNtohU16 ());
117 m_arphdType = i.ReadNtohU16 ();
118 m_addressLength = i.ReadNtohU16 ();
119 m_address = i.ReadNtohU64 ();
120 m_protocolType = i.ReadNtohU16 ();
121
122 return GetSerializedSize ();
123 }
124
125 }
126