A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
flame-protocol-mac.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Kirill Andreev <andreev@iitp.ru>
7
*/
8
9
#include "
flame-protocol-mac.h
"
10
11
#include "
flame-header.h
"
12
#include "
flame-protocol.h
"
13
14
#include "ns3/log.h"
15
#include "ns3/wifi-mac-header.h"
16
17
namespace
ns3
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"FlameProtocolMac"
);
21
22
namespace
flame
23
{
24
25
FlameProtocolMac::FlameProtocolMac
(
Ptr<FlameProtocol>
protocol)
26
: m_protocol(protocol)
27
{
28
}
29
30
FlameProtocolMac::~FlameProtocolMac
()
31
{
32
m_protocol
=
nullptr
;
33
m_parent
=
nullptr
;
34
}
35
36
void
37
FlameProtocolMac::SetParent
(
Ptr<MeshWifiInterfaceMac>
parent)
38
{
39
m_parent
= parent;
40
}
41
42
bool
43
FlameProtocolMac::Receive
(
Ptr<Packet>
packet,
const
WifiMacHeader
& header)
44
{
45
if
(!header.
IsData
())
46
{
47
return
true
;
48
}
49
FlameTag
tag;
50
if
(packet->PeekPacketTag(tag))
51
{
52
NS_FATAL_ERROR
(
"FLAME tag is not supposed to be received by network"
);
53
}
54
tag.
receiver
= header.
GetAddr1
();
55
tag.
transmitter
= header.
GetAddr2
();
56
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
57
{
58
m_stats
.
rxBroadcast
++;
59
}
60
else
61
{
62
m_stats
.
rxUnicast
++;
63
}
64
m_stats
.
rxBytes
+= packet->GetSize();
65
packet->AddPacketTag(tag);
66
return
true
;
67
}
68
69
bool
70
FlameProtocolMac::UpdateOutcomingFrame
(
Ptr<Packet>
packet,
71
WifiMacHeader
& header,
72
Mac48Address
from,
73
Mac48Address
to)
74
{
75
if
(!header.
IsData
())
76
{
77
return
true
;
78
}
79
FlameTag
tag;
80
if
(!packet->RemovePacketTag(tag))
81
{
82
NS_FATAL_ERROR
(
"FLAME tag must exist here"
);
83
}
84
header.
SetAddr1
(tag.
receiver
);
85
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
86
{
87
m_stats
.
txBroadcast
++;
88
}
89
else
90
{
91
m_stats
.
txUnicast
++;
92
}
93
m_stats
.
txBytes
+= packet->GetSize();
94
return
true
;
95
}
96
97
uint16_t
98
FlameProtocolMac::GetChannelId
()
const
99
{
100
return
m_parent
->GetFrequencyChannel();
101
}
102
103
FlameProtocolMac::Statistics::Statistics
()
104
: txUnicast(0),
105
txBroadcast(0),
106
txBytes(0),
107
rxUnicast(0),
108
rxBroadcast(0),
109
rxBytes(0)
110
{
111
}
112
113
void
114
FlameProtocolMac::Statistics::Print
(std::ostream& os)
const
115
{
116
os <<
"<Statistics "
117
"txUnicast=\""
118
<< txUnicast
119
<<
"\" "
120
"txBroadcast=\""
121
<< txBroadcast
122
<<
"\" "
123
"txBytes=\""
124
<< txBytes
125
<<
"\" "
126
"rxUnicast=\""
127
<< rxUnicast
128
<<
"\" "
129
"rxBroadcast=\""
130
<< rxBroadcast
131
<<
"\" "
132
"rxBytes=\""
133
<< rxBytes <<
"\"/>"
<< std::endl;
134
}
135
136
void
137
FlameProtocolMac::Report
(std::ostream& os)
const
138
{
139
os <<
"<FlameProtocolMac"
<< std::endl
140
<<
"address =\""
<<
m_parent
->GetAddress() <<
"\">"
<< std::endl;
141
m_stats
.
Print
(os);
142
os <<
"</FlameProtocolMac>"
<< std::endl;
143
}
144
145
void
146
FlameProtocolMac::ResetStats
()
147
{
148
m_stats
=
Statistics
();
149
}
150
151
}
// namespace flame
152
}
// namespace ns3
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::Mac48Address::GetBroadcast
static Mac48Address GetBroadcast()
Definition
mac48-address.cc:144
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition
wifi-mac-header.h:87
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
Definition
wifi-mac-header.cc:432
ns3::WifiMacHeader::SetAddr1
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Definition
wifi-mac-header.cc:80
ns3::WifiMacHeader::GetAddr2
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
Definition
wifi-mac-header.cc:438
ns3::WifiMacHeader::IsData
bool IsData() const
Return true if the Type is DATA.
Definition
wifi-mac-header.cc:568
ns3::flame::FlameProtocolMac::~FlameProtocolMac
~FlameProtocolMac() override
Definition
flame-protocol-mac.cc:30
ns3::flame::FlameProtocolMac::m_stats
Statistics m_stats
statistics
Definition
flame-protocol-mac.h:115
ns3::flame::FlameProtocolMac::ResetStats
void ResetStats()
Reset statistics function.
Definition
flame-protocol-mac.cc:146
ns3::flame::FlameProtocolMac::Report
void Report(std::ostream &os) const
Report statistics.
Definition
flame-protocol-mac.cc:137
ns3::flame::FlameProtocolMac::m_protocol
Ptr< FlameProtocol > m_protocol
protocol
Definition
flame-protocol-mac.h:93
ns3::flame::FlameProtocolMac::FlameProtocolMac
FlameProtocolMac(Ptr< FlameProtocol > protocol)
Constructor.
Definition
flame-protocol-mac.cc:25
ns3::flame::FlameProtocolMac::GetChannelId
uint16_t GetChannelId() const
Get channel ID function.
Definition
flame-protocol-mac.cc:98
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:70
ns3::flame::FlameProtocolMac::SetParent
void SetParent(Ptr< MeshWifiInterfaceMac > parent) override
Set parent of this instance.
Definition
flame-protocol-mac.cc:37
ns3::flame::FlameProtocolMac::m_parent
Ptr< MeshWifiInterfaceMac > m_parent
parent
Definition
flame-protocol-mac.h:94
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:43
ns3::flame::FlameTag
Transmitter and receiver addresses.
Definition
flame-protocol.h:46
ns3::flame::FlameTag::receiver
Mac48Address receiver
Receiver of the packet:
Definition
flame-protocol.h:51
ns3::flame::FlameTag::transmitter
Mac48Address transmitter
transmitter for incoming:
Definition
flame-protocol.h:49
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:168
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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:98
ns3::flame::FlameProtocolMac::Statistics::rxBytes
uint32_t rxBytes
receive bytes
Definition
flame-protocol-mac.h:104
ns3::flame::FlameProtocolMac::Statistics::txUnicast
uint16_t txUnicast
transmit unicast
Definition
flame-protocol-mac.h:99
ns3::flame::FlameProtocolMac::Statistics::txBroadcast
uint16_t txBroadcast
transit broadcast
Definition
flame-protocol-mac.h:100
ns3::flame::FlameProtocolMac::Statistics::txBytes
uint32_t txBytes
transmit bytes
Definition
flame-protocol-mac.h:101
ns3::flame::FlameProtocolMac::Statistics::rxUnicast
uint16_t rxUnicast
receive unicast
Definition
flame-protocol-mac.h:102
ns3::flame::FlameProtocolMac::Statistics::Print
void Print(std::ostream &os) const
Print function.
Definition
flame-protocol-mac.cc:114
ns3::flame::FlameProtocolMac::Statistics::Statistics
Statistics()
constructor
Definition
flame-protocol-mac.cc:103
ns3::flame::FlameProtocolMac::Statistics::rxBroadcast
uint16_t rxBroadcast
receive broadcast
Definition
flame-protocol-mac.h:103
src
mesh
model
flame
flame-protocol-mac.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0