src/devices/wifi/adhoc-wifi-mac.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 02 Mar 2008 06:43:12 +0100
changeset 2530 05f9cec44621
parent 2528 a527ec47b756
child 2592 3ebf97150166
permissions -rw-r--r--
avoid memory leaks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005 INRIA
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    21
#include "adhoc-wifi-mac.h"
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "dca-txop.h"
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    23
#include "mac-low.h"
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    24
#include "mac-rx-middle.h"
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
    25
#include "wifi-phy.h"
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    26
#include "dcf-manager.h"
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "ns3/packet.h"
1970
df11f51cd342 convert tracing to log system
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1964
diff changeset
    28
#include "ns3/log.h"
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    30
NS_LOG_COMPONENT_DEFINE ("AdhocWifiMac");
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
namespace ns3 {
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    34
NS_OBJECT_ENSURE_REGISTERED (AdhocWifiMac);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    35
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    36
TypeId 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    37
AdhocWifiMac::GetTypeId (void)
2054
ba8e810bae4c derive WifiPhy from Object and manage it with a Ptr<>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2006
diff changeset
    38
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    39
  static TypeId tid = TypeId ("AdhocWifiMac")
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    40
    .SetParent<WifiMac> ()
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    41
    .AddConstructor<AdhocWifiMac> ()
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    42
    ;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    43
  return tid;
2054
ba8e810bae4c derive WifiPhy from Object and manage it with a Ptr<>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2006
diff changeset
    44
}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    46
AdhocWifiMac::AdhocWifiMac ()
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    48
  m_rxMiddle = new MacRxMiddle ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    49
  m_rxMiddle->SetForwardCallback (MakeCallback (&AdhocWifiMac::ForwardUp, this));
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    50
2530
05f9cec44621 avoid memory leaks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2528
diff changeset
    51
  m_low = CreateObjectWith<MacLow> ();
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    52
  m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    53
  m_low->SetMac (this);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    54
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    55
  m_dcfManager = new DcfManager ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    56
  m_dcfManager->SetupLowListener (m_low);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    57
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    58
  m_dca = CreateObject<DcaTxop> ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    59
  m_dca->SetLow (m_low);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    60
  m_dca->SetManager (m_dcfManager);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    61
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    62
AdhocWifiMac::~AdhocWifiMac ()
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    63
{}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    65
void
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    66
AdhocWifiMac::DoDispose (void)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    67
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    68
  delete m_rxMiddle;
2528
a527ec47b756 avoid crashing AP wifi sample
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
    69
  delete m_dcfManager;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    70
  m_rxMiddle = 0;
2530
05f9cec44621 avoid memory leaks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2528
diff changeset
    71
  m_dcfManager = 0;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    72
  m_low = 0;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    73
  m_phy = 0;
2530
05f9cec44621 avoid memory leaks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2528
diff changeset
    74
  m_dca = 0;
05f9cec44621 avoid memory leaks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2528
diff changeset
    75
  m_stationManager = 0;
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    76
  WifiMac::DoDispose ();
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    77
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    78
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    79
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    80
AdhocWifiMac::SetSlot (Time slotTime)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    81
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    82
  m_dcfManager->SetSlot (slotTime);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    83
  WifiMac::SetSlot (slotTime);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    86
AdhocWifiMac::SetSifs (Time sifs)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    88
  m_dcfManager->SetSifs (sifs);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    89
  WifiMac::SetSifs (sifs);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    90
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    91
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    92
AdhocWifiMac::SetEifsNoDifs (Time eifsNoDifs)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    93
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    94
  m_dcfManager->SetEifsNoDifs (eifsNoDifs);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    95
  WifiMac::SetEifsNoDifs (eifsNoDifs);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    97
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    98
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
    99
AdhocWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   101
  m_phy = phy;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   102
  m_dcfManager->SetupPhyListener (phy);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   103
  m_low->SetPhy (phy);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   104
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   105
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   106
AdhocWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   107
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   108
  m_stationManager = stationManager;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   109
  m_dca->SetWifiRemoteStationManager (stationManager);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   110
  m_low->SetWifiRemoteStationManager (stationManager);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
}
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   112
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   113
AdhocWifiMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, const Mac48Address &> upCallback)
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   114
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   115
  m_upCallback = upCallback;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   116
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   117
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   118
AdhocWifiMac::SetLinkUpCallback (Callback<void> linkUp)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   119
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   120
  // an Adhoc network is always UP.
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   121
  linkUp ();
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   122
}
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   123
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   124
AdhocWifiMac::SetLinkDownCallback (Callback<void> linkDown)
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   125
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   126
  //XXX
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   127
}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
Mac48Address 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   129
AdhocWifiMac::GetAddress (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   130
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   131
  return m_address;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   132
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   133
Ssid 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   134
AdhocWifiMac::GetSsid (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   135
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   136
  return m_ssid;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   137
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   138
Mac48Address 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   139
AdhocWifiMac::GetBssid (void) const
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
  // XXX the bssid should be generated by the procedure
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
  // described in ieee802.11 section 11.1.3
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  return Mac48Address::GetBroadcast ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   145
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   146
AdhocWifiMac::SetAddress (Mac48Address address)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   147
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   148
  m_address = address;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   149
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   150
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   151
AdhocWifiMac::SetSsid (Ssid ssid)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   152
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   153
  // XXX: here, we should start a special adhoc network
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   154
  m_ssid = ssid;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   155
}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   158
AdhocWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
{
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2054
diff changeset
   160
  NS_LOG_DEBUG ("enqueue size="<<packet->GetSize ()<<", to="<<to);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
  WifiMacHeader hdr;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
  hdr.SetType (WIFI_MAC_DATA);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
  hdr.SetAddr1 (to);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   164
  hdr.SetAddr2 (GetAddress ());
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   165
  hdr.SetAddr3 (GetBssid ());
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
  hdr.SetDsNotFrom ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
  hdr.SetDsNotTo ();
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   168
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   169
  WifiRemoteStation *destination = m_stationManager->Lookup (to);
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   170
  if (destination->IsBrandNew ())
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   171
    {
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   172
      // in adhoc mode, we assume that every destination
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   173
      // supports all the rates we support.
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   174
      for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   175
        {
2006
6bb048d50235 make sure we record all needed supported modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2003
diff changeset
   176
          destination->AddSupportedMode (m_phy->GetMode (i));
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   177
        }
2006
6bb048d50235 make sure we record all needed supported modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2003
diff changeset
   178
      destination->RecordDisassociated ();
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   179
    }
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   180
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
  m_dca->Queue (packet, hdr);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   185
AdhocWifiMac::ForwardUp (Ptr<Packet> packet, WifiMacHeader const *hdr)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
{
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2054
diff changeset
   187
  NS_LOG_DEBUG ("received size="<<packet->GetSize ()<<", from="<<hdr->GetAddr2 ());
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   188
  if (hdr->GetAddr1 ().IsBroadcast () || hdr->GetAddr1 () == GetAddress ())
2288
362c382bffcf forward only packets for ourselves.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
   189
    {
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   190
      m_upCallback (packet, hdr->GetAddr2 ());
2288
362c382bffcf forward only packets for ourselves.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
   191
    }
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
1934
13c65460caee fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1933
diff changeset
   194
} // namespace ns3