src/devices/wifi/mac-high-adhoc.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 09 Oct 2007 16:11:37 +0200
changeset 1934 13c65460caee
parent 1933 59328b2e04e1
child 1964 041240a915f8
permissions -rw-r--r--
fix coding style
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
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "mac-high-adhoc.h"
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "dca-txop.h"
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "wifi-net-device.h"
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "ns3/packet.h"
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#define noADHOC_TRACE 1
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#ifdef ADHOC_TRACE
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
# include <iostream>
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
# define TRACE(x) \
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
  std::cout << "HIGH ADHOC "<<x<<std::endl;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
#else /* ADHOC_TRACE */
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
# define TRACE(x)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
#endif /* ADHOC_TRACE */
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
namespace ns3 {
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
MacHighAdhoc::MacHighAdhoc ()
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
{}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
MacHighAdhoc::~MacHighAdhoc ()
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
{}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
void
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
MacHighAdhoc::SetInterface (WifiNetDevice *interface)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
  m_interface = interface;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
void 
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
MacHighAdhoc::SetForwardCallback (ForwardCallback callback)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
  m_callback = callback;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
void
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
MacHighAdhoc::SetDcaTxop (DcaTxop *dca)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
  m_dca = dca;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
Mac48Address 
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
MacHighAdhoc::GetBssid (void) const
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
  // XXX the bssid should be generated by the procedure
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
  // described in ieee802.11 section 11.1.3
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
  return Mac48Address::GetBroadcast ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
void 
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
MacHighAdhoc::Enqueue (Packet packet, Mac48Address to)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  TRACE ("enqueue size="<<packet.GetSize ()<<", to="<<to<<
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
         ", queueSize="<<m_queue->GetSize ());
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  WifiMacHeader hdr;
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
  hdr.SetType (WIFI_MAC_DATA);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
  hdr.SetAddr1 (to);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  hdr.SetAddr2 (m_interface->GetSelfAddress ());
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
  hdr.SetAddr3 (m_interface->GetBssid ());
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
  hdr.SetDsNotFrom ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
  hdr.SetDsNotTo ();
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  m_dca->Queue (packet, hdr);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
void 
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
MacHighAdhoc::Receive (Packet packet, WifiMacHeader const *hdr)
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
{
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  TRACE ("received size="<<packet.GetSize ()<<", from="<<hdr->GetAddr2 ());
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  m_callback (packet);
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
}
59328b2e04e1 add MacHighAdhoc to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
1934
13c65460caee fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1933
diff changeset
    90
} // namespace ns3