A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flame-protocol-mac.cc
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 namespace ns3 {
26 namespace flame {
27 NS_LOG_COMPONENT_DEFINE ("FlameProtocolMac");
28 FlameProtocolMac::FlameProtocolMac (uint32_t ifIndex, Ptr<FlameProtocol> protocol) :
29  m_protocol (protocol), m_ifIndex (ifIndex)
30 {
31 }
32 FlameProtocolMac::~FlameProtocolMac ()
33 {
34  m_protocol = 0;
35  m_parent = 0;
36 }
37 void
39 {
40  m_parent = parent;
41 }
42 
43 bool
45 {
46  if (!header.IsData ())
47  {
48  return true;
49  }
50  FlameTag tag;
51  if (packet->PeekPacketTag (tag))
52  {
53  NS_FATAL_ERROR ("FLAME tag is not supposed to be received by network");
54  }
55  tag.receiver = header.GetAddr1 ();
56  tag.transmitter = header.GetAddr2 ();
58  {
59  m_stats.rxBroadcast++;
60  }
61  else
62  {
63  m_stats.rxUnicast++;
64  }
65  m_stats.rxBytes += packet->GetSize ();
66  packet->AddPacketTag (tag);
67  return true;
68 }
69 bool
71  Mac48Address to)
72 {
73  if (!header.IsData ())
74  {
75  return true;
76  }
77  FlameTag tag;
78  if (!packet->RemovePacketTag (tag))
79  {
80  NS_FATAL_ERROR ("FLAME tag must exist here");
81  }
82  header.SetAddr1 (tag.receiver);
84  {
85  m_stats.txBroadcast++;
86  }
87  else
88  {
89  m_stats.txUnicast++;
90  }
91  m_stats.txBytes += packet->GetSize ();
92  return true;
93 }
94 uint16_t
95 FlameProtocolMac::GetChannelId () const
96 {
97  return m_parent->GetFrequencyChannel ();
98 }
99 FlameProtocolMac::Statistics::Statistics () :
100  txUnicast (0), txBroadcast (0), txBytes (0), rxUnicast (0), rxBroadcast (0), rxBytes (0)
101 {
102 }
103 void
104 FlameProtocolMac::Statistics::Print (std::ostream &os) const
105 {
106  os << "<Statistics "
107  "txUnicast=\"" << txUnicast << "\" "
108  "txBroadcast=\"" << txBroadcast << "\" "
109  "txBytes=\"" << txBytes << "\" "
110  "rxUnicast=\"" << rxUnicast << "\" "
111  "rxBroadcast=\"" << rxBroadcast << "\" "
112  "rxBytes=\"" << rxBytes << "\"/>" << std::endl;
113 }
114 void
115 FlameProtocolMac::Report (std::ostream & os) const
116 {
117  os << "<FlameProtocolMac" << std::endl <<
118  "address =\"" << m_parent->GetAddress () << "\">" << std::endl;
119  m_stats.Print (os);
120  os << "</FlameProtocolMac>" << std::endl;
121 
122 }
123 void
124 FlameProtocolMac::ResetStats ()
125 {
126  m_stats = Statistics ();
127 }
128 
129 } // namespace flame
130 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void AddPacketTag(const Tag &tag) const
Definition: packet.cc:868
void Report(std::ostream &) const
Report statistics.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetSize(void) const
Definition: packet.h:620
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
bool PeekPacketTag(Tag &tag) const
Definition: packet.cc:881
static Mac48Address GetBroadcast(void)
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to)
Update frame before it will be forwarded down.
an EUI-48 address
Definition: mac48-address.h:41
bool RemovePacketTag(Tag &tag)
Definition: packet.cc:874
Mac48Address receiver
Receiver of the packet:
void SetParent(Ptr< MeshWifiInterfaceMac > parent)
Each plugin must be installed on interface to work.
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header)
Process received frame.
Transmitter and receiver addresses.
Mac48Address transmitter
transmitter for incoming: