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