src/devices/emu/emu-net-device.cc
author Craig Dowell <craigdo@ee.washington.edu>
Sat, 28 Feb 2009 16:25:24 -0800
changeset 4263 fec2f830d015
parent 4017 4521a81f94b8
child 4264 9d2e96c4e6e4
permissions -rw-r--r--
trace consistency changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2008 University of Washington
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    19
#include "emu-net-device.h"
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    20
#include "emu-encode-decode.h"
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/log.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/queue.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/simulator.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/ethernet-header.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/ethernet-trailer.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "ns3/llc-snap-header.h"
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    28
#include "ns3/boolean.h"
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    29
#include "ns3/uinteger.h"
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    30
#include "ns3/pointer.h"
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    31
#include "ns3/string.h"
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
#include "ns3/trace-source-accessor.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#include "ns3/channel.h"
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include "ns3/system-thread.h"
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    35
#include "ns3/realtime-simulator-impl.h"
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    36
#include "ns3/mac48-address.h"
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    38
#include <sys/wait.h>
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    39
#include <sys/stat.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
#include <sys/socket.h>
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    41
#include <sys/un.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
#include <sys/ioctl.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
#include <net/ethernet.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
#include <net/if.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
#include <netinet/in.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
#include <netpacket/packet.h>
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
#include <arpa/inet.h>
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    48
#include <errno.h>
3851
cc6a7f93dc3f g++ 4.3.2-1ubuntu7 too picky
Craig Dowell <craigdo@ee.washington.edu>
parents: 3850
diff changeset
    49
#include <limits>
cc6a7f93dc3f g++ 4.3.2-1ubuntu7 too picky
Craig Dowell <craigdo@ee.washington.edu>
parents: 3850
diff changeset
    50
#include <stdlib.h>
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    52
NS_LOG_COMPONENT_DEFINE ("EmuNetDevice");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
namespace ns3 {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    56
NS_OBJECT_ENSURE_REGISTERED (EmuNetDevice);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
    58
#define EMU_MAGIC 65867
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
    59
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
TypeId 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    61
EmuNetDevice::GetTypeId (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
{
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    63
  static TypeId tid = TypeId ("ns3::EmuNetDevice")
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
    .SetParent<NetDevice> ()
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    65
    .AddConstructor<EmuNetDevice> ()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
    .AddAttribute ("Address", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
                   "The ns-3 MAC address of this (virtual) device.",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
                   Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    69
                   MakeMac48AddressAccessor (&EmuNetDevice::m_address),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
                   MakeMac48AddressChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
    .AddAttribute ("DeviceName", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
                   "The name of the underlying real device (e.g. eth1).",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
                   StringValue ("eth1"),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    74
                   MakeStringAccessor (&EmuNetDevice::m_deviceName),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
                   MakeStringChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
    .AddAttribute ("Start", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
                   "The simulation time at which to spin up the device thread.",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
                   TimeValue (Seconds (0.)),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    79
                   MakeTimeAccessor (&EmuNetDevice::m_tStart),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
                   MakeTimeChecker ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
    .AddAttribute ("Stop", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
                   "The simulation time at which to tear down the device thread.",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
                   TimeValue (Seconds (0.)),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    84
                   MakeTimeAccessor (&EmuNetDevice::m_tStop),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
                   MakeTimeChecker ())
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    86
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    87
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    88
    // Transmit queueing discipline for the device which includes its own set
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    89
    // of trace hooks.  Note that this is really going to run "on top of" the 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    90
    // queueing discipline that will most likely be present in the devices of
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    91
    // the underlying operating system.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    92
    //
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
    .AddAttribute ("TxQueue", 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
                   "A queue to use as the transmit queue in the device.",
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
                   PointerValue (),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
    96
                   MakePointerAccessor (&EmuNetDevice::m_queue),
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
                   MakePointerChecker<Queue> ())
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    98
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
    99
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   100
    // Trace sources at the "top" of the net device, where packets transition
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   101
    // to/from higher layers.  These points do not really correspond to the 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   102
    // MAC layer of the underlying operating system, but exist to provide 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   103
    // a consitent tracing environment.  These trace hooks should really be
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   104
    // interpreted as the points at which a packet leaves the ns-3 environment
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   105
    // destined for the underlying operating system or vice-versa.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   106
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   107
    .AddTraceSource ("MacTx", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   108
                     "Trace source indicating a packet has arrived for transmission by this device",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   109
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macTxTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   110
    .AddTraceSource ("MacTxDrop", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   111
                     "Trace source indicating a packet has been dropped by the device before transmission",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   112
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macTxDropTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   113
    .AddTraceSource ("MacRx", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   114
                     "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   115
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macRxTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   116
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   117
    // In normal ns-3 net devices, these trace souces correspond to the "bottom"
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   118
    // of the net device, where packets transition to/from the channel.  In 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   119
    // the case of the emu device, there is no physical layer access and so
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   120
    // these are duplicates of the MAC-level hooks.  Intepret these points
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   121
    // also as the points at which a packet leaves the ns-3 environment
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   122
    // destined for the underlying operating system or vice-versa.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   123
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   124
    .AddTraceSource ("PhyTxStart", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   125
                     "Trace source indicating a packet has begun transmitting over the channel",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   126
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxStartTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   127
    .AddTraceSource ("PhyTx", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   128
                     "Trace source indicating a packet has been completely transmitted over the channel",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   129
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   130
    .AddTraceSource ("PhyTxDrop", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   131
                     "Trace source indicating a packet has been dropped by the device during transmission",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   132
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxDropTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   133
    .AddTraceSource ("PhyRxStart", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   134
                     "Trace source indicating a packet has begun being received by the device",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   135
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxStartTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   136
    .AddTraceSource ("PhyRx", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   137
                     "Trace source indicating a packet has been completely received by the device",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   138
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   139
    .AddTraceSource ("PhyRxDrop", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   140
                     "Trace source indicating a packet has been dropped by the device during reception",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   141
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxDropTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   142
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   143
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   144
    // Trace sources designed to simulate a packet sniffer facility (tcpdump). 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   145
    //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   146
    .AddTraceSource ("Sniffer", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   147
                     "Trace source simulating a non-promiscuous packet sniffer attached to the device",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   148
                     MakeTraceSourceAccessor (&EmuNetDevice::m_snifferTrace))
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   149
    .AddTraceSource ("PromiscSniffer", 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   150
                     "Trace source simulating a promiscuous packet sniffer attached to the device",
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   151
                     MakeTraceSourceAccessor (&EmuNetDevice::m_promiscSnifferTrace))
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
    ;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  return tid;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   157
EmuNetDevice::EmuNetDevice () 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
: 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
  m_startEvent (),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  m_stopEvent (),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
  m_sock (-1),
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
  m_readThread (0),
3850
03ebd59f4d06 keep gcc 3.4 from complaining
Craig Dowell <craigdo@ee.washington.edu>
parents: 3847
diff changeset
   163
  m_ifIndex (std::numeric_limits<uint32_t>::max ()),  // absurdly large value
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
  m_sll_ifindex (-1),
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   165
  m_name ("Emu NetDevice")
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  NS_LOG_FUNCTION (this);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  Start (m_tStart);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   171
EmuNetDevice::~EmuNetDevice ()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   176
EmuNetDevice::DoDispose()
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  m_node = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
  NetDevice::DoDispose ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   184
EmuNetDevice::Start (Time tStart)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
  NS_LOG_FUNCTION (tStart);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  // Cancel any pending start event and schedule a new one at some relative time in the future.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
  Simulator::Cancel (m_startEvent);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   192
  m_startEvent = Simulator::Schedule (tStart, &EmuNetDevice::StartDevice, this);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   196
EmuNetDevice::Stop (Time tStop)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
  NS_LOG_FUNCTION (tStop);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
  // Cancel any pending stop event and schedule a new one at some relative time in the future.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  Simulator::Cancel (m_stopEvent);
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   203
  m_startEvent = Simulator::Schedule (tStop, &EmuNetDevice::StopDevice, this);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   207
EmuNetDevice::StartDevice (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   212
  // Spin up the emu net device and start receiving packets.
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  //
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   214
  if (m_sock != -1)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   215
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   216
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Device is already started");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   217
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  NS_LOG_LOGIC ("Creating socket");
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   220
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   221
  // Call out to a separate process running as suid root in order to get a raw 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   222
  // socket.  We do this to avoid having the entire simulation running as root.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   223
  // If this method returns, we'll have a raw socket waiting for us in m_sock.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   224
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   225
  CreateSocket ();
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
  // Figure out which interface index corresponds to the device name in the corresponding attribute.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
  struct ifreq ifr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
  bzero (&ifr, sizeof(ifr));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
  strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
  NS_LOG_LOGIC ("Getting interface index");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
  int32_t rc = ioctl (m_sock, SIOCGIFINDEX, &ifr);
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   236
  if (rc == -1)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   237
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   238
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't get interface index");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   239
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
  // Save the real interface index for later calls to sendto
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
  m_sll_ifindex = ifr.ifr_ifindex;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
  // Bind the socket to the interface we just found.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
  struct sockaddr_ll ll;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
  bzero (&ll, sizeof(ll));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
  ll.sll_family = AF_PACKET;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
  ll.sll_ifindex = m_sll_ifindex;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
  ll.sll_protocol = htons(ETH_P_ALL); 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  NS_LOG_LOGIC ("Binding socket to interface");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
  rc = bind (m_sock, (struct sockaddr *)&ll, sizeof (ll));
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   259
  if (rc == -1)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   260
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   261
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't bind to specified interface");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   262
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   264
  rc = ioctl(m_sock, SIOCGIFFLAGS, &ifr);
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   265
  if (rc == -1)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   266
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   267
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Can't get interface flags");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   268
    }
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   269
  
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   270
  //
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   271
  // This device only works if the underlying interface is up in promiscuous 
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   272
  // mode.  We could have turned it on in the socket creator, but the situation
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   273
  // is that we expect these devices to be used in conjunction with virtual 
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   274
  // machines with connected host-only (simulated) networks, or in a testbed.
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   275
  // There is a lot of setup and configuration happening outside of this one 
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   276
  // issue, and we expect that configuration to include choosing a valid
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   277
  // interface (e.g, "ath1"), ensuring that the device supports promiscuous 
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   278
  // mode, and placing it in promiscuous mode.  We just make sure of the
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   279
  // end result.
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   280
  //
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   281
  if ((ifr.ifr_flags & IFF_PROMISC) == 0)
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   282
    {
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   283
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): " << m_deviceName << " is not in promiscuous mode");
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   284
    }
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   285
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
  // Now spin up a read thread to read packets.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
  //
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   289
  if (m_readThread != 0)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   290
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   291
      NS_FATAL_ERROR ("EmuNetDevice::StartDevice(): Receive thread is already running");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   292
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
  NS_LOG_LOGIC ("Spinning up read thread");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   296
  m_readThread = Create<SystemThread> (MakeCallback (&EmuNetDevice::ReadThread, this));
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
  m_readThread->Start ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
  NotifyLinkUp ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   303
EmuNetDevice::CreateSocket (void)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   304
{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   305
  NS_LOG_FUNCTION_NOARGS ();
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   306
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   307
  // We want to create a raw socket for our net device.  Unfortunately for us
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   308
  // you have to have root privileges to do that.  Instead of running the 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   309
  // entire simulation as root, we decided to make a small program who's whole
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   310
  // reason for being is to run as suid root and create a raw socket.  We're
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   311
  // going to fork and exec that program soon, but we need to have a socket
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   312
  // to talk to it with.  So we create a local interprocess (Unix) socket 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   313
  // for that purpose.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   314
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   315
  int sock = socket (PF_UNIX, SOCK_DGRAM, 0);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   316
  if (sock == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   317
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   318
      NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Unix socket creation error, errno = " << strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   319
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   320
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   321
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   322
  // Bind to that socket and let the kernel allocate an endpoint
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   323
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   324
  struct sockaddr_un un;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   325
  memset (&un, 0, sizeof (un));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   326
  un.sun_family = AF_UNIX;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   327
  int status = bind (sock, (struct sockaddr*)&un, sizeof (sa_family_t));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   328
  if (status == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   329
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   330
      NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Could not bind(): errno = " << strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   331
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   332
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   333
  NS_LOG_INFO ("Created Unix socket");
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   334
  NS_LOG_INFO ("sun_family = " << un.sun_family);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   335
  NS_LOG_INFO ("sun_path = " << un.sun_path);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   336
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   337
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   338
  // We have a socket here, but we want to get it there -- to the program we're
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   339
  // going to exec.  What we'll do is to do a getsockname and then encode the
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   340
  // resulting address information as a string, and then send the string to the
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   341
  // program as an argument.  So we need to get the sock name.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   342
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   343
  socklen_t len = sizeof (un);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   344
  status = getsockname (sock, (struct sockaddr*)&un, &len);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   345
  if (status == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   346
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   347
      NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Could not getsockname(): errno = " << strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   348
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   349
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   350
  //
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   351
  // Now encode that socket name (family and path) as a string of hex digits
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   352
  //
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   353
  std::string path = EmuBufferToString((uint8_t *)&un, len);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   354
  NS_LOG_INFO ("Encoded Unix socket as \"" << path << "\"");
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   355
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   356
  // Fork and exec the process to create our socket.  If we're us (the parent)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   357
  // we wait for the child (the socket creator) to complete and read the 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   358
  // socket it created using the ancillary data mechanism.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   359
  //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   360
  pid_t pid = ::fork ();
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   361
  if (pid == 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   362
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   363
      NS_LOG_DEBUG ("Child process");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   364
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   365
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   366
      // build a command line argument from the encoded endpoint string that 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   367
      // the socket creation process will use to figure out how to respond to
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   368
      // the (now) parent process.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   369
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   370
      std::ostringstream oss;
3835
8966e68809a6 turn off LOG in emu-sock-creator
Craig Dowell <craigdo@ee.washington.edu>
parents: 3831
diff changeset
   371
      oss << "-p" << path;
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   372
      NS_LOG_INFO ("Parameters set to \"" << oss.str () << "\"");
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   373
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   374
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   375
      // Execute the socket creation process image.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   376
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   377
      status = ::execl (FindCreator ().c_str (), "emu-sock-creator", oss.str ().c_str (), (char *)NULL);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   378
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   379
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   380
      // If the execl successfully completes, it never returns.  If it returns it failed or the OS is
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   381
      // broken.  In either case, we bail.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   382
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   383
      NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Back from execl(), errno = " << ::strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   384
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   385
  else
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   386
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   387
      NS_LOG_DEBUG ("Parent process");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   388
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   389
      // We're the process running the emu net device.  We need to wait for the
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   390
      // socket creator process to finish its job.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   391
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   392
      int st;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   393
      pid_t waited = waitpid (pid, &st, 0);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   394
      if (waited == -1)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   395
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   396
	  NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): waitpid() fails, errno = " << strerror (errno));
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   397
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   398
      NS_ASSERT_MSG (pid == waited, "EmuNetDevice::CreateSocket(): pid mismatch");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   399
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   400
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   401
      // Check to see if the socket creator exited normally and then take a 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   402
      // look at the exit code.  If it bailed, so should we.  If it didn't
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   403
      // even exit normally, we bail too.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   404
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   405
      if (WIFEXITED (st))
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   406
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   407
          int exitStatus = WEXITSTATUS (st);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   408
          if (exitStatus != 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   409
            {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   410
              NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): socket creator exited normally with status " << exitStatus);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   411
            }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   412
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   413
      else 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   414
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   415
          NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): socket creator exited abnormally");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   416
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   417
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   418
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   419
      // At this point, the socket creator has run successfully and should 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   420
      // have created our raw socket and sent it back to the socket address
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   421
      // we provided.  Our socket should be waiting on the Unix socket.  We've
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   422
      // got to do a bunch of grunto work to get at it, though.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   423
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   424
      // The struct iovec below is part of a scatter-gather list.  It describes a
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   425
      // buffer.  In this case, it describes a buffer (an integer) that will
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   426
      // get the data that comes back from the socket creator process.  It will
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   427
      // be a magic number that we use as a consistency/sanity check.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   428
      // 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   429
      struct iovec iov;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   430
      uint32_t magic;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   431
      iov.iov_base = &magic;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   432
      iov.iov_len = sizeof(magic);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   433
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   434
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   435
      // The CMSG macros you'll see below are used to create and access control 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   436
      // messages (which is another name for ancillary data).  The ancillary 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   437
      // data is made up of pairs of struct cmsghdr structures and associated
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   438
      // data arrays.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   439
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   440
      // First, we're going to allocate a buffer on the stack to receive our 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   441
      // data array (that contains the socket).  Sometimes you'll see this called
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   442
      // an "ancillary element" but the msghdr uses the control message termimology
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   443
      // so we call it "control."
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   444
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   445
      size_t msg_size = sizeof(int);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   446
      char control[CMSG_SPACE(msg_size)];
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   447
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   448
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   449
      // There is a msghdr that is used to minimize the number of parameters
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   450
      // passed to recvmsg (which we will use to receive our ancillary data).  
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   451
      // This structure uses terminology corresponding to control messages, so
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   452
      // you'll see msg_control, which is the pointer to the ancillary data and 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   453
      // controllen which is the size of the ancillary data array.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   454
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   455
      // So, initialize the message header that describes the ancillary/control
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   456
      // data we expect to receive and point it to buffer.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   457
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   458
      struct msghdr msg;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   459
      msg.msg_name = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   460
      msg.msg_namelen = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   461
      msg.msg_iov = &iov;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   462
      msg.msg_iovlen = 1;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   463
      msg.msg_control = control;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   464
      msg.msg_controllen = sizeof (control);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   465
      msg.msg_flags = 0;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   466
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   467
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   468
      // Now we can actually receive the interesting bits from the socket
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   469
      // creator process.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   470
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   471
      ssize_t bytesRead = recvmsg (sock, &msg, 0);
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   472
      if (bytesRead != sizeof(int))
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   473
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   474
          NS_FATAL_ERROR ("EmuNetDevice::CreateSocket(): Wrong byte count from socket creator");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   475
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   476
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   477
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   478
      // There may be a number of message headers/ancillary data arrays coming in.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   479
      // Let's look for the one with a type SCM_RIGHTS which indicates it' the
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   480
      // one we're interested in.
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   481
      //
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   482
      struct cmsghdr *cmsg;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   483
      for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   484
	{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   485
	  if (cmsg->cmsg_level == SOL_SOCKET &&
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   486
	      cmsg->cmsg_type == SCM_RIGHTS)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   487
	    {
3831
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   488
              //
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   489
              // This is the type of message we want.  Check to see if the magic 
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   490
              // number is correct and then pull out the socket we care about if
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   491
              // it matches
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   492
              //
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   493
              if (magic == EMU_MAGIC)
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   494
                {
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   495
                  NS_LOG_INFO ("Got SCM_RIGHTS with correct magic " << magic);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   496
                  int *rawSocket = (int*)CMSG_DATA (cmsg);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   497
                  NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket);
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   498
                  m_sock = *rawSocket;
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   499
                  return;
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   500
                }
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   501
              else
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   502
                {
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   503
                  NS_LOG_INFO ("Got SCM_RIGHTS, but with bad magic " << magic);                  
16c2970a0344 add emu-udp-echo example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3830
diff changeset
   504
                }
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   505
	    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   506
	}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   507
      NS_FATAL_ERROR ("Did not get the raw socket from the socket creator");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   508
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   509
}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   510
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   511
std::string
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   512
EmuNetDevice::FindCreator (void)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   513
{
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   514
  struct stat st;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   515
  std::string debug = "./build/debug/src/devices/emu/emu-sock-creator";
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   516
  std::string optimized = "./build/optimized/src/devices/emu/emu-sock-creator";
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   517
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   518
  if (::stat (debug.c_str (), &st) == 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   519
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   520
      return debug;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   521
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   522
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   523
  if (::stat (optimized.c_str (), &st) == 0)
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   524
    {
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   525
      return optimized;
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   526
    }
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   527
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   528
  NS_FATAL_ERROR ("EmuNetDevice::FindCreator(): Couldn't find creator");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   529
  return ""; // quiet compiler
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   530
}
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   531
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   532
void
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   533
EmuNetDevice::StopDevice (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   537
  close (m_sock);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
  m_sock = -1;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   539
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   540
  NS_ASSERT_MSG (m_readThread != 0, "EmuNetDevice::StopDevice(): Receive thread is not running");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   541
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   542
  NS_LOG_LOGIC ("Joining read thread");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   543
  m_readThread->Join ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   544
  m_readThread = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   545
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   548
EmuNetDevice::ForwardUp (uint8_t *buf, uint32_t len)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   550
  NS_LOG_FUNCTION (buf << len);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   552
  /* IPv6 support*/
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   553
  uint8_t mac[6];
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   554
  Mac48Address multicast6AllNodes("33:33:00:00:00:01");
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   555
  Mac48Address multicast6AllRouters("33:33:00:00:00:02");
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   556
  Mac48Address multicast6AllHosts("33:33:00:00:00:03");
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   557
  Mac48Address multicast6Node; /* multicast address addressed to our MAC address */
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   558
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   559
  /* generate IPv6 multicast ethernet destination that nodes will accept */
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   560
  GetAddress().CopyTo(mac);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   561
  mac[0]=0x33;
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   562
  mac[1]=0x33;
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   563
  multicast6Node.CopyFrom(mac);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   564
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   565
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
  // Create a packet out of the buffer we received and free that buffer.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
  Ptr<Packet> packet = Create<Packet> (reinterpret_cast<const uint8_t *> (buf), len);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   569
  free (buf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   570
  buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   572
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   573
  // Trace sinks will expect complete packets, not packets without some of the
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
  // headers.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   575
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
  Ptr<Packet> originalPacket = packet->Copy ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   578
  //
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   579
  // Hit the trace hook.  This trace will fire on all packets received from the
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   580
  // OS (promiscuous).  Packets are received instantaneously.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   581
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   582
  m_phyRxStartTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   583
  m_phyRxTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   584
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   585
  //
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
  // Checksum the packet
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   587
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   588
  EthernetTrailer trailer;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   589
  packet->RemoveTrailer (trailer);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   590
  trailer.CheckFcs (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
  EthernetHeader header (false);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   593
  packet->RemoveHeader (header);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   595
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   596
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   597
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   598
  uint16_t protocol;
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   599
  
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   600
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   601
  // If the length/type is less than 1500, it corresponds to a length 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   602
  // interpretation packet.  In this case, it is an 802.3 packet and 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   603
  // will also have an 802.2 LLC header.  If greater than 1500, we
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   604
  // find the protocol number (Ethernet type) directly.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   605
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   606
  if (header.GetLengthType () <= 1500)
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   607
    {
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   608
      LlcSnapHeader llc;
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   609
      packet->RemoveHeader (llc);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   610
      protocol = llc.GetType ();
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   611
    }
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   612
  else
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   613
    {
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   614
      protocol = header.GetLengthType ();
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   615
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   617
  PacketType packetType;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   618
      
3842
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   619
  if (header.GetDestination ().IsBroadcast ())
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   620
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   621
      packetType = NS3_PACKET_BROADCAST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
    }
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   623
  else if (header.GetDestination ().IsMulticast () ||
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   624
           header.GetDestination() == multicast6Node ||
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   625
           header.GetDestination() == multicast6AllNodes ||
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   626
           header.GetDestination() == multicast6AllRouters ||
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   627
           header.GetDestination() == multicast6AllHosts)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   628
    {
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   629
      packetType = NS3_PACKET_MULTICAST;          
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   630
    }
3842
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   631
  else if (header.GetDestination () == m_address)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   632
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   633
      packetType = NS3_PACKET_HOST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   635
  else
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
      packetType = NS3_PACKET_OTHERHOST;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   639
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   640
  // 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   641
  // For all kinds of packetType we receive, we hit the promiscuous sniffer
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   642
  // hook and pass a copy up to the promiscuous callback.  Pass a copy to 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   643
  // make sure that nobody messes with our packet.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   644
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   645
  m_promiscSnifferTrace (originalPacket);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
  if (!m_promiscRxCallback.IsNull ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   647
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   648
      m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), packetType);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   650
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   651
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   652
  // If this packet is not destined for some other host, it must be for us
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   653
  // as either a broadcast, multicast or unicast.  We need to hit the mac
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   654
  // packet received trace hook and forward the packet up the stack.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   655
  //
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
  if (packetType != NS3_PACKET_OTHERHOST)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
    {
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   658
      m_snifferTrace (originalPacket);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   659
      m_macRxTrace (originalPacket);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   660
      m_rxCallback (this, packet, protocol, header.GetSource ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   661
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   662
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   663
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   664
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   665
EmuNetDevice::ReadThread (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   666
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   667
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   668
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   669
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   670
  // It's important to remember that we're in a completely different thread than the simulator is running in.  We
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   671
  // need to synchronize with that other thread to get the packet up into ns-3.  What we will need to do is to schedule 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
  // a method to forward up the packet using the multithreaded simulator we are most certainly running.  However, I just 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
  // said it -- we are talking about two threads here, so it is very, very dangerous to do any kind of reference couning
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   674
  // on a shared object.  Just don't do it.  So what we're going to do is to allocate a buffer on the heap and pass that
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   675
  // buffer into the ns-3 context thread where it will create the packet.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   676
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
  int32_t len = -1;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   679
  struct sockaddr_ll addr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   680
  socklen_t addrSize = sizeof (addr);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
  for (;;) 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   684
      uint32_t bufferSize = 65536;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   685
      uint8_t *buf = (uint8_t *)malloc (bufferSize);
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   686
      if (buf == 0)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   687
        {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   688
          NS_FATAL_ERROR ("EmuNetDevice::ReadThread(): malloc packet buffer failed");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   689
        }
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   690
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   691
      NS_LOG_LOGIC ("Calling recvfrom");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   692
      len = recvfrom (m_sock, buf, bufferSize, 0, (struct sockaddr *)&addr, &addrSize);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
      if (len == -1)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
        {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
          free (buf);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   697
          buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   698
          return;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
        }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   700
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   701
      NS_LOG_INFO ("EmuNetDevice::ReadThread(): Received packet");
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   702
      NS_LOG_INFO ("EmuNetDevice::ReadThread(): Scheduling handler");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   703
      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   704
        MakeEvent (&EmuNetDevice::ForwardUp, this, buf, len));
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
      buf = 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   707
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   710
EmuNetDevice::Send (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   711
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   712
  NS_LOG_FUNCTION (packet << dest << protocolNumber);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   713
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
  // The immediate questions here are how are we going to encapsulate packets and what do we use as the MAC source and 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
  // destination (hardware) addresses?
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   716
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   717
  // If we return false from EmuNetDevice::NeedsArp, the ArpIpv4Interface will pass the broadcast address as the 
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   718
  // hardware (Ethernet) destination by default.  If we return true from EmuNetDevice::NeedsArp, then the hardware
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   719
  // destination is actually meaningful, but we'll have an ns-3 ARP running on this device.  There can also be an ARP
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   720
  // running on the underlying OS so we have to be very careful, both about multiple ARPs and also about TCP, UDP, etc.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
  // We are operating in promiscuous mode on the receive side (all ns-3 net devices are required to implement the 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
  // promiscuous callback in a meaningful way), so we have an option regarding the hardware addresses.  We don't actually have
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
  // to use the real hardware addresses and IP addresses of the underlying system.  We can completely use MAC-spoofing to
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
  // fake out the OS by using the ns-3 assigned MAC address (and also the ns-3 assigned IP addresses).  Ns-3 starts its 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   726
  // MAC address allocation using the OUI (vendor-code) 00:00:00 which is unassigned to any organization and is a globally
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
  // administered address, so there shouldn't be any collisions with real hardware.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
  //
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   729
  // So what we do is we return true from EmuNetDevice::NeedsArp which tells ns-3 to use its own ARP.  We spoof the 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   730
  // MAC address of the device and use promiscuous mode to receive traffic destined to that address.
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
  return SendFrom (packet, m_address, dest, protocolNumber);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   733
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   736
EmuNetDevice::SendFrom (Ptr<Packet> packet, const Address &src, const Address &dest, uint16_t protocolNumber)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   738
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   739
  NS_LOG_LOGIC ("packet =" << packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   740
  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   742
  if (IsLinkUp () == false)
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   743
    {
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   744
      m_macTxDropTrace (packet);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   745
      return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   746
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   748
  Mac48Address destination = Mac48Address::ConvertFrom (dest);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   749
  Mac48Address source = Mac48Address::ConvertFrom (src);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   750
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   751
  NS_LOG_LOGIC ("Transmit packet with UID " << packet->GetUid ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   752
  NS_LOG_LOGIC ("Transmit packet from " << source);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   753
  NS_LOG_LOGIC ("Transmit packet to " << destination);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   754
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   755
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   756
  // We've got to pick either DIX (Ethernet) or LLC/SNAP (IEEE 802.3) as a 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   757
  // packet format.  IEEE 802.3 is slightly more formally correct, so we 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   758
  // go that route.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   759
  //
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   760
  LlcSnapHeader llc;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
  llc.SetType (protocolNumber);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   762
  packet->AddHeader (llc);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   763
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   764
  EthernetHeader header (false);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   765
  header.SetSource (source);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   766
  header.SetDestination (destination);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   767
  header.SetLengthType (packet->GetSize ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   768
  packet->AddHeader (header);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   769
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
  EthernetTrailer trailer;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   771
  trailer.CalcFcs (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   772
  packet->AddTrailer (trailer);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   773
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   774
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   775
  // there's not much meaning associated with the different layers in this
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   776
  // device, so don't be surprised when they're all stacked together in 
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   777
  // essentially one place.  We do this for trace consistency across devices.
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   778
  //
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   779
  m_macTxTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   780
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   781
  // 
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   782
  // Enqueue and dequeue the packet to hit the queue tracing hooks.
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   783
  //
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   784
  m_queue->Enqueue (packet);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   785
  packet = m_queue->Dequeue ();
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   786
  NS_ASSERT_MSG (packet, "EmuNetDevice::SendFrom(): packet zero from queue");
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   787
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   788
  m_promiscSnifferTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   789
  m_snifferTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   790
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   791
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   792
  struct sockaddr_ll ll;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
  bzero (&ll, sizeof (ll));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   794
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   795
  ll.sll_family = AF_PACKET;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
  ll.sll_ifindex = m_sll_ifindex;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   797
  ll.sll_protocol = htons(ETH_P_ALL); 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   798
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   799
  NS_LOG_LOGIC ("calling sendto");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   800
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   801
  m_phyTxStartTrace (packet);
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   802
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   803
  int32_t rc;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   804
  rc = sendto (m_sock, packet->PeekData (), packet->GetSize (), 0, reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll));
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   805
  NS_LOG_LOGIC ("sendto returns " << rc);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   806
4263
fec2f830d015 trace consistency changes
Craig Dowell <craigdo@ee.washington.edu>
parents: 4017
diff changeset
   807
  m_phyTxTrace (packet);
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   809
  return rc == -1 ? false : true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   810
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   811
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   812
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   813
EmuNetDevice::SetDataRate(DataRate bps)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   814
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   815
  NS_LOG_FUNCTION (this << bps);
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   816
  NS_FATAL_ERROR ("EmuNetDevice::SetDataRate():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   817
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   818
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   819
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   820
EmuNetDevice::SetQueue (Ptr<Queue> q)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   821
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   822
  NS_LOG_FUNCTION (this << q);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   823
  m_queue = q;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   824
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   825
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   826
Ptr<Queue> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   827
EmuNetDevice::GetQueue(void) const 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   828
{ 
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   829
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   830
  return m_queue;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   831
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   832
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   833
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   834
EmuNetDevice::NotifyLinkUp (void)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   835
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   836
  m_linkUp = true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   837
  if (!m_linkChangeCallback.IsNull ())
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   838
    {
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   839
      m_linkChangeCallback ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   840
    }
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   841
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   842
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   843
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   844
EmuNetDevice::SetName(const std::string name)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   845
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   846
  m_name = name;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   847
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   848
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   849
std::string 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   850
EmuNetDevice::GetName(void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   851
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   852
  return m_name;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   853
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   854
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   855
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   856
EmuNetDevice::SetIfIndex(const uint32_t index)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   857
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   858
  m_ifIndex = index;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   859
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   860
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   861
uint32_t 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   862
EmuNetDevice::GetIfIndex(void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   863
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   864
  return m_ifIndex;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   865
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   866
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   867
Ptr<Channel> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   868
EmuNetDevice::GetChannel (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   869
{
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   870
  NS_FATAL_ERROR ("EmuNetDevice::GetChannel():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   871
  return 0;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   872
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   873
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   874
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   875
EmuNetDevice::SetAddress (Mac48Address addr)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   876
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   877
  NS_LOG_FUNCTION (addr);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   878
  m_address = addr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   879
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   880
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   881
Address 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   882
EmuNetDevice::GetAddress (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   883
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   884
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   885
  return m_address;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   886
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   887
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   888
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   889
EmuNetDevice::SetMtu (const uint16_t mtu)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   890
{
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   891
  NS_FATAL_ERROR ("EmuNetDevice::SetMtu():  Unable."); 
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   892
  return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   893
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   894
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   895
uint16_t 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   896
EmuNetDevice::GetMtu (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   897
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   898
  struct ifreq ifr;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   899
  bzero (&ifr, sizeof (ifr));
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   900
  strcpy(ifr.ifr_name, m_deviceName.c_str ());
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   901
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   902
  int32_t fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   903
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   904
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   905
  int32_t rc = ioctl(fd, SIOCGIFMTU, &ifr);
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   906
  if (rc == -1)
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   907
    {
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   908
      NS_FATAL_ERROR ("EmuNetDevice::GetMtu(): Can't ioctl SIOCGIFMTU");
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   909
    }
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   910
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   911
  close (fd);
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   912
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   913
  return ifr.ifr_mtu;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   914
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   915
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   916
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   917
EmuNetDevice::IsLinkUp (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   918
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   919
  return m_linkUp;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   920
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   921
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   922
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   923
EmuNetDevice::SetLinkChangeCallback (Callback<void> callback)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   924
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   925
  m_linkChangeCallback = callback;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   926
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   927
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   928
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   929
EmuNetDevice::IsBroadcast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   930
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   931
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   932
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   933
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   934
Address
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   935
EmuNetDevice::GetBroadcast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   936
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   937
  return Mac48Address ("ff:ff:ff:ff:ff:ff");
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   938
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   939
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   940
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   941
EmuNetDevice::IsMulticast (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   942
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   943
  return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   944
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   945
3842
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   946
  Address 
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   947
EmuNetDevice::GetMulticast (Ipv4Address multicastGroup) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   948
{
3836
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   949
  NS_LOG_FUNCTION (multicastGroup);
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   950
3842
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   951
  Mac48Address ad = Mac48Address::GetMulticast (multicastGroup);
3836
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   952
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   953
  //
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   954
  // Implicit conversion (operator Address ()) is defined for Mac48Address, so
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   955
  // use it by just returning the EUI-48 address which is automagically converted
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   956
  // to an Address.
e3aa8940f23b enable multicast in emu-net-device
Craig Dowell <craigdo@ee.washington.edu>
parents: 3835
diff changeset
   957
  //
3842
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   958
  NS_LOG_LOGIC ("multicast address is " << ad);
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   959
545ddf9398ed apply patch for bug 294 (GetMulticastAddr) + emu device update + rescan
vincent@clarinet.u-strasbg.fr
parents: 3836
diff changeset
   960
  return ad;
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   961
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   962
3852
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   963
Address
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   964
EmuNetDevice::GetMulticast (Ipv6Address addr) const
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   965
{
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   966
  NS_LOG_FUNCTION(this << addr);
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   967
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   968
  Mac48Address ad = Mac48Address::GetMulticast (addr);
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   969
  NS_LOG_LOGIC("MAC IPv6 multicast address is " << ad);
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   970
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   971
  return ad;
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   972
}
9cf7ad0cac85 Initial IPv6 capability
vincent@clarinet.u-strasbg.fr
parents: 3851
diff changeset
   973
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   974
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   975
EmuNetDevice::IsPointToPoint (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   976
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   977
  return false;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   978
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   979
3936
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   980
bool 
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   981
EmuNetDevice::IsBridge (void) const
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   982
{
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   983
  return false;
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   984
}
e525995ce5dc implement IsBridged for net devices
Craig Dowell <craigdo@ee.washington.edu>
parents: 3852
diff changeset
   985
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   986
void
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   987
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   988
{
3847
784c45b27326 asserts cut and paste into places where fatal error was appropriate
Craig Dowell <craigdo@ee.washington.edu>
parents: 3842
diff changeset
   989
  NS_FATAL_ERROR ("EmuNetDevice::SetPromiscReceiveCallback(): Not implemented");
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   990
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   991
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   992
  bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
   993
EmuNetDevice::SupportsSendFrom () const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   994
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   995
  NS_LOG_FUNCTION_NOARGS ();
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   996
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   997
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   998
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   999
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1000
Ptr<Node> 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
  1001
EmuNetDevice::GetNode (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1002
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1003
  return m_node;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1004
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1005
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1006
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
  1007
EmuNetDevice::SetNode (Ptr<Node> node)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1008
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1009
  m_node = node;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1010
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1011
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1012
bool 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
  1013
EmuNetDevice::NeedsArp (void) const
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1014
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1015
  return true;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1016
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1017
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1018
void 
3830
8862b9be62bb rework to address suid root issues
Craig Dowell <craigdo@ee.washington.edu>
parents: 3827
diff changeset
  1019
EmuNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
3827
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1020
{
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1021
  m_rxCallback = cb;
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1022
}
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1023
4b603cd4ee42 give up on merging tap and emulated, break apart
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1024
} // namespace ns3