src/mesh/model/flame/flame-protocol-mac.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 26 Sep 2014 15:51:00 -0700
changeset 10968 2d29fee2b7b8
parent 10218 97da49da2d6c
permissions -rw-r--r--
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7178
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5079
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     2
/*
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     3
 * Copyright (c) 2009 IITP RAS
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     4
 *
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     8
 *
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    13
 *
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    17
 *
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    18
 * Author: Kirill Andreev <andreev@iitp.ru>
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    19
 */
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    20
245215e5e6ed Added flame rtable, fixed DoDispose in HwmpRtable
Kirill Andreev <andreev@iitp.ru>
parents:
diff changeset
    21
#include "flame-protocol-mac.h"
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    22
#include "flame-protocol.h"
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    23
#include "flame-header.h"
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    24
#include "ns3/log.h"
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10218
diff changeset
    25
5132
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    26
namespace ns3 {
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10218
diff changeset
    27
  
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10218
diff changeset
    28
NS_LOG_COMPONENT_DEFINE ("FlameProtocolMac");
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10218
diff changeset
    29
  
5132
aee541a30256 Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents: 5129
diff changeset
    30
namespace flame {
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10218
diff changeset
    31
  
10218
97da49da2d6c Fix compilation with Clang 3.2 and newer versions, including Apple Clang 5.0
Vedran Miletić <rivanvx@gmail.com>
parents: 7386
diff changeset
    32
FlameProtocolMac::FlameProtocolMac (Ptr<FlameProtocol> protocol) :
97da49da2d6c Fix compilation with Clang 3.2 and newer versions, including Apple Clang 5.0
Vedran Miletić <rivanvx@gmail.com>
parents: 7386
diff changeset
    33
  m_protocol (protocol)
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    34
{
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    35
}
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
    36
FlameProtocolMac::~FlameProtocolMac ()
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    37
{
5464
050630fcf15e Mesh: fixed FLAME PATH_UPDATE procedure, fixed mesh.cc, valgrind errors in
Kirill Andreev <andreev@iitp.ru>
parents: 5157
diff changeset
    38
  m_protocol = 0;
050630fcf15e Mesh: fixed FLAME PATH_UPDATE procedure, fixed mesh.cc, valgrind errors in
Kirill Andreev <andreev@iitp.ru>
parents: 5157
diff changeset
    39
  m_parent = 0;
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    40
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    41
void
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
    42
FlameProtocolMac::SetParent (Ptr<MeshWifiInterfaceMac> parent)
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    43
{
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    44
  m_parent = parent;
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    45
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    46
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    47
bool
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
    48
FlameProtocolMac::Receive (Ptr<Packet> packet, const WifiMacHeader & header)
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    49
{
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    50
  if (!header.IsData ())
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    51
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    52
      return true;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    53
    }
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    54
  FlameTag tag;
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    55
  if (packet->PeekPacketTag (tag))
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    56
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    57
      NS_FATAL_ERROR ("FLAME tag is not supposed to be received by network");
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    58
    }
5092
39e4d3a81e1c Flame bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 5088
diff changeset
    59
  tag.receiver = header.GetAddr1 ();
39e4d3a81e1c Flame bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 5088
diff changeset
    60
  tag.transmitter = header.GetAddr2 ();
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    61
  if (tag.receiver == Mac48Address::GetBroadcast ())
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    62
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    63
      m_stats.rxBroadcast++;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    64
    }
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
    65
  else
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    66
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    67
      m_stats.rxUnicast++;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    68
    }
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
    69
  m_stats.rxBytes += packet->GetSize ();
5084
ddf23699f0b7 Initial flame implementation
Kirill Andreev <andreev@iitp.ru>
parents: 5082
diff changeset
    70
  packet->AddPacketTag (tag);
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    71
  return true;
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    72
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    73
bool
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    74
FlameProtocolMac::UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from,
7178
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    75
                                        Mac48Address to)
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    76
{
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    77
  if (!header.IsData ())
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    78
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    79
      return true;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    80
    }
5082
528da3d1e5a4 Flame stack initialized
Kirill Andreev <andreev@iitp.ru>
parents: 5080
diff changeset
    81
  FlameTag tag;
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    82
  if (!packet->RemovePacketTag (tag))
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    83
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    84
      NS_FATAL_ERROR ("FLAME tag must exist here");
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    85
    }
5092
39e4d3a81e1c Flame bugfixes
Kirill Andreev <andreev@iitp.ru>
parents: 5088
diff changeset
    86
  header.SetAddr1 (tag.receiver);
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    87
  if (tag.receiver == Mac48Address::GetBroadcast ())
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    88
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    89
      m_stats.txBroadcast++;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    90
    }
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
    91
  else
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    92
    {
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    93
      m_stats.txUnicast++;
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
    94
    }
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
    95
  m_stats.txBytes += packet->GetSize ();
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    96
  return true;
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    97
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
    98
uint16_t
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
    99
FlameProtocolMac::GetChannelId () const
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   100
{
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   101
  return m_parent->GetFrequencyChannel ();
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   102
}
5126
8e06088a785d Statistics removed from headers
Kirill Andreev <andreev@iitp.ru>
parents: 5106
diff changeset
   103
FlameProtocolMac::Statistics::Statistics () :
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
   104
  txUnicast (0), txBroadcast (0), txBytes (0), rxUnicast (0), rxBroadcast (0), rxBytes (0)
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
   105
{
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
   106
}
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   107
void
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   108
FlameProtocolMac::Statistics::Print (std::ostream &os) const
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   109
{
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   110
  os << "<Statistics "
7178
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   111
  "txUnicast=\"" << txUnicast << "\" "
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   112
  "txBroadcast=\"" << txBroadcast << "\" "
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   113
  "txBytes=\"" << txBytes << "\" "
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   114
  "rxUnicast=\"" << rxUnicast << "\" "
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   115
  "rxBroadcast=\"" << rxBroadcast << "\" "
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   116
  "rxBytes=\"" << rxBytes << "\"/>" << std::endl;
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   117
}
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   118
void
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
   119
FlameProtocolMac::Report (std::ostream & os) const
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   120
{
5157
ace422ad12df Cosmetics: '\n' was replaced with std::endl, Camel case for attributes
Kirill Andreev <andreev@iitp.ru>
parents: 5132
diff changeset
   121
  os << "<FlameProtocolMac" << std::endl << 
7178
1a07cbb68308 mesh coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
   122
  "address =\"" << m_parent->GetAddress () << "\">" << std::endl;
5129
5688b8da4526 Fixed coding style
Kirill Andreev <andreev@iitp.ru>
parents: 5126
diff changeset
   123
  m_stats.Print (os);
5157
ace422ad12df Cosmetics: '\n' was replaced with std::endl, Camel case for attributes
Kirill Andreev <andreev@iitp.ru>
parents: 5132
diff changeset
   124
  os << "</FlameProtocolMac>" << std::endl;
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   125
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   126
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   127
void
5086
fccfd0073ea3 Fixed names: now protocols are called *-protocol.[h,cc], plugin is called
Kirill Andreev <andreev@iitp.ru>
parents: 5084
diff changeset
   128
FlameProtocolMac::ResetStats ()
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   129
{
5106
de6fe90556c8 Added comments and statistics to flame
Kirill Andreev <andreev@iitp.ru>
parents: 5092
diff changeset
   130
  m_stats = Statistics ();
5080
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   131
}
f97dc799fea0 Added flame tag
Kirill Andreev <andreev@iitp.ru>
parents: 5079
diff changeset
   132
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7385
diff changeset
   133
} // namespace flame
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7385
diff changeset
   134
} // namespace ns3