Files
unison/src/node/llc-snap-header.cc

91 lines
2.0 KiB
C++
Raw Normal View History

2007-02-08 15:37:48 +01:00
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
2007-08-03 17:26:10 +02:00
#include "llc-snap-header.h"
#include "ns3/assert.h"
2007-08-03 17:26:10 +02:00
#include <string>
2007-02-08 15:37:48 +01:00
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (LlcSnapHeader);
2007-02-08 15:37:48 +01:00
LlcSnapHeader::LlcSnapHeader ()
{}
void
LlcSnapHeader::SetType (uint16_t type)
{
m_etherType = type;
}
uint16_t
LlcSnapHeader::GetType (void)
{
return m_etherType;
}
uint32_t
LlcSnapHeader::GetSerializedSize (void) const
{
return 1 + 1 + 1 + 3 + 2;
}
2008-03-17 14:49:52 -07:00
TypeId
LlcSnapHeader::GetTypeId (void)
2007-05-30 10:03:15 +02:00
{
2008-03-17 14:49:52 -07:00
static TypeId tid = TypeId ("ns3::LlcSnapHeader")
.SetParent<Header> ()
.AddConstructor<LlcSnapHeader> ()
2008-03-17 14:49:52 -07:00
;
return tid;
}
TypeId
LlcSnapHeader::GetInstanceTypeId (void) const
{
return GetTypeId ();
2007-05-30 10:03:15 +02:00
}
2007-02-08 15:37:48 +01:00
void
2007-08-08 09:12:55 +02:00
LlcSnapHeader::Print (std::ostream &os) const
2007-02-08 15:37:48 +01:00
{
2008-03-19 11:10:37 -07:00
os << "type 0x";
2007-02-08 15:37:48 +01:00
os.setf (std::ios::hex, std::ios::basefield);
os << m_etherType;
os.setf (std::ios::dec, std::ios::basefield);
}
void
2007-08-08 09:12:55 +02:00
LlcSnapHeader::Serialize (Buffer::Iterator start) const
2007-02-08 15:37:48 +01:00
{
Buffer::Iterator i = start;
uint8_t buf[] = {0xaa, 0xaa, 0x03, 0, 0, 0};
i.Write (buf, 6);
i.WriteHtonU16 (m_etherType);
}
uint32_t
2007-08-08 09:12:55 +02:00
LlcSnapHeader::Deserialize (Buffer::Iterator start)
2007-02-08 15:37:48 +01:00
{
Buffer::Iterator i = start;
i.Next (5+1);
m_etherType = i.ReadNtohU16 ();
return GetSerializedSize ();
2007-02-08 15:37:48 +01:00
}
2007-08-08 09:12:55 +02:00
} // namespace ns3