src/devices/wifi/adhoc-wifi-mac.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 02 Sep 2008 12:00:11 -0700
changeset 3596 6c39b712a535
parent 3517 5ba130a7f519
child 3597 fe35e5be4b78
permissions -rw-r--r--
move Address and ack timeout down to MacLow
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
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    39
  static TypeId tid = TypeId ("ns3::AdhocWifiMac")
2524
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
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2530
diff changeset
    51
  m_low = CreateObject<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);
2686
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    83
  m_slot = 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);
2686
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    89
  m_sifs = sifs;
2524
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);
2686
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    95
  m_eifsNoDifs = eifsNoDifs;
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    96
}
3596
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
    97
void 
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
    98
AdhocWifiMac::SetAckTimeout (Time ackTimeout)
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
    99
{
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   100
  m_low->SetAckTimeout (ackTimeout);
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   101
}
2686
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   102
Time 
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   103
AdhocWifiMac::GetSlot (void) const
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   104
{
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   105
  return m_slot;
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   106
}
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   107
Time 
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   108
AdhocWifiMac::GetSifs (void) const
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   109
{
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   110
  return m_sifs;
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   111
}
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   112
Time 
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   113
AdhocWifiMac::GetEifsNoDifs (void) const
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   114
{
e8cdac3c936f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   115
  return m_eifsNoDifs;
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
}
3596
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   117
Time 
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   118
AdhocWifiMac::GetAckTimeout (void) const
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   119
{
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   120
  return m_low->GetAckTimeout ();
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   121
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   122
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   123
AdhocWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   125
  m_phy = phy;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   126
  m_dcfManager->SetupPhyListener (phy);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   127
  m_low->SetPhy (phy);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   128
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   129
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   130
AdhocWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   131
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   132
  m_stationManager = stationManager;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   133
  m_dca->SetWifiRemoteStationManager (stationManager);
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   134
  m_low->SetWifiRemoteStationManager (stationManager);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
}
2003
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   136
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   137
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
   138
{
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   139
  m_upCallback = upCallback;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   140
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   141
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   142
AdhocWifiMac::SetLinkUpCallback (Callback<void> linkUp)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   143
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   144
  // an Adhoc network is always UP.
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   145
  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
   146
}
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   147
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   148
AdhocWifiMac::SetLinkDownCallback (Callback<void> linkDown)
3212
0c00342d6a73 improve attribute documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2686
diff changeset
   149
{}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
Mac48Address 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   151
AdhocWifiMac::GetAddress (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   152
{
3596
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   153
  return m_low->GetAddress ();
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   154
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   155
Ssid 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   156
AdhocWifiMac::GetSsid (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   157
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   158
  return m_ssid;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   159
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   160
Mac48Address 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   161
AdhocWifiMac::GetBssid (void) const
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
  // XXX the bssid should be generated by the procedure
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
  // described in ieee802.11 section 11.1.3
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
  return Mac48Address::GetBroadcast ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
}
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   167
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   168
AdhocWifiMac::SetAddress (Mac48Address address)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   169
{
3596
6c39b712a535 move Address and ack timeout down to MacLow
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3517
diff changeset
   170
  m_low->SetAddress (address);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   171
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   172
void 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   173
AdhocWifiMac::SetSsid (Ssid ssid)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   174
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   175
  // 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
   176
  m_ssid = ssid;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   177
}
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
void 
3517
5ba130a7f519 implement WifiNetDevice::SendFrom
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3212
diff changeset
   180
AdhocWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
{
3517
5ba130a7f519 implement WifiNetDevice::SendFrom
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3212
diff changeset
   182
  NS_LOG_FUNCTION (packet->GetSize () << to << from);
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
  WifiMacHeader hdr;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
  hdr.SetType (WIFI_MAC_DATA);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
  hdr.SetAddr1 (to);
3517
5ba130a7f519 implement WifiNetDevice::SendFrom
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3212
diff changeset
   186
  hdr.SetAddr2 (from);
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   187
  hdr.SetAddr3 (GetBssid ());
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
  hdr.SetDsNotFrom ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
  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
   190
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   191
  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
   192
  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
   193
    {
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   194
      // 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
   195
      // 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
   196
      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
   197
        {
2006
6bb048d50235 make sure we record all needed supported modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2003
diff changeset
   198
          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
   199
        }
2006
6bb048d50235 make sure we record all needed supported modes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2003
diff changeset
   200
      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
   201
    }
335dc094e52a support BRAND_NEW station in adhoc code. initialize the supported rates.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1970
diff changeset
   202
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
  m_dca->Queue (packet, hdr);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
void 
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   207
AdhocWifiMac::ForwardUp (Ptr<Packet> packet, WifiMacHeader const *hdr)
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
{
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2054
diff changeset
   209
  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
   210
  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
   211
    {
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2350
diff changeset
   212
      m_upCallback (packet, hdr->GetAddr2 ());
2288
362c382bffcf forward only packets for ourselves.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
   213
    }
1933
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
1934
13c65460caee fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1933
diff changeset
   216
} // namespace ns3