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/log.h"
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("FlameProtocolMac");
29 
30 namespace flame {
31 
33  m_protocol (protocol)
34 {
35 }
37 {
38  m_protocol = 0;
39  m_parent = 0;
40 }
41 void
43 {
44  m_parent = parent;
45 }
46 
47 bool
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 ();
62  {
64  }
65  else
66  {
68  }
69  m_stats.rxBytes += packet->GetSize ();
70  packet->AddPacketTag (tag);
71  return true;
72 }
73 bool
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);
88  {
90  }
91  else
92  {
94  }
95  m_stats.txBytes += packet->GetSize ();
96  return true;
97 }
98 uint16_t
100 {
101  return m_parent->GetFrequencyChannel ();
102 }
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
129 {
130  m_stats = Statistics ();
131 }
132 
133 } // namespace flame
134 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Statistics m_stats
statistics
void ResetStats()
Reset statistics function.
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void Print(std::ostream &os) const
Print function.
Ptr< MeshWifiInterfaceMac > m_parent
parent
void Report(std::ostream &os) const
Report statistics.
uint16_t GetChannelId() const
Get channel ID function.
static Mac48Address GetBroadcast(void)
bool UpdateOutcomingFrame(Ptr< Packet > packet, WifiMacHeader &header, Mac48Address from, Mac48Address to)
Process an outgoing frame.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsData(void) const
Return true if the Type is DATA.
FlameProtocolMac(Ptr< FlameProtocol > protocol)
Constructor.
an EUI-48 address
Definition: mac48-address.h:43
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:852
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:859
Mac48Address receiver
Receiver of the packet:
Ptr< FlameProtocol > m_protocol
protocol
void SetParent(Ptr< MeshWifiInterfaceMac > parent)
Set parent of this instance.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:874
bool Receive(Ptr< Packet > packet, const WifiMacHeader &header)
Receive and process a packet; packets are given a FlameTag packet tag.
Implements the IEEE 802.11 MAC header.
Transmitter and receiver addresses.
Mac48Address transmitter
transmitter for incoming: