From 508891973f5ef1b1537aac32bbaf09caedd7f2c9 Mon Sep 17 00:00:00 2001 From: pavlo Date: Mon, 16 Mar 2009 17:59:33 +0300 Subject: [PATCH] L2RoutingNetDevice refactored to MeshPointDevice --- src/devices/mesh/hwmp-helper.cc | 21 -- src/devices/mesh/hwmp-helper.h | 21 -- src/devices/mesh/l2-routing-net-device.cc | 355 ----------------- src/devices/mesh/mesh-point-device.cc | 357 ++++++++++++++++++ ...uting-net-device.h => mesh-point-device.h} | 131 ++++--- src/devices/mesh/mesh-wifi-helper.cc | 16 +- src/devices/mesh/mesh-wifi-helper.h | 5 + src/devices/mesh/wscript | 2 - 8 files changed, 441 insertions(+), 467 deletions(-) delete mode 100644 src/devices/mesh/hwmp-helper.cc delete mode 100644 src/devices/mesh/hwmp-helper.h delete mode 100644 src/devices/mesh/l2-routing-net-device.cc create mode 100644 src/devices/mesh/mesh-point-device.cc rename src/devices/mesh/{l2-routing-net-device.h => mesh-point-device.h} (54%) diff --git a/src/devices/mesh/hwmp-helper.cc b/src/devices/mesh/hwmp-helper.cc deleted file mode 100644 index f1a5adab4..000000000 --- a/src/devices/mesh/hwmp-helper.cc +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2008,2009 IITP RAS - * - * 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: Kirill Andreev - */ - - diff --git a/src/devices/mesh/hwmp-helper.h b/src/devices/mesh/hwmp-helper.h deleted file mode 100644 index f1a5adab4..000000000 --- a/src/devices/mesh/hwmp-helper.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2008,2009 IITP RAS - * - * 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: Kirill Andreev - */ - - diff --git a/src/devices/mesh/l2-routing-net-device.cc b/src/devices/mesh/l2-routing-net-device.cc deleted file mode 100644 index ca43dde16..000000000 --- a/src/devices/mesh/l2-routing-net-device.cc +++ /dev/null @@ -1,355 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2008,2009 IITP RAS - * - * 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: Kirill Andreev - */ - - -#include "ns3/node.h" -#include "ns3/channel.h" -#include "ns3/packet.h" -#include "ns3/log.h" -#include "ns3/boolean.h" -#include "ns3/simulator.h" -#include "ns3/l2-routing-net-device.h" - -NS_LOG_COMPONENT_DEFINE ("L2RoutingNetDevice"); - -namespace ns3 { - -NS_OBJECT_ENSURE_REGISTERED (L2RoutingNetDevice); - - -TypeId -L2RoutingNetDevice::GetTypeId () -{ - static TypeId tid = TypeId ("ns3::L2RoutingNetDevice") - .SetParent () - .AddConstructor () - ; - return tid; -} - - -L2RoutingNetDevice::L2RoutingNetDevice () -{ - NS_LOG_FUNCTION_NOARGS (); - m_channel = CreateObject (); -} - -L2RoutingNetDevice::~L2RoutingNetDevice() -{ - NS_LOG_FUNCTION_NOARGS (); -} - -void -L2RoutingNetDevice::DoDispose () -{ - NS_LOG_FUNCTION_NOARGS (); - for (std::vector< Ptr >::iterator iter = m_ports.begin (); iter != m_ports.end (); iter++) - *iter = 0; - m_ports.clear (); - m_node = 0; - NetDevice::DoDispose (); - -} - -void -L2RoutingNetDevice::ReceiveFromDevice (Ptr incomingPort, Ptr packet, uint16_t protocol, - Address const &src, Address const &dst, PacketType packetType) -{ - NS_LOG_FUNCTION_NOARGS (); - NS_LOG_DEBUG ("UID is " << packet->GetUid ()); - const Mac48Address src48 = Mac48Address::ConvertFrom (src); - const Mac48Address dst48 = Mac48Address::ConvertFrom (dst); - if (!m_promiscRxCallback.IsNull ()) - m_promiscRxCallback (this, packet, protocol, src, dst, packetType); - switch (packetType) - { - case PACKET_HOST: - if (dst48 == m_address) - m_rxCallback (this, packet, protocol, src); - break; - case PACKET_BROADCAST: - case PACKET_MULTICAST: - m_rxCallback (this, packet, protocol, src); - case PACKET_OTHERHOST: - Forward (incomingPort, packet->Copy(), protocol, src48, dst48); - break; - } - -} - -void -L2RoutingNetDevice::Forward (Ptr inport, Ptr packet, - uint16_t protocol, const Mac48Address src, const Mac48Address dst) -{ - //pass through routing protocol - m_requestRoute(inport->GetIfIndex(), src, dst, packet, protocol, m_myResponse); -} - -uint32_t -L2RoutingNetDevice::GetNPorts () const - { - NS_LOG_FUNCTION_NOARGS (); - return m_ports.size (); - } - -Ptr -L2RoutingNetDevice::GetPort (uint32_t n) const - { - NS_ASSERT(m_ports.size () > n); - return m_ports[n]; - } - -void -L2RoutingNetDevice::AddPort (Ptr routingPort) -{ - NS_LOG_FUNCTION_NOARGS (); - NS_ASSERT (routingPort != this); - if (!Mac48Address::IsMatchingType (routingPort->GetAddress ())) - NS_FATAL_ERROR ("Device does not support eui 48 addresses: cannot be added to bridge."); - if (!routingPort->SupportsSendFrom ()) - NS_FATAL_ERROR ("Device does not support SendFrom: cannot be added to bridge."); - m_address = Mac48Address::ConvertFrom (routingPort->GetAddress ()); - NS_LOG_DEBUG ("RegisterProtocolHandler for " << routingPort->GetName ()); - m_node->RegisterProtocolHandler (MakeCallback (&L2RoutingNetDevice::ReceiveFromDevice, this), - 0, routingPort, true); - m_ports.push_back (routingPort); - m_channel->AddChannel (routingPort->GetChannel ()); -} - -void -L2RoutingNetDevice::SetName(const std::string name) -{ - NS_LOG_FUNCTION_NOARGS (); - m_name = name; -} - -std::string -L2RoutingNetDevice::GetName() const - { - NS_LOG_FUNCTION_NOARGS (); - return m_name; - } - -void -L2RoutingNetDevice::SetIfIndex(const uint32_t index) -{ - NS_LOG_FUNCTION_NOARGS (); - m_ifIndex = index; -} - -uint32_t -L2RoutingNetDevice::GetIfIndex() const - { - NS_LOG_FUNCTION_NOARGS (); - return m_ifIndex; - } - -Ptr -L2RoutingNetDevice::GetChannel () const - { - NS_LOG_FUNCTION_NOARGS (); - return m_channel; - } - -Address -L2RoutingNetDevice::GetAddress () const - { - NS_LOG_FUNCTION_NOARGS (); - return m_address; - } - -bool -L2RoutingNetDevice::SetMtu (const uint16_t mtu) -{ - NS_LOG_FUNCTION_NOARGS (); - m_mtu = mtu; - return true; -} - -uint16_t -L2RoutingNetDevice::GetMtu () const - { - NS_LOG_FUNCTION_NOARGS (); - return 1500; - } - - -bool -L2RoutingNetDevice::IsLinkUp () const - { - NS_LOG_FUNCTION_NOARGS (); - return true; - } - - -void -L2RoutingNetDevice::SetLinkChangeCallback (Callback callback) -{} - -bool -L2RoutingNetDevice::IsBroadcast () const - { - NS_LOG_FUNCTION_NOARGS (); - return true; - } - - -Address -L2RoutingNetDevice::GetBroadcast () const - { - NS_LOG_FUNCTION_NOARGS (); - return Mac48Address ("ff:ff:ff:ff:ff:ff"); - } - -bool -L2RoutingNetDevice::IsMulticast () const - { - NS_LOG_FUNCTION_NOARGS (); - return true; - } - -Address -L2RoutingNetDevice::GetMulticast (Ipv4Address multicastGroup) const - { - NS_LOG_FUNCTION (this << multicastGroup); - Mac48Address multicast = Mac48Address::GetMulticast (multicastGroup); - return multicast; - } - - -bool -L2RoutingNetDevice::IsPointToPoint () const - { - NS_LOG_FUNCTION_NOARGS (); - return false; - } - -bool -L2RoutingNetDevice::IsBridge () const - { - NS_LOG_FUNCTION_NOARGS (); - return false; - } - - -bool -L2RoutingNetDevice::Send (Ptr packet, const Address& dest, uint16_t protocolNumber) -{ - - const Mac48Address dst48 = Mac48Address::ConvertFrom (dest); - return m_requestRoute(m_ifIndex, m_address, dst48, packet, protocolNumber, m_myResponse); -} - -bool -L2RoutingNetDevice::SendFrom (Ptr packet, const Address& src, const Address& dest, uint16_t protocolNumber) -{ - const Mac48Address src48 = Mac48Address::ConvertFrom (src); - const Mac48Address dst48 = Mac48Address::ConvertFrom (dest); - return m_requestRoute(m_ifIndex, src48, dst48, packet, protocolNumber, m_myResponse); -} - - -Ptr -L2RoutingNetDevice::GetNode () const - { - NS_LOG_FUNCTION_NOARGS (); - return m_node; - } - - -void -L2RoutingNetDevice::SetNode (Ptr node) -{ - NS_LOG_FUNCTION_NOARGS (); - m_node = node; -} - - -bool -L2RoutingNetDevice::NeedsArp () const - { - NS_LOG_FUNCTION_NOARGS (); - return true; - } - - -void -L2RoutingNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) -{ - NS_LOG_FUNCTION_NOARGS (); - m_rxCallback = cb; -} - -void -L2RoutingNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb) -{ - NS_LOG_FUNCTION_NOARGS (); - m_promiscRxCallback = cb; -} - -bool -L2RoutingNetDevice::SupportsSendFrom () const - { - NS_LOG_FUNCTION_NOARGS (); - return true; - } - -Address -L2RoutingNetDevice::GetMulticast (Ipv6Address addr) const - { - NS_LOG_FUNCTION (this << addr); - return Mac48Address::GetMulticast (addr); - } -//L2RouitingSpecific methods: - -bool -L2RoutingNetDevice::AttachProtocol(Ptr protocol) -{ - m_requestRoute = MakeCallback(&L2RoutingProtocol::RequestRoute, protocol); - m_myResponse = MakeCallback(&L2RoutingNetDevice::ProtocolResponse, this); - protocol->SetIfIndex(m_ifIndex); - return protocol->AttachPorts(m_ports); -} - -void -L2RoutingNetDevice::ProtocolResponse( - bool success, - Ptr packet, - Mac48Address src, - Mac48Address dst, - uint16_t protocol, - uint32_t outPort -) -{ - if (!success) - { - NS_LOG_UNCOND("Resolve failed"); - //TODO: SendError callback - return; - } - //just do sendFrom! - if (outPort!=0xffffffff) - GetPort(outPort)->SendFrom(packet, src, dst, protocol); - else - for (std::vector >::iterator i = m_ports.begin(); i != m_ports.end(); i++) - (*i) -> SendFrom(packet, src, dst, protocol); -} - -} // namespace ns3 diff --git a/src/devices/mesh/mesh-point-device.cc b/src/devices/mesh/mesh-point-device.cc new file mode 100644 index 000000000..bede6e232 --- /dev/null +++ b/src/devices/mesh/mesh-point-device.cc @@ -0,0 +1,357 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2008,2009 IITP RAS + * + * 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: Kirill Andreev + */ + + +#include "ns3/node.h" +#include "ns3/channel.h" +#include "ns3/packet.h" +#include "ns3/log.h" +#include "ns3/boolean.h" +#include "ns3/simulator.h" +#include "ns3/l2-routing-net-device.h" + +NS_LOG_COMPONENT_DEFINE ("MeshPointDevice"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MeshPointDevice); + +TypeId +MeshPointDevice::GetTypeId () +{ + static TypeId tid = TypeId ("ns3::MeshPointDevice") + .SetParent () + .AddConstructor () + ; + // TODO Add station-level attributes here + return tid; +} + +MeshPointDevice::MeshPointDevice () : m_ifIndex(0), m_mtu(1500) +{ + NS_LOG_FUNCTION_NOARGS (); + m_channel = CreateObject (); +} + +MeshPointDevice::~MeshPointDevice() +{ + NS_LOG_FUNCTION_NOARGS (); +} + +void +MeshPointDevice::DoDispose () +{ + NS_LOG_FUNCTION_NOARGS (); + for (std::vector< Ptr >::iterator iter = m_ifaces.begin (); iter != m_ifaces.end (); iter++) + *iter = 0; + m_ifaces.clear (); + m_node = 0; + NetDevice::DoDispose (); + +} + +//----------------------------------------------------------------------------- +// NetDevice interface implementation +//----------------------------------------------------------------------------- + +void +MeshPointDevice::ReceiveFromDevice (Ptr incomingPort, Ptr packet, uint16_t protocol, + Address const &src, Address const &dst, PacketType packetType) +{ + NS_LOG_FUNCTION_NOARGS (); + NS_LOG_DEBUG ("UID is " << packet->GetUid ()); + const Mac48Address src48 = Mac48Address::ConvertFrom (src); + const Mac48Address dst48 = Mac48Address::ConvertFrom (dst); + if (!m_promiscRxCallback.IsNull ()) + m_promiscRxCallback (this, packet, protocol, src, dst, packetType); + switch (packetType) + { + case PACKET_HOST: + if (dst48 == m_address) + m_rxCallback (this, packet, protocol, src); + break; + case PACKET_BROADCAST: + case PACKET_MULTICAST: + m_rxCallback (this, packet, protocol, src); + case PACKET_OTHERHOST: + Forward (incomingPort, packet->Copy(), protocol, src48, dst48); + break; + } +} + +void +MeshPointDevice::Forward (Ptr inport, Ptr packet, + uint16_t protocol, const Mac48Address src, const Mac48Address dst) +{ + // pass through routing protocol + m_requestRoute(inport->GetIfIndex(), src, dst, packet, protocol, m_myResponse); +} + +void +MeshPointDevice::SetName(const std::string name) +{ + NS_LOG_FUNCTION_NOARGS (); + m_name = name; +} + +std::string +MeshPointDevice::GetName() const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_name; +} + +void +MeshPointDevice::SetIfIndex(const uint32_t index) +{ + NS_LOG_FUNCTION_NOARGS (); + m_ifIndex = index; +} + +uint32_t +MeshPointDevice::GetIfIndex() const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_ifIndex; +} + +Ptr +MeshPointDevice::GetChannel () const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_channel; +} + +Address +MeshPointDevice::GetAddress () const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_address; +} + +bool +MeshPointDevice::SetMtu (const uint16_t mtu) +{ + NS_LOG_FUNCTION_NOARGS (); + m_mtu = mtu; + return true; +} + +uint16_t +MeshPointDevice::GetMtu () const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_mtu; +} + +bool +MeshPointDevice::IsLinkUp () const +{ + NS_LOG_FUNCTION_NOARGS (); + return true; +} + +void +MeshPointDevice::SetLinkChangeCallback (Callback callback) +{ + // do nothing +} + +bool +MeshPointDevice::IsBroadcast () const +{ + NS_LOG_FUNCTION_NOARGS (); + return true; +} + +Address +MeshPointDevice::GetBroadcast () const +{ + NS_LOG_FUNCTION_NOARGS (); + return Mac48Address ("ff:ff:ff:ff:ff:ff"); +} + +bool +MeshPointDevice::IsMulticast () const +{ + NS_LOG_FUNCTION_NOARGS (); + return true; +} + +Address +MeshPointDevice::GetMulticast (Ipv4Address multicastGroup) const +{ + NS_LOG_FUNCTION (this << multicastGroup); + Mac48Address multicast = Mac48Address::GetMulticast (multicastGroup); + return multicast; +} + +bool +MeshPointDevice::IsPointToPoint () const +{ + NS_LOG_FUNCTION_NOARGS (); + return false; +} + +bool +MeshPointDevice::IsBridge () const +{ + NS_LOG_FUNCTION_NOARGS (); + return false; +} + + +bool +MeshPointDevice::Send (Ptr packet, const Address& dest, uint16_t protocolNumber) +{ + const Mac48Address dst48 = Mac48Address::ConvertFrom (dest); + return m_requestRoute(m_ifIndex, m_address, dst48, packet, protocolNumber, m_myResponse); +} + +bool +MeshPointDevice::SendFrom (Ptr packet, const Address& src, const Address& dest, uint16_t protocolNumber) +{ + const Mac48Address src48 = Mac48Address::ConvertFrom (src); + const Mac48Address dst48 = Mac48Address::ConvertFrom (dest); + return m_requestRoute(m_ifIndex, src48, dst48, packet, protocolNumber, m_myResponse); +} + +Ptr +MeshPointDevice::GetNode () const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_node; +} + +void +MeshPointDevice::SetNode (Ptr node) +{ + NS_LOG_FUNCTION_NOARGS (); + m_node = node; +} + +bool +MeshPointDevice::NeedsArp () const +{ + NS_LOG_FUNCTION_NOARGS (); + return true; +} + +void +MeshPointDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) +{ + NS_LOG_FUNCTION_NOARGS (); + m_rxCallback = cb; +} + +void +MeshPointDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb) +{ + NS_LOG_FUNCTION_NOARGS (); + m_promiscRxCallback = cb; +} + +bool +MeshPointDevice::SupportsSendFrom () const +{ + NS_LOG_FUNCTION_NOARGS (); + return true; +} + +Address +MeshPointDevice::GetMulticast (Ipv6Address addr) const +{ + NS_LOG_FUNCTION (this << addr); + return Mac48Address::GetMulticast (addr); +} + +//----------------------------------------------------------------------------- +// Interfaces +//----------------------------------------------------------------------------- +uint32_t +MeshPointDevice::GetNInterfaces () const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_ifaces.size (); +} + +Ptr +MeshPointDevice::GetInterface (uint32_t n) const +{ + NS_ASSERT(m_ifaces.size () > n); + return m_ifaces[n]; +} + +void +MeshPointDevice::AddInterface (Ptr iface) +{ + NS_LOG_FUNCTION_NOARGS (); + + NS_ASSERT (iface != this); + if (!Mac48Address::IsMatchingType (iface->GetAddress ())) + NS_FATAL_ERROR ("Device does not support eui 48 addresses: cannot be added to bridge."); + if (!iface->SupportsSendFrom ()) + NS_FATAL_ERROR ("Device does not support SendFrom: cannot be added to bridge."); + m_address = Mac48Address::ConvertFrom (iface->GetAddress ()); + + NS_LOG_DEBUG ("RegisterProtocolHandler for " << iface->GetName ()); + m_node->RegisterProtocolHandler (MakeCallback (&MeshPointDevice::ReceiveFromDevice, this), + 0, iface, /*promiscuous = */true); + + m_ifaces.push_back (iface); + m_channel->AddChannel (iface->GetChannel ()); +} + +//----------------------------------------------------------------------------- +// Protocols +//----------------------------------------------------------------------------- + +bool +MeshPointDevice::SetRoutingProtocol(Ptr protocol) +{ + NS_LOG_FUNCTION_NOARGS (); + + m_requestRoute = MakeCallback(&L2RoutingProtocol::RequestRoute, protocol); + m_myResponse = MakeCallback(&MeshPointDevice::DoSend, this); + protocol->SetIfIndex(m_ifIndex); + // TODO don't install protocol on ifaces here, this must be done separately. Just set callbacks. + return protocol->AttachPorts(m_ifaces); +} + +void +MeshPointDevice::DoSend(bool success, Ptr packet, Mac48Address src, Mac48Address dst, uint16_t protocol, uint32_t outIface) +{ + if (!success) + { + NS_LOG_UNCOND("Resolve failed"); + //TODO: SendError callback + return; + } + + // Ok, now I know the route, just SendFrom + + if (outIface != 0xffffffff) + GetInterface(outIface)->SendFrom(packet, src, dst, protocol); + else + for (std::vector >::iterator i = m_ifaces.begin(); i != m_ifaces.end(); i++) + (*i) -> SendFrom(packet, src, dst, protocol); +} + +} // namespace ns3 diff --git a/src/devices/mesh/l2-routing-net-device.h b/src/devices/mesh/mesh-point-device.h similarity index 54% rename from src/devices/mesh/l2-routing-net-device.h rename to src/devices/mesh/mesh-point-device.h index 768ab3dcc..21292032f 100644 --- a/src/devices/mesh/l2-routing-net-device.h +++ b/src/devices/mesh/mesh-point-device.h @@ -30,53 +30,63 @@ #include "ns3/l2-routing-protocol.h" namespace ns3 { + class Node; /** * \ingroup mesh * - * \brief a virtual net device that may forward packets - * between real network devices using routing protocols of - * MAC-layer + * \brief Virtual net device modeling mesh point. * - * \details This is a virtual netdevice, which aggreagates - * real netdevices and uses interface of L2RoutingProtocol to - * forward packets + * Mesh point is a virtual net device which is responsible for + * - Aggreagating and coordinating 1..* real devices -- mesh interfaces, see MeshInterfaceDevice class. + * - Hosting all mesh-related level 2 protocols. + * + * One of hosted L2 protocols must inplement L2RoutingProtocol interface and is used for packets forwarding. * - * \attention The idea of L2RoutingNetDevice is similar to - * BridgeNetDevice, but the packets, which going through - * L2RoutingNetDevice may be changed (because routing protocol - * may require its own headers or tags). + * From the level 3 point of view MeshPointDevice is similar to BridgeNetDevice, but the packets, + * which going through may be changed (because L2 protocols may require their own headers or tags). + * + * Attributes: TODO */ -class L2RoutingNetDevice : public NetDevice +class MeshPointDevice : public NetDevice { public: + /// Object type ID for NS3 object system static TypeId GetTypeId (); - L2RoutingNetDevice (); - virtual ~L2RoutingNetDevice (); + /// C-tor create empty (without interfaces and protocols) mesh point + MeshPointDevice (); + /// D-tor + virtual ~MeshPointDevice (); + + ///\name Interfaces + //\{ /** - * \brief Attaches a 'port' to a virtual - * L2RoutingNetDevice, and this port is handled - * by L2RoutingProtocol. - * \attention Like in a bridge, - * L2RoutingNetDevice's ports must not have IP - * addresses, and only L2RoutingNetDevice - * itself may have an IP address. - * - * \attention L2RoutingNetDevice may be a port - * of BridgeNetDevice. + * Attach new interface to the station. Interface must support 48-bit MAC address and SendFrom method. + * + * \attention Only MeshPointDevice can have IP address, but not individual interfaces. */ - void AddPort (Ptr port); + void AddInterface (Ptr port); /** - * \returns number of ports attached to - * L2RoutingNetDevice + * \return number of interfaces */ - uint32_t GetNPorts () const; + uint32_t GetNInterfaces () const; /** - * \returns a pointer to netdevice - * \param n is device ID to be returned + * \return interface device by its index (aka ID) + * \param id is interface id, 0 <= id < GetNInterfaces */ - Ptr GetPort (uint32_t n) const; - //inherited from netdevice: + Ptr GetInterface (uint32_t id) const; + //\} + + ///\name Protocols + //\{ + /** + * Register routing protocol to be used \return true on success + */ + virtual bool SetRoutingProtocol(Ptr protocol); + //\} + + ///\name NetDevice interface for upper layers + //\{ virtual void SetName(const std::string name); virtual std::string GetName() const; virtual void SetIfIndex(const uint32_t index); @@ -103,48 +113,48 @@ public: virtual bool SupportsSendFrom () const; virtual Address GetMulticast (Ipv6Address addr) const; virtual void DoDispose (); - /** - * \brief Attaches protocol to a given virtual - * device - * \returns true if success - */ - virtual bool AttachProtocol(Ptr protocol); -protected: - /** - * \brief This is similar to BridgeNetDevice - * method - */ + //\} + +private: + /// Receive packet from interface void ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType); - /** - * \brief This is similar to BridgeNetDevice - * method - */ + /// Forward packet down to interfaces void Forward (Ptr incomingPort, Ptr packet, uint16_t protocol, const Mac48Address src, const Mac48Address dst); /** - * \brief This is a function, which should be - * passed to L2RoutingProtocol as response - * callback (see L2RoutingProtocol). + * Response callback for L2 routing protocol. This will be executed when routing information is ready. + * + * \param success True is route found. TODO: diagnose routing errors + * \param packet Packet to send + * \param src Source MAC address + * \param dst Destination MAC address + * \param protocol Protocol ID + * \param outIface Interface to use (ID) for send (decided by routing protocol). All interfaces will be used if outIface = 0xffffffff */ - virtual void ProtocolResponse( - bool success, - Ptr, - Mac48Address src, - Mac48Address dst, - uint16_t protocol, - uint32_t outPort - ); + virtual void DoSend(bool success, Ptr packet, Mac48Address src, Mac48Address dst, uint16_t protocol, uint32_t iface); + private: + /// Receive action NetDevice::ReceiveCallback m_rxCallback; + /// Promisc receive action NetDevice::PromiscReceiveCallback m_promiscRxCallback; + /// Mesh point MAC address, supposed to be the address of the first added interface Mac48Address m_address; + /// Parent node Ptr m_node; + /// Station name std::string m_name; - std::vector< Ptr > m_ports; + /// List of interfaces + std::vector< Ptr > m_ifaces; + /// If index uint32_t m_ifIndex; + /// MTU in bytes uint16_t m_mtu; - Ptr m_channel; + /// Virtual channel for upper layers + Ptr m_channel; + + /// Routing request callback Callback, uint16_t, L2RoutingProtocol::RouteReplyCallback> m_requestRoute; - //What we give to L2Routing + + /// Routing response callback, this is supplied to mesh routing protocol L2RoutingProtocol::RouteReplyCallback m_myResponse; }; } //namespace ns3 diff --git a/src/devices/mesh/mesh-wifi-helper.cc b/src/devices/mesh/mesh-wifi-helper.cc index b7f3f1cfc..5de2964ab 100644 --- a/src/devices/mesh/mesh-wifi-helper.cc +++ b/src/devices/mesh/mesh-wifi-helper.cc @@ -172,12 +172,12 @@ MeshWifiHelper::SetPeerLinkManager (std::string type, NetDeviceContainer MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c, uint8_t numOfPorts) const - { +{ NetDeviceContainer devices; for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr node = *i; - Ptr virtualDevice = m_deviceFactory.Create (); + Ptr virtualDevice = m_deviceFactory.Create (); Ptr pPeer = m_peerManager.Create (); devices.Add (virtualDevice); std::vector > nodeDevices; @@ -197,21 +197,21 @@ MeshWifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c, uint8_ } node -> AddDevice(virtualDevice); for (std::vector > ::iterator iter=nodeDevices.begin();iter!=nodeDevices.end(); ++iter) - virtualDevice->AddPort(*iter); + virtualDevice->AddInterface(*iter); // nodeDevice.pop_back() pPeer->AttachPorts(nodeDevices); Ptr routingProtocol = m_routingProtocol.Create (); - virtualDevice->AttachProtocol(routingProtocol); + virtualDevice->SetRoutingProtocol(routingProtocol); //hwmp->SetRoot(device->GetIfIndex(), Seconds(5)); nodeDevices.clear(); } return devices; - } +} NetDeviceContainer MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr node, uint8_t numOfPorts) const - { - return Install (phy, NodeContainer (node), numOfPorts); - } +{ + return Install (phy, NodeContainer (node), numOfPorts); +} } //namespace ns3 diff --git a/src/devices/mesh/mesh-wifi-helper.h b/src/devices/mesh/mesh-wifi-helper.h index 4b27fb322..bf09196c4 100644 --- a/src/devices/mesh/mesh-wifi-helper.h +++ b/src/devices/mesh/mesh-wifi-helper.h @@ -30,8 +30,13 @@ #include "ns3/wifi-helper.h" namespace ns3 { + class WifiChannel; +/** + * \ingroup mesh + * + */ class MeshWifiHelper { public: diff --git a/src/devices/mesh/wscript b/src/devices/mesh/wscript index 294bd58b0..c6d99bdb8 100644 --- a/src/devices/mesh/wscript +++ b/src/devices/mesh/wscript @@ -7,7 +7,6 @@ def build(bld): 'mesh-wifi-mac-header.cc', 'mesh-wifi-peer-manager.cc', 'tx-statistics.cc', - 'hwmp-helper.cc', 'l2-routing-protocol.cc', 'mesh-wifi-beacon-timing-element.cc', 'hwmp-rtable.cc', @@ -38,7 +37,6 @@ def build(bld): 'hwmp.h', 'tx-statistics.h', 'dot11s-peer-management-element.h', - 'hwmp-helper.h', 'mac48-address-comparator.h', 'mesh-wifi-preq-information-element.h', 'hwmp-rtable.h',