src/devices/csma/csma-net-device.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed, 16 Jul 2008 16:06:50 +0100
changeset 3460 99698bc858e8
parent 3448 0bd851bb1225
child 3476 b834a9204124
permissions -rw-r--r--
New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     2
/*
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     3
 * Copyright (c) 2007 Emmanuelle Laprise
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     4
 *
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     8
 *
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    12
 * GNU General Public License for more details.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    13
 *
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    17
 *
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    18
 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    19
 */
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    20
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    21
#include "ns3/log.h"
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    22
#include "ns3/queue.h"
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    23
#include "ns3/simulator.h"
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    24
#include "ns3/ethernet-header.h"
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    25
#include "ns3/ethernet-trailer.h"
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    26
#include "ns3/llc-snap-header.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
    27
#include "ns3/error-model.h"
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    28
#include "ns3/enum.h"
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    29
#include "ns3/boolean.h"
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    30
#include "ns3/pointer.h"
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    31
#include "ns3/trace-source-accessor.h"
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    32
#include "csma-net-device.h"
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    33
#include "csma-channel.h"
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    34
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    35
NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    36
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    37
namespace ns3 {
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    38
2501
3eaeac1dd5ed add missing NS_OBJECT_ENSURE_REGISTERED calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2500
diff changeset
    39
NS_OBJECT_ENSURE_REGISTERED (CsmaNetDevice);
3eaeac1dd5ed add missing NS_OBJECT_ENSURE_REGISTERED calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2500
diff changeset
    40
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    41
TypeId 
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    42
CsmaNetDevice::GetTypeId (void)
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    43
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    44
  static TypeId tid = TypeId ("ns3::CsmaNetDevice")
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    45
    .SetParent<NetDevice> ()
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    46
    .AddConstructor<CsmaNetDevice> ()
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    47
    .AddAttribute ("Address", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    48
                   "The address of this device.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    49
                   Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")),
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    50
                   MakeMac48AddressAccessor (&CsmaNetDevice::m_address),
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    51
                   MakeMac48AddressChecker ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    52
    .AddAttribute ("EncapsulationMode", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    53
                   "The link-layer encapsulation type to use.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    54
                   EnumValue (LLC),
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    55
                   MakeEnumAccessor (&CsmaNetDevice::m_encapMode),
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    56
                   MakeEnumChecker (ETHERNET_V1, "EthernetV1",
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    57
                                    IP_ARP, "IpArp",
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    58
                                    RAW, "Raw",
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    59
                                    LLC, "Llc"))
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    60
    .AddAttribute ("SendEnable", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    61
                   "Enable or disable the transmitter section of the device.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    62
                   BooleanValue (true),
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    63
                   MakeBooleanAccessor (&CsmaNetDevice::m_sendEnable),
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    64
                   MakeBooleanChecker ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    65
    .AddAttribute ("ReceiveEnable",
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    66
                   "Enable or disable the receiver section of the device.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    67
                   BooleanValue (true),
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    68
                   MakeBooleanAccessor (&CsmaNetDevice::m_receiveEnable),
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    69
                   MakeBooleanChecker ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    70
    .AddAttribute ("RxErrorModel", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    71
                   "The receiver error model used to simulate packet loss",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    72
                   PointerValue (),
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    73
                   MakePointerAccessor (&CsmaNetDevice::m_receiveErrorModel),
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    74
                   MakePointerChecker<ErrorModel> ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    75
    .AddAttribute ("TxQueue", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    76
                   "A queue to use as the transmit queue in the device.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    77
                   PointerValue (),
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    78
                   MakePointerAccessor (&CsmaNetDevice::m_queue),
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    79
                   MakePointerChecker<Queue> ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    80
    .AddTraceSource ("Rx", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    81
                     "Trace source to fire on reception of a MAC packet.",
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    82
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_rxTrace))
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    83
    .AddTraceSource ("Drop", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    84
                     "Trace source to fire on when a MAC packet is dropped.",
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    85
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_dropTrace))
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    86
    ;
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    87
  return tid;
1229
e4cfe4094c10 build with the new TraceContextElement API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1209
diff changeset
    88
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    89
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    90
CsmaNetDevice::CsmaNetDevice ()
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    91
  : m_name (""),
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
    92
    m_linkUp (false),
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
    93
    m_mtu (0xffff)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    94
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
    95
  NS_LOG_FUNCTION (this);
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    96
  m_txMachineState = READY;
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    97
  m_tInterframeGap = Seconds (0);
2500
1fb9430f642d convert CsmaNetDevice to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2470
diff changeset
    98
  m_channel = 0; 
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
    99
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   100
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   101
CsmaNetDevice::~CsmaNetDevice()
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   102
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   103
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   104
  m_queue = 0;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   105
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   106
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   107
  void 
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   108
CsmaNetDevice::DoDispose ()
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   109
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   110
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   111
  m_channel = 0;
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   112
  m_node = 0;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   113
  NetDevice::DoDispose ();
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   114
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   115
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   116
  void 
2655
a71d888ca2e8 add SetAddress methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   117
CsmaNetDevice::SetAddress (Mac48Address self)
a71d888ca2e8 add SetAddress methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   118
{
a71d888ca2e8 add SetAddress methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   119
  m_address = self;
a71d888ca2e8 add SetAddress methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   120
}
a71d888ca2e8 add SetAddress methods.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   121
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   122
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   123
CsmaNetDevice::SetSendEnable (bool sendEnable)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   124
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   125
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   126
  m_sendEnable = sendEnable;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   127
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   128
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   129
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   130
CsmaNetDevice::SetReceiveEnable (bool receiveEnable)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   131
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   132
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   133
  m_receiveEnable = receiveEnable;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   134
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   135
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   136
  bool
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   137
CsmaNetDevice::IsSendEnabled (void)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   138
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   139
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   140
  return (m_sendEnable);
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   141
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   142
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   143
  bool
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   144
CsmaNetDevice::IsReceiveEnabled (void)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   145
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   146
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   147
  return (m_receiveEnable);
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   148
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   149
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   150
  void 
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   151
CsmaNetDevice::SetInterframeGap (Time t)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   152
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   153
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   154
  m_tInterframeGap = t;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   155
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   156
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   157
  void 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   158
CsmaNetDevice::SetBackoffParams (
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   159
  Time slotTime, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   160
  uint32_t minSlots, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   161
  uint32_t maxSlots, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   162
  uint32_t ceiling, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   163
  uint32_t maxRetries)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   164
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   165
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   166
  m_backoff.m_slotTime = slotTime;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   167
  m_backoff.m_minSlots = minSlots;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   168
  m_backoff.m_maxSlots = maxSlots;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   169
  m_backoff.m_ceiling = ceiling;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   170
  m_backoff.m_maxRetries = maxRetries;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   171
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   172
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   173
  void 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   174
CsmaNetDevice::AddHeader (
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   175
  Ptr<Packet> p, 
3442
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   176
  Mac48Address source,
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   177
  Mac48Address dest,
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   178
  uint16_t protocolNumber)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   179
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   180
  NS_LOG_FUNCTION_NOARGS ();
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   181
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   182
  if (m_encapMode == RAW)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   183
    {
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   184
      return;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   185
    }
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   186
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   187
  EthernetHeader header (false);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   188
  header.SetSource (source);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   189
  header.SetDestination (dest);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   190
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   191
  EthernetTrailer trailer;
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   192
1001
33cf9c56e3cd Fix lengthType initialization for optimized build
Tom Henderson <tomh@tomh.org>
parents: 997
diff changeset
   193
  uint16_t lengthType = 0;
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   194
  switch (m_encapMode) 
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   195
    {
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   196
    case ETHERNET_V1:
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   197
      lengthType = p->GetSize () + header.GetSerializedSize () + 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   198
        trailer.GetSerializedSize ();
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   199
      break;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   200
    case IP_ARP:
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   201
      lengthType = protocolNumber;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   202
      break;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   203
    case LLC: {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   204
      lengthType = p->GetSize () + header.GetSerializedSize () + 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   205
        trailer.GetSerializedSize ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   206
      LlcSnapHeader llc;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   207
      llc.SetType (protocolNumber);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   208
      p->AddHeader (llc);
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   209
    } break;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   210
    case RAW:
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   211
      NS_ASSERT (false);
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   212
      break;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   213
    }
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   214
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   215
  header.SetLengthType (lengthType);
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   216
  p->AddHeader (header);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   217
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   218
  trailer.CalcFcs (p);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   219
  p->AddTrailer (trailer);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   220
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   221
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   222
  bool 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   223
CsmaNetDevice::ProcessHeader (Ptr<Packet> p, uint16_t & param)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   224
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   225
  NS_LOG_FUNCTION_NOARGS ();
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   226
  if (m_encapMode == RAW)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   227
    {
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   228
      return true;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   229
    }
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   230
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   231
  EthernetTrailer trailer;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   232
      
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   233
  p->RemoveTrailer (trailer);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   234
  trailer.CheckFcs (p);
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   235
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   236
  EthernetHeader header (false);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   237
  p->RemoveHeader (header);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   238
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   239
  if ((header.GetDestination () != GetBroadcast ()) &&
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   240
      (header.GetDestination () != GetAddress ()))
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   241
    {
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   242
      return false;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   243
    }
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   244
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   245
  switch (m_encapMode)
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   246
    {
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   247
    case ETHERNET_V1:
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   248
    case IP_ARP:
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   249
      param = header.GetLengthType ();
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   250
      break;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   251
    case LLC: {
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   252
      LlcSnapHeader llc;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   253
      p->RemoveHeader (llc);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   254
      param = llc.GetType ();
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   255
    } break;
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   256
    case RAW:
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   257
      NS_ASSERT (false);
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   258
      break;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   259
    }
995
22821dd9152e param is a 16 bit integer. implement proper llc encapsulation/decapsulation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 993
diff changeset
   260
  return true;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   261
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   262
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   263
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   264
CsmaNetDevice::TransmitStart ()
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   265
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   266
  NS_LOG_FUNCTION_NOARGS ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   267
  NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   268
  NS_LOG_LOGIC ("UID is " << m_currentPkt->GetUid ());
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   269
//
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   270
// This function is called to start the process of transmitting a packet.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   271
// We need to tell the channel that we've started wiggling the wire and
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   272
// schedule an event that will be executed when it's time to tell the 
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   273
// channel that we're done wiggling the wire.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   274
//
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   275
  NS_ASSERT_MSG ((m_txMachineState == READY) || (m_txMachineState == BACKOFF), 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   276
    "Must be READY to transmit. Tx state is: " << m_txMachineState);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   277
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   278
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   279
// Only transmit if send side of net device is enabled
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   280
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   281
  if (IsSendEnabled () == false)
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   282
    {
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   283
      return;
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   284
    }
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   285
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   286
  if (m_channel->GetState () != IDLE)
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   287
    {
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   288
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   289
// The channel is busy -- backoff and rechedule TransmitStart ()
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   290
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   291
      m_txMachineState = BACKOFF;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   292
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   293
      if (m_backoff.MaxRetriesReached ())
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   294
        { 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   295
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   296
// Too many retries, abort transmission of packet
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   297
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   298
          TransmitAbort ();
997
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   299
        } 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   300
      else 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   301
        {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   302
          m_backoff.IncrNumRetries ();
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   303
          Time backoffTime = m_backoff.GetBackoffTime ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   304
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   305
          NS_LOG_LOGIC ("Channel busy, backing off for " << 
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   306
            backoffTime.GetSeconds () << " sec");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   307
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   308
          Simulator::Schedule (backoffTime, &CsmaNetDevice::TransmitStart,
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   309
            this);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   310
        }
997
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   311
    } 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   312
  else 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   313
    {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   314
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   315
// The channel is free, transmit the packet
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   316
//
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   317
      m_txMachineState = BUSY;
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   318
      Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   319
      
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   320
      NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << 
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   321
        tEvent.GetSeconds () << "sec");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   322
      
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   323
      Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   324
        this);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   325
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   326
      if (m_channel->TransmitStart (m_currentPkt, m_deviceId) == false)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   327
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   328
          NS_LOG_WARN ("Channel transmit start did not work at " << 
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   329
            tEvent.GetSeconds () << "sec");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   330
          m_txMachineState = READY;
997
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   331
        } 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   332
      else 
d95ffcec6523 fix indent, basic coding style issues
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 995
diff changeset
   333
        {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   334
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   335
// Transmission succeeded, reset the backoff time parameters.
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   336
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   337
          m_backoff.ResetBackoffTime ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   338
        }
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   339
    }
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   340
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   341
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   342
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   343
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   344
CsmaNetDevice::TransmitAbort (void)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   345
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   346
  NS_LOG_FUNCTION_NOARGS ();
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   347
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   348
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   349
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   350
// Since we were transmitting a packet, that packet had better be on the
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   351
// transmit queue.
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   352
//
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   353
  m_currentPkt = m_queue->Dequeue ();
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   354
  NS_ASSERT_MSG (m_currentPkt != 0, "No Packet on queue during"
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   355
    "CsmaNetDevice::TransmitAbort()");
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   356
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   357
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   358
// The last one failed.  Let's try to transmit the next one (if there)
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   359
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   360
  m_backoff.ResetBackoffTime ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   361
  m_txMachineState = READY;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   362
  TransmitStart ();
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   363
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   364
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   365
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   366
CsmaNetDevice::TransmitCompleteEvent (void)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   367
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   368
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   369
//
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   370
// This function is called to finish the  process of transmitting a packet.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   371
// We need to tell the channel that we've stopped wiggling the wire and
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   372
// schedule an event that will be executed when it's time to re-enable
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   373
// the transmitter after the interframe gap.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   374
//
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   375
  NS_ASSERT_MSG (m_txMachineState == BUSY, "Must be BUSY if transmitting");
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   376
  NS_ASSERT (m_channel->GetState () == TRANSMITTING);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   377
  m_txMachineState = GAP;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   378
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   379
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   380
  m_channel->TransmitEnd (); 
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   381
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   382
  NS_LOG_LOGIC ("Schedule TransmitReadyEvent in "
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   383
    << m_tInterframeGap.GetSeconds () << "sec");
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   384
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   385
  Simulator::Schedule (m_tInterframeGap, &CsmaNetDevice::TransmitReadyEvent, 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   386
    this);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   387
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   388
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   389
  void
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   390
CsmaNetDevice::TransmitReadyEvent (void)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   391
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   392
  NS_LOG_FUNCTION_NOARGS ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   393
//
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   394
// This function is called to enable the transmitter after the interframe
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   395
// gap has passed.  If there are pending transmissions, we use this opportunity
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   396
// to start the next transmit.
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   397
//
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   398
  NS_ASSERT_MSG (m_txMachineState == GAP, "Must be in interframe gap");
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   399
  m_txMachineState = READY;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   400
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   401
  // Get the next packet from the queue for transmitting
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   402
  if (m_queue->IsEmpty ())
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   403
    {
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   404
      return;
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   405
    }
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   406
  else
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   407
    {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   408
      m_currentPkt = m_queue->Dequeue ();
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   409
      NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitReadyEvent():"
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   410
        " IsEmpty false but no Packet on queue?");
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   411
      TransmitStart ();
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   412
    }
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   413
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   414
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   415
bool
1276
e0b88ec7a6be merge ns-3-csma with tip
Craig Dowell <craigdo@ee.washington.edu>
parents: 1270
diff changeset
   416
CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   417
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   418
  NS_LOG_FUNCTION (this << &ch);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   419
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   420
  m_channel = ch;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   421
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   422
  m_deviceId = m_channel->Attach (this);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   423
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   424
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   425
// The channel provides us with the transmitter data rate.
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   426
//
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   427
  m_bps = m_channel->GetDataRate ();
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   428
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   429
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   430
// We use the Ethernet interframe gap of 96 bit times.
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   431
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   432
  m_tInterframeGap = Seconds (m_bps.CalculateTxTime (96/8));
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   433
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   434
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   435
// This device is up whenever a channel is attached to it.
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   436
//
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   437
  NotifyLinkUp ();
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   438
  return true;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   439
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   440
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   441
  void
3011
2d507430219e bug 153 applied to CSMA
Craig Dowell <craigdo@ee.washington.edu>
parents: 2989
diff changeset
   442
CsmaNetDevice::SetQueue (Ptr<Queue> q)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   443
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   444
  NS_LOG_FUNCTION (this << q);
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   445
  m_queue = q;
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   446
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   447
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   448
  void
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   449
CsmaNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em)
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   450
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   451
  NS_LOG_FUNCTION (em);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   452
  m_receiveErrorModel = em; 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   453
}
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   454
3447
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   455
void
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   456
CsmaNetDevice::Receive (Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   457
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   458
  NS_LOG_FUNCTION_NOARGS ();
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   459
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   460
3447
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   461
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   462
  //
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   463
  // We never forward up packets that we sent. Real devices don't do this since
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   464
  // their receivers are disabled during send, so we don't. Drop the packet
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   465
  // silently (no tracing) since it would really never get here in a real device.
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   466
  // 
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   467
  if (senderDevice == this)
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   468
    {
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   469
      return;
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   470
    }
48f371a8ae8e Move the csma packet-from-self receive filtering away from the CsmaChannel into the CsmaNetDevice, with the help of an extra Ptr<CsmaNetDevice> parameter in Receive(). As discussed in the mailing list.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3446
diff changeset
   471
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   472
// 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   473
// Only receive if the send side of net device is enabled
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   474
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   475
  if (IsReceiveEnabled () == false)
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   476
    {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
   477
      m_dropTrace (packet);
1210
599a311daef6 fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents: 1209
diff changeset
   478
      return;
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   479
    }
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   480
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   481
  if (m_encapMode == RAW)
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   482
    {
3326
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   483
      m_rxTrace (packet);
3460
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   484
      if (!m_promiscRxCallback.IsNull ())
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   485
        {
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   486
          m_promiscRxCallback (this, packet, 0, GetBroadcast (), GetAddress (), PACKET_HOST);
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   487
        }
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   488
      m_rxCallback (this, packet, 0, GetBroadcast ());
1210
599a311daef6 fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents: 1209
diff changeset
   489
      return;
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   490
    }
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   491
3326
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   492
//
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   493
// Trace sinks will expect complete packets, not packets without some of the
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   494
// headers.
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   495
//
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   496
  Ptr<Packet> originalPacket = packet->Copy ();
239c4bc21ebf reposition trace hook in csma to address bug 241.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
   497
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   498
  EthernetTrailer trailer;
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   499
  packet->RemoveTrailer (trailer);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   500
  trailer.CheckFcs (packet);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   501
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   502
  EthernetHeader header (false);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   503
  packet->RemoveHeader (header);
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   504
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   505
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   506
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   507
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   508
//
1441
d6f8a7546e7f semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1278
diff changeset
   509
// An IP host group address is mapped to an Ethernet multicast address
d6f8a7546e7f semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1278
diff changeset
   510
// by placing the low-order 23-bits of the IP address into the low-order
d6f8a7546e7f semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1278
diff changeset
   511
// 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex).
d6f8a7546e7f semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1278
diff changeset
   512
//
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   513
// We are going to receive all packets destined to any multicast address,
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   514
// which means clearing the low-order 23 bits the header destination 
1441
d6f8a7546e7f semi-real multicast hardware addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1278
diff changeset
   515
//
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
   516
  Mac48Address mcDest;
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   517
  uint8_t      mcBuf[6];
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   518
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   519
  header.GetDestination ().CopyTo (mcBuf);
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   520
  mcBuf[3] &= 0x80;
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   521
  mcBuf[4] = 0;
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   522
  mcBuf[5] = 0;
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   523
  mcDest.CopyFrom (mcBuf);
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   524
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   525
  Mac48Address multicast = Mac48Address::ConvertFrom (GetMulticast ());
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   526
  Mac48Address broadcast = Mac48Address::ConvertFrom (GetBroadcast ());
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   527
  Mac48Address destination = Mac48Address::ConvertFrom (GetAddress ());
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   528
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828 1866
diff changeset
   529
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   530
    {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   531
      NS_LOG_LOGIC ("Dropping pkt due to error model ");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   532
      m_dropTrace (packet);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   533
    }
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   534
  else
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   535
    {
1210
599a311daef6 fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents: 1209
diff changeset
   536
//
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   537
// variable <protocol> must be initialized to avoid a compiler warning in the 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   538
// RAW case that breaks the optimized build.
1210
599a311daef6 fix opt warnings, let compiler do tail call optimization in csma nd, remove protected access from router iface
Craig Dowell <craigdo@ee.washington.edu>
parents: 1209
diff changeset
   539
//
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   540
      uint16_t protocol = 0;
1186
909e9eb2124e rework the NetDevice <-> Node interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
   541
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   542
      switch (m_encapMode)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   543
        {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   544
        case ETHERNET_V1:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   545
        case IP_ARP:
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   546
          protocol = header.GetLengthType ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   547
          break;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   548
        case LLC: 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   549
          {
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   550
            LlcSnapHeader llc;
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828 1866
diff changeset
   551
            packet->RemoveHeader (llc);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   552
            protocol = llc.GetType ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   553
          } 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   554
          break;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   555
        case RAW:
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   556
          NS_ASSERT (false);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   557
          break;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   558
        }
3438
86e262420fbf Implement the promiscuous receive callback for CsmaNetDevice.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3436
diff changeset
   559
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   560
      PacketType packetType;
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   561
      
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   562
      if (header.GetDestination () == broadcast)
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   563
        {
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   564
          packetType = PACKET_BROADCAST;
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   565
          m_rxTrace (originalPacket);
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   566
        }
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   567
      else if (mcDest == multicast)
3438
86e262420fbf Implement the promiscuous receive callback for CsmaNetDevice.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3436
diff changeset
   568
        {
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   569
          packetType = PACKET_MULTICAST;          
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   570
          m_rxTrace (originalPacket);
3438
86e262420fbf Implement the promiscuous receive callback for CsmaNetDevice.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3436
diff changeset
   571
        }
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   572
      else if (header.GetDestination () == destination)
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   573
        {
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   574
          packetType = PACKET_HOST;
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   575
          m_rxTrace (originalPacket);
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   576
        }
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   577
      else
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   578
        {
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   579
          packetType = PACKET_OTHERHOST;
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   580
        }
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3447
diff changeset
   581
      
3460
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   582
      if (!m_promiscRxCallback.IsNull ())
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   583
        {
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   584
          m_promiscRxCallback (this, packet, protocol, header.GetSource (), header.GetDestination (), packetType);
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   585
        }
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   586
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   587
      if (packetType != PACKET_OTHERHOST)
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   588
        {
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   589
          m_rxCallback (this, packet, protocol, header.GetSource ());
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   590
        }
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   591
    }
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   592
}
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   593
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   594
  Ptr<Queue>
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   595
CsmaNetDevice::GetQueue (void) const 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   596
{ 
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   597
  NS_LOG_FUNCTION_NOARGS ();
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   598
  return m_queue;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   599
}
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   600
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   601
  void
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   602
CsmaNetDevice::NotifyLinkUp (void)
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   603
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   604
  m_linkUp = true;
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   605
  if (m_linkChangeCallback.IsNull () == false)
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   606
    {
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   607
      m_linkChangeCallback ();
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   608
    }
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   609
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   610
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   611
  void 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   612
CsmaNetDevice::SetName (const std::string name)
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   613
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   614
  m_name = name;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   615
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   616
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   617
  std::string 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   618
CsmaNetDevice::GetName (void) const
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   619
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   620
  return m_name;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   621
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   622
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   623
  void 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   624
CsmaNetDevice::SetIfIndex (const uint32_t index)
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   625
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   626
  m_ifIndex = index;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   627
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   628
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   629
  uint32_t 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   630
CsmaNetDevice::GetIfIndex (void) const
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   631
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   632
  return m_ifIndex;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   633
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   634
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   635
  Ptr<Channel> 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   636
CsmaNetDevice::GetChannel (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   637
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   638
  return m_channel;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   639
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   640
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   641
  Address 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   642
CsmaNetDevice::GetAddress (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   643
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   644
  return m_address;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   645
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   646
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   647
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   648
CsmaNetDevice::SetMtu (const uint16_t mtu)
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   649
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   650
  m_mtu = mtu;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   651
  return true;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   652
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   653
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   654
  uint16_t 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   655
CsmaNetDevice::GetMtu (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   656
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   657
  return m_mtu;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   658
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   659
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   660
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   661
CsmaNetDevice::IsLinkUp (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   662
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   663
  return m_linkUp;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   664
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   665
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   666
  void 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   667
CsmaNetDevice::SetLinkChangeCallback (Callback<void> callback)
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   668
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   669
  m_linkChangeCallback = callback;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   670
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   671
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   672
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   673
CsmaNetDevice::IsBroadcast (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   674
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   675
  return true;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   676
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   677
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   678
  Address
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   679
CsmaNetDevice::GetBroadcast (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   680
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   681
  return Mac48Address ("ff:ff:ff:ff:ff:ff");
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   682
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   683
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   684
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   685
CsmaNetDevice::IsMulticast (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   686
{
2795
720104ef3fce enable csma multicast
Tom Henderson <tomh@tomh.org>
parents: 2777
diff changeset
   687
  return true;
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   688
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   689
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   690
  Address 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   691
CsmaNetDevice::GetMulticast (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   692
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   693
  return Mac48Address ("01:00:5e:00:00:00");
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   694
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   695
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   696
  Address 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   697
CsmaNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   698
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   699
  NS_LOG_FUNCTION (this << multicastGroup);
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   700
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   701
// First, get the generic multicast address.
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   702
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   703
  Address hardwareDestination = GetMulticast ();
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   704
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   705
  NS_LOG_LOGIC ("Device multicast address: " << hardwareDestination);
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   706
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   707
// It's our address, and we know we're playing with an EUI-48 address here
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   708
// primarily since we know that by construction, but also since the parameter
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   709
// is an Ipv4Address.
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   710
//
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
   711
  Mac48Address etherAddr = Mac48Address::ConvertFrom (hardwareDestination);
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   712
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   713
// We now have the multicast address in an abstract 48-bit container.  We 
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   714
// need to pull it out so we can play with it.  When we're done, we have the 
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   715
// high order bits in etherBuffer[0], etc.
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   716
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   717
  uint8_t etherBuffer[6];
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   718
  etherAddr.CopyTo (etherBuffer);
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   719
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   720
// Now we need to pull the raw bits out of the Ipv4 destination address.
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   721
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   722
  uint8_t ipBuffer[4];
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   723
  multicastGroup.Serialize (ipBuffer);
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   724
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   725
// RFC 1112 says that an Ipv4 host group address is mapped to an EUI-48
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   726
// multicast address by placing the low-order 23-bits of the IP address into 
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   727
// the low-order 23 bits of the Ethernet multicast address 
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   728
// 01-00-5E-00-00-00 (hex). 
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   729
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   730
  etherBuffer[3] |= ipBuffer[1] & 0x7f;
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   731
  etherBuffer[4] = ipBuffer[2];
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   732
  etherBuffer[5] = ipBuffer[3];
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   733
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   734
// Now, etherBuffer has the desired ethernet multicast address.  We have to
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
   735
// suck these bits back into the Mac48Address,
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   736
//
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   737
  etherAddr.CopyFrom (etherBuffer);
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   738
//
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
   739
// Implicit conversion (operator Address ()) is defined for Mac48Address, so
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   740
// use it by just returning the EUI-48 address which is automagically converted
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   741
// to an Address.
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   742
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   743
  NS_LOG_LOGIC ("multicast address is " << etherAddr);
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   744
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   745
  return etherAddr;
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   746
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   747
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   748
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   749
CsmaNetDevice::IsPointToPoint (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   750
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   751
  return false;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   752
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   753
3442
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   754
bool
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   755
CsmaNetDevice::Send (Ptr<Packet> packet, 
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   756
                     const Address& dest, 
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   757
                     uint16_t protocolNumber)
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   758
{
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   759
  return SendFrom (packet, m_address, dest, protocolNumber);
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   760
}
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   761
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   762
bool
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   763
CsmaNetDevice::SendFrom (Ptr<Packet> packet,
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   764
                         const Address& src,
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   765
                         const Address& dest,
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   766
                         uint16_t protocolNumber)
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   767
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   768
  NS_LOG_FUNCTION_NOARGS ();
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   769
  NS_LOG_LOGIC ("p=" << packet);
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   770
  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   771
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   772
  NS_ASSERT (IsLinkUp ());
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   773
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   774
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   775
// Only transmit if send side of net device is enabled
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   776
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   777
  if (IsSendEnabled () == false)
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   778
    {
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   779
      return false;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   780
    }
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   781
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   782
  Mac48Address destination = Mac48Address::ConvertFrom (dest);
3442
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   783
  Mac48Address source = Mac48Address::ConvertFrom (src);
8eef02250bc9 Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3438
diff changeset
   784
  AddHeader (packet, source, destination, protocolNumber);
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   785
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   786
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   787
// Place the packet to be sent on the send queue
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   788
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   789
  if (m_queue->Enqueue(packet) == false)
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   790
    {
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   791
      return false;
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   792
    }
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   793
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   794
// If the device is idle, we need to start a transmission. Otherwise,
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   795
// the transmission will be started when the current packet finished
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   796
// transmission (see TransmitCompleteEvent)
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   797
//
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   798
  if (m_txMachineState == READY) 
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   799
    {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   800
//
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   801
// The next packet to be transmitted goes in m_currentPkt
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   802
//
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   803
      m_currentPkt = m_queue->Dequeue ();
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   804
      if (m_currentPkt != 0)
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   805
        {
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   806
          TransmitStart ();
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   807
        }
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   808
    }
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   809
  return true;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   810
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   811
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   812
  Ptr<Node> 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   813
CsmaNetDevice::GetNode (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   814
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   815
  return m_node;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   816
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   817
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   818
  void 
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2501
diff changeset
   819
CsmaNetDevice::SetNode (Ptr<Node> node)
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2501
diff changeset
   820
{
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2501
diff changeset
   821
  m_node = node;
3436
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   822
  int count = -1;
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   823
  if (m_name.size () == 0)
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   824
    {
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   825
      for (uint32_t i = 0; i < node->GetNDevices (); i++)
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   826
        {
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   827
          Ptr<NetDevice> dev = node->GetDevice (i);
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   828
          if (dynamic_cast<CsmaNetDevice*> (PeekPointer (dev)))
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   829
            {
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   830
              count++;
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   831
              if (dev == this)
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   832
                {
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   833
                  break;
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   834
                }
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   835
            }
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   836
        }
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   837
      std::ostringstream s;
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   838
      s << "eth" << count;
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   839
      m_name = s.str ();
c741d41f9bfb For csma, set a sensible netdevice name, if none has been set.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3435
diff changeset
   840
    }
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2501
diff changeset
   841
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   842
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   843
  bool 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   844
CsmaNetDevice::NeedsArp (void) const
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   845
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   846
  if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   847
    {
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   848
      return true;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   849
    } 
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   850
  else 
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   851
    {
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   852
      return false;
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   853
    }
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   854
}
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   855
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
   856
  void 
2470
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   857
CsmaNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   858
{
254581fb9e9c make NetDevice fully virtual.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   859
  m_rxCallback = cb;
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   860
}
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   861
3460
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   862
void 
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   863
CsmaNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   864
{
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   865
  m_promiscRxCallback = cb;
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   866
}
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   867
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   868
bool 
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   869
CsmaNetDevice::SupportsPromiscuous () const
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   870
{
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   871
  return true;
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   872
}
99698bc858e8 New API considering comments from Craig: NetDevice->Node uses two callbacks; Node->ProtocolHandlers uses a single API with a promiscuous flag.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3448
diff changeset
   873
977
09bf4e458015 a csma/cd NetDevice subclass and a test script
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents:
diff changeset
   874
} // namespace ns3