src/devices/mesh/mesh-wifi-beacon.cc
author Kirill Andreev <andreev@iitp.ru>
Sun, 22 Mar 2009 12:34:24 +0300
changeset 4865 e331ed5d3662
parent 4852 123dc54d734e
child 4890 8ee0a72c0ae0
permissions -rw-r--r--
Added header for peer link frame (first fields without information element)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     2
/* 
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     3
 * Copyright (c) 2009 IITP RAS
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     4
 * 
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     8
 *
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    13
 *
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    17
 * 
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    18
 * Author: Pavel Boyko <boyko@iitp.ru>
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    19
 */
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    20
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    21
#include "ns3/mesh-wifi-beacon.h"
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    22
#include <algorithm>
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    23
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    24
namespace ns3 {
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    25
  
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    26
MeshWifiBeacon::MeshWifiBeacon (Ssid ssid, SupportedRates rates, uint64_t us)
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    27
{
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    28
  m_header.SetSsid (ssid);
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    29
  m_header.SetSupportedRates (rates);
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    30
  m_header.SetBeaconIntervalUs (us);
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    31
}
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    32
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    33
void MeshWifiBeacon::AddInformationElement (Ptr<WifiInformationElement> ie)
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    34
{
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    35
  m_elements.push_back (ie);
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    36
}
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    37
4823
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    38
namespace {
4842
605a2680b56b Use reference counting for WifiInformationElement
Pavel Boyko <boyko@iitp.ru>
parents: 4823
diff changeset
    39
/// aux sorter for Ptr<WifiInformationElement>
605a2680b56b Use reference counting for WifiInformationElement
Pavel Boyko <boyko@iitp.ru>
parents: 4823
diff changeset
    40
struct PIEComparator
4823
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    41
{
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    42
  bool operator () (Ptr<WifiInformationElement> a, Ptr<WifiInformationElement> b) const
4823
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    43
  {
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    44
    return ((*PeekPointer (a)) < (*PeekPointer(b)));
4823
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    45
  }
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    46
};
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    47
}
7c2d9ff2d4ab Bugfix, sort by element ID not by pointer addresses
Pavel Boyko <boyko@iitp.ru>
parents: 4822
diff changeset
    48
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    49
Ptr<Packet> MeshWifiBeacon::CreatePacket ()
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    50
{
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    51
  Ptr<Packet> packet = Create<Packet> ();
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    52
  
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    53
  std::sort (m_elements.begin(), m_elements.end(), PIEComparator());
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    54
  
4842
605a2680b56b Use reference counting for WifiInformationElement
Pavel Boyko <boyko@iitp.ru>
parents: 4823
diff changeset
    55
  std::vector< Ptr<WifiInformationElement> >::const_reverse_iterator i;
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    56
  for (i = m_elements.rbegin(); i != m_elements.rend(); ++i)
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    57
  {
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    58
    packet->AddHeader (**i);
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    59
  }
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    60
  
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    61
  packet->AddHeader (BeaconHeader());
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    62
  
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    63
  return packet;
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    64
}
4843
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    65
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    66
WifiMacHeader MeshWifiBeacon::CreateHeader (Mac48Address address)
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    67
{
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    68
  WifiMacHeader hdr;
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    69
    
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    70
  hdr.SetBeacon ();
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    71
  hdr.SetAddr1 (Mac48Address::GetBroadcast ());
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    72
  hdr.SetAddr2 (address);
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    73
  hdr.SetAddr3 (address);
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    74
  hdr.SetDsNotFrom ();
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    75
  hdr.SetDsNotTo ();
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    76
  
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    77
  return hdr;
f65f22ef327e MeshWifiInterfaceMac just added and beacon generation refactored
Pavel Boyko <boyko@iitp.ru>
parents: 4842
diff changeset
    78
}
4852
123dc54d734e Coding style changes: indentation (some fixes), spaces in operators, function
Andrey Mazo <mazo@iitp.ru>
parents: 4843
diff changeset
    79
4822
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    80
} // namespace 
55868bb52909 MeshWifiBeacon class created
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    81