A Discrete-Event Network Simulator
API
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 
32  m_cost (0), m_seqno (0), m_origDst (Mac48Address ()), m_origSrc (Mac48Address ())
33 {
34 }
36 {
37 }
38 TypeId
40 {
41  static TypeId tid = TypeId ("ns3::flame::FlameHeader")
42  .SetParent<Header> ()
43  .SetGroupName ("Mesh")
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 << ", Sequence number= " << m_seqno
56  << ", Orig Destination= " << m_origDst << ", Orig Source= " << m_origSrc;
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
iterator in a Buffer instance
Definition: buffer.h:99
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU8(uint8_t data)
Definition: buffer.h:869
void Next(void)
go forward by one byte
Definition: buffer.h:845
uint8_t ReadU8(void)
Definition: buffer.h:1021
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Protocol header serialization and deserialization.
Definition: header.h:43
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
an EUI-48 address
Definition: mac48-address.h:44
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Mac48Address m_origDst
origin destination
Definition: flame-header.h:111
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: flame-header.cc:48
uint16_t m_protocol
protocol
Definition: flame-header.h:113
uint8_t GetCost() const
Get cost value.
Definition: flame-header.cc:98
uint16_t m_seqno
sequence number
Definition: flame-header.h:110
Mac48Address GetOrigDst() const
Get origin destination address.
Mac48Address GetOrigSrc() const
Get origin source address.
void SetOrigSrc(Mac48Address OrigSrc)
Set origin source function.
void AddCost(uint8_t cost)
Add cost value.
Definition: flame-header.cc:93
virtual void Serialize(Buffer::Iterator start) const
Definition: flame-header.cc:70
uint16_t GetSeqno() const
Get sequence number value.
void SetOrigDst(Mac48Address dst)
Set origin destination address.
void SetProtocol(uint16_t protocol)
Set protocol value.
Mac48Address m_origSrc
origin source
Definition: flame-header.h:112
virtual uint32_t GetSerializedSize(void) const
Definition: flame-header.cc:59
virtual void Print(std::ostream &os) const
Definition: flame-header.cc:53
uint16_t GetProtocol() const
Get protocol value.
void SetSeqno(uint16_t seqno)
Set sequence number value.
static TypeId GetTypeId(void)
Get the type ID.
Definition: flame-header.cc:39
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool operator==(const FlameHeader &a, const FlameHeader &b)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1853