A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
flame-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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: Kirill Andreev <andreev@iitp.ru>
19  */
20 #include "ns3/assert.h"
21 #include "ns3/address-utils.h"
22 #include "ns3/packet.h"
23 
24 #include "flame-header.h"
25 
26 namespace ns3 {
27 namespace flame {
28 
30  ;
31 
33  m_cost (0), m_seqno (0), m_origDst (Mac48Address ()), m_origSrc (Mac48Address ())
34 {
35 }
37 {
38 }
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::flame::FlameHeader")
43  .SetParent<Header> ()
44  .AddConstructor<FlameHeader> ();
45  return tid;
46 }
47 TypeId
49 {
50  return GetTypeId ();
51 }
52 void
53 FlameHeader::Print (std::ostream &os) const
54 {
55  os << "Cost = " << (uint16_t) m_cost << std::endl << "Sequence number = " << m_seqno
56  << std::endl << "Orig Destination = " << m_origDst << std::endl << "Orig Source = " << m_origSrc << std::endl;
57 }
58 uint32_t
60 {
61  return 1 // Reserved
62  + 1 // Cost
63  + 2 // Seqno
64  + 6 // Orig Dst
65  + 6 // Orig Src
66  + 2 // Flame Port
67  ;
68 }
69 void
71 {
73  i.WriteU8 (0); //Reserved
74  i.WriteU8 (m_cost); //Cost
75  i.WriteHtonU16 (m_seqno); //Seqno
76  WriteTo (i, m_origDst);
77  WriteTo (i, m_origSrc);
79 }
80 uint32_t
82 {
84  i.Next (1);
85  m_cost = i.ReadU8 ();
86  m_seqno = i.ReadNtohU16 ();
87  ReadFrom (i, m_origDst);
88  ReadFrom (i, m_origSrc);
89  m_protocol = i.ReadNtohU16 ();
90  return i.GetDistanceFrom (start);
91 }
92 void
93 FlameHeader::AddCost (uint8_t cost)
94 {
95  m_cost = (((uint16_t) cost + (uint16_t) m_cost) > 255) ? 255 : cost + m_cost;
96 }
97 uint8_t
99 {
100  return m_cost;
101 }
102 void
103 FlameHeader::SetSeqno (uint16_t seqno)
104 {
105  m_seqno = seqno;
106 }
107 uint16_t
109 {
110  return m_seqno;
111 }
112 void
114 {
115  m_origDst = dst;
116 }
119 {
120  return m_origDst;
121 }
122 void
124 {
125  m_origSrc = src;
126 }
129 {
130  return m_origSrc;
131 }
132 void
133 FlameHeader::SetProtocol (uint16_t protocol)
134 {
135  m_protocol = protocol;
136 }
137 uint16_t
139 {
140  return m_protocol;
141 }
142 bool
143 operator== (const FlameHeader & a, const FlameHeader & b)
144 {
145  return ((a.m_cost == b.m_cost) && (a.m_seqno == b.m_seqno) && (a.m_origDst == b.m_origDst) && (a.m_origSrc
146  == b.m_origSrc) && (a.m_protocol == b.m_protocol));
147 }
148 
149 } // namespace flame
150 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
bool operator==(const FlameHeader &a, const FlameHeader &b)
void SetSeqno(uint16_t seqno)
void SetOrigDst(Mac48Address dst)
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
virtual uint32_t GetSerializedSize(void) const
Definition: flame-header.cc:59
Mac48Address m_origDst
Definition: flame-header.h:72
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Mac48Address GetOrigDst() const
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
static TypeId GetTypeId(void)
Definition: flame-header.cc:40
iterator in a Buffer instance
Definition: buffer.h:98
void SetProtocol(uint16_t protocol)
uint16_t GetProtocol() const
uint8_t GetCost() const
Definition: flame-header.cc:98
virtual void Print(std::ostream &os) const
Definition: flame-header.cc:53
void WriteHtonU16(uint16_t data)
Definition: buffer.h:726
void Next(void)
go forward by one byte
Definition: buffer.h:666
uint16_t GetSeqno() const
void AddCost(uint8_t cost)
Definition: flame-header.cc:93
virtual TypeId GetInstanceTypeId(void) const
Definition: flame-header.cc:48
Mac48Address GetOrigSrc() const
void SetOrigSrc(Mac48Address OrigSrc)
an EUI-48 address
Definition: mac48-address.h:41
void WriteU8(uint8_t data)
Definition: buffer.h:690
virtual void Serialize(Buffer::Iterator start) const
Definition: flame-header.cc:70
Mac48Address m_origSrc
Definition: flame-header.h:73
uint8_t ReadU8(void)
Definition: buffer.h:819
uint16_t ReadNtohU16(void)
Definition: buffer.h:767
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: flame-header.cc:81
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611