2007-02-08 15:37:48 +01:00
|
|
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2005,2006 INRIA
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
* published by the Free Software Foundation;
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2007-02-16 09:56:21 +01:00
|
|
|
#include "ns3/assert.h"
|
2007-05-25 10:56:03 +02:00
|
|
|
#include "ns3/object.h"
|
2007-02-08 15:37:48 +01:00
|
|
|
|
2007-05-11 19:26:01 +02:00
|
|
|
#include "channel.h"
|
2007-02-08 15:37:48 +01:00
|
|
|
#include "net-device.h"
|
|
|
|
|
#include "llc-snap-header.h"
|
2007-06-04 16:21:05 +02:00
|
|
|
#include "node.h"
|
2007-02-08 15:37:48 +01:00
|
|
|
|
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
2007-05-25 10:56:03 +02:00
|
|
|
const InterfaceId NetDevice::iid = MakeInterfaceId ("NetDevice", Object::iid);
|
2007-05-11 19:26:01 +02:00
|
|
|
|
2007-06-04 16:17:01 +02:00
|
|
|
NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) :
|
2007-02-08 15:37:48 +01:00
|
|
|
m_node (node),
|
|
|
|
|
m_name(""),
|
|
|
|
|
m_ifIndex (0),
|
|
|
|
|
m_address (addr),
|
2007-03-25 07:20:24 -07:00
|
|
|
m_mtu (0xffff),
|
2007-02-08 15:37:48 +01:00
|
|
|
m_isUp (false),
|
|
|
|
|
m_isBroadcast (false),
|
|
|
|
|
m_isMulticast (false),
|
|
|
|
|
m_isPointToPoint (false)
|
2007-05-13 09:58:53 +02:00
|
|
|
{
|
2007-05-25 10:56:03 +02:00
|
|
|
SetInterfaceId (NetDevice::iid);
|
2007-05-13 09:58:53 +02:00
|
|
|
m_node->AddDevice (this);
|
|
|
|
|
}
|
2007-05-02 14:40:40 +02:00
|
|
|
|
|
|
|
|
NetDevice::~NetDevice ()
|
2007-05-10 08:18:41 +02:00
|
|
|
{}
|
2007-02-08 15:37:48 +01:00
|
|
|
|
|
|
|
|
MacAddress
|
|
|
|
|
NetDevice::GetAddress (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::SetMtu (const uint16_t mtu)
|
|
|
|
|
{
|
|
|
|
|
m_mtu = mtu;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
|
NetDevice::GetMtu (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_mtu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::SetName(const std::string name)
|
|
|
|
|
{
|
|
|
|
|
m_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
NetDevice::GetName(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-04 12:17:14 -07:00
|
|
|
void
|
|
|
|
|
NetDevice::SetIfIndex(uint32_t index)
|
|
|
|
|
{
|
|
|
|
|
m_ifIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
|
NetDevice::GetIfIndex(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_ifIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
bool
|
|
|
|
|
NetDevice::IsLinkUp (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_isUp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::SetLinkChangeCallback (Callback<void> callback)
|
|
|
|
|
{
|
|
|
|
|
m_linkChangeCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::IsBroadcast (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_isBroadcast;
|
|
|
|
|
}
|
|
|
|
|
MacAddress const &
|
|
|
|
|
NetDevice::GetBroadcast (void) const
|
|
|
|
|
{
|
2007-02-16 09:56:21 +01:00
|
|
|
NS_ASSERT (m_isBroadcast);
|
2007-02-08 15:37:48 +01:00
|
|
|
return m_broadcast;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::EnableBroadcast (MacAddress broadcast)
|
|
|
|
|
{
|
|
|
|
|
m_isBroadcast = true;
|
|
|
|
|
m_broadcast = broadcast;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::DisableBroadcast (void)
|
|
|
|
|
{
|
|
|
|
|
m_isBroadcast = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::IsMulticast (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_isMulticast;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::EnableMulticast (void)
|
|
|
|
|
{
|
|
|
|
|
m_isMulticast = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::DisableMulticast (void)
|
|
|
|
|
{
|
|
|
|
|
m_isMulticast = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::IsPointToPoint (void) const
|
|
|
|
|
{
|
|
|
|
|
return m_isPointToPoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::EnablePointToPoint (void)
|
|
|
|
|
{
|
|
|
|
|
m_isPointToPoint = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::DisablePointToPoint (void)
|
|
|
|
|
{
|
|
|
|
|
m_isPointToPoint = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Receive packet from above
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber)
|
|
|
|
|
{
|
|
|
|
|
if (m_isUp)
|
|
|
|
|
{
|
|
|
|
|
LlcSnapHeader llc;
|
|
|
|
|
llc.SetType (protocolNumber);
|
2007-05-01 11:54:21 +02:00
|
|
|
p.AddHeader (llc);
|
2007-02-08 15:37:48 +01:00
|
|
|
return SendTo(p, dest);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-18 14:06:51 -07:00
|
|
|
TraceResolver *
|
|
|
|
|
NetDevice::CreateTraceResolver (TraceContext const &context)
|
|
|
|
|
{
|
|
|
|
|
return DoCreateTraceResolver (context);
|
|
|
|
|
}
|
2007-02-08 15:37:48 +01:00
|
|
|
|
2007-05-10 20:19:26 +02:00
|
|
|
Ptr<Channel>
|
2007-03-29 17:07:04 +02:00
|
|
|
NetDevice::GetChannel (void) const
|
|
|
|
|
{
|
|
|
|
|
return DoGetChannel ();
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
// Receive packet from below
|
|
|
|
|
bool
|
|
|
|
|
NetDevice::ForwardUp (Packet& packet)
|
|
|
|
|
{
|
2007-04-30 10:37:22 +02:00
|
|
|
bool retval = false;
|
2007-02-08 15:37:48 +01:00
|
|
|
LlcSnapHeader llc;
|
2007-05-01 11:54:21 +02:00
|
|
|
packet.RemoveHeader (llc);
|
2007-04-30 10:37:22 +02:00
|
|
|
if (!m_receiveCallback.IsNull ())
|
2007-02-08 15:37:48 +01:00
|
|
|
{
|
2007-04-30 10:37:22 +02:00
|
|
|
retval = m_receiveCallback (this, packet, llc.GetType ());
|
2007-02-08 15:37:48 +01:00
|
|
|
}
|
2007-04-30 10:37:22 +02:00
|
|
|
return retval;
|
2007-02-08 15:37:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::NotifyLinkUp (void)
|
|
|
|
|
{
|
|
|
|
|
m_isUp = true;
|
|
|
|
|
if (!m_linkChangeCallback.IsNull ())
|
|
|
|
|
{
|
|
|
|
|
m_linkChangeCallback ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetDevice::NotifyLinkDown (void)
|
|
|
|
|
{
|
|
|
|
|
m_isUp = false;
|
|
|
|
|
if (!m_linkChangeCallback.IsNull ())
|
|
|
|
|
{
|
|
|
|
|
m_linkChangeCallback ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-04 16:17:01 +02:00
|
|
|
Ptr<Node>
|
|
|
|
|
NetDevice::GetNode (void) const
|
2007-02-08 15:37:48 +01:00
|
|
|
{
|
|
|
|
|
return m_node;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 10:05:46 +02:00
|
|
|
bool
|
|
|
|
|
NetDevice::NeedsArp (void) const
|
|
|
|
|
{
|
|
|
|
|
return DoNeedsArp ();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 10:37:22 +02:00
|
|
|
void
|
2007-05-10 20:19:26 +02:00
|
|
|
NetDevice::SetReceiveCallback (Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> cb)
|
2007-04-30 10:37:22 +02:00
|
|
|
{
|
|
|
|
|
m_receiveCallback = cb;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-02 09:10:19 +02:00
|
|
|
void
|
2007-05-03 13:24:43 +02:00
|
|
|
NetDevice::DoDispose()
|
2007-05-10 08:18:41 +02:00
|
|
|
{
|
|
|
|
|
m_node = 0;
|
|
|
|
|
}
|
2007-05-02 09:10:19 +02:00
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
}; // namespace ns3
|