A Discrete-Event Network Simulator
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
27namespace ns3 {
28
29NS_LOG_COMPONENT_DEFINE ("FlameProtocolMac");
30
31namespace flame {
32
34 m_protocol (protocol)
35{
36}
38{
39 m_protocol = 0;
40 m_parent = 0;
41}
42void
44{
45 m_parent = parent;
46}
47
48bool
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 ();
63 {
65 }
66 else
67 {
69 }
70 m_stats.rxBytes += packet->GetSize ();
71 packet->AddPacketTag (tag);
72 return true;
73}
74bool
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);
89 {
91 }
92 else
93 {
95 }
96 m_stats.txBytes += packet->GetSize ();
97 return true;
98}
99uint16_t
101{
102 return m_parent->GetFrequencyChannel ();
103}
105 txUnicast (0), txBroadcast (0), txBytes (0), rxUnicast (0), rxBroadcast (0), rxBytes (0)
106{
107}
108void
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}
119void
120FlameProtocolMac::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}
128void
130{
131 m_stats = Statistics ();
132}
133
134} // namespace flame
135} // namespace ns3
an EUI-48 address
Definition: mac48-address.h:44
static Mac48Address GetBroadcast(void)
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:963
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:978
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
bool IsData(void) const
Return true if the Type is DATA.
void SetParent(Ptr< MeshWifiInterfaceMac > parent)
Set parent of this instance.
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to)
Process an outgoing frame.
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.
Ptr< MeshWifiInterfaceMac > m_parent
parent
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header)
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:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Print(std::ostream &os) const
Print function.