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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
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
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("FlameProtocolMac");
21
22namespace flame
23{
24
26 : m_protocol(protocol)
27{
28}
29
31{
32 m_protocol = nullptr;
33 m_parent = nullptr;
34}
35
36void
41
42bool
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();
57 {
59 }
60 else
61 {
63 }
64 m_stats.rxBytes += packet->GetSize();
65 packet->AddPacketTag(tag);
66 return true;
67}
68
69bool
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);
86 {
88 }
89 else
90 {
92 }
93 m_stats.txBytes += packet->GetSize();
94 return true;
95}
96
97uint16_t
99{
100 return m_parent->GetFrequencyChannel();
101}
102
104 : txUnicast(0),
105 txBroadcast(0),
106 txBytes(0),
107 rxUnicast(0),
108 rxBroadcast(0),
109 rxBytes(0)
110{
111}
112
113void
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
136void
137FlameProtocolMac::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
145void
150
151} // namespace flame
152} // namespace ns3
an EUI-48 address
static Mac48Address GetBroadcast()
Smart pointer class similar to boost::intrusive_ptr.
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Print(std::ostream &os) const
Print function.