A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
flame-protocol-mac.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Kirill Andreev <andreev@iitp.ru>
18
*/
19
20
#include "
flame-protocol-mac.h
"
21
22
#include "
flame-header.h
"
23
#include "
flame-protocol.h
"
24
25
#include "ns3/log.h"
26
#include "ns3/wifi-mac-header.h"
27
28
namespace
ns3
29
{
30
31
NS_LOG_COMPONENT_DEFINE
(
"FlameProtocolMac"
);
32
33
namespace
flame
34
{
35
36
FlameProtocolMac::FlameProtocolMac
(
Ptr<FlameProtocol>
protocol)
37
: m_protocol(protocol)
38
{
39
}
40
41
FlameProtocolMac::~FlameProtocolMac
()
42
{
43
m_protocol
=
nullptr
;
44
m_parent
=
nullptr
;
45
}
46
47
void
48
FlameProtocolMac::SetParent
(
Ptr<MeshWifiInterfaceMac>
parent)
49
{
50
m_parent
= parent;
51
}
52
53
bool
54
FlameProtocolMac::Receive
(
Ptr<Packet>
packet,
const
WifiMacHeader
& header)
55
{
56
if
(!header.
IsData
())
57
{
58
return
true
;
59
}
60
FlameTag
tag;
61
if
(packet->
PeekPacketTag
(tag))
62
{
63
NS_FATAL_ERROR
(
"FLAME tag is not supposed to be received by network"
);
64
}
65
tag.
receiver
= header.
GetAddr1
();
66
tag.
transmitter
= header.
GetAddr2
();
67
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
68
{
69
m_stats
.
rxBroadcast
++;
70
}
71
else
72
{
73
m_stats
.
rxUnicast
++;
74
}
75
m_stats
.
rxBytes
+= packet->
GetSize
();
76
packet->
AddPacketTag
(tag);
77
return
true
;
78
}
79
80
bool
81
FlameProtocolMac::UpdateOutcomingFrame
(
Ptr<Packet>
packet,
82
WifiMacHeader
& header,
83
Mac48Address
from,
84
Mac48Address
to)
85
{
86
if
(!header.
IsData
())
87
{
88
return
true
;
89
}
90
FlameTag
tag;
91
if
(!packet->
RemovePacketTag
(tag))
92
{
93
NS_FATAL_ERROR
(
"FLAME tag must exist here"
);
94
}
95
header.
SetAddr1
(tag.
receiver
);
96
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
97
{
98
m_stats
.
txBroadcast
++;
99
}
100
else
101
{
102
m_stats
.
txUnicast
++;
103
}
104
m_stats
.
txBytes
+= packet->
GetSize
();
105
return
true
;
106
}
107
108
uint16_t
109
FlameProtocolMac::GetChannelId
()
const
110
{
111
return
m_parent
->GetFrequencyChannel();
112
}
113
114
FlameProtocolMac::Statistics::Statistics
()
115
: txUnicast(0),
116
txBroadcast(0),
117
txBytes(0),
118
rxUnicast(0),
119
rxBroadcast(0),
120
rxBytes(0)
121
{
122
}
123
124
void
125
FlameProtocolMac::Statistics::Print
(std::ostream& os)
const
126
{
127
os <<
"<Statistics "
128
"txUnicast=\""
129
<< txUnicast
130
<<
"\" "
131
"txBroadcast=\""
132
<< txBroadcast
133
<<
"\" "
134
"txBytes=\""
135
<< txBytes
136
<<
"\" "
137
"rxUnicast=\""
138
<< rxUnicast
139
<<
"\" "
140
"rxBroadcast=\""
141
<< rxBroadcast
142
<<
"\" "
143
"rxBytes=\""
144
<< rxBytes <<
"\"/>"
<< std::endl;
145
}
146
147
void
148
FlameProtocolMac::Report
(std::ostream& os)
const
149
{
150
os <<
"<FlameProtocolMac"
<< std::endl
151
<<
"address =\""
<<
m_parent
->GetAddress() <<
"\">"
<< std::endl;
152
m_stats
.
Print
(os);
153
os <<
"</FlameProtocolMac>"
<< std::endl;
154
}
155
156
void
157
FlameProtocolMac::ResetStats
()
158
{
159
m_stats
=
Statistics
();
160
}
161
162
}
// namespace flame
163
}
// namespace ns3
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:46
ns3::Mac48Address::GetBroadcast
static Mac48Address GetBroadcast()
Definition:
mac48-address.cc:155
ns3::Packet::RemovePacketTag
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition:
packet.cc:967
ns3::Packet::GetSize
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition:
packet.h:861
ns3::Packet::AddPacketTag
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition:
packet.cc:960
ns3::Packet::PeekPacketTag
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition:
packet.cc:983
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition:
wifi-mac-header.h:98
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
Definition:
wifi-mac-header.cc:463
ns3::WifiMacHeader::SetAddr1
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Definition:
wifi-mac-header.cc:111
ns3::WifiMacHeader::GetAddr2
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
Definition:
wifi-mac-header.cc:469
ns3::WifiMacHeader::IsData
bool IsData() const
Return true if the Type is DATA.
Definition:
wifi-mac-header.cc:599
ns3::flame::FlameProtocolMac::~FlameProtocolMac
~FlameProtocolMac() override
Definition:
flame-protocol-mac.cc:41
ns3::flame::FlameProtocolMac::m_stats
Statistics m_stats
statistics
Definition:
flame-protocol-mac.h:126
ns3::flame::FlameProtocolMac::ResetStats
void ResetStats()
Reset statistics function.
Definition:
flame-protocol-mac.cc:157
ns3::flame::FlameProtocolMac::Report
void Report(std::ostream &os) const
Report statistics.
Definition:
flame-protocol-mac.cc:148
ns3::flame::FlameProtocolMac::m_protocol
Ptr< FlameProtocol > m_protocol
protocol
Definition:
flame-protocol-mac.h:104
ns3::flame::FlameProtocolMac::FlameProtocolMac
FlameProtocolMac(Ptr< FlameProtocol > protocol)
Constructor.
Definition:
flame-protocol-mac.cc:36
ns3::flame::FlameProtocolMac::GetChannelId
uint16_t GetChannelId() const
Get channel ID function.
Definition:
flame-protocol-mac.cc:109
ns3::flame::FlameProtocolMac::UpdateOutcomingFrame
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to) override
Process an outgoing frame.
Definition:
flame-protocol-mac.cc:81
ns3::flame::FlameProtocolMac::SetParent
void SetParent(Ptr< MeshWifiInterfaceMac > parent) override
Set parent of this instance.
Definition:
flame-protocol-mac.cc:48
ns3::flame::FlameProtocolMac::m_parent
Ptr< MeshWifiInterfaceMac > m_parent
parent
Definition:
flame-protocol-mac.h:105
ns3::flame::FlameProtocolMac::Receive
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header) override
Receive and process a packet; packets are given a FlameTag packet tag.
Definition:
flame-protocol-mac.cc:54
ns3::flame::FlameTag
Transmitter and receiver addresses.
Definition:
flame-protocol.h:57
ns3::flame::FlameTag::receiver
Mac48Address receiver
Receiver of the packet:
Definition:
flame-protocol.h:62
ns3::flame::FlameTag::transmitter
Mac48Address transmitter
transmitter for incoming:
Definition:
flame-protocol.h:60
flame-header.h
flame-protocol-mac.h
flame-protocol.h
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::flame::FlameProtocolMac::Statistics
Statistics structure.
Definition:
flame-protocol-mac.h:109
ns3::flame::FlameProtocolMac::Statistics::rxBytes
uint32_t rxBytes
receive bytes
Definition:
flame-protocol-mac.h:115
ns3::flame::FlameProtocolMac::Statistics::txUnicast
uint16_t txUnicast
transmit unicast
Definition:
flame-protocol-mac.h:110
ns3::flame::FlameProtocolMac::Statistics::txBroadcast
uint16_t txBroadcast
transit broadcast
Definition:
flame-protocol-mac.h:111
ns3::flame::FlameProtocolMac::Statistics::txBytes
uint32_t txBytes
transmit bytes
Definition:
flame-protocol-mac.h:112
ns3::flame::FlameProtocolMac::Statistics::rxUnicast
uint16_t rxUnicast
receive unicast
Definition:
flame-protocol-mac.h:113
ns3::flame::FlameProtocolMac::Statistics::Print
void Print(std::ostream &os) const
Print function.
Definition:
flame-protocol-mac.cc:125
ns3::flame::FlameProtocolMac::Statistics::Statistics
Statistics()
constructor
Definition:
flame-protocol-mac.cc:114
ns3::flame::FlameProtocolMac::Statistics::rxBroadcast
uint16_t rxBroadcast
receive broadcast
Definition:
flame-protocol-mac.h:114
src
mesh
model
flame
flame-protocol-mac.cc
Generated on Sun Mar 3 2024 17:11:05 for ns-3 by
1.9.1