A Discrete-Event Network Simulator
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 * 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
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("FlameProtocolMac");
32
33namespace flame
34{
35
37 : m_protocol(protocol)
38{
39}
40
42{
43 m_protocol = nullptr;
44 m_parent = nullptr;
45}
46
47void
49{
50 m_parent = parent;
51}
52
53bool
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();
68 {
70 }
71 else
72 {
74 }
75 m_stats.rxBytes += packet->GetSize();
76 packet->AddPacketTag(tag);
77 return true;
78}
79
80bool
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);
97 {
99 }
100 else
101 {
103 }
104 m_stats.txBytes += packet->GetSize();
105 return true;
106}
107
108uint16_t
110{
111 return m_parent->GetFrequencyChannel();
112}
113
115 : txUnicast(0),
116 txBroadcast(0),
117 txBytes(0),
118 rxUnicast(0),
119 rxBroadcast(0),
120 rxBytes(0)
121{
122}
123
124void
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
147void
148FlameProtocolMac::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
156void
158{
160}
161
162} // namespace flame
163} // namespace ns3
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Mac48Address GetAddr2() const
Return the address in the Address 2 field.
bool IsData() const
Return true if the Type is DATA.
void ResetStats()
Reset statistics function.
void Report(std::ostream &os) const
Report statistics.
Ptr< FlameProtocol > m_protocol
protocol
FlameProtocolMac(Ptr< FlameProtocol > protocol)
Constructor.
uint16_t GetChannelId() const
Get channel ID function.
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to) override
Process an outgoing frame.
void SetParent(Ptr< MeshWifiInterfaceMac > parent) override
Set parent of this instance.
Ptr< MeshWifiInterfaceMac > m_parent
parent
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header) override
Receive and process a packet; packets are given a FlameTag packet tag.
Transmitter and receiver addresses.
Mac48Address receiver
Receiver of the packet:
Mac48Address transmitter
transmitter for incoming:
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Print(std::ostream &os) const
Print function.