From ca2fef3bd87d54394e891f8bbbfa98355a88b914 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 24 Jul 2008 11:41:15 +0100 Subject: [PATCH] Make the new NetDevice APIs pure virtual methods, by Mathieu's insistence. --- RELEASE_NOTES | 4 +++- bindings/python/ns3_module_node.py | 16 +++++++++++--- bindings/python/ns3_module_point_to_point.py | 10 +++++++++ bindings/python/ns3_module_simulator.py | 8 +++---- bindings/python/ns3_module_wifi.py | 15 +++++++++++++ .../point-to-point-net-device.cc | 12 +++++++++++ .../point-to-point-net-device.h | 3 +++ src/devices/wifi/wifi-net-device.cc | 19 +++++++++++++++++ src/devices/wifi/wifi-net-device.h | 4 ++++ src/node/net-device.cc | 21 ------------------- src/node/net-device.h | 6 +++--- src/node/simple-net-device.cc | 11 ++++++++++ src/node/simple-net-device.h | 2 ++ 13 files changed, 99 insertions(+), 32 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 7c4ce5cb1..f6dd3c125 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -36,7 +36,9 @@ API changes from 3.1 to 3.2 - remove references to Parameter in helper APIs (changeset 3cdd9d60f7c7, bug 232); old variants are currently deprecated API and will be removed in a future release -- New NetDevice APIs: SendFrom and SetPromiscRxCallback; +- New NetDevice APIs: SendFrom, SetPromiscRxCallback, + SupportsPromiscuous. These are pure virtual methods, so they need + to be implemented by NetDevice subclasses; In order to support the learning bridge, some API changes in Node and NetDevice were made. diff --git a/bindings/python/ns3_module_node.py b/bindings/python/ns3_module_node.py index 5d3741594..bb904c61f 100644 --- a/bindings/python/ns3_module_node.py +++ b/bindings/python/ns3_module_node.py @@ -1538,7 +1538,7 @@ def register_Ns3NetDevice_methods(root_module, cls): cls.add_method('SendFrom', 'bool', [param('ns3::Ptr< ns3::Packet >', 'packet'), param('ns3::Address&', 'source', is_const=True), param('ns3::Address&', 'dest', is_const=True), param('uint16_t', 'protocolNumber')], - is_virtual=True) + is_pure_virtual=True, is_virtual=True) ## net-device.h: ns3::Ptr ns3::NetDevice::GetNode() const [member function] cls.add_method('GetNode', 'ns3::Ptr< ns3::Node >', @@ -1563,12 +1563,12 @@ def register_Ns3NetDevice_methods(root_module, cls): cls.add_method('SetPromiscReceiveCallback', 'void', [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType >', 'cb')], - is_virtual=True) + is_pure_virtual=True, is_virtual=True) ## net-device.h: bool ns3::NetDevice::SupportsPromiscuous() const [member function] cls.add_method('SupportsPromiscuous', 'bool', [], - is_const=True, is_virtual=True) + is_pure_virtual=True, is_const=True, is_virtual=True) cls.add_constructor([]) return @@ -2444,6 +2444,16 @@ def register_Ns3SimpleNetDevice_methods(root_module, cls): 'void', [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::empty, ns3::empty >', 'cb')], is_virtual=True) + ## simple-net-device.h: void ns3::SimpleNetDevice::SetPromiscReceiveCallback(ns3::Callback, ns3::Ptr, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType> cb) [member function] + cls.add_method('SetPromiscReceiveCallback', + 'void', + [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType >', 'cb')], + is_virtual=True) + ## simple-net-device.h: bool ns3::SimpleNetDevice::SupportsPromiscuous() const [member function] + cls.add_method('SupportsPromiscuous', + 'bool', + [], + is_const=True, is_virtual=True) ## simple-net-device.h: void ns3::SimpleNetDevice::DoDispose() [member function] cls.add_method('DoDispose', 'void', diff --git a/bindings/python/ns3_module_point_to_point.py b/bindings/python/ns3_module_point_to_point.py index f83aa39ae..4d7cf9ff0 100644 --- a/bindings/python/ns3_module_point_to_point.py +++ b/bindings/python/ns3_module_point_to_point.py @@ -232,6 +232,16 @@ def register_Ns3PointToPointNetDevice_methods(root_module, cls): 'void', [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::empty, ns3::empty >', 'cb')], is_virtual=True) + ## point-to-point-net-device.h: void ns3::PointToPointNetDevice::SetPromiscReceiveCallback(ns3::Callback, ns3::Ptr, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType> cb) [member function] + cls.add_method('SetPromiscReceiveCallback', + 'void', + [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType >', 'cb')], + is_virtual=True) + ## point-to-point-net-device.h: bool ns3::PointToPointNetDevice::SupportsPromiscuous() const [member function] + cls.add_method('SupportsPromiscuous', + 'bool', + [], + is_const=True, is_virtual=True) ## point-to-point-net-device.h: void ns3::PointToPointNetDevice::DoDispose() [member function] cls.add_method('DoDispose', 'void', diff --git a/bindings/python/ns3_module_simulator.py b/bindings/python/ns3_module_simulator.py index 923df6ad4..badde30a5 100644 --- a/bindings/python/ns3_module_simulator.py +++ b/bindings/python/ns3_module_simulator.py @@ -333,10 +333,10 @@ def register_Ns3Watchdog_methods(root_module, cls): def register_Ns3Simulator_methods(root_module, cls): ## simulator.h: static void ns3::Simulator::SetImplementation(ns3::Ptr impl) [member function] - #cls.add_method('SetImplementation', - # 'void', - # [param('ns3::Ptr< ns3::SimulatorImpl >', 'impl')], - # is_static=True) + cls.add_method('SetImplementation', + 'void', + [param('ns3::Ptr< ns3::SimulatorImpl >', 'impl')], + is_static=True) ## simulator.h: static void ns3::Simulator::SetScheduler(ns3::Ptr scheduler) [member function] cls.add_method('SetScheduler', 'void', diff --git a/bindings/python/ns3_module_wifi.py b/bindings/python/ns3_module_wifi.py index 6ba85ee09..339e4cdc0 100644 --- a/bindings/python/ns3_module_wifi.py +++ b/bindings/python/ns3_module_wifi.py @@ -2155,6 +2155,21 @@ def register_Ns3WifiNetDevice_methods(root_module, cls): 'void', [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::empty, ns3::empty >', 'cb')], is_virtual=True) + ## wifi-net-device.h: bool ns3::WifiNetDevice::SendFrom(ns3::Ptr packet, ns3::Address const & source, ns3::Address const & dest, uint16_t protocolNumber) [member function] + cls.add_method('SendFrom', + 'bool', + [param('ns3::Ptr< ns3::Packet >', 'packet'), param('ns3::Address&', 'source', is_const=True), param('ns3::Address&', 'dest', is_const=True), param('uint16_t', 'protocolNumber')], + is_virtual=True) + ## wifi-net-device.h: void ns3::WifiNetDevice::SetPromiscReceiveCallback(ns3::Callback, ns3::Ptr, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType> cb) [member function] + cls.add_method('SetPromiscReceiveCallback', + 'void', + [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet >, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType >', 'cb')], + is_virtual=True) + ## wifi-net-device.h: bool ns3::WifiNetDevice::SupportsPromiscuous() const [member function] + cls.add_method('SupportsPromiscuous', + 'bool', + [], + is_const=True, is_virtual=True) ## wifi-net-device.h: void ns3::WifiNetDevice::DoDispose() [member function] cls.add_method('DoDispose', 'void', diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index b2953d070..d7fa004e2 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -467,4 +467,16 @@ PointToPointNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) m_rxCallback = cb; } + void +PointToPointNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) +{ + NS_FATAL_ERROR ("not implemented"); +} + + bool +PointToPointNetDevice::SupportsPromiscuous (void) const +{ + return false; +} + } // namespace ns3 diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index 352050ec4..e5694e750 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -177,6 +177,9 @@ public: virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); + virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); + virtual bool SupportsPromiscuous (void) const; + private: virtual void DoDispose (void); diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index f3bcad80d..7f2848540 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -332,5 +332,24 @@ WifiNetDevice::LinkDown (void) } } +bool +WifiNetDevice::SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) +{ + NS_FATAL_ERROR ("TODO"); + return false; +} + +void +WifiNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) +{ + NS_FATAL_ERROR ("TODO"); +} + +bool +WifiNetDevice::SupportsPromiscuous (void) const +{ + return false; // TODO +} + } // namespace ns3 diff --git a/src/devices/wifi/wifi-net-device.h b/src/devices/wifi/wifi-net-device.h index 08867ae89..690bb8ad5 100644 --- a/src/devices/wifi/wifi-net-device.h +++ b/src/devices/wifi/wifi-net-device.h @@ -101,6 +101,10 @@ public: virtual bool NeedsArp (void) const; virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); + virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); + virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); + virtual bool SupportsPromiscuous (void) const; + private: virtual void DoDispose (void); void ForwardUp (Ptr packet, const Mac48Address &from); diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 048fb1fe2..410cc3f49 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -38,25 +38,4 @@ TypeId NetDevice::GetTypeId (void) NetDevice::~NetDevice () {} -bool -NetDevice::SupportsPromiscuous () const -{ - return false; -} - -void -NetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) -{ - // assert that the virtual method was overridden in a subclass if it - // claims to support promiscuous mode. - NS_ASSERT (!SupportsPromiscuous ()); -} - -bool -NetDevice::SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) -{ - NS_FATAL_ERROR ("NetDevice::SendFrom not implemented for " << GetInstanceTypeId ().GetName ()); - return false; -} - } // namespace ns3 diff --git a/src/node/net-device.h b/src/node/net-device.h index c718013c9..b8f799ed3 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -228,7 +228,7 @@ public: * * \return whether the Send operation succeeded */ - virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); + virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0; /** * \returns the node base class which contains this network * interface. @@ -309,12 +309,12 @@ public: * sensed by the netdevice but which are intended to be received by * other hosts. */ - virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); + virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb) = 0; /** * \return true if this interface supports a promiscuous mode, false otherwise. */ - virtual bool SupportsPromiscuous (void) const; + virtual bool SupportsPromiscuous (void) const = 0; }; diff --git a/src/node/simple-net-device.cc b/src/node/simple-net-device.cc index 8f1b0d718..481306da7 100644 --- a/src/node/simple-net-device.cc +++ b/src/node/simple-net-device.cc @@ -200,5 +200,16 @@ SimpleNetDevice::DoDispose (void) } +void +SimpleNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) +{ + NS_FATAL_ERROR ("Not supported"); +} + +bool +SimpleNetDevice::SupportsPromiscuous (void) const +{ + return false; +} } // namespace ns3 diff --git a/src/node/simple-net-device.h b/src/node/simple-net-device.h index ac77c5cc5..cd441021f 100644 --- a/src/node/simple-net-device.h +++ b/src/node/simple-net-device.h @@ -68,6 +68,8 @@ public: virtual void SetNode (Ptr node); virtual bool NeedsArp (void) const; virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); + virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); + virtual bool SupportsPromiscuous (void) const; protected: virtual void DoDispose (void);