--- a/src/devices/mesh/hwmp-helper.cc Mon Mar 16 15:45:37 2009 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 <andreev@iitp.ru>
- */
-
-
--- a/src/devices/mesh/hwmp-helper.h Mon Mar 16 15:45:37 2009 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 <andreev@iitp.ru>
- */
-
-
--- a/src/devices/mesh/l2-routing-net-device.cc Mon Mar 16 15:45:37 2009 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 <andreev@iitp.ru>
- */
-
-
-#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<NetDevice> ()
- .AddConstructor<L2RoutingNetDevice> ()
- ;
- return tid;
-}
-
-
-L2RoutingNetDevice::L2RoutingNetDevice ()
-{
- NS_LOG_FUNCTION_NOARGS ();
- m_channel = CreateObject<BridgeChannel> ();
-}
-
-L2RoutingNetDevice::~L2RoutingNetDevice()
-{
- NS_LOG_FUNCTION_NOARGS ();
-}
-
-void
-L2RoutingNetDevice::DoDispose ()
-{
- NS_LOG_FUNCTION_NOARGS ();
- for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin (); iter != m_ports.end (); iter++)
- *iter = 0;
- m_ports.clear ();
- m_node = 0;
- NetDevice::DoDispose ();
-
-}
-
-void
-L2RoutingNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Packet> 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<NetDevice> inport, Ptr<Packet> 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<NetDevice>
-L2RoutingNetDevice::GetPort (uint32_t n) const
- {
- NS_ASSERT(m_ports.size () > n);
- return m_ports[n];
- }
-
-void
-L2RoutingNetDevice::AddPort (Ptr<NetDevice> 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<Channel>
-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<void> 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> 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> 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<Node>
-L2RoutingNetDevice::GetNode () const
- {
- NS_LOG_FUNCTION_NOARGS ();
- return m_node;
- }
-
-
-void
-L2RoutingNetDevice::SetNode (Ptr<Node> 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<L2RoutingProtocol> 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> 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<Ptr<NetDevice> >::iterator i = m_ports.begin(); i != m_ports.end(); i++)
- (*i) -> SendFrom(packet, src, dst, protocol);
-}
-
-} // namespace ns3
--- a/src/devices/mesh/l2-routing-net-device.h Mon Mar 16 15:45:37 2009 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +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 <andreev@iitp.ru>
- */
-
-
-#ifndef L2ROUTING_NET_DEVICE_H
-#define L2ROUTING_NET_DEVICE_H
-
-#include "ns3/net-device.h"
-#include "ns3/mac48-address.h"
-#include "ns3/nstime.h"
-#include "ns3/bridge-net-device.h"
-#include "ns3/bridge-channel.h"
-#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
- *
- * \details This is a virtual netdevice, which aggreagates
- * real netdevices and uses interface of L2RoutingProtocol to
- * forward packets
- *
- * \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).
- */
-class L2RoutingNetDevice : public NetDevice
-{
-public:
- static TypeId GetTypeId ();
- L2RoutingNetDevice ();
- virtual ~L2RoutingNetDevice ();
- /**
- * \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.
- */
- void AddPort (Ptr<NetDevice> port);
- /**
- * \returns number of ports attached to
- * L2RoutingNetDevice
- */
- uint32_t GetNPorts () const;
- /**
- * \returns a pointer to netdevice
- * \param n is device ID to be returned
- */
- Ptr<NetDevice> GetPort (uint32_t n) const;
- //inherited from netdevice:
- virtual void SetName(const std::string name);
- virtual std::string GetName() const;
- virtual void SetIfIndex(const uint32_t index);
- virtual uint32_t GetIfIndex() const;
- virtual Ptr<Channel> GetChannel () const;
- virtual Address GetAddress () const;
- virtual bool SetMtu (const uint16_t mtu);
- virtual uint16_t GetMtu () const;
- virtual bool IsLinkUp () const;
- virtual void SetLinkChangeCallback (Callback<void> callback);
- virtual bool IsBroadcast () const;
- virtual Address GetBroadcast () const;
- virtual bool IsMulticast () const;
- virtual Address GetMulticast (Ipv4Address multicastGroup) const;
- virtual bool IsPointToPoint () const;
- virtual bool IsBridge () const;
- virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
- virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
- virtual Ptr<Node> GetNode () const;
- virtual void SetNode (Ptr<Node> node);
- virtual bool NeedsArp () const;
- virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
- virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb);
- 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<L2RoutingProtocol> protocol);
-protected:
- /**
- * \brief This is similar to BridgeNetDevice
- * method
- */
- void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
- Address const &source, Address const &destination, PacketType packetType);
- /**
- * \brief This is similar to BridgeNetDevice
- * method
- */
- void Forward (Ptr<NetDevice> incomingPort, Ptr<Packet> 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).
- */
- virtual void ProtocolResponse(
- bool success,
- Ptr<Packet>,
- Mac48Address src,
- Mac48Address dst,
- uint16_t protocol,
- uint32_t outPort
- );
-private:
- NetDevice::ReceiveCallback m_rxCallback;
- NetDevice::PromiscReceiveCallback m_promiscRxCallback;
- Mac48Address m_address;
- Ptr<Node> m_node;
- std::string m_name;
- std::vector< Ptr<NetDevice> > m_ports;
- uint32_t m_ifIndex;
- uint16_t m_mtu;
- Ptr<BridgeChannel> m_channel;
- Callback<bool,
- uint32_t,
- Mac48Address,
- Mac48Address,
- Ptr<Packet>,
- uint16_t,
- L2RoutingProtocol::RouteReplyCallback> m_requestRoute;
- //What we give to L2Routing
- L2RoutingProtocol::RouteReplyCallback m_myResponse;
-};
-} //namespace ns3
-#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/mesh-point-device.cc Mon Mar 16 17:59:33 2009 +0300
@@ -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 <andreev@iitp.ru>
+ */
+
+
+#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<NetDevice> ()
+ .AddConstructor<MeshPointDevice> ()
+ ;
+ // TODO Add station-level attributes here
+ return tid;
+}
+
+MeshPointDevice::MeshPointDevice () : m_ifIndex(0), m_mtu(1500)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_channel = CreateObject<BridgeChannel> ();
+}
+
+MeshPointDevice::~MeshPointDevice()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+void
+MeshPointDevice::DoDispose ()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ for (std::vector< Ptr<NetDevice> >::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<NetDevice> incomingPort, Ptr<const Packet> 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<NetDevice> inport, Ptr<Packet> 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<Channel>
+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<void> 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> 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> 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<Node>
+MeshPointDevice::GetNode () const
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ return m_node;
+}
+
+void
+MeshPointDevice::SetNode (Ptr<Node> 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<NetDevice>
+MeshPointDevice::GetInterface (uint32_t n) const
+{
+ NS_ASSERT(m_ifaces.size () > n);
+ return m_ifaces[n];
+}
+
+void
+MeshPointDevice::AddInterface (Ptr<NetDevice> 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<L2RoutingProtocol> 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> 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<Ptr<NetDevice> >::iterator i = m_ifaces.begin(); i != m_ifaces.end(); i++)
+ (*i) -> SendFrom(packet, src, dst, protocol);
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/mesh/mesh-point-device.h Mon Mar 16 17:59:33 2009 +0300
@@ -0,0 +1,170 @@
+/* -*- 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 <andreev@iitp.ru>
+ */
+
+
+#ifndef L2ROUTING_NET_DEVICE_H
+#define L2ROUTING_NET_DEVICE_H
+
+#include "ns3/net-device.h"
+#include "ns3/mac48-address.h"
+#include "ns3/nstime.h"
+#include "ns3/bridge-net-device.h"
+#include "ns3/bridge-channel.h"
+#include "ns3/l2-routing-protocol.h"
+
+namespace ns3 {
+
+class Node;
+/**
+ * \ingroup mesh
+ *
+ * \brief Virtual net device modeling mesh point.
+ *
+ * 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.
+ *
+ * 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 MeshPointDevice : public NetDevice
+{
+public:
+ /// Object type ID for NS3 object system
+ static TypeId GetTypeId ();
+ /// C-tor create empty (without interfaces and protocols) mesh point
+ MeshPointDevice ();
+ /// D-tor
+ virtual ~MeshPointDevice ();
+
+ ///\name Interfaces
+ //\{
+ /**
+ * 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 AddInterface (Ptr<NetDevice> port);
+ /**
+ * \return number of interfaces
+ */
+ uint32_t GetNInterfaces () const;
+ /**
+ * \return interface device by its index (aka ID)
+ * \param id is interface id, 0 <= id < GetNInterfaces
+ */
+ Ptr<NetDevice> GetInterface (uint32_t id) const;
+ //\}
+
+ ///\name Protocols
+ //\{
+ /**
+ * Register routing protocol to be used \return true on success
+ */
+ virtual bool SetRoutingProtocol(Ptr<L2RoutingProtocol> 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);
+ virtual uint32_t GetIfIndex() const;
+ virtual Ptr<Channel> GetChannel () const;
+ virtual Address GetAddress () const;
+ virtual bool SetMtu (const uint16_t mtu);
+ virtual uint16_t GetMtu () const;
+ virtual bool IsLinkUp () const;
+ virtual void SetLinkChangeCallback (Callback<void> callback);
+ virtual bool IsBroadcast () const;
+ virtual Address GetBroadcast () const;
+ virtual bool IsMulticast () const;
+ virtual Address GetMulticast (Ipv4Address multicastGroup) const;
+ virtual bool IsPointToPoint () const;
+ virtual bool IsBridge () const;
+ virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
+ virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
+ virtual Ptr<Node> GetNode () const;
+ virtual void SetNode (Ptr<Node> node);
+ virtual bool NeedsArp () const;
+ virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
+ virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb);
+ virtual bool SupportsSendFrom () const;
+ virtual Address GetMulticast (Ipv6Address addr) const;
+ virtual void DoDispose ();
+ //\}
+
+private:
+ /// Receive packet from interface
+ void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
+ Address const &source, Address const &destination, PacketType packetType);
+ /// Forward packet down to interfaces
+ void Forward (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
+ uint16_t protocol, const Mac48Address src, const Mac48Address dst);
+ /**
+ * 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 DoSend(bool success, Ptr<Packet> 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<Node> m_node;
+ /// Station name
+ std::string m_name;
+ /// List of interfaces
+ std::vector< Ptr<NetDevice> > m_ifaces;
+ /// If index
+ uint32_t m_ifIndex;
+ /// MTU in bytes
+ uint16_t m_mtu;
+ /// Virtual channel for upper layers
+ Ptr<BridgeChannel> m_channel;
+
+ /// Routing request callback
+ Callback<bool,
+ uint32_t,
+ Mac48Address,
+ Mac48Address,
+ Ptr<Packet>,
+ uint16_t,
+ L2RoutingProtocol::RouteReplyCallback> m_requestRoute;
+
+ /// Routing response callback, this is supplied to mesh routing protocol
+ L2RoutingProtocol::RouteReplyCallback m_myResponse;
+};
+} //namespace ns3
+#endif
--- a/src/devices/mesh/mesh-wifi-helper.cc Mon Mar 16 15:45:37 2009 +0300
+++ b/src/devices/mesh/mesh-wifi-helper.cc Mon Mar 16 17:59:33 2009 +0300
@@ -172,12 +172,12 @@
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> node = *i;
- Ptr<L2RoutingNetDevice> virtualDevice = m_deviceFactory.Create<L2RoutingNetDevice> ();
+ Ptr<MeshPointDevice> virtualDevice = m_deviceFactory.Create<MeshPointDevice> ();
Ptr<WifiPeerManager> pPeer = m_peerManager.Create<WifiPeerManager > ();
devices.Add (virtualDevice);
std::vector<Ptr<WifiNetDevice> > nodeDevices;
@@ -197,21 +197,21 @@
}
node -> AddDevice(virtualDevice);
for (std::vector<Ptr<WifiNetDevice> > ::iterator iter=nodeDevices.begin();iter!=nodeDevices.end(); ++iter)
- virtualDevice->AddPort(*iter);
+ virtualDevice->AddInterface(*iter);
// nodeDevice.pop_back()
pPeer->AttachPorts(nodeDevices);
Ptr<L2RoutingProtocol> routingProtocol = m_routingProtocol.Create <L2RoutingProtocol>();
- virtualDevice->AttachProtocol(routingProtocol);
+ virtualDevice->SetRoutingProtocol(routingProtocol);
//hwmp->SetRoot(device->GetIfIndex(), Seconds(5));
nodeDevices.clear();
}
return devices;
- }
+}
NetDeviceContainer
MeshWifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node, uint8_t numOfPorts) const
- {
- return Install (phy, NodeContainer (node), numOfPorts);
- }
+{
+ return Install (phy, NodeContainer (node), numOfPorts);
+}
} //namespace ns3
--- a/src/devices/mesh/mesh-wifi-helper.h Mon Mar 16 15:45:37 2009 +0300
+++ b/src/devices/mesh/mesh-wifi-helper.h Mon Mar 16 17:59:33 2009 +0300
@@ -30,8 +30,13 @@
#include "ns3/wifi-helper.h"
namespace ns3 {
+
class WifiChannel;
+/**
+ * \ingroup mesh
+ *
+ */
class MeshWifiHelper
{
public:
--- a/src/devices/mesh/wscript Mon Mar 16 15:45:37 2009 +0300
+++ b/src/devices/mesh/wscript Mon Mar 16 17:59:33 2009 +0300
@@ -7,7 +7,6 @@
'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 @@
'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',