A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
flame-protocol-mac.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
21
#include "
flame-protocol-mac.h
"
22
#include "
flame-protocol.h
"
23
#include "
flame-header.h
"
24
#include "ns3/wifi-mac-header.h"
25
#include "ns3/log.h"
26
27
namespace
ns3
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"FlameProtocolMac"
);
30
31
namespace
flame {
32
33
FlameProtocolMac::FlameProtocolMac
(
Ptr<FlameProtocol>
protocol) :
34
m_protocol (protocol)
35
{
36
}
37
FlameProtocolMac::~FlameProtocolMac
()
38
{
39
m_protocol
= 0;
40
m_parent
= 0;
41
}
42
void
43
FlameProtocolMac::SetParent
(
Ptr<MeshWifiInterfaceMac>
parent)
44
{
45
m_parent
= parent;
46
}
47
48
bool
49
FlameProtocolMac::Receive
(
Ptr<Packet>
packet,
const
WifiMacHeader
& header)
50
{
51
if
(!header.
IsData
())
52
{
53
return
true
;
54
}
55
FlameTag
tag;
56
if
(packet->
PeekPacketTag
(tag))
57
{
58
NS_FATAL_ERROR
(
"FLAME tag is not supposed to be received by network"
);
59
}
60
tag.
receiver
= header.
GetAddr1
();
61
tag.
transmitter
= header.
GetAddr2
();
62
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
63
{
64
m_stats
.
rxBroadcast
++;
65
}
66
else
67
{
68
m_stats
.
rxUnicast
++;
69
}
70
m_stats
.
rxBytes
+= packet->
GetSize
();
71
packet->
AddPacketTag
(tag);
72
return
true
;
73
}
74
bool
75
FlameProtocolMac::UpdateOutcomingFrame
(
Ptr<Packet>
packet,
WifiMacHeader
& header,
Mac48Address
from,
76
Mac48Address
to)
77
{
78
if
(!header.
IsData
())
79
{
80
return
true
;
81
}
82
FlameTag
tag;
83
if
(!packet->
RemovePacketTag
(tag))
84
{
85
NS_FATAL_ERROR
(
"FLAME tag must exist here"
);
86
}
87
header.
SetAddr1
(tag.
receiver
);
88
if
(tag.
receiver
==
Mac48Address::GetBroadcast
())
89
{
90
m_stats
.
txBroadcast
++;
91
}
92
else
93
{
94
m_stats
.
txUnicast
++;
95
}
96
m_stats
.
txBytes
+= packet->
GetSize
();
97
return
true
;
98
}
99
uint16_t
100
FlameProtocolMac::GetChannelId
()
const
101
{
102
return
m_parent
->GetFrequencyChannel ();
103
}
104
FlameProtocolMac::Statistics::Statistics
() :
105
txUnicast (0), txBroadcast (0), txBytes (0), rxUnicast (0), rxBroadcast (0), rxBytes (0)
106
{
107
}
108
void
109
FlameProtocolMac::Statistics::Print
(std::ostream &os)
const
110
{
111
os <<
"<Statistics "
112
"txUnicast=\""
<< txUnicast <<
"\" "
113
"txBroadcast=\""
<< txBroadcast <<
"\" "
114
"txBytes=\""
<< txBytes <<
"\" "
115
"rxUnicast=\""
<< rxUnicast <<
"\" "
116
"rxBroadcast=\""
<< rxBroadcast <<
"\" "
117
"rxBytes=\""
<< rxBytes <<
"\"/>"
<< std::endl;
118
}
119
void
120
FlameProtocolMac::Report
(std::ostream & os)
const
121
{
122
os <<
"<FlameProtocolMac"
<< std::endl <<
123
"address =\""
<<
m_parent
->GetAddress () <<
"\">"
<< std::endl;
124
m_stats
.
Print
(os);
125
os <<
"</FlameProtocolMac>"
<< std::endl;
126
127
}
128
void
129
FlameProtocolMac::ResetStats
()
130
{
131
m_stats
=
Statistics
();
132
}
133
134
}
// namespace flame
135
}
// namespace ns3
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:44
ns3::Mac48Address::GetBroadcast
static Mac48Address GetBroadcast(void)
Definition:
mac48-address.cc:170
ns3::Packet::RemovePacketTag
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition:
packet.cc:963
ns3::Packet::AddPacketTag
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition:
packet.cc:956
ns3::Packet::PeekPacketTag
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition:
packet.cc:978
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition:
packet.h:856
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition:
wifi-mac-header.h:85
ns3::WifiMacHeader::GetAddr2
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
Definition:
wifi-mac-header.cc:430
ns3::WifiMacHeader::SetAddr1
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Definition:
wifi-mac-header.cc:108
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition:
wifi-mac-header.cc:424
ns3::WifiMacHeader::IsData
bool IsData(void) const
Return true if the Type is DATA.
Definition:
wifi-mac-header.cc:558
ns3::flame::FlameProtocolMac::SetParent
void SetParent(Ptr< MeshWifiInterfaceMac > parent)
Set parent of this instance.
Definition:
flame-protocol-mac.cc:43
ns3::flame::FlameProtocolMac::UpdateOutcomingFrame
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to)
Process an outgoing frame.
Definition:
flame-protocol-mac.cc:75
ns3::flame::FlameProtocolMac::m_stats
Statistics m_stats
statistics
Definition:
flame-protocol-mac.h:116
ns3::flame::FlameProtocolMac::ResetStats
void ResetStats()
Reset statistics function.
Definition:
flame-protocol-mac.cc:129
ns3::flame::FlameProtocolMac::Report
void Report(std::ostream &os) const
Report statistics.
Definition:
flame-protocol-mac.cc:120
ns3::flame::FlameProtocolMac::m_protocol
Ptr< FlameProtocol > m_protocol
protocol
Definition:
flame-protocol-mac.h:96
ns3::flame::FlameProtocolMac::FlameProtocolMac
FlameProtocolMac(Ptr< FlameProtocol > protocol)
Constructor.
Definition:
flame-protocol-mac.cc:33
ns3::flame::FlameProtocolMac::GetChannelId
uint16_t GetChannelId() const
Get channel ID function.
Definition:
flame-protocol-mac.cc:100
ns3::flame::FlameProtocolMac::m_parent
Ptr< MeshWifiInterfaceMac > m_parent
parent
Definition:
flame-protocol-mac.h:97
ns3::flame::FlameProtocolMac::Receive
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header)
Receive and process a packet; packets are given a FlameTag packet tag.
Definition:
flame-protocol-mac.cc:49
ns3::flame::FlameProtocolMac::~FlameProtocolMac
~FlameProtocolMac()
Definition:
flame-protocol-mac.cc:37
ns3::flame::FlameTag
Transmitter and receiver addresses.
Definition:
flame-protocol.h:55
ns3::flame::FlameTag::receiver
Mac48Address receiver
Receiver of the packet:
Definition:
flame-protocol.h:60
ns3::flame::FlameTag::transmitter
Mac48Address transmitter
transmitter for incoming:
Definition:
flame-protocol.h:58
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:165
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
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:100
ns3::flame::FlameProtocolMac::Statistics::rxBytes
uint32_t rxBytes
receive bytes
Definition:
flame-protocol-mac.h:106
ns3::flame::FlameProtocolMac::Statistics::txUnicast
uint16_t txUnicast
transmit unicast
Definition:
flame-protocol-mac.h:101
ns3::flame::FlameProtocolMac::Statistics::txBroadcast
uint16_t txBroadcast
transit broadcast
Definition:
flame-protocol-mac.h:102
ns3::flame::FlameProtocolMac::Statistics::txBytes
uint32_t txBytes
transmit bytes
Definition:
flame-protocol-mac.h:103
ns3::flame::FlameProtocolMac::Statistics::rxUnicast
uint16_t rxUnicast
receive unicast
Definition:
flame-protocol-mac.h:104
ns3::flame::FlameProtocolMac::Statistics::Print
void Print(std::ostream &os) const
Print function.
Definition:
flame-protocol-mac.cc:109
ns3::flame::FlameProtocolMac::Statistics::Statistics
Statistics()
constructor
Definition:
flame-protocol-mac.cc:104
ns3::flame::FlameProtocolMac::Statistics::rxBroadcast
uint16_t rxBroadcast
receive broadcast
Definition:
flame-protocol-mac.h:105
src
mesh
model
flame
flame-protocol-mac.cc
Generated on Tue Feb 6 2024 19:21:24 for ns-3 by
1.9.1