make NetDevice fully virtual.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 25 Feb 2008 19:33:46 +0100
changeset 2470254581fb9e9c
parent 2469 181c6a5b14c1
child 2476 febce6836ef3
make NetDevice fully virtual.
examples/csma-packet-socket.cc
samples/main-adhoc-wifi.cc
samples/main-ap-wifi.cc
src/devices/csma/csma-ipv4-topology.cc
src/devices/csma/csma-net-device.cc
src/devices/csma/csma-net-device.h
src/devices/point-to-point/point-to-point-net-device.cc
src/devices/point-to-point/point-to-point-net-device.h
src/devices/point-to-point/point-to-point-topology.cc
src/devices/wifi/wifi-net-device.cc
src/devices/wifi/wifi-net-device.h
src/internet-node/udp-socket.cc
src/node/net-device.cc
src/node/net-device.h
tutorial/point-to-point-ipv4-topology.cc
utils/print-introspected-doxygen.cc
     1.1 --- a/examples/csma-packet-socket.cc	Sun Feb 24 20:18:02 2008 +0100
     1.2 +++ b/examples/csma-packet-socket.cc	Mon Feb 25 19:33:46 2008 +0100
     1.3 @@ -61,7 +61,9 @@
     1.4  static Ptr<CsmaNetDevice>
     1.5  CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
     1.6  {
     1.7 -  Ptr<CsmaNetDevice> device = CreateObject<CsmaNetDevice> (node);
     1.8 +  Ptr<CsmaNetDevice> device = CreateObject<CsmaNetDevice> (node, Mac48Address::Allocate (),
     1.9 +                                                           CsmaNetDevice::LLC);
    1.10 +  node->AddDevice (device);
    1.11    device->Attach (channel);
    1.12    Ptr<Queue> queue = Queue::CreateDefault ();
    1.13    device->AddQueue (queue);
     2.1 --- a/samples/main-adhoc-wifi.cc	Sun Feb 24 20:18:02 2008 +0100
     2.2 +++ b/samples/main-adhoc-wifi.cc	Mon Feb 25 19:33:46 2008 +0100
     2.3 @@ -47,6 +47,7 @@
     2.4  {
     2.5    Ptr<Node> node = CreateObject<Node> ();  
     2.6    Ptr<AdhocWifiNetDevice> device = CreateObject<AdhocWifiNetDevice> (node, Mac48Address (address));
     2.7 +  node->AddDevice (device);
     2.8    device->Attach (channel);
     2.9    Ptr<MobilityModel> mobility = CreateObject<StaticMobilityModel> ();
    2.10    mobility->SetPosition (position);
     3.1 --- a/samples/main-ap-wifi.cc	Sun Feb 24 20:18:02 2008 +0100
     3.2 +++ b/samples/main-ap-wifi.cc	Mon Feb 25 19:33:46 2008 +0100
     3.3 @@ -73,6 +73,7 @@
     3.4  {
     3.5    Ptr<Node> node = CreateObject<Node> ();  
     3.6    Ptr<NqapWifiNetDevice> device = CreateObject<NqapWifiNetDevice> (node, Mac48Address (macAddress));
     3.7 +  node->AddDevice (device);
     3.8    device->SetSsid (ssid);
     3.9    Simulator::Schedule (at, &NqapWifiNetDevice::StartBeaconing, device);
    3.10    device->Attach (channel);
    3.11 @@ -90,6 +91,7 @@
    3.12  {
    3.13    Ptr<Node> node = CreateObject<Node> ();  
    3.14    Ptr<NqstaWifiNetDevice> device = CreateObject<NqstaWifiNetDevice> (node, Mac48Address (macAddress));
    3.15 +  node->AddDevice (device);
    3.16    Simulator::ScheduleNow (&NqstaWifiNetDevice::StartActiveAssociation, device, 
    3.17                            ssid);
    3.18    device->Attach (channel);
     4.1 --- a/src/devices/csma/csma-ipv4-topology.cc	Sun Feb 24 20:18:02 2008 +0100
     4.2 +++ b/src/devices/csma/csma-ipv4-topology.cc	Mon Feb 25 19:33:46 2008 +0100
     4.3 @@ -43,7 +43,8 @@
     4.4  
     4.5    // assume full-duplex
     4.6    Ptr<CsmaNetDevice> nd = CreateObject<CsmaNetDevice> (node, addr, 
     4.7 -    ns3::CsmaNetDevice::IP_ARP, true, true);
     4.8 +                                                       ns3::CsmaNetDevice::IP_ARP);
     4.9 +  node->AddDevice (nd);
    4.10  
    4.11    nd->AddQueue(q);
    4.12    nd->Attach (channel);
    4.13 @@ -59,14 +60,18 @@
    4.14    Ptr<Queue> q = Queue::CreateDefault ();
    4.15  
    4.16    Ptr<CsmaNetDevice> nd0 = CreateObject<CsmaNetDevice> (n1, addr,
    4.17 -                                                  ns3::CsmaNetDevice::LLC,
    4.18 -                                                  true, false);
    4.19 +                                                        ns3::CsmaNetDevice::LLC);
    4.20 +  n1->AddDevice (nd0);
    4.21 +  nd0->SetSendEnable (true);
    4.22 +  nd0->SetReceiveEnable (false);
    4.23    nd0->AddQueue(q);
    4.24    nd0->Attach (ch);
    4.25  
    4.26    Ptr<CsmaNetDevice> nd1 = CreateObject<CsmaNetDevice> (n1, addr,
    4.27 -                                                  ns3::CsmaNetDevice::LLC,
    4.28 -                                                  false, true);
    4.29 +                                                        ns3::CsmaNetDevice::LLC);
    4.30 +  n1->AddDevice (nd1);
    4.31 +  nd1->SetSendEnable (false);
    4.32 +  nd1->SetReceiveEnable (true);
    4.33    nd1->AddQueue(q);
    4.34    nd1->Attach (ch);
    4.35  }
    4.36 @@ -79,14 +84,19 @@
    4.37    Ptr<Queue> q = Queue::CreateDefault ();
    4.38  
    4.39    Ptr<CsmaNetDevice> nd0 = CreateObject<CsmaNetDevice> (n1, addr,
    4.40 -                                                  ns3::CsmaNetDevice::RAW,
    4.41 -                                                  true, false);
    4.42 +                                                        ns3::CsmaNetDevice::RAW);
    4.43 +  n1->AddDevice (nd0);
    4.44 +  nd0->SetSendEnable (true);
    4.45 +  nd0->SetReceiveEnable (false);
    4.46    nd0->AddQueue(q);
    4.47    nd0->Attach (ch);
    4.48  
    4.49    Ptr<CsmaNetDevice> nd1 = CreateObject<CsmaNetDevice> (n1, addr,
    4.50 -                                                  ns3::CsmaNetDevice::RAW,
    4.51 -                                                  false, true);
    4.52 +                                                        ns3::CsmaNetDevice::RAW);
    4.53 +  n1->AddDevice (nd1);
    4.54 +  nd1->SetSendEnable (false);
    4.55 +  nd1->SetReceiveEnable (true);
    4.56 +
    4.57    nd1->AddQueue(q);
    4.58    nd1->Attach (ch);
    4.59  }
     5.1 --- a/src/devices/csma/csma-net-device.cc	Sun Feb 24 20:18:02 2008 +0100
     5.2 +++ b/src/devices/csma/csma-net-device.cc	Mon Feb 25 19:33:46 2008 +0100
     5.3 @@ -81,22 +81,15 @@
     5.4    return m_type;
     5.5  }
     5.6  
     5.7 -CsmaNetDevice::CsmaNetDevice (Ptr<Node> node)
     5.8 -  : NetDevice (node, Mac48Address::Allocate ()),
     5.9 -    m_bps (DataRate (0xffffffff)),
    5.10 -    m_receiveErrorModel (0)
    5.11 -{
    5.12 -  NS_LOG_FUNCTION;
    5.13 -  NS_LOG_PARAMS (this << node);
    5.14 -  m_encapMode = IP_ARP;
    5.15 -  Init(true, true);
    5.16 -}
    5.17 -
    5.18  CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr, 
    5.19 -                              CsmaEncapsulationMode encapMode) 
    5.20 -  : NetDevice(node, addr), 
    5.21 -    m_bps (DataRate (0xffffffff)),
    5.22 -    m_receiveErrorModel (0)
    5.23 +                              CsmaEncapsulationMode encapMode)
    5.24 +  : m_bps (DataRate (0xffffffff)),
    5.25 +    m_receiveErrorModel (0),
    5.26 +    m_node (node),
    5.27 +    m_address (addr),
    5.28 +    m_name (""),
    5.29 +    m_linkUp (false),
    5.30 +    m_mtu (0xffff)
    5.31  {
    5.32    NS_LOG_FUNCTION;
    5.33    NS_LOG_PARAMS (this << node);
    5.34 @@ -105,19 +98,6 @@
    5.35    Init(true, true);
    5.36  }
    5.37  
    5.38 -CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr, 
    5.39 -                              CsmaEncapsulationMode encapMode,
    5.40 -                              bool sendEnable, bool receiveEnable) 
    5.41 -  : NetDevice(node, addr), 
    5.42 -    m_bps (DataRate (0xffffffff))
    5.43 -{
    5.44 -  NS_LOG_FUNCTION;
    5.45 -  NS_LOG_PARAMS (this << node);
    5.46 -  m_encapMode = encapMode;
    5.47 -
    5.48 -  Init(sendEnable, receiveEnable);
    5.49 -}
    5.50 -
    5.51  CsmaNetDevice::~CsmaNetDevice()
    5.52  {
    5.53    NS_LOG_FUNCTION;
    5.54 @@ -129,27 +109,10 @@
    5.55  {
    5.56    NS_LOG_FUNCTION;
    5.57    m_channel = 0;
    5.58 +  m_node = 0;
    5.59    NetDevice::DoDispose ();
    5.60  }
    5.61  
    5.62 -//
    5.63 -// Assignment operator for CsmaNetDevice.
    5.64 -//
    5.65 -// This uses the non-obvious trick of taking the source net device passed by
    5.66 -// value instead of by reference.  This causes the copy constructor to be
    5.67 -// invoked (where the real work is done -- see above).  All we have to do
    5.68 -// here is to return the newly constructed net device.
    5.69 -//
    5.70 -/*
    5.71 -CsmaNetDevice&
    5.72 -CsmaNetDevice::operator= (const CsmaNetDevice nd)
    5.73 -{
    5.74 -  NS_LOG_FUNCTION;
    5.75 -  NS_LOG_PARAMS (this << &nd);
    5.76 -  return *this;
    5.77 -}
    5.78 -*/
    5.79 -
    5.80  void 
    5.81  CsmaNetDevice::Init(bool sendEnable, bool receiveEnable)
    5.82  {
    5.83 @@ -159,9 +122,6 @@
    5.84    m_channel = 0; 
    5.85    m_queue = 0;
    5.86  
    5.87 -  EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff"));
    5.88 -  EnableMulticast (Mac48Address ("01:00:5e:00:00:00"));
    5.89 -
    5.90    SetSendEnable (sendEnable);
    5.91    SetReceiveEnable (receiveEnable);
    5.92  }
    5.93 @@ -302,58 +262,6 @@
    5.94    return true;
    5.95  }
    5.96  
    5.97 -bool
    5.98 -CsmaNetDevice::DoNeedsArp (void) const
    5.99 -{
   5.100 -  NS_LOG_FUNCTION;
   5.101 -  if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
   5.102 -    {
   5.103 -      return true;
   5.104 -    } 
   5.105 -  else 
   5.106 -    {
   5.107 -      return false;
   5.108 -    }
   5.109 -}
   5.110 -
   5.111 -bool
   5.112 -CsmaNetDevice::SendTo (Ptr<Packet> packet, 
   5.113 -                       const Address& dest, 
   5.114 -                       uint16_t protocolNumber)
   5.115 -{
   5.116 -  NS_LOG_FUNCTION;
   5.117 -  NS_LOG_LOGIC ("p=" << packet);
   5.118 -  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
   5.119 -
   5.120 -  NS_ASSERT (IsLinkUp ());
   5.121 -
   5.122 -  // Only transmit if send side of net device is enabled
   5.123 -  if (!IsSendEnabled())
   5.124 -    return false;
   5.125 -
   5.126 -  Mac48Address destination = Mac48Address::ConvertFrom (dest);
   5.127 -  AddHeader(packet, destination, protocolNumber);
   5.128 -
   5.129 -  // Place the packet to be sent on the send queue
   5.130 -  if (m_queue->Enqueue(packet) == false )
   5.131 -    {
   5.132 -      return false;
   5.133 -    }
   5.134 -  // If the device is idle, we need to start a transmission. Otherwise,
   5.135 -  // the transmission will be started when the current packet finished
   5.136 -  // transmission (see TransmitCompleteEvent)
   5.137 -  if (m_txMachineState == READY) 
   5.138 -    {
   5.139 -      // Store the next packet to be transmitted
   5.140 -      m_currentPkt = m_queue->Dequeue ();
   5.141 -      if (m_currentPkt != 0)
   5.142 -        {
   5.143 -          TransmitStart();
   5.144 -        }
   5.145 -    }
   5.146 -  return true;
   5.147 -}
   5.148 -
   5.149  void
   5.150  CsmaNetDevice::TransmitStart ()
   5.151  {
   5.152 @@ -565,7 +473,7 @@
   5.153  
   5.154    if (m_encapMode == RAW)
   5.155      {
   5.156 -      ForwardUp (packet, 0, GetBroadcast ());
   5.157 +      m_rxCallback (this, packet, 0, GetBroadcast ());
   5.158        m_dropTrace (packet);
   5.159        return;
   5.160      }
   5.161 @@ -636,12 +544,100 @@
   5.162            NS_ASSERT (false);
   5.163            break;
   5.164          }
   5.165 -      ForwardUp (packet, protocol, header.GetSource ());
   5.166 +      m_rxCallback (this, packet, protocol, header.GetSource ());
   5.167      }
   5.168  }
   5.169  
   5.170 +Ptr<Queue>
   5.171 +CsmaNetDevice::GetQueue(void) const 
   5.172 +{ 
   5.173 +  NS_LOG_FUNCTION;
   5.174 +  return m_queue;
   5.175 +}
   5.176 +
   5.177 +void
   5.178 +CsmaNetDevice::NotifyLinkUp (void)
   5.179 +{
   5.180 +  m_linkUp = true;
   5.181 +  if (!m_linkChangeCallback.IsNull ())
   5.182 +    {
   5.183 +      m_linkChangeCallback ();
   5.184 +    }
   5.185 +}
   5.186 +
   5.187 +void 
   5.188 +CsmaNetDevice::SetName(const std::string name)
   5.189 +{
   5.190 +  m_name = name;
   5.191 +}
   5.192 +std::string 
   5.193 +CsmaNetDevice::GetName(void) const
   5.194 +{
   5.195 +  return m_name;
   5.196 +}
   5.197 +void 
   5.198 +CsmaNetDevice::SetIfIndex(const uint32_t index)
   5.199 +{
   5.200 +  m_ifIndex = index;
   5.201 +}
   5.202 +uint32_t 
   5.203 +CsmaNetDevice::GetIfIndex(void) const
   5.204 +{
   5.205 +  return m_ifIndex;
   5.206 +}
   5.207 +Ptr<Channel> 
   5.208 +CsmaNetDevice::GetChannel (void) const
   5.209 +{
   5.210 +  return m_channel;
   5.211 +}
   5.212 +Address 
   5.213 +CsmaNetDevice::GetAddress (void) const
   5.214 +{
   5.215 +  return m_address;
   5.216 +}
   5.217 +bool 
   5.218 +CsmaNetDevice::SetMtu (const uint16_t mtu)
   5.219 +{
   5.220 +  m_mtu = mtu;
   5.221 +  return true;
   5.222 +}
   5.223 +uint16_t 
   5.224 +CsmaNetDevice::GetMtu (void) const
   5.225 +{
   5.226 +  return m_mtu;
   5.227 +}
   5.228 +bool 
   5.229 +CsmaNetDevice::IsLinkUp (void) const
   5.230 +{
   5.231 +  return m_linkUp;
   5.232 +}
   5.233 +void 
   5.234 +CsmaNetDevice::SetLinkChangeCallback (Callback<void> callback)
   5.235 +{
   5.236 +  m_linkChangeCallback = callback;
   5.237 +}
   5.238 +bool 
   5.239 +CsmaNetDevice::IsBroadcast (void) const
   5.240 +{
   5.241 +  return true;
   5.242 +}
   5.243  Address
   5.244 -CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
   5.245 +CsmaNetDevice::GetBroadcast (void) const
   5.246 +{
   5.247 +  return Mac48Address ("ff:ff:ff:ff:ff:ff");
   5.248 +}
   5.249 +bool 
   5.250 +CsmaNetDevice::IsMulticast (void) const
   5.251 +{
   5.252 +  return false;
   5.253 +}
   5.254 +Address 
   5.255 +CsmaNetDevice::GetMulticast (void) const
   5.256 +{
   5.257 +  return Mac48Address ("01:00:5e:00:00:00");
   5.258 +}
   5.259 +Address 
   5.260 +CsmaNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
   5.261  {
   5.262    NS_LOG_FUNCTION;
   5.263    NS_LOG_PARAMS (this << multicastGroup);
   5.264 @@ -692,20 +688,67 @@
   5.265  
   5.266    return etherAddr;
   5.267  }
   5.268 +bool 
   5.269 +CsmaNetDevice::IsPointToPoint (void) const
   5.270 +{
   5.271 +  return false;
   5.272 +}
   5.273 +bool 
   5.274 +CsmaNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
   5.275 +{
   5.276 +  NS_LOG_FUNCTION;
   5.277 +  NS_LOG_LOGIC ("p=" << packet);
   5.278 +  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
   5.279  
   5.280 -Ptr<Queue>
   5.281 -CsmaNetDevice::GetQueue(void) const 
   5.282 -{ 
   5.283 -  NS_LOG_FUNCTION;
   5.284 -  return m_queue;
   5.285 +  NS_ASSERT (IsLinkUp ());
   5.286 +
   5.287 +  // Only transmit if send side of net device is enabled
   5.288 +  if (!IsSendEnabled())
   5.289 +    return false;
   5.290 +
   5.291 +  Mac48Address destination = Mac48Address::ConvertFrom (dest);
   5.292 +  AddHeader(packet, destination, protocolNumber);
   5.293 +
   5.294 +  // Place the packet to be sent on the send queue
   5.295 +  if (m_queue->Enqueue(packet) == false )
   5.296 +    {
   5.297 +      return false;
   5.298 +    }
   5.299 +  // If the device is idle, we need to start a transmission. Otherwise,
   5.300 +  // the transmission will be started when the current packet finished
   5.301 +  // transmission (see TransmitCompleteEvent)
   5.302 +  if (m_txMachineState == READY) 
   5.303 +    {
   5.304 +      // Store the next packet to be transmitted
   5.305 +      m_currentPkt = m_queue->Dequeue ();
   5.306 +      if (m_currentPkt != 0)
   5.307 +        {
   5.308 +          TransmitStart();
   5.309 +        }
   5.310 +    }
   5.311 +  return true;
   5.312 +}
   5.313 +Ptr<Node> 
   5.314 +CsmaNetDevice::GetNode (void) const
   5.315 +{
   5.316 +  return m_node;
   5.317 +}
   5.318 +bool 
   5.319 +CsmaNetDevice::NeedsArp (void) const
   5.320 +{
   5.321 +  if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
   5.322 +    {
   5.323 +      return true;
   5.324 +    } 
   5.325 +  else 
   5.326 +    {
   5.327 +      return false;
   5.328 +    }
   5.329 +}
   5.330 +void 
   5.331 +CsmaNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
   5.332 +{
   5.333 +  m_rxCallback = cb;
   5.334  }
   5.335  
   5.336 -Ptr<Channel>
   5.337 -CsmaNetDevice::DoGetChannel(void) const 
   5.338 -{ 
   5.339 -  NS_LOG_FUNCTION;
   5.340 -  return m_channel;
   5.341 -}
   5.342 -
   5.343 -
   5.344  } // namespace ns3
     6.1 --- a/src/devices/csma/csma-net-device.h	Sun Feb 24 20:18:02 2008 +0100
     6.2 +++ b/src/devices/csma/csma-net-device.h	Mon Feb 25 19:33:46 2008 +0100
     6.3 @@ -98,7 +98,6 @@
     6.4    LLC,         /**< LLC packet encapsulation */  
     6.5  };
     6.6  
     6.7 -  CsmaNetDevice (Ptr<Node> node);
     6.8    /**
     6.9     * Construct a CsmaNetDevice
    6.10     *
    6.11 @@ -113,22 +112,6 @@
    6.12    CsmaNetDevice (Ptr<Node> node, Mac48Address addr, CsmaEncapsulationMode pktType);
    6.13  
    6.14    /**
    6.15 -   * Construct a CsmaNetDevice
    6.16 -   *
    6.17 -   * This is the constructor for the CsmaNetDevice.  It takes as a
    6.18 -   * parameter the Node to which this device is connected.  Ownership of the
    6.19 -   * Node pointer is not implied and the node must not be deleted.
    6.20 -   *
    6.21 -   * \param node the Node to which this device is connected.
    6.22 -   * \param addr The source MAC address of the net device.
    6.23 -   * \param pktType the type of encapsulation
    6.24 -   * \param sendEnable whether this device is able to send
    6.25 -   * \param receiveEnable whether this device is able to receive
    6.26 -   */
    6.27 -  CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
    6.28 -                   CsmaEncapsulationMode pktType,
    6.29 -                   bool sendEnable, bool receiveEnable);
    6.30 -  /**
    6.31     * Destroy a CsmaNetDevice
    6.32     *
    6.33     * This is the destructor for the CsmaNetDevice.
    6.34 @@ -216,6 +199,28 @@
    6.35     */
    6.36    void Receive (Ptr<Packet> p);
    6.37  
    6.38 +  bool IsSendEnabled (void);
    6.39 +  bool IsReceiveEnabled (void);
    6.40 +
    6.41 +  void SetSendEnable (bool);
    6.42 +  void SetReceiveEnable (bool);
    6.43 +
    6.44 +
    6.45 +  // inherited from NetDevice base class.
    6.46 +  virtual void SetName(const std::string name);
    6.47 +  virtual std::string GetName(void) const;
    6.48 +  virtual void SetIfIndex(const uint32_t index);
    6.49 +  virtual uint32_t GetIfIndex(void) const;
    6.50 +  virtual Ptr<Channel> GetChannel (void) const;
    6.51 +  virtual Address GetAddress (void) const;
    6.52 +  virtual bool SetMtu (const uint16_t mtu);
    6.53 +  virtual uint16_t GetMtu (void) const;
    6.54 +  virtual bool IsLinkUp (void) const;
    6.55 +  virtual void SetLinkChangeCallback (Callback<void> callback);
    6.56 +  virtual bool IsBroadcast (void) const;
    6.57 +  virtual Address GetBroadcast (void) const;
    6.58 +  virtual bool IsMulticast (void) const;
    6.59 +  virtual Address GetMulticast (void) const;
    6.60    /**
    6.61     * @brief Make and return a MAC multicast address using the provided
    6.62     *        multicast group
    6.63 @@ -229,13 +234,6 @@
    6.64     * to an EUI-48-based CSMA device.  This MAC address is encapsulated in an
    6.65     *  abstract Address to avoid dependencies on the exact address format.
    6.66     *
    6.67 -   * A default imlementation of MakeMulticastAddress is provided, but this
    6.68 -   * method simply NS_ASSERTS.  In the case of net devices that do not support
    6.69 -   * multicast, clients are expected to test NetDevice::IsMulticast and avoid
    6.70 -   * attempting to map multicast packets.  Subclasses of NetDevice that do
    6.71 -   * support multicasting are expected to override this method and provide an
    6.72 -   * implementation appropriate to the particular device.
    6.73 -   *
    6.74     * @param multicastGroup The IP address for the multicast group destination
    6.75     * of the packet.
    6.76     * @return The MAC multicast Address used to send packets to the provided
    6.77 @@ -245,16 +243,14 @@
    6.78     * @see Mac48Address
    6.79     * @see Address
    6.80     */
    6.81 -  Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
    6.82 -
    6.83 -  bool IsSendEnabled (void);
    6.84 -  bool IsReceiveEnabled (void);
    6.85 -
    6.86 -  void SetSendEnable (bool);
    6.87 -  void SetReceiveEnable (bool);
    6.88 +  virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
    6.89 +  virtual bool IsPointToPoint (void) const;
    6.90 +  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
    6.91 +  virtual Ptr<Node> GetNode (void) const;
    6.92 +  virtual bool NeedsArp (void) const;
    6.93 +  virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
    6.94  
    6.95  protected:
    6.96 -  virtual bool DoNeedsArp (void) const;
    6.97    virtual void DoDispose (void);
    6.98    /**
    6.99     * Create a Trace Resolver for events in the net device.
   6.100 @@ -273,15 +269,6 @@
   6.101     */
   6.102    Ptr<Queue> GetQueue (void) const; 
   6.103    /**
   6.104 -   * Get a copy of the attached Channel
   6.105 -   *
   6.106 -   * This method is provided for any derived class that may need to get
   6.107 -   * direct access to the connected channel
   6.108 -   *
   6.109 -   * \return a pointer to the channel
   6.110 -   */
   6.111 -  virtual Ptr<Channel> DoGetChannel (void) const;
   6.112 -  /**
   6.113     * Adds the necessary headers and trailers to a packet of data in order to
   6.114     * respect the packet type
   6.115     *
   6.116 @@ -312,22 +299,6 @@
   6.117     * Initializes variablea when construction object.
   6.118     */
   6.119    void Init (bool sendEnable, bool receiveEnable);
   6.120 -  /**
   6.121 -   * Send a Packet on the Csma network
   6.122 -   *
   6.123 -   * This method does not use a destination address since all packets
   6.124 -   * are broadcast to all NetDevices attached to the channel. Packet
   6.125 -   * should contain all needed headers at this time.
   6.126 -   *
   6.127 -   * If the device is ready to transmit, the next packet is read off
   6.128 -   * of the queue and stored locally until it has been transmitted.
   6.129 -   *
   6.130 -   * \param p a reference to the packet to send
   6.131 -   * \param dest destination address
   6.132 -   * \param protocolNumber -- this parameter is not used here
   6.133 -   * \return true if success, false on failure
   6.134 -   */
   6.135 -  virtual bool SendTo (Ptr<Packet> p, const Address& dest, uint16_t protocolNumber);
   6.136  
   6.137    /**
   6.138     * Start Sending a Packet Down the Wire.
   6.139 @@ -388,6 +359,7 @@
   6.140     *
   6.141     */
   6.142    void TransmitAbort (void);
   6.143 +  void NotifyLinkUp (void);
   6.144  
   6.145    /** 
   6.146     * Device ID returned by the attached functions. It is used by the
   6.147 @@ -481,6 +453,14 @@
   6.148    CallbackTraceSource<Ptr<const Packet> > m_rxTrace;
   6.149    CallbackTraceSource<Ptr<const Packet> > m_dropTrace;
   6.150  
   6.151 +  Ptr<Node> m_node;
   6.152 +  Mac48Address m_address;
   6.153 +  NetDevice::ReceiveCallback m_rxCallback;
   6.154 +  uint32_t m_ifIndex;
   6.155 +  std::string m_name;
   6.156 +  bool m_linkUp;
   6.157 +  Callback<void> m_linkChangeCallback;
   6.158 +  uint16_t m_mtu;
   6.159  };
   6.160  
   6.161  }; // namespace ns3
     7.1 --- a/src/devices/point-to-point/point-to-point-net-device.cc	Sun Feb 24 20:18:02 2008 +0100
     7.2 +++ b/src/devices/point-to-point/point-to-point-net-device.cc	Mon Feb 25 19:33:46 2008 +0100
     7.3 @@ -86,9 +86,9 @@
     7.4  }
     7.5  
     7.6  PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
     7.7 +                                              Mac48Address address,
     7.8                                                const DataRate& rate) 
     7.9  : 
    7.10 -  NetDevice(node, Mac48Address::Allocate ()), 
    7.11    m_txMachineState (READY),
    7.12    m_bps (rate),
    7.13    m_tInterframeGap (Seconds(0)),
    7.14 @@ -96,29 +96,19 @@
    7.15    m_queue (0),
    7.16    m_rxTrace (),
    7.17    m_dropTrace (),
    7.18 -  m_receiveErrorModel (0)
    7.19 +  m_receiveErrorModel (0),
    7.20 +  m_node (node),
    7.21 +  m_address (address),
    7.22 +  m_name (""),
    7.23 +  m_linkUp (false),
    7.24 +  m_mtu (0xffff)
    7.25  {
    7.26    NS_LOG_FUNCTION;
    7.27    NS_LOG_PARAMS (this << node);
    7.28 -//
    7.29 -// XXX BUGBUG
    7.30 -//
    7.31 -// You _must_ support broadcast to get any sort of packet from the ARP layer.
    7.32 -//
    7.33 -  EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff"));
    7.34 -//
    7.35 -// We want to allow multicast packets to flow across this link
    7.36 -//
    7.37 -  EnableMulticast (Mac48Address ("01:00:5e:00:00:00"));
    7.38 -  EnablePointToPoint();
    7.39  }
    7.40  
    7.41 -PointToPointNetDevice::~PointToPointNetDevice()
    7.42 -{
    7.43 -  NS_LOG_FUNCTION;
    7.44 -  m_queue = 0;
    7.45 -  m_receiveErrorModel = 0;
    7.46 -}
    7.47 +PointToPointNetDevice::~PointToPointNetDevice ()
    7.48 +{}
    7.49  
    7.50  void 
    7.51  PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
    7.52 @@ -144,7 +134,9 @@
    7.53  void PointToPointNetDevice::DoDispose()
    7.54  {
    7.55    NS_LOG_FUNCTION;
    7.56 +  m_node = 0;
    7.57    m_channel = 0;
    7.58 +  m_receiveErrorModel = 0;
    7.59    NetDevice::DoDispose ();
    7.60  }
    7.61  
    7.62 @@ -163,40 +155,7 @@
    7.63    m_tInterframeGap = t;
    7.64  }
    7.65  
    7.66 -bool PointToPointNetDevice::SendTo (Ptr<Packet> packet, const Address& dest, 
    7.67 -                                    uint16_t protocolNumber)
    7.68 -{
    7.69 -  NS_LOG_FUNCTION;
    7.70 -  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
    7.71 -  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
    7.72 -
    7.73 -  // GFR Comment. Why is this an assertion? Can't a link legitimately
    7.74 -  // "go down" during the simulation?  Shouldn't we just wait for it
    7.75 -  // to come back up?
    7.76 -  NS_ASSERT (IsLinkUp ());
    7.77 -  AddHeader(packet, protocolNumber);
    7.78 -
    7.79 -//
    7.80 -// This class simulates a point to point device.  In the case of a serial
    7.81 -// link, this means that we're simulating something like a UART.
    7.82 -//
    7.83 -//
    7.84 -// If there's a transmission in progress, we enque the packet for later
    7.85 -// transmission; otherwise we send it now.
    7.86 -  if (m_txMachineState == READY) 
    7.87 -    {
    7.88 -// We still enqueue and dequeue it to hit the tracing hooks
    7.89 -      m_queue->Enqueue (packet);
    7.90 -      packet = m_queue->Dequeue ();
    7.91 -      return TransmitStart (packet);
    7.92 -    }
    7.93 -  else
    7.94 -    {
    7.95 -      return m_queue->Enqueue(packet);
    7.96 -    }
    7.97 -}
    7.98 -
    7.99 -  bool
   7.100 +bool
   7.101  PointToPointNetDevice::TransmitStart (Ptr<Packet> p)
   7.102  {
   7.103    NS_LOG_FUNCTION;
   7.104 @@ -320,7 +279,7 @@
   7.105      {
   7.106        m_rxTrace (packet);
   7.107        ProcessHeader(packet, protocol);
   7.108 -      ForwardUp (packet, protocol, GetBroadcast ());
   7.109 +      m_rxCallback (this, packet, protocol, GetBroadcast ());
   7.110      }
   7.111  }
   7.112  
   7.113 @@ -330,16 +289,144 @@
   7.114    return m_queue;
   7.115  }
   7.116  
   7.117 -Ptr<Channel> PointToPointNetDevice::DoGetChannel(void) const 
   7.118 -{ 
   7.119 -  NS_LOG_FUNCTION;
   7.120 +void
   7.121 +PointToPointNetDevice::NotifyLinkUp (void)
   7.122 +{
   7.123 +  m_linkUp = true;
   7.124 +  if (!m_linkChangeCallback.IsNull ())
   7.125 +    {
   7.126 +      m_linkChangeCallback ();
   7.127 +    }
   7.128 +}
   7.129 +
   7.130 +void 
   7.131 +PointToPointNetDevice::SetName(const std::string name)
   7.132 +{
   7.133 +  m_name = name;
   7.134 +}
   7.135 +std::string 
   7.136 +PointToPointNetDevice::GetName(void) const
   7.137 +{
   7.138 +  return m_name;
   7.139 +}
   7.140 +void 
   7.141 +PointToPointNetDevice::SetIfIndex(const uint32_t index)
   7.142 +{
   7.143 +  m_ifIndex = index;
   7.144 +}
   7.145 +uint32_t 
   7.146 +PointToPointNetDevice::GetIfIndex(void) const
   7.147 +{
   7.148 +  return m_ifIndex;
   7.149 +}
   7.150 +Ptr<Channel> 
   7.151 +PointToPointNetDevice::GetChannel (void) const
   7.152 +{
   7.153    return m_channel;
   7.154  }
   7.155 -
   7.156 -bool PointToPointNetDevice::DoNeedsArp (void) const
   7.157 +Address 
   7.158 +PointToPointNetDevice::GetAddress (void) const
   7.159  {
   7.160 -  NS_LOG_FUNCTION;
   7.161 +  return m_address;
   7.162 +}
   7.163 +bool 
   7.164 +PointToPointNetDevice::SetMtu (const uint16_t mtu)
   7.165 +{
   7.166 +  m_mtu = mtu;
   7.167 +  return true;
   7.168 +}
   7.169 +uint16_t 
   7.170 +PointToPointNetDevice::GetMtu (void) const
   7.171 +{
   7.172 +  return m_mtu;
   7.173 +}
   7.174 +bool 
   7.175 +PointToPointNetDevice::IsLinkUp (void) const
   7.176 +{
   7.177 +  return m_linkUp;
   7.178 +}
   7.179 +void 
   7.180 +PointToPointNetDevice::SetLinkChangeCallback (Callback<void> callback)
   7.181 +{
   7.182 +  m_linkChangeCallback = callback;
   7.183 +}
   7.184 +bool 
   7.185 +PointToPointNetDevice::IsBroadcast (void) const
   7.186 +{
   7.187 +  return true;
   7.188 +}
   7.189 +Address
   7.190 +PointToPointNetDevice::GetBroadcast (void) const
   7.191 +{
   7.192 +  return Mac48Address ("ff:ff:ff:ff:ff:ff");
   7.193 +}
   7.194 +bool 
   7.195 +PointToPointNetDevice::IsMulticast (void) const
   7.196 +{
   7.197    return false;
   7.198  }
   7.199 +Address 
   7.200 +PointToPointNetDevice::GetMulticast (void) const
   7.201 +{
   7.202 +  return Mac48Address ("01:00:5e:00:00:00");
   7.203 +}
   7.204 +Address 
   7.205 +PointToPointNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
   7.206 +{
   7.207 +  return Mac48Address ("01:00:5e:00:00:00");
   7.208 +}
   7.209 +bool 
   7.210 +PointToPointNetDevice::IsPointToPoint (void) const
   7.211 +{
   7.212 +  return true;
   7.213 +}
   7.214 +bool 
   7.215 +PointToPointNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
   7.216 +{
   7.217 +    NS_LOG_FUNCTION;
   7.218 +  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
   7.219 +  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
   7.220 +
   7.221 +  // GFR Comment. Why is this an assertion? Can't a link legitimately
   7.222 +  // "go down" during the simulation?  Shouldn't we just wait for it
   7.223 +  // to come back up?
   7.224 +  NS_ASSERT (IsLinkUp ());
   7.225 +  AddHeader(packet, protocolNumber);
   7.226 +
   7.227 +//
   7.228 +// This class simulates a point to point device.  In the case of a serial
   7.229 +// link, this means that we're simulating something like a UART.
   7.230 +//
   7.231 +//
   7.232 +// If there's a transmission in progress, we enque the packet for later
   7.233 +// transmission; otherwise we send it now.
   7.234 +  if (m_txMachineState == READY) 
   7.235 +    {
   7.236 +// We still enqueue and dequeue it to hit the tracing hooks
   7.237 +      m_queue->Enqueue (packet);
   7.238 +      packet = m_queue->Dequeue ();
   7.239 +      return TransmitStart (packet);
   7.240 +    }
   7.241 +  else
   7.242 +    {
   7.243 +      return m_queue->Enqueue(packet);
   7.244 +    }
   7.245 +}
   7.246 +Ptr<Node> 
   7.247 +PointToPointNetDevice::GetNode (void) const
   7.248 +{
   7.249 +  return m_node;
   7.250 +}
   7.251 +bool 
   7.252 +PointToPointNetDevice::NeedsArp (void) const
   7.253 +{
   7.254 +  return false;
   7.255 +}
   7.256 +void 
   7.257 +PointToPointNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
   7.258 +{
   7.259 +  m_rxCallback = cb;
   7.260 +}
   7.261 +
   7.262  
   7.263  } // namespace ns3
     8.1 --- a/src/devices/point-to-point/point-to-point-net-device.h	Sun Feb 24 20:18:02 2008 +0100
     8.2 +++ b/src/devices/point-to-point/point-to-point-net-device.h	Mon Feb 25 19:33:46 2008 +0100
     8.3 @@ -32,6 +32,7 @@
     8.4  #include "ns3/data-rate.h"
     8.5  #include "ns3/default-value.h"
     8.6  #include "ns3/ptr.h"
     8.7 +#include "ns3/mac48-address.h"
     8.8  
     8.9  namespace ns3 {
    8.10  
    8.11 @@ -74,7 +75,8 @@
    8.12   * include a queue, data rate, and interframe transmission gap (the 
    8.13   * propagation delay is set in the PointToPointChannel).
    8.14   */
    8.15 -class PointToPointNetDevice : public NetDevice {
    8.16 +class PointToPointNetDevice : public NetDevice 
    8.17 +{
    8.18  public:
    8.19    /**
    8.20     * Construct a PointToPointNetDevice
    8.21 @@ -88,6 +90,7 @@
    8.22     * @param rate (optional) DataRate object
    8.23     */
    8.24    PointToPointNetDevice (Ptr<Node> node,
    8.25 +                         Mac48Address address,
    8.26                           const DataRate& rate = g_defaultRate.GetValue());
    8.27    /**
    8.28     * Destroy a PointToPointNetDevice
    8.29 @@ -168,6 +171,28 @@
    8.30     */
    8.31    void Receive (Ptr<Packet> p);
    8.32  
    8.33 +  // inherited from NetDevice base class.
    8.34 +  virtual void SetName(const std::string name);
    8.35 +  virtual std::string GetName(void) const;
    8.36 +  virtual void SetIfIndex(const uint32_t index);
    8.37 +  virtual uint32_t GetIfIndex(void) const;
    8.38 +  virtual Ptr<Channel> GetChannel (void) const;
    8.39 +  virtual Address GetAddress (void) const;
    8.40 +  virtual bool SetMtu (const uint16_t mtu);
    8.41 +  virtual uint16_t GetMtu (void) const;
    8.42 +  virtual bool IsLinkUp (void) const;
    8.43 +  virtual void SetLinkChangeCallback (Callback<void> callback);
    8.44 +  virtual bool IsBroadcast (void) const;
    8.45 +  virtual Address GetBroadcast (void) const;
    8.46 +  virtual bool IsMulticast (void) const;
    8.47 +  virtual Address GetMulticast (void) const;
    8.48 +  virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
    8.49 +  virtual bool IsPointToPoint (void) const;
    8.50 +  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
    8.51 +  virtual Ptr<Node> GetNode (void) const;
    8.52 +  virtual bool NeedsArp (void) const;
    8.53 +  virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
    8.54 +
    8.55  private:
    8.56    /**
    8.57     * Create a Trace Resolver for events in the net device.
    8.58 @@ -188,16 +213,6 @@
    8.59     */
    8.60    Ptr<Queue> GetQueue(void) const; 
    8.61  
    8.62 -  /**
    8.63 -   * Get a copy of the attached Channel
    8.64 -   *
    8.65 -   * This method is provided for any derived class that may need to get
    8.66 -   * direct access to the connected channel
    8.67 -   *
    8.68 -   * @see PointToPointChannel
    8.69 -   * @returns a pointer to the channel
    8.70 -   */
    8.71 -  virtual Ptr<Channel> DoGetChannel(void) const;
    8.72  
    8.73    /**
    8.74     * Set a new default data rate
    8.75 @@ -224,21 +239,6 @@
    8.76     */
    8.77    bool ProcessHeader(Ptr<Packet> p, uint16_t& param);
    8.78    /**
    8.79 -   * Send a Packet Down the Wire.
    8.80 -   *
    8.81 -   * The SendTo method is defined as the standard way that the level three
    8.82 -   * protocol uses to tell a NetDevice to send a packet.  SendTo is declared
    8.83 -   * as abstract in the NetDevice class and we declare it here.
    8.84 -   *
    8.85 -   * @see NetDevice
    8.86 -   * @param p a reference to the packet to send
    8.87 -   * @param dest a reference to the Address of the destination device
    8.88 -   * @param protocolNumber Protocol Number used to find protocol touse
    8.89 -   * @returns true if success, false on failure
    8.90 -   */
    8.91 -  virtual bool SendTo (Ptr<Packet> p, const Address& dest, 
    8.92 -                       uint16_t protocolNumber);
    8.93 -  /**
    8.94     * Start Sending a Packet Down the Wire.
    8.95     *
    8.96     * The TransmitStart method is the method that is used internally in the
    8.97 @@ -262,7 +262,8 @@
    8.98     *
    8.99     */
   8.100    void TransmitComplete(void);
   8.101 -  virtual bool DoNeedsArp (void) const;
   8.102 +  void NotifyLinkUp (void);
   8.103 +
   8.104    /**
   8.105     * Enumeration of the states of the transmit machine of the net device.
   8.106     */
   8.107 @@ -327,6 +328,15 @@
   8.108     * Error model for receive packet events
   8.109     */
   8.110    Ptr<ErrorModel> m_receiveErrorModel;
   8.111 +
   8.112 +  Ptr<Node> m_node;
   8.113 +  Mac48Address m_address;
   8.114 +  NetDevice::ReceiveCallback m_rxCallback;
   8.115 +  uint32_t m_ifIndex;
   8.116 +  std::string m_name;
   8.117 +  bool m_linkUp;
   8.118 +  Callback<void> m_linkChangeCallback;
   8.119 +  uint16_t m_mtu;
   8.120  };
   8.121  
   8.122  }; // namespace ns3
     9.1 --- a/src/devices/point-to-point/point-to-point-topology.cc	Sun Feb 24 20:18:02 2008 +0100
     9.2 +++ b/src/devices/point-to-point/point-to-point-topology.cc	Mon Feb 25 19:33:46 2008 +0100
     9.3 @@ -47,13 +47,15 @@
     9.4  {
     9.5    Ptr<PointToPointChannel> channel = CreateObject<PointToPointChannel> (bps, delay);
     9.6  
     9.7 -  Ptr<PointToPointNetDevice> net1 = CreateObject<PointToPointNetDevice> (n1);
     9.8 +  Ptr<PointToPointNetDevice> net1 = CreateObject<PointToPointNetDevice> (n1, Mac48Address::Allocate ());
     9.9 +  n1->AddDevice (net1);
    9.10  
    9.11    Ptr<Queue> q = Queue::CreateDefault ();
    9.12    net1->AddQueue(q);
    9.13    net1->Attach (channel);
    9.14    
    9.15 -  Ptr<PointToPointNetDevice> net2 = CreateObject<PointToPointNetDevice> (n2);
    9.16 +  Ptr<PointToPointNetDevice> net2 = CreateObject<PointToPointNetDevice> (n2, Mac48Address::Allocate ());
    9.17 +  n2->AddDevice (net2);
    9.18  
    9.19    q = Queue::CreateDefault ();
    9.20    net2->AddQueue(q);
    10.1 --- a/src/devices/wifi/wifi-net-device.cc	Sun Feb 24 20:18:02 2008 +0100
    10.2 +++ b/src/devices/wifi/wifi-net-device.cc	Mon Feb 25 19:33:46 2008 +0100
    10.3 @@ -158,14 +158,12 @@
    10.4   ***************************************************************/
    10.5  
    10.6  
    10.7 -WifiNetDevice::WifiNetDevice (Ptr<Node> node)
    10.8 -  : NetDevice (node, Mac48Address::Allocate ())
    10.9 -{
   10.10 -  Construct ();
   10.11 -}
   10.12  
   10.13  WifiNetDevice::WifiNetDevice (Ptr<Node> node, Mac48Address self)
   10.14 -  : NetDevice (node, self)
   10.15 +  : m_node (node),
   10.16 +    m_address (self),
   10.17 +    m_name (""),
   10.18 +    m_linkUp (false)
   10.19  {
   10.20    Construct ();
   10.21  }
   10.22 @@ -176,9 +174,7 @@
   10.23  void
   10.24  WifiNetDevice::Construct (void)
   10.25  {
   10.26 -  SetMtu (2300);
   10.27 -  EnableBroadcast (Mac48Address ("ff:ff:ff:ff:ff:ff"));
   10.28 -
   10.29 +  m_mtu = 2300;
   10.30    // the physical layer.
   10.31    m_phy = Create<WifiPhy> (this);
   10.32  
   10.33 @@ -307,21 +303,6 @@
   10.34    m_phy->SetChannel (channel);
   10.35    NotifyAttached ();
   10.36  }
   10.37 -bool
   10.38 -WifiNetDevice::SendTo (Ptr<Packet> packet, const Address &to, uint16_t protocolNumber)
   10.39 -{
   10.40 -  NS_ASSERT (Mac48Address::IsMatchingType (to));
   10.41 -
   10.42 -  Mac48Address realTo = Mac48Address::ConvertFrom (to);
   10.43 -
   10.44 -  LlcSnapHeader llc;
   10.45 -  llc.SetType (protocolNumber);
   10.46 -  packet->AddHeader (llc);
   10.47 -
   10.48 -  m_txLogger (packet, realTo);
   10.49 -
   10.50 -  return DoSendTo (packet, realTo);
   10.51 -}
   10.52  void 
   10.53  WifiNetDevice::DoForwardUp (Ptr<Packet> packet, const Mac48Address &from)
   10.54  {
   10.55 @@ -329,7 +310,7 @@
   10.56  
   10.57    LlcSnapHeader llc;
   10.58    packet->RemoveHeader (llc);
   10.59 -  NetDevice::ForwardUp (packet, llc.GetType (), from);
   10.60 +  m_rxCallback (this, packet, llc.GetType (), from);
   10.61  }
   10.62  Mac48Address 
   10.63  WifiNetDevice::GetSelfAddress (void) const
   10.64 @@ -338,22 +319,11 @@
   10.65    Mac48Address self = Mac48Address::ConvertFrom (GetAddress ());
   10.66    return self;
   10.67  }
   10.68 -bool 
   10.69 -WifiNetDevice::DoNeedsArp (void) const
   10.70 -{
   10.71 -  return true;
   10.72 -}
   10.73 -Ptr<Channel> 
   10.74 -WifiNetDevice::DoGetChannel (void) const
   10.75 -{
   10.76 -  return m_channel;
   10.77 -}
   10.78  void 
   10.79  WifiNetDevice::DoDispose (void)
   10.80  {
   10.81 -  // chain up.
   10.82 -  NetDevice::DoDispose ();
   10.83    // cleanup local
   10.84 +  m_node = 0;
   10.85    m_channel = 0;
   10.86    delete m_stations;
   10.87    delete m_low;
   10.88 @@ -369,6 +339,136 @@
   10.89    m_rxMiddle = 0;
   10.90    m_txMiddle = 0;
   10.91    m_parameters = 0;
   10.92 +  // chain up.
   10.93 +  NetDevice::DoDispose ();
   10.94 +}
   10.95 +
   10.96 +void
   10.97 +WifiNetDevice::NotifyLinkUp (void)
   10.98 +{
   10.99 +  m_linkUp = true;
  10.100 +  if (!m_linkChangeCallback.IsNull ())
  10.101 +    {
  10.102 +      m_linkChangeCallback ();
  10.103 +    }
  10.104 +}
  10.105 +void
  10.106 +WifiNetDevice::NotifyLinkDown (void)
  10.107 +{
  10.108 +  m_linkUp = false;
  10.109 +  m_linkChangeCallback ();
  10.110 +}
  10.111 +
  10.112 +void 
  10.113 +WifiNetDevice::SetName(const std::string name)
  10.114 +{
  10.115 +  m_name = name;
  10.116 +}
  10.117 +std::string 
  10.118 +WifiNetDevice::GetName(void) const
  10.119 +{
  10.120 +  return m_name;
  10.121 +}
  10.122 +void 
  10.123 +WifiNetDevice::SetIfIndex(const uint32_t index)
  10.124 +{
  10.125 +  m_ifIndex = index;
  10.126 +}
  10.127 +uint32_t 
  10.128 +WifiNetDevice::GetIfIndex(void) const
  10.129 +{
  10.130 +  return m_ifIndex;
  10.131 +}
  10.132 +Ptr<Channel> 
  10.133 +WifiNetDevice::GetChannel (void) const
  10.134 +{
  10.135 +  return m_channel;
  10.136 +}
  10.137 +Address 
  10.138 +WifiNetDevice::GetAddress (void) const
  10.139 +{
  10.140 +  return m_address;
  10.141 +}
  10.142 +bool 
  10.143 +WifiNetDevice::SetMtu (const uint16_t mtu)
  10.144 +{
  10.145 +  m_mtu = mtu;
  10.146 +  return true;
  10.147 +}
  10.148 +uint16_t 
  10.149 +WifiNetDevice::GetMtu (void) const
  10.150 +{
  10.151 +  return m_mtu;
  10.152 +}
  10.153 +bool 
  10.154 +WifiNetDevice::IsLinkUp (void) const
  10.155 +{
  10.156 +  return m_linkUp;
  10.157 +}
  10.158 +void 
  10.159 +WifiNetDevice::SetLinkChangeCallback (Callback<void> callback)
  10.160 +{
  10.161 +  m_linkChangeCallback = callback;
  10.162 +}
  10.163 +bool 
  10.164 +WifiNetDevice::IsBroadcast (void) const
  10.165 +{
  10.166 +  return true;
  10.167 +}
  10.168 +Address
  10.169 +WifiNetDevice::GetBroadcast (void) const
  10.170 +{
  10.171 +  return Mac48Address ("ff:ff:ff:ff:ff:ff");
  10.172 +}
  10.173 +bool 
  10.174 +WifiNetDevice::IsMulticast (void) const
  10.175 +{
  10.176 +  return false;
  10.177 +}
  10.178 +Address 
  10.179 +WifiNetDevice::GetMulticast (void) const
  10.180 +{
  10.181 +  return Mac48Address ("01:00:5e:00:00:00");
  10.182 +}
  10.183 +Address 
  10.184 +WifiNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
  10.185 +{
  10.186 +  return Mac48Address ("01:00:5e:00:00:00");
  10.187 +}
  10.188 +bool 
  10.189 +WifiNetDevice::IsPointToPoint (void) const
  10.190 +{
  10.191 +  return false;
  10.192 +}
  10.193 +bool 
  10.194 +WifiNetDevice::Send(Ptr<Packet> packet, const Address& to, uint16_t protocolNumber)
  10.195 +{
  10.196 +  NS_ASSERT (Mac48Address::IsMatchingType (to));
  10.197 +
  10.198 +  Mac48Address realTo = Mac48Address::ConvertFrom (to);
  10.199 +
  10.200 +  LlcSnapHeader llc;
  10.201 +  llc.SetType (protocolNumber);
  10.202 +  packet->AddHeader (llc);
  10.203 +
  10.204 +  m_txLogger (packet, realTo);
  10.205 +
  10.206 +  return DoSendTo (packet, realTo);
  10.207 +}
  10.208 +Ptr<Node> 
  10.209 +WifiNetDevice::GetNode (void) const
  10.210 +{
  10.211 +  return m_node;
  10.212 +}
  10.213 +bool 
  10.214 +WifiNetDevice::NeedsArp (void) const
  10.215 +{
  10.216 +  return true;
  10.217 +}
  10.218 +void 
  10.219 +WifiNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
  10.220 +{
  10.221 +  m_rxCallback = cb;
  10.222  }
  10.223  
  10.224  
  10.225 @@ -376,11 +476,6 @@
  10.226   *            Adhoc code
  10.227   *****************************************************/
  10.228  
  10.229 -AdhocWifiNetDevice::AdhocWifiNetDevice (Ptr<Node> node)
  10.230 -  : WifiNetDevice (node)
  10.231 -{
  10.232 -  DoConstruct ();
  10.233 -}
  10.234  AdhocWifiNetDevice::AdhocWifiNetDevice (Ptr<Node> node, Mac48Address self)
  10.235    : WifiNetDevice (node, self)
  10.236  {
  10.237 @@ -449,11 +544,6 @@
  10.238   *            STA code
  10.239   *****************************************************/
  10.240  
  10.241 -NqstaWifiNetDevice::NqstaWifiNetDevice (Ptr<Node> node)
  10.242 -  : WifiNetDevice (node)
  10.243 -{
  10.244 -  DoConstruct ();
  10.245 -}
  10.246  NqstaWifiNetDevice::NqstaWifiNetDevice (Ptr<Node> node, Mac48Address self)
  10.247    : WifiNetDevice (node, self)
  10.248  {
  10.249 @@ -513,13 +603,13 @@
  10.250  void 
  10.251  NqstaWifiNetDevice::Associated (void)
  10.252  {
  10.253 -  NetDevice::NotifyLinkUp ();
  10.254 +  WifiNetDevice::NotifyLinkUp ();
  10.255  }
  10.256  
  10.257  void 
  10.258  NqstaWifiNetDevice::DisAssociated (void)
  10.259  {
  10.260 -  NetDevice::NotifyLinkDown ();
  10.261 +  WifiNetDevice::NotifyLinkDown ();
  10.262  }
  10.263  void 
  10.264  NqstaWifiNetDevice::DoDispose (void)
  10.265 @@ -539,11 +629,6 @@
  10.266   *****************************************************/
  10.267  
  10.268  
  10.269 -NqapWifiNetDevice::NqapWifiNetDevice (Ptr<Node> node)
  10.270 -  : WifiNetDevice (node)
  10.271 -{
  10.272 -  DoConstruct ();
  10.273 -}
  10.274  NqapWifiNetDevice::NqapWifiNetDevice (Ptr<Node> node, Mac48Address self)
  10.275    : WifiNetDevice (node, self)
  10.276  {
    11.1 --- a/src/devices/wifi/wifi-net-device.h	Sun Feb 24 20:18:02 2008 +0100
    11.2 +++ b/src/devices/wifi/wifi-net-device.h	Mon Feb 25 19:33:46 2008 +0100
    11.3 @@ -98,14 +98,32 @@
    11.4     */
    11.5    virtual Ssid GetSsid (void) const = 0;
    11.6  
    11.7 +  // inherited from NetDevice base class.
    11.8 +  virtual void SetName(const std::string name);
    11.9 +  virtual std::string GetName(void) const;
   11.10 +  virtual void SetIfIndex(const uint32_t index);
   11.11 +  virtual uint32_t GetIfIndex(void) const;
   11.12 +  virtual Ptr<Channel> GetChannel (void) const;
   11.13 +  virtual Address GetAddress (void) const;
   11.14 +  virtual bool SetMtu (const uint16_t mtu);
   11.15 +  virtual uint16_t GetMtu (void) const;
   11.16 +  virtual bool IsLinkUp (void) const;
   11.17 +  virtual void SetLinkChangeCallback (Callback<void> callback);
   11.18 +  virtual bool IsBroadcast (void) const;
   11.19 +  virtual Address GetBroadcast (void) const;
   11.20 +  virtual bool IsMulticast (void) const;
   11.21 +  virtual Address GetMulticast (void) const;
   11.22 +  virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
   11.23 +  virtual bool IsPointToPoint (void) const;
   11.24 +  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
   11.25 +  virtual Ptr<Node> GetNode (void) const;
   11.26 +  virtual bool NeedsArp (void) const;
   11.27 +  virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
   11.28 +
   11.29  private:
   11.30    class PhyListener;
   11.31    class NavListener;
   11.32  
   11.33 -  // inherited from NetDevice
   11.34 -  virtual bool DoNeedsArp (void) const;
   11.35 -  virtual Ptr<Channel> DoGetChannel (void) const;
   11.36 -  virtual bool SendTo (Ptr<Packet> packet, const Address &to, uint16_t protocolNumber);
   11.37    // inherited from Object
   11.38    virtual Ptr<TraceResolver> GetTraceResolver (void) const;
   11.39    // defined for children
   11.40 @@ -117,10 +135,11 @@
   11.41    CallbackTraceSource<Ptr<const Packet>, Mac48Address> m_rxLogger;
   11.42    CallbackTraceSource<Ptr<const Packet>, Mac48Address> m_txLogger;
   11.43  protected:
   11.44 -  WifiNetDevice (Ptr<Node> node);
   11.45    WifiNetDevice (Ptr<Node> node, Mac48Address self);
   11.46    void DoForwardUp (Ptr<Packet> packet, const Mac48Address &from);
   11.47    DcaTxop *CreateDca (uint32_t minCw, uint32_t maxCw, uint32_t aifsn) const;
   11.48 +  void NotifyLinkUp (void);
   11.49 +  void NotifyLinkDown (void);
   11.50    // inherited from Object
   11.51    virtual void DoDispose (void);
   11.52  
   11.53 @@ -134,6 +153,15 @@
   11.54    DcfManager *m_manager;
   11.55    PhyListener *m_phyListener;
   11.56    NavListener *m_navListener;
   11.57 +
   11.58 +  Ptr<Node> m_node;
   11.59 +  Mac48Address m_address;
   11.60 +  NetDevice::ReceiveCallback m_rxCallback;
   11.61 +  uint32_t m_ifIndex;
   11.62 +  std::string m_name;
   11.63 +  bool m_linkUp;
   11.64 +  Callback<void> m_linkChangeCallback;
   11.65 +  uint16_t m_mtu;
   11.66  };
   11.67  
   11.68  /**
   11.69 @@ -144,7 +172,6 @@
   11.70   */
   11.71  class AdhocWifiNetDevice : public WifiNetDevice {
   11.72  public:
   11.73 -  AdhocWifiNetDevice (Ptr<Node> node);
   11.74    AdhocWifiNetDevice (Ptr<Node> node, Mac48Address self);
   11.75    virtual ~AdhocWifiNetDevice ();
   11.76  
   11.77 @@ -183,7 +210,6 @@
   11.78    /**
   11.79     * The ssid is initialized from \valueref{WifiSsid}.
   11.80     */
   11.81 -  NqstaWifiNetDevice (Ptr<Node> node);
   11.82    NqstaWifiNetDevice (Ptr<Node> node, Mac48Address self);
   11.83    virtual ~NqstaWifiNetDevice ();
   11.84  
    12.1 --- a/src/internet-node/udp-socket.cc	Sun Feb 24 20:18:02 2008 +0100
    12.2 +++ b/src/internet-node/udp-socket.cc	Mon Feb 25 19:33:46 2008 +0100
    12.3 @@ -388,7 +388,8 @@
    12.4    
    12.5    // Receiver Node
    12.6    Ptr<Node> rxNode = CreateObject<InternetNode> ();
    12.7 -  Ptr<PointToPointNetDevice> rxDev = CreateObject<PointToPointNetDevice> (rxNode);
    12.8 +  Ptr<PointToPointNetDevice> rxDev = CreateObject<PointToPointNetDevice> (rxNode, Mac48Address::Allocate ());
    12.9 +  rxNode->AddDevice (rxDev);
   12.10    rxDev->AddQueue(CreateObject<DropTailQueue> ());
   12.11    Ptr<Ipv4> ipv4 = rxNode->GetObject<Ipv4> ();
   12.12    uint32_t netdev_idx = ipv4->AddInterface (rxDev);
   12.13 @@ -398,7 +399,8 @@
   12.14  
   12.15    // Sender Node
   12.16    Ptr<Node> txNode = CreateObject<InternetNode> ();
   12.17 -  Ptr<PointToPointNetDevice> txDev = CreateObject<PointToPointNetDevice> (txNode);
   12.18 +  Ptr<PointToPointNetDevice> txDev = CreateObject<PointToPointNetDevice> (txNode, Mac48Address::Allocate ());
   12.19 +  txNode->AddDevice (txDev);
   12.20    txDev->AddQueue(CreateObject<DropTailQueue> ());
   12.21    ipv4 = txNode->GetObject<Ipv4> ();
   12.22    netdev_idx = ipv4->AddInterface (txDev);
    13.1 --- a/src/node/net-device.cc	Sun Feb 24 20:18:02 2008 +0100
    13.2 +++ b/src/node/net-device.cc	Mon Feb 25 19:33:46 2008 +0100
    13.3 @@ -19,15 +19,9 @@
    13.4   * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    13.5   */
    13.6  
    13.7 -#include <iostream>
    13.8 -#include "ns3/assert.h"
    13.9  #include "ns3/object.h"
   13.10  #include "ns3/log.h"
   13.11 -#include "ns3/trace-resolver.h"
   13.12 -#include "ns3/packet.h"
   13.13 -#include "channel.h"
   13.14  #include "net-device.h"
   13.15 -#include "node.h"
   13.16  
   13.17  NS_LOG_COMPONENT_DEFINE ("NetDevice");
   13.18  
   13.19 @@ -42,272 +36,7 @@
   13.20    return tid;
   13.21  }
   13.22  
   13.23 -NetDevice::NetDevice(Ptr<Node> node, const Address& addr) : 
   13.24 -  m_node (node), 
   13.25 -  m_name(""), 
   13.26 -  m_ifIndex (0), 
   13.27 -  m_address (addr),
   13.28 -  m_mtu (0xffff), 
   13.29 -  m_isUp (false), 
   13.30 -  m_isBroadcast (false), 
   13.31 -  m_isMulticast (false), 
   13.32 -  m_isPointToPoint (false)
   13.33 -{
   13.34 -  NS_LOG_FUNCTION;
   13.35 -  m_node->AddDevice (this);
   13.36 -}
   13.37 +NetDevice::~NetDevice ()
   13.38 +{}
   13.39  
   13.40 -NetDevice::~NetDevice ()
   13.41 -{
   13.42 -  NS_LOG_FUNCTION;
   13.43 -}
   13.44 -
   13.45 -Address 
   13.46 -NetDevice::GetAddress (void) const
   13.47 -{
   13.48 -  NS_LOG_FUNCTION;
   13.49 -  return m_address;
   13.50 -}
   13.51 -
   13.52 -bool
   13.53 -NetDevice::SetMtu (const uint16_t mtu) 
   13.54 -{
   13.55 -  NS_LOG_FUNCTION;
   13.56 -  m_mtu = mtu;
   13.57 -  return true;
   13.58 -}
   13.59 -
   13.60 -uint16_t 
   13.61 -NetDevice::GetMtu (void) const
   13.62 -{
   13.63 -  NS_LOG_FUNCTION;
   13.64 -  return m_mtu;
   13.65 -}
   13.66 -
   13.67 -void
   13.68 -NetDevice::SetName(const std::string name) 
   13.69 -{ 
   13.70 -  NS_LOG_FUNCTION;
   13.71 -  m_name = name; 
   13.72 -}
   13.73 -
   13.74 -std::string 
   13.75 -NetDevice::GetName(void) const 
   13.76 -{ 
   13.77 -  NS_LOG_FUNCTION;
   13.78 -  return m_name; 
   13.79 -}
   13.80 -
   13.81 -void
   13.82 -NetDevice::SetIfIndex(uint32_t index) 
   13.83 -{ 
   13.84 -  NS_LOG_FUNCTION;
   13.85 -  m_ifIndex = index; 
   13.86 -}
   13.87 -
   13.88 -uint32_t
   13.89 -NetDevice::GetIfIndex(void) const 
   13.90 -{ 
   13.91 -  NS_LOG_FUNCTION;
   13.92 -  return m_ifIndex; 
   13.93 -}
   13.94 -
   13.95 -bool 
   13.96 -NetDevice::IsLinkUp (void) const
   13.97 -{
   13.98 -  NS_LOG_FUNCTION;
   13.99 -  return m_isUp;
  13.100 -}
  13.101 -
  13.102 -void 
  13.103 -NetDevice::SetLinkChangeCallback (Callback<void> callback)
  13.104 -{
  13.105 -  NS_LOG_FUNCTION;
  13.106 -  m_linkChangeCallback = callback;
  13.107 -}
  13.108 -
  13.109 -bool
  13.110 -NetDevice::IsBroadcast (void) const
  13.111 -{
  13.112 -  NS_LOG_FUNCTION;
  13.113 -  return m_isBroadcast;
  13.114 -}
  13.115 -
  13.116 -Address const &
  13.117 -NetDevice::GetBroadcast (void) const
  13.118 -{
  13.119 -  NS_LOG_FUNCTION;
  13.120 -  NS_ASSERT (m_isBroadcast);
  13.121 -  return m_broadcast;
  13.122 -}
  13.123 -
  13.124 -void
  13.125 -NetDevice::EnableBroadcast (Address broadcast)
  13.126 -{
  13.127 -  NS_LOG_FUNCTION;
  13.128 -  m_isBroadcast = true;
  13.129 -  m_broadcast = broadcast;
  13.130 -}
  13.131 -
  13.132 -void
  13.133 -NetDevice::DisableBroadcast (void)
  13.134 -{
  13.135 -  NS_LOG_FUNCTION;
  13.136 -  m_isBroadcast = false;
  13.137 -}
  13.138 -
  13.139 -bool
  13.140 -NetDevice::IsMulticast (void) const
  13.141 -{
  13.142 -  NS_LOG_FUNCTION;
  13.143 -  return m_isMulticast;
  13.144 -}
  13.145 -
  13.146 -Address 
  13.147 -NetDevice::GetMulticast (void) const
  13.148 -{
  13.149 -  NS_LOG_FUNCTION;
  13.150 -  NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
  13.151 -    "Invalid operation when not IsMulticast ()");
  13.152 -  return m_multicast;
  13.153 -}
  13.154 -
  13.155 -Address
  13.156 -NetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
  13.157 -{
  13.158 -  NS_LOG_FUNCTION;
  13.159 -  NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
  13.160 -    "Invalid operation when not IsMulticast ()");
  13.161 -  return m_multicast;
  13.162 -}
  13.163 -
  13.164 -void
  13.165 -NetDevice::EnableMulticast (Address multicast)
  13.166 -{
  13.167 -  NS_LOG_FUNCTION;
  13.168 -  m_isMulticast = true;
  13.169 -  m_multicast = multicast;
  13.170 -}
  13.171 -
  13.172 -void
  13.173 -NetDevice::DisableMulticast (void)
  13.174 -{
  13.175 -  NS_LOG_FUNCTION;
  13.176 -  m_isMulticast = false;
  13.177 -}
  13.178 -
  13.179 -bool
  13.180 -NetDevice::IsPointToPoint (void) const
  13.181 -{
  13.182 -  NS_LOG_FUNCTION;
  13.183 -  return m_isPointToPoint;
  13.184 -}
  13.185 -
  13.186 -void
  13.187 -NetDevice::EnablePointToPoint (void)
  13.188 -{
  13.189 -  NS_LOG_FUNCTION;
  13.190 -  m_isPointToPoint = true;
  13.191 -}
  13.192 -
  13.193 -void
  13.194 -NetDevice::DisablePointToPoint (void)
  13.195 -{
  13.196 -  NS_LOG_FUNCTION;
  13.197 -  m_isPointToPoint = false;
  13.198 -}
  13.199 -
  13.200 -// Receive packet from above
  13.201 -bool 
  13.202 -NetDevice::Send(Ptr<Packet> p, const Address& dest, uint16_t protocolNumber)
  13.203 -{
  13.204 -  NS_LOG_FUNCTION;
  13.205 -  if (m_isUp)
  13.206 -    {
  13.207 -      return SendTo(p, dest, protocolNumber);
  13.208 -    }
  13.209 -  else
  13.210 -    {
  13.211 -      return false;
  13.212 -    }
  13.213 -}
  13.214 -
  13.215 -Ptr<Channel>
  13.216 -NetDevice::GetChannel (void) const
  13.217 -{
  13.218 -  NS_LOG_FUNCTION;
  13.219 -  return DoGetChannel ();
  13.220 -}
  13.221 -
  13.222 -// Receive packets from below
  13.223 -bool
  13.224 -NetDevice::ForwardUp(Ptr<Packet> p, uint16_t param, const Address &from)
  13.225 -{
  13.226 -  NS_LOG_FUNCTION;
  13.227 -  bool retval = false;
  13.228 -
  13.229 -  NS_LOG_LOGIC ("UID is " << p->GetUid() << " device is: " << GetName());
  13.230 -  
  13.231 -  if (!m_receiveCallback.IsNull ())
  13.232 -    {
  13.233 -      retval = m_receiveCallback (this, p, param, from);
  13.234 -    } 
  13.235 -  else 
  13.236 -    {
  13.237 -      NS_LOG_WARN ("NetDevice::Receive call back is NULL");
  13.238 -    }
  13.239 -
  13.240 -    return retval;
  13.241 -}
  13.242 -
  13.243 -void 
  13.244 -NetDevice::NotifyLinkUp (void)
  13.245 -{
  13.246 -  NS_LOG_FUNCTION;
  13.247 -  m_isUp = true;
  13.248 -  if (!m_linkChangeCallback.IsNull ())
  13.249 -    {
  13.250 -      m_linkChangeCallback ();
  13.251 -    }
  13.252 -}
  13.253 -
  13.254 -void 
  13.255 -NetDevice::NotifyLinkDown (void)
  13.256 -{
  13.257 -  NS_LOG_FUNCTION;
  13.258 -  m_isUp = false;
  13.259 -  if (!m_linkChangeCallback.IsNull ())
  13.260 -    {
  13.261 -      m_linkChangeCallback ();
  13.262 -    }
  13.263 -}
  13.264 -
  13.265 -Ptr<Node>
  13.266 -NetDevice::GetNode (void) const
  13.267 -{
  13.268 -  NS_LOG_FUNCTION;
  13.269 -  return m_node;
  13.270 -}
  13.271 -
  13.272 -bool
  13.273 -NetDevice::NeedsArp (void) const
  13.274 -{
  13.275 -  NS_LOG_FUNCTION;
  13.276 -  return DoNeedsArp ();
  13.277 -}
  13.278 -
  13.279 -void 
  13.280 -NetDevice::SetReceiveCallback (ReceiveCallback cb)
  13.281 -{
  13.282 -  NS_LOG_FUNCTION;
  13.283 -  m_receiveCallback = cb;
  13.284 -}
  13.285 -
  13.286 -void
  13.287 -NetDevice::DoDispose()
  13.288 -{
  13.289 -  NS_LOG_FUNCTION;
  13.290 -  m_node = 0;
  13.291 -}
  13.292 -
  13.293 -}; // namespace ns3
  13.294 +} // namespace ns3
    14.1 --- a/src/node/net-device.h	Sun Feb 24 20:18:02 2008 +0100
    14.2 +++ b/src/node/net-device.h	Mon Feb 25 19:33:46 2008 +0100
    14.3 @@ -63,52 +63,53 @@
    14.4    static TypeId GetTypeId (void);
    14.5    virtual ~NetDevice();
    14.6  
    14.7 +  /**
    14.8 +   * \param name name of the device (e.g. "eth0")
    14.9 +   */
   14.10 +  virtual void SetName(const std::string name) = 0;
   14.11 +  /**
   14.12 +   * \return name name of the device (e.g. "eth0")
   14.13 +   */
   14.14 +  virtual std::string GetName(void) const = 0;
   14.15 +  /**
   14.16 +   * \param index ifIndex of the device 
   14.17 +   */
   14.18 +  virtual void SetIfIndex(const uint32_t index) = 0;
   14.19 +  /**
   14.20 +   * \return index ifIndex of the device 
   14.21 +   */
   14.22 +  virtual uint32_t GetIfIndex(void) const = 0;
   14.23 +
   14.24  
   14.25    /**
   14.26     * \return the channel this NetDevice is connected to. The value
   14.27     *         returned can be zero if the NetDevice is not yet connected
   14.28     *         to any channel.
   14.29     */
   14.30 -  Ptr<Channel> GetChannel (void) const;
   14.31 +  virtual Ptr<Channel> GetChannel (void) const = 0;
   14.32  
   14.33    /**
   14.34     * \return the current Address of this interface.
   14.35     */
   14.36 -  Address GetAddress (void) const;
   14.37 +  virtual Address GetAddress (void) const = 0;
   14.38    /**
   14.39     * \param mtu MTU value, in bytes, to set for the device
   14.40     * \return whether the MTU value was within legal bounds
   14.41     * 
   14.42     * Override for default MTU defined on a per-type basis.
   14.43     */
   14.44 -  bool SetMtu (const uint16_t mtu);
   14.45 +  virtual bool SetMtu (const uint16_t mtu) = 0;
   14.46    /**
   14.47     * \return the link-level MTU in bytes for this interface.
   14.48     * 
   14.49     * This value is typically used by the IP layer to perform
   14.50     * IP fragmentation when needed.
   14.51     */
   14.52 -  uint16_t GetMtu (void) const;
   14.53 -  /**
   14.54 -   * \param name name of the device (e.g. "eth0")
   14.55 -   */
   14.56 -  void SetName(const std::string name); 
   14.57 -  /**
   14.58 -   * \return name name of the device (e.g. "eth0")
   14.59 -   */
   14.60 -  std::string GetName(void) const;
   14.61 -  /**
   14.62 -   * \param index ifIndex of the device 
   14.63 -   */
   14.64 -  void SetIfIndex(const uint32_t index);
   14.65 -  /**
   14.66 -   * \return index ifIndex of the device 
   14.67 -   */
   14.68 -  uint32_t GetIfIndex(void) const;
   14.69 +  virtual uint16_t GetMtu (void) const = 0;
   14.70    /**
   14.71     * \return true if link is up; false otherwise
   14.72     */
   14.73 -  bool IsLinkUp (void) const;
   14.74 +  virtual bool IsLinkUp (void) const = 0;
   14.75    /**
   14.76     * \param callback the callback to invoke
   14.77     *
   14.78 @@ -117,12 +118,12 @@
   14.79     * by the IP/ARP layer to flush the ARP cache 
   14.80     * whenever the link goes up.
   14.81     */
   14.82 -  void SetLinkChangeCallback (Callback<void> callback);
   14.83 +  virtual void SetLinkChangeCallback (Callback<void> callback) = 0;
   14.84    /**
   14.85     * \return true if this interface supports a broadcast address,
   14.86     *         false otherwise.
   14.87     */
   14.88 -  bool IsBroadcast (void) const;
   14.89 +  virtual bool IsBroadcast (void) const = 0;
   14.90    /**
   14.91     * \return the broadcast address supported by
   14.92     *         this netdevice.
   14.93 @@ -130,12 +131,12 @@
   14.94     * Calling this method is invalid if IsBroadcast returns
   14.95     * not true.
   14.96     */
   14.97 -  Address const &GetBroadcast (void) const;
   14.98 +  virtual Address GetBroadcast (void) const = 0;
   14.99  
  14.100    /**
  14.101     * \return value of m_isMulticast flag
  14.102     */
  14.103 -  bool IsMulticast (void) const;
  14.104 +  virtual bool IsMulticast (void) const = 0;
  14.105  
  14.106    /**
  14.107     * \brief Return the MAC multicast base address used when mapping multicast
  14.108 @@ -160,8 +161,8 @@
  14.109     * The method NS_ASSERTs if the device is not a multicast device.
  14.110     * \see NetDevice::MakeMulticastAddress
  14.111     */
  14.112 -  Address GetMulticast (void) const;
  14.113 -
  14.114 +  virtual Address GetMulticast (void) const = 0;
  14.115 +  
  14.116    /**
  14.117     * \brief Make and return a MAC multicast address using the provided
  14.118     *        multicast group
  14.119 @@ -192,12 +193,12 @@
  14.120     * \see Address
  14.121     * \see NetDevice::IsMulticast
  14.122     */
  14.123 -  virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
  14.124 -
  14.125 +  virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const = 0;
  14.126 +  
  14.127    /**
  14.128     * \return value of m_isPointToPoint flag
  14.129     */
  14.130 -  bool IsPointToPoint (void) const;
  14.131 +  virtual bool IsPointToPoint (void) const = 0;
  14.132    /**
  14.133     * \param packet packet sent from above down to Network Device
  14.134     * \param dest mac address of the destination (already resolved)
  14.135 @@ -210,7 +211,7 @@
  14.136     * 
  14.137     * \return whether the Send operation succeeded 
  14.138     */
  14.139 -  bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
  14.140 +  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
  14.141    /**
  14.142     * \returns the node base class which contains this network
  14.143     *          interface.
  14.144 @@ -219,7 +220,7 @@
  14.145     * base class to print the nodeid for example, it can invoke
  14.146     * this method.
  14.147     */
  14.148 -  Ptr<Node> GetNode (void) const;
  14.149 +  virtual Ptr<Node> GetNode (void) const = 0;
  14.150  
  14.151    /**
  14.152     * \returns true if ARP is needed, false otherwise.
  14.153 @@ -227,7 +228,7 @@
  14.154     * Called by higher-layers to check if this NetDevice requires
  14.155     * ARP to be used.
  14.156     */
  14.157 -  bool NeedsArp (void) const;
  14.158 +  virtual bool NeedsArp (void) const = 0;
  14.159  
  14.160    /**
  14.161     * \param device a pointer to the net device which is calling this callback
  14.162 @@ -246,116 +247,10 @@
  14.163     *        be forwarded to the higher layers.
  14.164     *
  14.165     */
  14.166 -  void SetReceiveCallback (ReceiveCallback cb);
  14.167 +  virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
  14.168  
  14.169 - protected:
  14.170 -  /**
  14.171 -   * \param node base class node pointer of device's node 
  14.172 -   * \param addr MAC address of this device.
  14.173 -   */
  14.174 -  NetDevice(Ptr<Node> node, const Address& addr);
  14.175 -  /**
  14.176 -   * Enable broadcast support. This method should be
  14.177 -   * called by subclasses from their constructor
  14.178 -   */
  14.179 -  void EnableBroadcast (Address broadcast);
  14.180 -  /**
  14.181 -   * Set m_isBroadcast flag to false
  14.182 -   */
  14.183 -  void DisableBroadcast (void);
  14.184 -  /**
  14.185 -   * Enable multicast support. This method should be
  14.186 -   * called by subclasses from their constructor
  14.187 -   */
  14.188 -  void EnableMulticast (Address multicast);
  14.189 -  /**
  14.190 -   * Set m_isMulticast flag to false
  14.191 -   */
  14.192 -  void DisableMulticast (void);
  14.193 -  /**
  14.194 -   * Set m_isPointToPoint flag to true
  14.195 -   */
  14.196 -  void EnablePointToPoint (void);
  14.197 -  /**
  14.198 -   * Set m_isPointToPoint flag to false
  14.199 -   */
  14.200 -  void DisablePointToPoint (void);
  14.201 -  /**
  14.202 -   * When a subclass notices that the link status has changed to up,
  14.203 -   * it notifies its parent class by calling this method. This method
  14.204 -   * is responsible for notifying any LinkUp callbacks. 
  14.205 -   */
  14.206 -  void NotifyLinkUp (void);
  14.207 -  /**
  14.208 -   * When a subclass notices that the link status has changed to 
  14.209 -   * down, it notifies its parent class by calling this method.
  14.210 -   */
  14.211 -  void NotifyLinkDown (void);
  14.212 -
  14.213 -  /**
  14.214 -   * \param p packet sent from below up to Network Device
  14.215 -   * \param param Extra parameter extracted from header and needed by
  14.216 -   * some protocols
  14.217 -   * \param address the address of the sender of this packet.
  14.218 -   * \returns true if the packet was forwarded successfully,
  14.219 -   *          false otherwise.
  14.220 -   *
  14.221 -   * When a subclass gets a packet from the channel, it 
  14.222 -   * forwards it to the higher layers by calling this method
  14.223 -   * which is responsible for passing it up to the Rx callback.
  14.224 -   */
  14.225 -  bool ForwardUp (Ptr<Packet> p, uint16_t param, const Address &address);
  14.226 -
  14.227 -
  14.228 -  /**
  14.229 -   * The dispose method for this NetDevice class.
  14.230 -   * Subclasses are expected to override this method _and_
  14.231 -   * to chain up to it by calling NetDevice::DoDispose
  14.232 -   * at the end of their own DoDispose method.
  14.233 -   */
  14.234 -  virtual void DoDispose (void);
  14.235 -
  14.236 - private:
  14.237 -  /**
  14.238 -   * \param p packet to send
  14.239 -   * \param dest address of destination to which packet must be sent
  14.240 -   * \param protocolNumber Number of the protocol (used with some protocols)
  14.241 -   * \returns true if the packet could be sent successfully, false
  14.242 -   *          otherwise.
  14.243 -   *
  14.244 -   * This is the private virtual target function of the public Send()
  14.245 -   * method.  When the link is Up, this method is invoked to ask 
  14.246 -   * subclasses to forward packets. Subclasses MUST override this method.
  14.247 -   */
  14.248 -  virtual bool SendTo (Ptr<Packet> p, const Address &dest, uint16_t protocolNumber) = 0;
  14.249 -  /**
  14.250 -   * \returns true if this NetDevice needs the higher-layers
  14.251 -   *          to perform ARP over it, false otherwise.
  14.252 -   *
  14.253 -   * Subclasses must implement this method.
  14.254 -   */
  14.255 -  virtual bool DoNeedsArp (void) const = 0;
  14.256 -  /**
  14.257 -   * \returns the channel associated to this NetDevice.
  14.258 -   *
  14.259 -   * Subclasses must implement this method.
  14.260 -   */
  14.261 -  virtual Ptr<Channel> DoGetChannel (void) const = 0;
  14.262 -
  14.263 -  Ptr<Node>     m_node;
  14.264 -  std::string   m_name;
  14.265 -  uint16_t      m_ifIndex;
  14.266 -  Address       m_address;
  14.267 -  Address       m_broadcast;
  14.268 -  Address       m_multicast;
  14.269 -  uint16_t      m_mtu;
  14.270 -  bool          m_isUp;
  14.271 -  bool          m_isBroadcast;
  14.272 -  bool          m_isMulticast;
  14.273 -  bool          m_isPointToPoint;
  14.274 -  Callback<void> m_linkChangeCallback;
  14.275 -  ReceiveCallback m_receiveCallback;
  14.276  };
  14.277  
  14.278 -}; // namespace ns3
  14.279 -#endif
  14.280 +} // namespace ns3
  14.281 +
  14.282 +#endif /* NET_DEVICE_H */
    15.1 --- a/tutorial/point-to-point-ipv4-topology.cc	Sun Feb 24 20:18:02 2008 +0100
    15.2 +++ b/tutorial/point-to-point-ipv4-topology.cc	Mon Feb 25 19:33:46 2008 +0100
    15.3 @@ -43,8 +43,8 @@
    15.4  {
    15.5    NS_ASSERT (channel->GetNDevices () <= 1);
    15.6  
    15.7 -  Ptr<PointToPointNetDevice> nd = CreateObject<PointToPointNetDevice> (node);
    15.8 -
    15.9 +  Ptr<PointToPointNetDevice> nd = CreateObject<PointToPointNetDevice> (node, Mac48Address::Allocate ());
   15.10 +  node->AddDevice (nd);
   15.11    Ptr<Queue> q = Queue::CreateDefault ();
   15.12    nd->AddQueue(q);
   15.13    nd->Attach (channel);
    16.1 --- a/utils/print-introspected-doxygen.cc	Sun Feb 24 20:18:02 2008 +0100
    16.2 +++ b/utils/print-introspected-doxygen.cc	Mon Feb 25 19:33:46 2008 +0100
    16.3 @@ -119,9 +119,12 @@
    16.4    Ptr<Node> node = CreateObject<InternetNode> ();
    16.5    node->AggregateObject (CreateObject<MobilityModelNotifier> ());
    16.6  
    16.7 -  Ptr<PointToPointNetDevice> p2p = CreateObject<PointToPointNetDevice> (node);
    16.8 +  Ptr<PointToPointNetDevice> p2p = CreateObject<PointToPointNetDevice> (node, Mac48Address::Allocate ());
    16.9 +  node->AddDevice (p2p);
   16.10    p2p->AddQueue (Queue::CreateDefault ());
   16.11 -  Ptr<CsmaNetDevice> csma = CreateObject<CsmaNetDevice> (node);
   16.12 +  Ptr<CsmaNetDevice> csma = CreateObject<CsmaNetDevice> (node, Mac48Address::Allocate (),
   16.13 +							 CsmaNetDevice::LLC);
   16.14 +  node->AddDevice (csma);
   16.15    csma->AddQueue (Queue::CreateDefault ());
   16.16  
   16.17    TraceResolver::SourceCollection collection;