--- a/CHANGES.html Fri Jun 19 12:38:01 2009 +0400
+++ b/CHANGES.html Fri Jun 19 12:58:35 2009 +0400
@@ -79,6 +79,12 @@
<h2>Changes to existing API:</h2>
<ul>
+<li><b>CreateObject changes</b>
+ <p>CreateObject is now able to construct objects with a non-default constructor.
+ If you used to pass attribute lists to CreateObject, you must now use CreateObjectWithAttributes.
+ </p>
+</li>
+
<li> <b>packet byte tags renaming</b>
<ul>
<li>Packet::AddTag to Packet::AddByteTag</li>
--- a/bindings/python/callbacks_list.py Fri Jun 19 12:38:01 2009 +0400
+++ b/bindings/python/callbacks_list.py Fri Jun 19 12:58:35 2009 +0400
@@ -1,5 +1,6 @@
callback_classes = [
['void', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
+ ['bool', 'ns3::Ptr<ns3::Packet>', 'ns3::Address const&', 'ns3::Address const&', 'unsigned short', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
['void', 'ns3::Ptr<ns3::Packet>', 'ns3::Mac48Address', 'ns3::Mac48Address', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
['void', 'ns3::Ptr<ns3::Socket>', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
['void', 'ns3::Ptr<ns3::Socket>', 'unsigned int', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty', 'ns3::empty'],
--- a/bindings/python/ns3_module_simulator.py Fri Jun 19 12:38:01 2009 +0400
+++ b/bindings/python/ns3_module_simulator.py Fri Jun 19 12:58:35 2009 +0400
@@ -836,11 +836,6 @@
'void',
[param('ns3::Ptr< ns3::Scheduler >', 'scheduler')],
is_pure_virtual=True, is_virtual=True)
- ## simulator-impl.h: ns3::Ptr<ns3::Scheduler> ns3::SimulatorImpl::GetScheduler() const [member function]
- cls.add_method('GetScheduler',
- 'ns3::Ptr< ns3::Scheduler >',
- [],
- is_pure_virtual=True, is_const=True, is_virtual=True)
return
def register_Ns3Synchronizer_methods(root_module, cls):
@@ -1205,11 +1200,6 @@
'void',
[param('ns3::Ptr< ns3::Scheduler >', 'scheduler')],
is_virtual=True)
- ## default-simulator-impl.h: ns3::Ptr<ns3::Scheduler> ns3::DefaultSimulatorImpl::GetScheduler() const [member function]
- cls.add_method('GetScheduler',
- 'ns3::Ptr< ns3::Scheduler >',
- [],
- is_const=True, is_virtual=True)
return
def register_Ns3HeapScheduler_methods(root_module, cls):
@@ -1450,11 +1440,6 @@
'void',
[param('ns3::Ptr< ns3::Scheduler >', 'scheduler')],
is_virtual=True)
- ## realtime-simulator-impl.h: ns3::Ptr<ns3::Scheduler> ns3::RealtimeSimulatorImpl::GetScheduler() const [member function]
- cls.add_method('GetScheduler',
- 'ns3::Ptr< ns3::Scheduler >',
- [],
- is_const=True, is_virtual=True)
## realtime-simulator-impl.h: void ns3::RealtimeSimulatorImpl::ScheduleRealtime(ns3::Time const & time, ns3::EventImpl * event) [member function]
cls.add_method('ScheduleRealtime',
'void',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/python/ns3_module_virtual_net_device.py Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,242 @@
+from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers
+
+def register_types(module):
+ root_module = module.get_root()
+
+ ## virtual-net-device.h: ns3::VirtualNetDevice [class]
+ module.add_class('VirtualNetDevice', parent=root_module['ns3::NetDevice'])
+
+ ## Register a nested module for the namespace Config
+
+ nested_module = module.add_cpp_namespace('Config')
+ register_types_ns3_Config(nested_module)
+
+
+ ## Register a nested module for the namespace TimeStepPrecision
+
+ nested_module = module.add_cpp_namespace('TimeStepPrecision')
+ register_types_ns3_TimeStepPrecision(nested_module)
+
+
+ ## Register a nested module for the namespace addressUtils
+
+ nested_module = module.add_cpp_namespace('addressUtils')
+ register_types_ns3_addressUtils(nested_module)
+
+
+ ## Register a nested module for the namespace internal
+
+ nested_module = module.add_cpp_namespace('internal')
+ register_types_ns3_internal(nested_module)
+
+
+ ## Register a nested module for the namespace olsr
+
+ nested_module = module.add_cpp_namespace('olsr')
+ register_types_ns3_olsr(nested_module)
+
+
+def register_types_ns3_Config(module):
+ root_module = module.get_root()
+
+
+def register_types_ns3_TimeStepPrecision(module):
+ root_module = module.get_root()
+
+
+def register_types_ns3_addressUtils(module):
+ root_module = module.get_root()
+
+
+def register_types_ns3_internal(module):
+ root_module = module.get_root()
+
+
+def register_types_ns3_olsr(module):
+ root_module = module.get_root()
+
+
+def register_methods(root_module):
+ register_Ns3VirtualNetDevice_methods(root_module, root_module['ns3::VirtualNetDevice'])
+ return
+
+def register_Ns3VirtualNetDevice_methods(root_module, cls):
+ ## virtual-net-device.h: ns3::VirtualNetDevice::VirtualNetDevice(ns3::VirtualNetDevice const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::VirtualNetDevice const &', 'arg0')])
+ ## virtual-net-device.h: static ns3::TypeId ns3::VirtualNetDevice::GetTypeId() [member function]
+ cls.add_method('GetTypeId',
+ 'ns3::TypeId',
+ [],
+ is_static=True)
+ ## virtual-net-device.h: ns3::VirtualNetDevice::VirtualNetDevice() [constructor]
+ cls.add_constructor([])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetSendCallback(ns3::Callback<bool, ns3::Ptr<ns3::Packet>, ns3::Address const&, ns3::Address const&, unsigned short, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty> transmitCb) [member function]
+ cls.add_method('SetSendCallback',
+ 'void',
+ [param('ns3::Callback< bool, ns3::Ptr< ns3::Packet >, ns3::Address const &, ns3::Address const &, unsigned short, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'transmitCb')])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetNeedsArp(bool needsArp) [member function]
+ cls.add_method('SetNeedsArp',
+ 'void',
+ [param('bool', 'needsArp')])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetIsPointToPoint(bool isPointToPoint) [member function]
+ cls.add_method('SetIsPointToPoint',
+ 'void',
+ [param('bool', 'isPointToPoint')])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetSupportsSendFrom(bool supportsSendFrom) [member function]
+ cls.add_method('SetSupportsSendFrom',
+ 'void',
+ [param('bool', 'supportsSendFrom')])
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::SetMtu(uint16_t const mtu) [member function]
+ cls.add_method('SetMtu',
+ 'bool',
+ [param('uint16_t const', 'mtu')],
+ is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::Receive(ns3::Ptr<ns3::Packet> packet, uint16_t protocol, ns3::Address const & source, ns3::Address const & destination, ns3::NetDevice::PacketType packetType) [member function]
+ cls.add_method('Receive',
+ 'bool',
+ [param('ns3::Ptr< ns3::Packet >', 'packet'), param('uint16_t', 'protocol'), param('ns3::Address const &', 'source'), param('ns3::Address const &', 'destination'), param('ns3::NetDevice::PacketType', 'packetType')])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetAddress(ns3::Address addr) [member function]
+ cls.add_method('SetAddress',
+ 'void',
+ [param('ns3::Address', 'addr')])
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetIfIndex(uint32_t const index) [member function]
+ cls.add_method('SetIfIndex',
+ 'void',
+ [param('uint32_t const', 'index')],
+ is_virtual=True)
+ ## virtual-net-device.h: uint32_t ns3::VirtualNetDevice::GetIfIndex() const [member function]
+ cls.add_method('GetIfIndex',
+ 'uint32_t',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: ns3::Ptr<ns3::Channel> ns3::VirtualNetDevice::GetChannel() const [member function]
+ cls.add_method('GetChannel',
+ 'ns3::Ptr< ns3::Channel >',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: ns3::Address ns3::VirtualNetDevice::GetAddress() const [member function]
+ cls.add_method('GetAddress',
+ 'ns3::Address',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: uint16_t ns3::VirtualNetDevice::GetMtu() const [member function]
+ cls.add_method('GetMtu',
+ 'uint16_t',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::IsLinkUp() const [member function]
+ cls.add_method('IsLinkUp',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetLinkChangeCallback(ns3::Callback<void, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty> callback) [member function]
+ cls.add_method('SetLinkChangeCallback',
+ 'void',
+ [param('ns3::Callback< void, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'callback')],
+ is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::IsBroadcast() const [member function]
+ cls.add_method('IsBroadcast',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: ns3::Address ns3::VirtualNetDevice::GetBroadcast() const [member function]
+ cls.add_method('GetBroadcast',
+ 'ns3::Address',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::IsMulticast() const [member function]
+ cls.add_method('IsMulticast',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: ns3::Address ns3::VirtualNetDevice::GetMulticast(ns3::Ipv4Address multicastGroup) const [member function]
+ cls.add_method('GetMulticast',
+ 'ns3::Address',
+ [param('ns3::Ipv4Address', 'multicastGroup')],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: ns3::Address ns3::VirtualNetDevice::GetMulticast(ns3::Ipv6Address addr) const [member function]
+ cls.add_method('GetMulticast',
+ 'ns3::Address',
+ [param('ns3::Ipv6Address', 'addr')],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::IsPointToPoint() const [member function]
+ cls.add_method('IsPointToPoint',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::Send(ns3::Ptr<ns3::Packet> packet, ns3::Address const & dest, uint16_t protocolNumber) [member function]
+ cls.add_method('Send',
+ 'bool',
+ [param('ns3::Ptr< ns3::Packet >', 'packet'), param('ns3::Address const &', 'dest'), param('uint16_t', 'protocolNumber')],
+ is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::SendFrom(ns3::Ptr<ns3::Packet> 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 const &', 'source'), param('ns3::Address const &', 'dest'), param('uint16_t', 'protocolNumber')],
+ is_virtual=True)
+ ## virtual-net-device.h: ns3::Ptr<ns3::Node> ns3::VirtualNetDevice::GetNode() const [member function]
+ cls.add_method('GetNode',
+ 'ns3::Ptr< ns3::Node >',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetNode(ns3::Ptr<ns3::Node> node) [member function]
+ cls.add_method('SetNode',
+ 'void',
+ [param('ns3::Ptr< ns3::Node >', 'node')],
+ is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::NeedsArp() const [member function]
+ cls.add_method('NeedsArp',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetReceiveCallback(ns3::Callback<bool, ns3::Ptr<ns3::NetDevice>, ns3::Ptr<ns3::Packet const>, unsigned short, ns3::Address const&, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty> cb) [member function]
+ cls.add_method('SetReceiveCallback',
+ 'void',
+ [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet const >, unsigned short, ns3::Address const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'cb')],
+ is_virtual=True)
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::SetPromiscReceiveCallback(ns3::Callback<bool, ns3::Ptr<ns3::NetDevice>, ns3::Ptr<ns3::Packet const>, unsigned short, ns3::Address const&, ns3::Address const&, ns3::NetDevice::PacketType, ns3::empty, ns3::empty, ns3::empty> cb) [member function]
+ cls.add_method('SetPromiscReceiveCallback',
+ 'void',
+ [param('ns3::Callback< bool, ns3::Ptr< ns3::NetDevice >, ns3::Ptr< ns3::Packet const >, unsigned short, ns3::Address const &, ns3::Address const &, ns3::NetDevice::PacketType, ns3::empty, ns3::empty, ns3::empty >', 'cb')],
+ is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::SupportsSendFrom() const [member function]
+ cls.add_method('SupportsSendFrom',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: bool ns3::VirtualNetDevice::IsBridge() const [member function]
+ cls.add_method('IsBridge',
+ 'bool',
+ [],
+ is_const=True, is_virtual=True)
+ ## virtual-net-device.h: void ns3::VirtualNetDevice::DoDispose() [member function]
+ cls.add_method('DoDispose',
+ 'void',
+ [],
+ visibility='protected', is_virtual=True)
+ return
+
+def register_functions(root_module):
+ module = root_module
+ register_functions_ns3_Config(module.get_submodule('Config'), root_module)
+ register_functions_ns3_TimeStepPrecision(module.get_submodule('TimeStepPrecision'), root_module)
+ register_functions_ns3_addressUtils(module.get_submodule('addressUtils'), root_module)
+ register_functions_ns3_internal(module.get_submodule('internal'), root_module)
+ register_functions_ns3_olsr(module.get_submodule('olsr'), root_module)
+ return
+
+def register_functions_ns3_Config(module, root_module):
+ return
+
+def register_functions_ns3_TimeStepPrecision(module, root_module):
+ return
+
+def register_functions_ns3_addressUtils(module, root_module):
+ return
+
+def register_functions_ns3_internal(module, root_module):
+ return
+
+def register_functions_ns3_olsr(module, root_module):
+ return
+
--- a/bindings/python/ns3modulegen_core_customizations.py Fri Jun 19 12:38:01 2009 +0400
+++ b/bindings/python/ns3modulegen_core_customizations.py Fri Jun 19 12:58:35 2009 +0400
@@ -325,7 +325,7 @@
"NS_OBJECT_ENSURE_REGISTERED (%s);" % helper_class.name)
Object.add_helper_class_hook(helper_class_hook)
- ## Replace all class constructors with a generic constructor based on CreateObject<T> (AttributeList)
+ ## Replace all class constructors with a generic constructor based on CreateObjectWithAttributes<T> (AttributeList)
module.header.writeln('''
namespace ns3 {
@@ -357,7 +357,7 @@
if construct_name and not cls.helper_class:
construct_code = '''
- ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObject< %(CONSTRUCT_NAME)s > (attrList);
+ ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObjectWithAttributes< %(CONSTRUCT_NAME)s > (attrList);
obj->Ref ();
self->obj = ns3::PeekPointer (obj);
''' % dict (CONSTRUCT_NAME=construct_name)
@@ -393,7 +393,7 @@
obj->Ref ();
self->obj = ns3::PeekPointer (obj);
} else {
- ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObject< %(CONSTRUCT_NAME)s > (attrList);
+ ns3::Ptr< %(CONSTRUCT_NAME)s > obj = ns3::CreateObjectWithAttributes< %(CONSTRUCT_NAME)s > (attrList);
obj->Ref ();
self->obj = ns3::PeekPointer (obj);
}
--- a/bindings/python/ns3modulegen_generated.py Fri Jun 19 12:38:01 2009 +0400
+++ b/bindings/python/ns3modulegen_generated.py Fri Jun 19 12:58:35 2009 +0400
@@ -16,19 +16,20 @@
import ns3_module_simulator
import ns3_module_mobility
import ns3_module_common
+import ns3_module_contrib
import ns3_module_node
-import ns3_module_contrib
+import ns3_module_tap_bridge
+import ns3_module_v4ping
+import ns3_module_packet_sink
+import ns3_module_stats
+import ns3_module_virtual_net_device
+import ns3_module_onoff
+import ns3_module_internet_stack
import ns3_module_point_to_point
-import ns3_module_stats
-import ns3_module_tap_bridge
-import ns3_module_internet_stack
+import ns3_module_csma
+import ns3_module_bridge
import ns3_module_wifi
-import ns3_module_csma
import ns3_module_emu
-import ns3_module_bridge
-import ns3_module_onoff
-import ns3_module_packet_sink
-import ns3_module_v4ping
import ns3_module_global_routing
import ns3_module_udp_echo
import ns3_module_olsr
@@ -85,17 +86,6 @@
ns3_module_common__local.register_types(module)
root_module.end_section('ns3_module_common')
- root_module.begin_section('ns3_module_node')
- ns3_module_node.register_types(module)
-
- try:
- import ns3_module_node__local
- except ImportError:
- pass
- else:
- ns3_module_node__local.register_types(module)
-
- root_module.end_section('ns3_module_node')
root_module.begin_section('ns3_module_contrib')
ns3_module_contrib.register_types(module)
@@ -107,17 +97,50 @@
ns3_module_contrib__local.register_types(module)
root_module.end_section('ns3_module_contrib')
- root_module.begin_section('ns3_module_point_to_point')
- ns3_module_point_to_point.register_types(module)
+ root_module.begin_section('ns3_module_node')
+ ns3_module_node.register_types(module)
try:
- import ns3_module_point_to_point__local
+ import ns3_module_node__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_node__local.register_types(module)
+
+ root_module.end_section('ns3_module_node')
+ root_module.begin_section('ns3_module_tap_bridge')
+ ns3_module_tap_bridge.register_types(module)
+
+ try:
+ import ns3_module_tap_bridge__local
except ImportError:
pass
else:
- ns3_module_point_to_point__local.register_types(module)
+ ns3_module_tap_bridge__local.register_types(module)
+
+ root_module.end_section('ns3_module_tap_bridge')
+ root_module.begin_section('ns3_module_v4ping')
+ ns3_module_v4ping.register_types(module)
+
+ try:
+ import ns3_module_v4ping__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_v4ping__local.register_types(module)
- root_module.end_section('ns3_module_point_to_point')
+ root_module.end_section('ns3_module_v4ping')
+ root_module.begin_section('ns3_module_packet_sink')
+ ns3_module_packet_sink.register_types(module)
+
+ try:
+ import ns3_module_packet_sink__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_packet_sink__local.register_types(module)
+
+ root_module.end_section('ns3_module_packet_sink')
root_module.begin_section('ns3_module_stats')
ns3_module_stats.register_types(module)
@@ -129,17 +152,28 @@
ns3_module_stats__local.register_types(module)
root_module.end_section('ns3_module_stats')
- root_module.begin_section('ns3_module_tap_bridge')
- ns3_module_tap_bridge.register_types(module)
+ root_module.begin_section('ns3_module_virtual_net_device')
+ ns3_module_virtual_net_device.register_types(module)
try:
- import ns3_module_tap_bridge__local
+ import ns3_module_virtual_net_device__local
except ImportError:
pass
else:
- ns3_module_tap_bridge__local.register_types(module)
+ ns3_module_virtual_net_device__local.register_types(module)
+
+ root_module.end_section('ns3_module_virtual_net_device')
+ root_module.begin_section('ns3_module_onoff')
+ ns3_module_onoff.register_types(module)
- root_module.end_section('ns3_module_tap_bridge')
+ try:
+ import ns3_module_onoff__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_onoff__local.register_types(module)
+
+ root_module.end_section('ns3_module_onoff')
root_module.begin_section('ns3_module_internet_stack')
ns3_module_internet_stack.register_types(module)
@@ -151,6 +185,39 @@
ns3_module_internet_stack__local.register_types(module)
root_module.end_section('ns3_module_internet_stack')
+ root_module.begin_section('ns3_module_point_to_point')
+ ns3_module_point_to_point.register_types(module)
+
+ try:
+ import ns3_module_point_to_point__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_point_to_point__local.register_types(module)
+
+ root_module.end_section('ns3_module_point_to_point')
+ root_module.begin_section('ns3_module_csma')
+ ns3_module_csma.register_types(module)
+
+ try:
+ import ns3_module_csma__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_csma__local.register_types(module)
+
+ root_module.end_section('ns3_module_csma')
+ root_module.begin_section('ns3_module_bridge')
+ ns3_module_bridge.register_types(module)
+
+ try:
+ import ns3_module_bridge__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_bridge__local.register_types(module)
+
+ root_module.end_section('ns3_module_bridge')
root_module.begin_section('ns3_module_wifi')
ns3_module_wifi.register_types(module)
@@ -162,17 +229,6 @@
ns3_module_wifi__local.register_types(module)
root_module.end_section('ns3_module_wifi')
- root_module.begin_section('ns3_module_csma')
- ns3_module_csma.register_types(module)
-
- try:
- import ns3_module_csma__local
- except ImportError:
- pass
- else:
- ns3_module_csma__local.register_types(module)
-
- root_module.end_section('ns3_module_csma')
root_module.begin_section('ns3_module_emu')
ns3_module_emu.register_types(module)
@@ -184,50 +240,6 @@
ns3_module_emu__local.register_types(module)
root_module.end_section('ns3_module_emu')
- root_module.begin_section('ns3_module_bridge')
- ns3_module_bridge.register_types(module)
-
- try:
- import ns3_module_bridge__local
- except ImportError:
- pass
- else:
- ns3_module_bridge__local.register_types(module)
-
- root_module.end_section('ns3_module_bridge')
- root_module.begin_section('ns3_module_onoff')
- ns3_module_onoff.register_types(module)
-
- try:
- import ns3_module_onoff__local
- except ImportError:
- pass
- else:
- ns3_module_onoff__local.register_types(module)
-
- root_module.end_section('ns3_module_onoff')
- root_module.begin_section('ns3_module_packet_sink')
- ns3_module_packet_sink.register_types(module)
-
- try:
- import ns3_module_packet_sink__local
- except ImportError:
- pass
- else:
- ns3_module_packet_sink__local.register_types(module)
-
- root_module.end_section('ns3_module_packet_sink')
- root_module.begin_section('ns3_module_v4ping')
- ns3_module_v4ping.register_types(module)
-
- try:
- import ns3_module_v4ping__local
- except ImportError:
- pass
- else:
- ns3_module_v4ping__local.register_types(module)
-
- root_module.end_section('ns3_module_v4ping')
root_module.begin_section('ns3_module_global_routing')
ns3_module_global_routing.register_types(module)
@@ -372,17 +384,6 @@
ns3_module_common__local.register_methods(root_module)
root_module.end_section('ns3_module_common')
- root_module.begin_section('ns3_module_node')
- ns3_module_node.register_methods(root_module)
-
- try:
- import ns3_module_node__local
- except ImportError:
- pass
- else:
- ns3_module_node__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_node')
root_module.begin_section('ns3_module_contrib')
ns3_module_contrib.register_methods(root_module)
@@ -394,17 +395,50 @@
ns3_module_contrib__local.register_methods(root_module)
root_module.end_section('ns3_module_contrib')
- root_module.begin_section('ns3_module_point_to_point')
- ns3_module_point_to_point.register_methods(root_module)
+ root_module.begin_section('ns3_module_node')
+ ns3_module_node.register_methods(root_module)
try:
- import ns3_module_point_to_point__local
+ import ns3_module_node__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_node__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_node')
+ root_module.begin_section('ns3_module_tap_bridge')
+ ns3_module_tap_bridge.register_methods(root_module)
+
+ try:
+ import ns3_module_tap_bridge__local
except ImportError:
pass
else:
- ns3_module_point_to_point__local.register_methods(root_module)
+ ns3_module_tap_bridge__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_tap_bridge')
+ root_module.begin_section('ns3_module_v4ping')
+ ns3_module_v4ping.register_methods(root_module)
+
+ try:
+ import ns3_module_v4ping__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_v4ping__local.register_methods(root_module)
- root_module.end_section('ns3_module_point_to_point')
+ root_module.end_section('ns3_module_v4ping')
+ root_module.begin_section('ns3_module_packet_sink')
+ ns3_module_packet_sink.register_methods(root_module)
+
+ try:
+ import ns3_module_packet_sink__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_packet_sink__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_packet_sink')
root_module.begin_section('ns3_module_stats')
ns3_module_stats.register_methods(root_module)
@@ -416,17 +450,28 @@
ns3_module_stats__local.register_methods(root_module)
root_module.end_section('ns3_module_stats')
- root_module.begin_section('ns3_module_tap_bridge')
- ns3_module_tap_bridge.register_methods(root_module)
+ root_module.begin_section('ns3_module_virtual_net_device')
+ ns3_module_virtual_net_device.register_methods(root_module)
try:
- import ns3_module_tap_bridge__local
+ import ns3_module_virtual_net_device__local
except ImportError:
pass
else:
- ns3_module_tap_bridge__local.register_methods(root_module)
+ ns3_module_virtual_net_device__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_virtual_net_device')
+ root_module.begin_section('ns3_module_onoff')
+ ns3_module_onoff.register_methods(root_module)
- root_module.end_section('ns3_module_tap_bridge')
+ try:
+ import ns3_module_onoff__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_onoff__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_onoff')
root_module.begin_section('ns3_module_internet_stack')
ns3_module_internet_stack.register_methods(root_module)
@@ -438,6 +483,39 @@
ns3_module_internet_stack__local.register_methods(root_module)
root_module.end_section('ns3_module_internet_stack')
+ root_module.begin_section('ns3_module_point_to_point')
+ ns3_module_point_to_point.register_methods(root_module)
+
+ try:
+ import ns3_module_point_to_point__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_point_to_point__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_point_to_point')
+ root_module.begin_section('ns3_module_csma')
+ ns3_module_csma.register_methods(root_module)
+
+ try:
+ import ns3_module_csma__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_csma__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_csma')
+ root_module.begin_section('ns3_module_bridge')
+ ns3_module_bridge.register_methods(root_module)
+
+ try:
+ import ns3_module_bridge__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_bridge__local.register_methods(root_module)
+
+ root_module.end_section('ns3_module_bridge')
root_module.begin_section('ns3_module_wifi')
ns3_module_wifi.register_methods(root_module)
@@ -449,17 +527,6 @@
ns3_module_wifi__local.register_methods(root_module)
root_module.end_section('ns3_module_wifi')
- root_module.begin_section('ns3_module_csma')
- ns3_module_csma.register_methods(root_module)
-
- try:
- import ns3_module_csma__local
- except ImportError:
- pass
- else:
- ns3_module_csma__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_csma')
root_module.begin_section('ns3_module_emu')
ns3_module_emu.register_methods(root_module)
@@ -471,50 +538,6 @@
ns3_module_emu__local.register_methods(root_module)
root_module.end_section('ns3_module_emu')
- root_module.begin_section('ns3_module_bridge')
- ns3_module_bridge.register_methods(root_module)
-
- try:
- import ns3_module_bridge__local
- except ImportError:
- pass
- else:
- ns3_module_bridge__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_bridge')
- root_module.begin_section('ns3_module_onoff')
- ns3_module_onoff.register_methods(root_module)
-
- try:
- import ns3_module_onoff__local
- except ImportError:
- pass
- else:
- ns3_module_onoff__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_onoff')
- root_module.begin_section('ns3_module_packet_sink')
- ns3_module_packet_sink.register_methods(root_module)
-
- try:
- import ns3_module_packet_sink__local
- except ImportError:
- pass
- else:
- ns3_module_packet_sink__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_packet_sink')
- root_module.begin_section('ns3_module_v4ping')
- ns3_module_v4ping.register_methods(root_module)
-
- try:
- import ns3_module_v4ping__local
- except ImportError:
- pass
- else:
- ns3_module_v4ping__local.register_methods(root_module)
-
- root_module.end_section('ns3_module_v4ping')
root_module.begin_section('ns3_module_global_routing')
ns3_module_global_routing.register_methods(root_module)
@@ -607,17 +630,6 @@
ns3_module_common__local.register_functions(root_module)
root_module.end_section('ns3_module_common')
- root_module.begin_section('ns3_module_node')
- ns3_module_node.register_functions(root_module)
-
- try:
- import ns3_module_node__local
- except ImportError:
- pass
- else:
- ns3_module_node__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_node')
root_module.begin_section('ns3_module_contrib')
ns3_module_contrib.register_functions(root_module)
@@ -629,17 +641,50 @@
ns3_module_contrib__local.register_functions(root_module)
root_module.end_section('ns3_module_contrib')
- root_module.begin_section('ns3_module_point_to_point')
- ns3_module_point_to_point.register_functions(root_module)
+ root_module.begin_section('ns3_module_node')
+ ns3_module_node.register_functions(root_module)
try:
- import ns3_module_point_to_point__local
+ import ns3_module_node__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_node__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_node')
+ root_module.begin_section('ns3_module_tap_bridge')
+ ns3_module_tap_bridge.register_functions(root_module)
+
+ try:
+ import ns3_module_tap_bridge__local
except ImportError:
pass
else:
- ns3_module_point_to_point__local.register_functions(root_module)
+ ns3_module_tap_bridge__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_tap_bridge')
+ root_module.begin_section('ns3_module_v4ping')
+ ns3_module_v4ping.register_functions(root_module)
+
+ try:
+ import ns3_module_v4ping__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_v4ping__local.register_functions(root_module)
- root_module.end_section('ns3_module_point_to_point')
+ root_module.end_section('ns3_module_v4ping')
+ root_module.begin_section('ns3_module_packet_sink')
+ ns3_module_packet_sink.register_functions(root_module)
+
+ try:
+ import ns3_module_packet_sink__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_packet_sink__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_packet_sink')
root_module.begin_section('ns3_module_stats')
ns3_module_stats.register_functions(root_module)
@@ -651,17 +696,28 @@
ns3_module_stats__local.register_functions(root_module)
root_module.end_section('ns3_module_stats')
- root_module.begin_section('ns3_module_tap_bridge')
- ns3_module_tap_bridge.register_functions(root_module)
+ root_module.begin_section('ns3_module_virtual_net_device')
+ ns3_module_virtual_net_device.register_functions(root_module)
try:
- import ns3_module_tap_bridge__local
+ import ns3_module_virtual_net_device__local
except ImportError:
pass
else:
- ns3_module_tap_bridge__local.register_functions(root_module)
+ ns3_module_virtual_net_device__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_virtual_net_device')
+ root_module.begin_section('ns3_module_onoff')
+ ns3_module_onoff.register_functions(root_module)
- root_module.end_section('ns3_module_tap_bridge')
+ try:
+ import ns3_module_onoff__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_onoff__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_onoff')
root_module.begin_section('ns3_module_internet_stack')
ns3_module_internet_stack.register_functions(root_module)
@@ -673,6 +729,39 @@
ns3_module_internet_stack__local.register_functions(root_module)
root_module.end_section('ns3_module_internet_stack')
+ root_module.begin_section('ns3_module_point_to_point')
+ ns3_module_point_to_point.register_functions(root_module)
+
+ try:
+ import ns3_module_point_to_point__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_point_to_point__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_point_to_point')
+ root_module.begin_section('ns3_module_csma')
+ ns3_module_csma.register_functions(root_module)
+
+ try:
+ import ns3_module_csma__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_csma__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_csma')
+ root_module.begin_section('ns3_module_bridge')
+ ns3_module_bridge.register_functions(root_module)
+
+ try:
+ import ns3_module_bridge__local
+ except ImportError:
+ pass
+ else:
+ ns3_module_bridge__local.register_functions(root_module)
+
+ root_module.end_section('ns3_module_bridge')
root_module.begin_section('ns3_module_wifi')
ns3_module_wifi.register_functions(root_module)
@@ -684,17 +773,6 @@
ns3_module_wifi__local.register_functions(root_module)
root_module.end_section('ns3_module_wifi')
- root_module.begin_section('ns3_module_csma')
- ns3_module_csma.register_functions(root_module)
-
- try:
- import ns3_module_csma__local
- except ImportError:
- pass
- else:
- ns3_module_csma__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_csma')
root_module.begin_section('ns3_module_emu')
ns3_module_emu.register_functions(root_module)
@@ -706,50 +784,6 @@
ns3_module_emu__local.register_functions(root_module)
root_module.end_section('ns3_module_emu')
- root_module.begin_section('ns3_module_bridge')
- ns3_module_bridge.register_functions(root_module)
-
- try:
- import ns3_module_bridge__local
- except ImportError:
- pass
- else:
- ns3_module_bridge__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_bridge')
- root_module.begin_section('ns3_module_onoff')
- ns3_module_onoff.register_functions(root_module)
-
- try:
- import ns3_module_onoff__local
- except ImportError:
- pass
- else:
- ns3_module_onoff__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_onoff')
- root_module.begin_section('ns3_module_packet_sink')
- ns3_module_packet_sink.register_functions(root_module)
-
- try:
- import ns3_module_packet_sink__local
- except ImportError:
- pass
- else:
- ns3_module_packet_sink__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_packet_sink')
- root_module.begin_section('ns3_module_v4ping')
- ns3_module_v4ping.register_functions(root_module)
-
- try:
- import ns3_module_v4ping__local
- except ImportError:
- pass
- else:
- ns3_module_v4ping__local.register_functions(root_module)
-
- root_module.end_section('ns3_module_v4ping')
root_module.begin_section('ns3_module_global_routing')
ns3_module_global_routing.register_functions(root_module)
--- a/bindings/python/wscript Fri Jun 19 12:38:01 2009 +0400
+++ b/bindings/python/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -439,6 +439,8 @@
bindgen.name = "pybindgen-command"
pymod = bld.new_task_gen('cxx', 'shlib', 'pyext')
+ if sys.platform == 'cygwin':
+ pymod.features.append('implib') # workaround for WAF bug #472
pymod.source = ['ns3module.cc', 'ns3module_helpers.cc']
pymod.includes = '.'
for module in scanned_modules:
--- a/examples/csma-packet-socket.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/examples/csma-packet-socket.cc Fri Jun 19 12:58:35 2009 +0400
@@ -72,7 +72,7 @@
// create the shared medium used by all csma devices.
NS_LOG_INFO ("Create channels.");
- Ptr<CsmaChannel> channel = CreateObject<CsmaChannel> (
+ Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> (
"DataRate", DataRateValue (DataRate(5000000)),
"Delay", TimeValue (MilliSeconds(2)));
--- a/examples/simple-error-model.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/examples/simple-error-model.cc Fri Jun 19 12:58:35 2009 +0400
@@ -153,7 +153,7 @@
//
// Create an ErrorModel based on the implementation (constructor)
// specified by the default classId
- Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)),
+ Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)),
"ErrorRate", DoubleValue (0.001));
d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
--- a/examples/tcp-nsc-lfn.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/examples/tcp-nsc-lfn.cc Fri Jun 19 12:58:35 2009 +0400
@@ -109,9 +109,9 @@
DoubleValue rate(errRate);
RandomVariableValue u01(UniformVariable (0.0, 1.0));
Ptr<RateErrorModel> em1 =
- CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
+ CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
Ptr<RateErrorModel> em2 =
- CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
+ CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
// This enables the specified errRate on both link endpoints.
p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/virtual-net-device.cc Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,289 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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
+ *
+ * Based on simple-global-routing.cc
+ * ns-2 simple.tcl script (ported from ns-2)
+ * Originally authored by Steve McCanne, 12/19/1996
+ */
+
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 -------------------------n3
+// /
+// / 5 Mb/s, 2ms
+// n1
+//
+// - all links are point-to-point links with indicated one-way BW/delay
+// - CBR/UDP flows from n0 to n3, and from n3 to n1
+// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
+// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
+// (i.e., DataRate of 448,000 bps)
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "virtual-net-device.tr"
+
+// Tunneling changes (relative to the simple-global-routing example):
+// n0 will receive an extra virtual interface with address 11.0.0.1
+// n1 will also receive an extra virtual interface with the same address 11.0.0.1
+// n3 will receive an extra virtual interface with address 11.0.0.254
+// The flows will be between 11.0.0.x (tunnel) addresses instead of 10.1.x.y ones
+// n3 will decide, on a per-packet basis, via random number, whether to
+// send the packet to n0 or to n1.
+//
+// Note: here we create a tunnel where IP packets are tunneled over
+// UDP/IP, but tunneling directly IP-over-IP would also be possible;
+// see src/node/ipv4-raw-socket-factory.h.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/global-route-manager.h"
+#include "ns3/virtual-net-device.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample");
+
+class Tunnel
+{
+ Ptr<Socket> m_n3Socket;
+ Ptr<Socket> m_n0Socket;
+ Ptr<Socket> m_n1Socket;
+ Ipv4Address m_n3Address;
+ Ipv4Address m_n0Address;
+ Ipv4Address m_n1Address;
+ UniformVariable m_rng;
+ Ptr<VirtualNetDevice> m_n0Tap;
+ Ptr<VirtualNetDevice> m_n1Tap;
+ Ptr<VirtualNetDevice> m_n3Tap;
+
+
+ bool
+ N0N1VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+ {
+ m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
+ return true;
+ }
+
+ bool
+ N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+ {
+
+ if (m_rng.GetValue () < 0.25)
+ {
+ m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
+ }
+ else
+ {
+ m_n1Socket->SendTo (packet, 0, InetSocketAddress (m_n1Address, 667));
+ }
+ return true;
+ }
+
+ void N3SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+ void N0SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+ void N1SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+public:
+
+ Tunnel (Ptr<Node> n3, Ptr<Node> n0, Ptr<Node> n1,
+ Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr)
+ : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr)
+ {
+ m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));
+
+ m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this));
+
+ m_n1Socket = Socket::CreateSocket (n1, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n1Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n1Socket->SetRecvCallback (MakeCallback (&Tunnel::N1SocketRecv, this));
+
+ // n0 tap device
+ m_n0Tap = CreateObject<VirtualNetDevice> ();
+ m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01"));
+ m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0N1VirtualSend, this));
+ n0->AddDevice (m_n0Tap);
+ Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> ();
+ uint32_t i = ipv4->AddInterface (m_n0Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ // n1 tap device
+ m_n1Tap = CreateObject<VirtualNetDevice> ();
+ m_n1Tap->SetAddress (Mac48Address ("11:00:01:02:03:02"));
+ m_n1Tap->SetSendCallback (MakeCallback (&Tunnel::N0N1VirtualSend, this));
+ n1->AddDevice (m_n1Tap);
+ ipv4 = n1->GetObject<Ipv4> ();
+ i = ipv4->AddInterface (m_n1Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ // n3 tap device
+ m_n3Tap = CreateObject<VirtualNetDevice> ();
+ m_n3Tap->SetAddress (Mac48Address ("11:00:01:02:03:04"));
+ m_n3Tap->SetSendCallback (MakeCallback (&Tunnel::N3VirtualSend, this));
+ n3->AddDevice (m_n3Tap);
+ ipv4 = n3->GetObject<Ipv4> ();
+ i = ipv4->AddInterface (m_n3Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.254"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ }
+
+
+};
+
+
+
+int
+main (int argc, char *argv[])
+{
+ // Users may find it convenient to turn on explicit debugging
+ // for selected modules; the below lines suggest how to do this
+#if 0
+ LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO);
+#endif
+
+ // Set up some default values for the simulation. Use the
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+ NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
+ NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d3d2 = p2p.Install (n3n2);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ GlobalRouteManager::PopulateRoutingTables ();
+
+ // Add the tunnels
+ Tunnel tunnel (c.Get (3), c.Get (0), c.Get (1),
+ i3i2.GetAddress (0), i0i2.GetAddress (0), i1i2.GetAddress (0));
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address ("11.0.0.254"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a similar flow from n3 to n1, starting at time 1.1 seconds
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (Ipv4Address ("11.0.0.2"), port)));
+ apps = onoff.Install (c.Get (3));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("virtual-net-device.tr");
+ PointToPointHelper::EnablePcapAll ("virtual-net-device");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- a/examples/wscript Fri Jun 19 12:38:01 2009 +0400
+++ b/examples/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -40,6 +40,10 @@
['point-to-point', 'internet-stack', 'global-routing'])
obj.source = 'simple-global-routing.cc'
+ obj = bld.create_ns3_program('virtual-net-device',
+ ['point-to-point', 'internet-stack', 'global-routing', 'virtual-net-device'])
+ obj.source = 'virtual-net-device.cc'
+
obj = bld.create_ns3_program('simple-alternate-routing',
['point-to-point', 'internet-stack', 'global-routing'])
obj.source = 'simple-alternate-routing.cc'
--- a/src/common/tag-buffer.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/common/tag-buffer.cc Fri Jun 19 12:58:35 2009 +0400
@@ -99,7 +99,7 @@
WriteU8 ((data >> 32) & 0xff);
WriteU8 ((data >> 40) & 0xff);
WriteU8 ((data >> 48) & 0xff);
- WriteU8 ((data >> 54) & 0xff);
+ WriteU8 ((data >> 56) & 0xff);
}
void
TagBuffer::WriteDouble (double v)
--- a/src/core/attribute-test.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/core/attribute-test.cc Fri Jun 19 12:58:35 2009 +0400
@@ -279,7 +279,7 @@
AttributeList params;
Ptr<AttributeObjectTest> p;
NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
- p = CreateObject<AttributeObjectTest> (params);
+ p = CreateObjectWithAttributes<AttributeObjectTest> (params);
CHECK_GET_STR (p, "TestBoolName", "false");
CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
@@ -291,11 +291,11 @@
CHECK_GET_STR (p, "TestBoolName", "false");
CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
- p = CreateObject<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
CHECK_GET_STR (p, "TestBoolName", "true");
CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
- p = CreateObject<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
CHECK_GET_STR (p, "TestBoolName", "true");
CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
@@ -502,7 +502,7 @@
Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
NS_TEST_ASSERT (x == 0);
- p = CreateObject<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
NS_TEST_ASSERT (p != 0);
derived = 0;
p->GetAttribute ("Pointer", ptr);
--- a/src/core/object.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/core/object.h Fri Jun 19 12:58:35 2009 +0400
@@ -200,7 +200,7 @@
private:
template <typename T>
- friend Ptr<T> CreateObject (const AttributeList &attributes);
+ friend Ptr<T> CreateObjectWithAttributes (const AttributeList &attributes);
template <typename T>
friend Ptr<T> CopyObject (Ptr<T> object);
template <typename T>
@@ -209,6 +209,8 @@
// by our python bindings to call the protected ObjectBase::Construct
// method.
friend void PythonCompleteConstruct (Ptr<Object> object, TypeId typeId, const AttributeList &attributes);
+ template <typename T>
+ friend Ptr<T> CompleteConstruct (T *object);
friend class ObjectFactory;
friend class AggregateIterator;
@@ -290,7 +292,7 @@
* it with a set of attributes.
*/
template <typename T>
-Ptr<T> CreateObject (const AttributeList &attributes);
+Ptr<T> CreateObjectWithAttributes (const AttributeList &attributes);
/**
* \param n1 name of attribute
@@ -318,7 +320,7 @@
*/
template <typename T>
Ptr<T>
-CreateObject (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (),
+CreateObjectWithAttributes (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (),
std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (),
std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (),
std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (),
@@ -398,9 +400,15 @@
return p;
}
-
template <typename T>
-Ptr<T> CreateObject (const AttributeList &attributes)
+Ptr<T> CompleteConstruct (T *p)
+{
+ p->SetTypeId (T::GetTypeId ());
+ p->Object::Construct (AttributeList());
+ return Ptr<T> (p, false);
+}
+template <typename T>
+Ptr<T> CreateObjectWithAttributes (const AttributeList &attributes)
{
Ptr<T> p = Ptr<T> (new T (), false);
p->SetTypeId (T::GetTypeId ());
@@ -410,7 +418,7 @@
template <typename T>
Ptr<T>
-CreateObject (std::string n1 , const AttributeValue & v1,
+CreateObjectWithAttributes (std::string n1 , const AttributeValue & v1,
std::string n2 , const AttributeValue & v2,
std::string n3 , const AttributeValue & v3,
std::string n4 , const AttributeValue & v4,
@@ -467,9 +475,58 @@
}
attributes.SetWithTid (T::GetTypeId (), n9, v9);
end:
- return CreateObject<T> (attributes);
+ return CreateObjectWithAttributes<T> (attributes);
+}
+
+template <typename T>
+Ptr<T> CreateObject (void)
+{
+ return CompleteConstruct (new T ());
+}
+
+template <typename T, typename T1>
+Ptr<T> CreateObject (T1 a1)
+{
+ return CompleteConstruct (new T (a1));
+}
+
+template <typename T, typename T1, typename T2>
+Ptr<T> CreateObject (T1 a1, T2 a2)
+{
+ return CompleteConstruct (new T (a1,a2));
+}
+
+template <typename T, typename T1, typename T2, typename T3>
+Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3)
+{
+ return CompleteConstruct (new T (a1,a2,a3));
}
+template <typename T, typename T1, typename T2, typename T3, typename T4>
+Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4)
+{
+ return CompleteConstruct (new T (a1,a2,a3,a4));
+}
+
+template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
+Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
+{
+ return CompleteConstruct (new T (a1,a2,a3,a4,a5));
+}
+
+template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
+Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
+{
+ return CompleteConstruct (new T (a1,a2,a3,a4,a5,a6));
+}
+
+template <typename T, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
+Ptr<T> CreateObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
+{
+ return CompleteConstruct (new T (a1,a2,a3,a4,a5,a6,a7));
+}
+
+
} // namespace ns3
#endif /* OBJECT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/virtual-net-device/virtual-net-device.cc Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,300 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 INESC Porto
+ *
+ * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
+ */
+
+#include "ns3/log.h"
+#include "ns3/queue.h"
+#include "ns3/simulator.h"
+#include "ns3/mac48-address.h"
+#include "ns3/llc-snap-header.h"
+#include "ns3/error-model.h"
+#include "virtual-net-device.h"
+#include "ns3/channel.h"
+#include "ns3/trace-source-accessor.h"
+
+
+NS_LOG_COMPONENT_DEFINE ("VirtualNetDevice");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (VirtualNetDevice);
+
+TypeId
+VirtualNetDevice::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::VirtualNetDevice")
+ .SetParent<NetDevice> ()
+ .AddConstructor<VirtualNetDevice> ()
+ .AddTraceSource ("MacTx",
+ "Trace source indicating a packet has arrived for transmission by this device",
+ MakeTraceSourceAccessor (&VirtualNetDevice::m_macTxTrace))
+ .AddTraceSource ("MacPromiscRx",
+ "A packet has been received by this device, has been passed up from the physical layer "
+ "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
+ MakeTraceSourceAccessor (&VirtualNetDevice::m_macPromiscRxTrace))
+ .AddTraceSource ("MacRx",
+ "A packet has been received by this device, has been passed up from the physical layer "
+ "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
+ MakeTraceSourceAccessor (&VirtualNetDevice::m_macRxTrace))
+ //
+ // Trace sources designed to simulate a packet sniffer facility (tcpdump).
+ //
+ .AddTraceSource ("Sniffer",
+ "Trace source simulating a non-promiscuous packet sniffer attached to the device",
+ MakeTraceSourceAccessor (&VirtualNetDevice::m_snifferTrace))
+ .AddTraceSource ("PromiscSniffer",
+ "Trace source simulating a promiscuous packet sniffer attached to the device",
+ MakeTraceSourceAccessor (&VirtualNetDevice::m_promiscSnifferTrace))
+ ;
+ return tid;
+}
+
+VirtualNetDevice::VirtualNetDevice ()
+{
+ m_needsArp = false;
+ m_supportsSendFrom = true;
+ m_mtu = 65535;
+ m_isPointToPoint = true;
+}
+
+
+void
+VirtualNetDevice::SetSendCallback (SendCallback sendCb)
+{
+ m_sendCb = sendCb;
+}
+
+void
+VirtualNetDevice::SetNeedsArp (bool needsArp)
+{
+ m_needsArp = needsArp;
+}
+
+void
+VirtualNetDevice::SetSupportsSendFrom (bool supportsSendFrom)
+{
+ m_supportsSendFrom = supportsSendFrom;
+}
+
+void
+VirtualNetDevice::SetIsPointToPoint (bool isPointToPoint)
+{
+ m_isPointToPoint = isPointToPoint;
+}
+
+bool
+VirtualNetDevice::SetMtu (const uint16_t mtu)
+{
+ m_mtu = mtu;
+ return true;
+}
+
+
+VirtualNetDevice::~VirtualNetDevice()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+}
+
+
+void VirtualNetDevice::DoDispose()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ NetDevice::DoDispose ();
+}
+
+bool
+VirtualNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
+ const Address &source, const Address &destination,
+ PacketType packetType)
+{
+ //
+ // For all kinds of packetType we receive, we hit the promiscuous sniffer
+ // hook and pass a copy up to the promiscuous callback. Pass a copy to
+ // make sure that nobody messes with our packet.
+ //
+ m_promiscSnifferTrace (packet);
+ if (!m_promiscRxCallback.IsNull ())
+ {
+ m_macPromiscRxTrace (packet);
+ m_promiscRxCallback (this, packet, protocol, source, destination, packetType);
+ }
+
+ //
+ // If this packet is not destined for some other host, it must be for us
+ // as either a broadcast, multicast or unicast. We need to hit the mac
+ // packet received trace hook and forward the packet up the stack.
+ //
+ if (packetType != PACKET_OTHERHOST)
+ {
+ m_snifferTrace (packet);
+ m_macRxTrace (packet);
+ return m_rxCallback (this, packet, protocol, source);
+ }
+ return true;
+}
+
+
+void
+VirtualNetDevice::SetIfIndex (const uint32_t index)
+{
+ m_index = index;
+}
+
+uint32_t
+VirtualNetDevice::GetIfIndex (void) const
+{
+ return m_index;
+}
+
+Ptr<Channel>
+VirtualNetDevice::GetChannel (void) const
+{
+ return Ptr<Channel> ();
+}
+
+Address
+VirtualNetDevice::GetAddress (void) const
+{
+ return m_myAddress;
+}
+
+void
+VirtualNetDevice::SetAddress (Address addr)
+{
+ m_myAddress = addr;
+}
+
+uint16_t
+VirtualNetDevice::GetMtu (void) const
+{
+ return m_mtu;
+}
+
+bool
+VirtualNetDevice::IsLinkUp (void) const
+{
+ return true;
+}
+
+void
+VirtualNetDevice::SetLinkChangeCallback (Callback<void> callback)
+{
+}
+
+bool
+VirtualNetDevice::IsBroadcast (void) const
+{
+ return true;
+}
+
+Address
+VirtualNetDevice::GetBroadcast (void) const
+{
+ return Mac48Address ("ff:ff:ff:ff:ff:ff");
+}
+
+bool
+VirtualNetDevice::IsMulticast (void) const
+{
+ return false;
+}
+
+Address VirtualNetDevice::GetMulticast (Ipv4Address multicastGroup) const
+{
+ return Mac48Address ("ff:ff:ff:ff:ff:ff");
+}
+
+Address VirtualNetDevice::GetMulticast (Ipv6Address addr) const
+{
+ return Mac48Address ("ff:ff:ff:ff:ff:ff");
+}
+
+
+bool
+VirtualNetDevice::IsPointToPoint (void) const
+{
+ return m_isPointToPoint;
+}
+
+bool
+VirtualNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
+{
+ m_macTxTrace (packet);
+ if (m_sendCb (packet, GetAddress (), dest, protocolNumber))
+ {
+ return true;
+ }
+ return false;
+}
+
+bool
+VirtualNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+{
+ NS_ASSERT (m_supportsSendFrom);
+ m_macTxTrace (packet);
+ if (m_sendCb (packet, source, dest, protocolNumber))
+ {
+ return true;
+ }
+ return false;
+}
+
+Ptr<Node>
+VirtualNetDevice::GetNode (void) const
+{
+ return m_node;
+}
+
+void
+VirtualNetDevice::SetNode (Ptr<Node> node)
+{
+ m_node = node;
+}
+
+bool
+VirtualNetDevice::NeedsArp (void) const
+{
+ return m_needsArp;
+}
+
+void
+VirtualNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
+{
+ m_rxCallback = cb;
+}
+
+void
+VirtualNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
+{
+ m_promiscRxCallback = cb;
+}
+
+bool
+VirtualNetDevice::SupportsSendFrom () const
+{
+ return m_supportsSendFrom;
+}
+
+bool VirtualNetDevice::IsBridge (void) const
+{
+ return false;
+}
+
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/virtual-net-device/virtual-net-device.h Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,175 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 INESC Porto
+ *
+ * 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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
+ */
+
+#ifndef VIRTUAL_NET_DEVICE_H
+#define VIRTUAL_NET_DEVICE_H
+
+#include "ns3/address.h"
+#include "ns3/node.h"
+#include "ns3/net-device.h"
+#include "ns3/callback.h"
+#include "ns3/packet.h"
+#include "ns3/ptr.h"
+#include "ns3/traced-callback.h"
+
+namespace ns3 {
+
+
+/**
+ * \class VirtualNetDevice
+ * \brief A virtual device, similar to Linux TUN/TAP interfaces.
+ *
+ * A VirtualNetDevice is a "virtual" NetDevice implementation which
+ * delegates to a user callback (see method SetSendCallback()) the
+ * task of actually transmitting a packet. It also allows the user
+ * code to inject the packet as if it had been received by the
+ * VirtualNetDevice. Together, these features allow one to build tunnels.
+ * For instance, by transmitting packets into a UDP socket we end up
+ * building an IP-over-UDP-over-IP tunnel, or IP-over-IP tunnels.
+ *
+ * The same thing could be accomplished by subclassing NetDevice
+ * directly. However, VirtualNetDevice is usually much simpler to program
+ * than a NetDevice subclass.
+ */
+class VirtualNetDevice : public NetDevice
+{
+public:
+ /**
+ * Callback the be invoked when the VirtualNetDevice is asked to queue/transmit a packet.
+ * For more information, consult the documentation of NetDevice::SendFrom().
+ */
+ typedef Callback<bool, Ptr<Packet>, const Address&, const Address&, uint16_t> SendCallback;
+
+ static TypeId GetTypeId (void);
+ VirtualNetDevice ();
+
+ virtual ~VirtualNetDevice ();
+
+ /**
+ * \brief Set the user callback to be called when a L2 packet is to be transmitted
+ * \param transmitCb the new transmit callback
+ */
+ void SetSendCallback (SendCallback transmitCb);
+
+ /**
+ * \brief Configure whether the virtual device needs ARP
+ *
+ * \param needsArp the the 'needs arp' value that will be returned
+ * by the NeedsArp() method. The method IsBroadcast() will also
+ * return this value.
+ */
+ void SetNeedsArp (bool needsArp);
+
+ /**
+ * \brief Configure whether the virtual device is point-to-point
+ *
+ * \param isPointToPoint the value that should be returned by the
+ * IsPointToPoint method for this instance.
+ */
+ void SetIsPointToPoint (bool isPointToPoint);
+
+ /**
+ * \brief Configure whether the virtual device supports SendFrom
+ */
+ void SetSupportsSendFrom (bool supportsSendFrom);
+
+ /**
+ * \brief Configure the reported MTU for the virtual device. The
+ * default value is 65535.
+ * \return whether the MTU value was within legal bounds
+ */
+ bool SetMtu (const uint16_t mtu);
+
+
+ /**
+ * \param packet packet sent from below up to Network Device
+ * \param protocol Protocol type
+ * \param source the address of the sender of this packet.
+ * \param destination the address of the receiver of this packet.
+ * \param packetType type of packet received (broadcast/multicast/unicast/otherhost)
+ * \returns true if the packet was forwarded successfully, false otherwise.
+ *
+ * Forward a "virtually received" packet up
+ * the node's protocol stack.
+ */
+ bool Receive (Ptr<Packet> packet, uint16_t protocol,
+ const Address &source, const Address &destination,
+ PacketType packetType);
+
+
+ /**
+ * Set the MAC address of the the network device.
+ *
+ * \param addr The Address to use as the address of the device.
+ */
+ void SetAddress (Address addr);
+
+ // inherited from NetDevice base class.
+ virtual void SetIfIndex(const uint32_t index);
+ virtual uint32_t GetIfIndex(void) const;
+ virtual Ptr<Channel> GetChannel (void) const;
+ virtual Address GetAddress (void) const;
+ virtual uint16_t GetMtu (void) const;
+ virtual bool IsLinkUp (void) const;
+ virtual void SetLinkChangeCallback (Callback<void> callback);
+ virtual bool IsBroadcast (void) const;
+ virtual Address GetBroadcast (void) const;
+ virtual bool IsMulticast (void) const;
+ virtual Address GetMulticast (Ipv4Address multicastGroup) const;
+ virtual Address GetMulticast (Ipv6Address addr) const;
+ virtual bool IsPointToPoint (void) 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 (void) const;
+ virtual void SetNode (Ptr<Node> node);
+ virtual bool NeedsArp (void) const;
+ virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
+ virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb);
+ virtual bool SupportsSendFrom () const;
+ virtual bool IsBridge (void) const;
+
+protected:
+
+ virtual void DoDispose (void);
+
+private:
+
+ Address m_myAddress;
+ SendCallback m_sendCb;
+ TracedCallback<Ptr<const Packet> > m_macRxTrace;
+ TracedCallback<Ptr<const Packet> > m_macTxTrace;
+ TracedCallback<Ptr<const Packet> > m_macPromiscRxTrace;
+ TracedCallback<Ptr<const Packet> > m_snifferTrace;
+ TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
+ Ptr<Node> m_node;
+ ReceiveCallback m_rxCallback;
+ PromiscReceiveCallback m_promiscRxCallback;
+ std::string m_name;
+ uint32_t m_index;
+ uint16_t m_mtu;
+ bool m_needsArp;
+ bool m_supportsSendFrom;
+ bool m_isPointToPoint;
+};
+
+}; // namespace ns3
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/virtual-net-device/waf Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/virtual-net-device/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+
+def build(bld):
+ module = bld.create_ns3_module('virtual-net-device', ['node'])
+ module.source = [
+ 'virtual-net-device.cc',
+ ]
+ headers = bld.new_task_gen('ns3header')
+ headers.module = 'virtual-net-device'
+ headers.source = [
+ 'virtual-net-device.h',
+ ]
+
--- a/src/devices/wifi/mac-low.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/devices/wifi/mac-low.cc Fri Jun 19 12:58:35 2009 +0400
@@ -869,13 +869,6 @@
", duration=" << hdr->GetDuration () <<
", seq=0x"<< std::hex << m_currentHdr.GetSequenceControl () << std::dec);
m_phy->SendPacket (packet, txMode, WIFI_PREAMBLE_LONG, 0);
- /*
- * We have to notify the NAV of transmitted packets because of the 802.11e
- * requirement from section 9.9.1.4 that each EDCAF update its NAV from the
- * transmission of any other EDCAF within the same QSTA.
- */
- Time txDuration = m_phy->CalculateTxDuration (packet->GetSize (), txMode, WIFI_PREAMBLE_LONG);
- Simulator::Schedule (txDuration, &MacLow::NotifyNav, this, *hdr, txMode, WIFI_PREAMBLE_LONG);
}
void
--- a/src/helper/mobility-helper.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/helper/mobility-helper.cc Fri Jun 19 12:58:35 2009 +0400
@@ -34,7 +34,7 @@
MobilityHelper::MobilityHelper ()
{
- m_position = CreateObject<RandomRectanglePositionAllocator>
+ m_position = CreateObjectWithAttributes<RandomRectanglePositionAllocator>
("X", RandomVariableValue (ConstantVariable (0.0)),
"Y", RandomVariableValue (ConstantVariable (0.0)));
m_mobility.SetTypeId ("ns3::ConstantPositionMobilityModel");
@@ -147,7 +147,7 @@
// we need to setup a hierarchical mobility model
Ptr<MobilityModel> parent = m_mobilityStack.back ();
Ptr<MobilityModel> hierarchical =
- CreateObject<HierarchicalMobilityModel> ("Child", PointerValue (model),
+ CreateObjectWithAttributes<HierarchicalMobilityModel> ("Child", PointerValue (model),
"Parent", PointerValue (parent));
object->AggregateObject (hierarchical);
NS_LOG_DEBUG ("node="<<object<<", mob="<<hierarchical);
--- a/src/internet-stack/icmpv4-l4-protocol.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/icmpv4-l4-protocol.cc Fri Jun 19 12:58:35 2009 +0400
@@ -26,11 +26,6 @@
static TypeId tid = TypeId ("ns3::Icmpv4L4Protocol")
.SetParent<Ipv4L4Protocol> ()
.AddConstructor<Icmpv4L4Protocol> ()
- .AddAttribute ("CalcChecksum",
- "Control whether the icmp header checksum is calculated and stored in outgoing icmpv4 headers",
- BooleanValue (false),
- MakeBooleanAccessor (&Icmpv4L4Protocol::m_calcChecksum),
- MakeBooleanChecker ())
;
return tid;
}
@@ -111,7 +106,7 @@
Icmpv4Header icmp;
icmp.SetType (type);
icmp.SetCode (code);
- if (m_calcChecksum)
+ if (Node::ChecksumEnabled ())
{
icmp.EnableChecksum ();
}
--- a/src/internet-stack/icmpv4-l4-protocol.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/icmpv4-l4-protocol.h Fri Jun 19 12:58:35 2009 +0400
@@ -60,7 +60,6 @@
virtual void DoDispose (void);
Ptr<Node> m_node;
- bool m_calcChecksum;
};
} // namespace ns3
--- a/src/internet-stack/ipv4-l3-protocol.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/ipv4-l3-protocol.cc Fri Jun 19 12:58:35 2009 +0400
@@ -61,11 +61,6 @@
UintegerValue (64),
MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
MakeUintegerChecker<uint8_t> ())
- .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
- " and verify the checksum of incoming packets.",
- BooleanValue (false),
- MakeBooleanAccessor (&Ipv4L3Protocol::m_calcChecksum),
- MakeBooleanChecker ())
.AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.",
MakeTraceSourceAccessor (&Ipv4L3Protocol::m_txTrace))
.AddTraceSource ("Rx", "Receive ipv4 packet from incoming interface.",
@@ -422,7 +417,7 @@
}
Ipv4Header ipHeader;
- if (m_calcChecksum)
+ if (Node::ChecksumEnabled ())
{
ipHeader.EnableChecksum ();
}
@@ -609,7 +604,7 @@
ipHeader.SetIdentification (m_identification);
m_identification ++;
}
- if (m_calcChecksum)
+ if (Node::ChecksumEnabled ())
{
ipHeader.EnableChecksum ();
}
--- a/src/internet-stack/ipv4-l3-protocol.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/ipv4-l3-protocol.h Fri Jun 19 12:58:35 2009 +0400
@@ -211,7 +211,6 @@
Ipv4InterfaceList m_interfaces;
uint32_t m_nInterfaces;
uint8_t m_defaultTtl;
- bool m_calcChecksum;
uint16_t m_identification;
Ptr<Node> m_node;
TracedCallback<Ptr<const Packet>, uint32_t> m_txTrace;
--- a/src/internet-stack/tcp-l4-protocol.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/tcp-l4-protocol.cc Fri Jun 19 12:58:35 2009 +0400
@@ -332,11 +332,6 @@
ObjectFactoryValue (GetDefaultRttEstimatorFactory ()),
MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory),
MakeObjectFactoryChecker ())
- .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
- " and verify the checksum of incoming packets.",
- BooleanValue (false),
- MakeBooleanAccessor (&TcpL4Protocol::m_calcChecksum),
- MakeBooleanChecker ())
.AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
ObjectVectorValue (),
MakeObjectVectorAccessor (&TcpL4Protocol::m_sockets),
@@ -477,7 +472,7 @@
NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface);
TcpHeader tcpHeader;
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
tcpHeader.EnableChecksums();
tcpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
@@ -529,7 +524,7 @@
TcpHeader tcpHeader;
tcpHeader.SetDestinationPort (dport);
tcpHeader.SetSourcePort (sport);
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
tcpHeader.EnableChecksums();
}
@@ -571,7 +566,7 @@
outgoingHeader.SetLength (5); //header length in units of 32bit words
/* outgoingHeader.SetUrgentPointer (0); //XXX */
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
outgoingHeader.EnableChecksums();
}
--- a/src/internet-stack/tcp-l4-protocol.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/tcp-l4-protocol.h Fri Jun 19 12:58:35 2009 +0400
@@ -124,8 +124,6 @@
Ipv4Address, Ipv4Address);
static ObjectFactory GetDefaultRttEstimatorFactory (void);
- bool m_goodChecksum;
- bool m_calcChecksum;
std::vector<Ptr<TcpSocketImpl> > m_sockets;
};
--- a/src/internet-stack/udp-l4-protocol.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/udp-l4-protocol.cc Fri Jun 19 12:58:35 2009 +0400
@@ -48,11 +48,6 @@
static TypeId tid = TypeId ("ns3::UdpL4Protocol")
.SetParent<Ipv4L4Protocol> ()
.AddConstructor<UdpL4Protocol> ()
- .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
- " and verify the checksum of incoming packets.",
- BooleanValue (false),
- MakeBooleanAccessor (&UdpL4Protocol::m_calcChecksum),
- MakeBooleanChecker ())
;
return tid;
}
@@ -204,7 +199,7 @@
{
NS_LOG_FUNCTION (this << packet << source << destination);
UdpHeader udpHeader;
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
udpHeader.EnableChecksums();
}
@@ -243,7 +238,7 @@
NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport);
UdpHeader udpHeader;
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
udpHeader.EnableChecksums();
udpHeader.InitializeChecksum (saddr,
@@ -272,7 +267,7 @@
NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport);
UdpHeader udpHeader;
- if(m_calcChecksum)
+ if(Node::ChecksumEnabled ())
{
udpHeader.EnableChecksums();
udpHeader.InitializeChecksum (saddr,
--- a/src/internet-stack/udp-l4-protocol.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/udp-l4-protocol.h Fri Jun 19 12:58:35 2009 +0400
@@ -118,7 +118,6 @@
private:
Ptr<Node> m_node;
Ipv4EndPointDemux *m_endPoints;
- bool m_calcChecksum;
};
}; // namespace ns3
--- a/src/internet-stack/udp-test.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/internet-stack/udp-test.cc Fri Jun 19 12:58:35 2009 +0400
@@ -251,8 +251,8 @@
NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123);
NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123);
- m_receivedPacket->RemoveAllByteTags ();
- m_receivedPacket2->RemoveAllByteTags ();
+ m_receivedPacket = 0;
+ m_receivedPacket2 = 0;
Simulator::Destroy ();
--- a/src/node/node.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/node/node.cc Fri Jun 19 12:58:35 2009 +0400
@@ -28,6 +28,8 @@
#include "ns3/uinteger.h"
#include "ns3/log.h"
#include "ns3/assert.h"
+#include "ns3/global-value.h"
+#include "ns3/boolean.h"
NS_LOG_COMPONENT_DEFINE ("Node");
@@ -35,6 +37,11 @@
NS_OBJECT_ENSURE_REGISTERED (Node);
+GlobalValue g_checksumEnabled = GlobalValue ("ChecksumEnabled",
+ "A global switch to enable all checksums for all protocols",
+ BooleanValue (false),
+ MakeBooleanChecker ());
+
TypeId
Node::GetTypeId (void)
{
@@ -223,6 +230,14 @@
}
bool
+Node::ChecksumEnabled (void)
+{
+ BooleanValue val;
+ g_checksumEnabled.GetValue (val);
+ return val.Get ();
+}
+
+bool
Node::PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType)
{
--- a/src/node/node.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/node/node.h Fri Jun 19 12:58:35 2009 +0400
@@ -172,6 +172,12 @@
*/
void UnregisterProtocolHandler (ProtocolHandler handler);
+
+ /**
+ * \returns true if checksums are enabled, false otherwise.
+ */
+ static bool ChecksumEnabled (void);
+
protected:
/**
--- a/src/simulator/default-simulator-impl.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/simulator/default-simulator-impl.cc Fri Jun 19 12:58:35 2009 +0400
@@ -99,13 +99,6 @@
m_events = scheduler;
}
-Ptr<Scheduler>
-DefaultSimulatorImpl::GetScheduler (void) const
-{
- return m_events;
-}
-
-
void
DefaultSimulatorImpl::ProcessOneEvent (void)
{
--- a/src/simulator/default-simulator-impl.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/simulator/default-simulator-impl.h Fri Jun 19 12:58:35 2009 +0400
@@ -57,7 +57,6 @@
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetScheduler (Ptr<Scheduler> scheduler);
- virtual Ptr<Scheduler> GetScheduler (void) const;
private:
void ProcessOneEvent (void);
--- a/src/simulator/realtime-simulator-impl.cc Fri Jun 19 12:38:01 2009 +0400
+++ b/src/simulator/realtime-simulator-impl.cc Fri Jun 19 12:58:35 2009 +0400
@@ -141,13 +141,6 @@
}
}
-Ptr<Scheduler>
-RealtimeSimulatorImpl::GetScheduler (void) const
-{
- NS_LOG_FUNCTION_NOARGS ();
- return m_events;
-}
-
void
RealtimeSimulatorImpl::ProcessOneEvent (void)
{
--- a/src/simulator/realtime-simulator-impl.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/simulator/realtime-simulator-impl.h Fri Jun 19 12:58:35 2009 +0400
@@ -67,7 +67,6 @@
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
virtual void SetScheduler (Ptr<Scheduler> scheduler);
- virtual Ptr<Scheduler> GetScheduler (void) const;
void ScheduleRealtime (Time const &time, EventImpl *event);
void ScheduleRealtimeNow (EventImpl *event);
--- a/src/simulator/simulator-impl.h Fri Jun 19 12:38:01 2009 +0400
+++ b/src/simulator/simulator-impl.h Fri Jun 19 12:58:35 2009 +0400
@@ -50,7 +50,6 @@
virtual Time GetDelayLeft (const EventId &id) const = 0;
virtual Time GetMaximumSimulationTime (void) const = 0;
virtual void SetScheduler (Ptr<Scheduler> scheduler) = 0;
- virtual Ptr<Scheduler> GetScheduler (void) const = 0;
};
} // namespace ns3
--- a/src/wscript Fri Jun 19 12:38:01 2009 +0400
+++ b/src/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -23,6 +23,7 @@
'devices/emu',
'devices/bridge',
'devices/tap-bridge',
+ 'devices/virtual-net-device',
'applications/onoff',
'applications/packet-sink',
'applications/udp-echo',
--- a/utils/mobility-generator.cc Fri Jun 19 12:38:01 2009 +0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2007 INRIA
- *
- * 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 "ns3/ns2-mobility-file-topology.h"
-#include "ns3/object.h"
-#include "ns3/simulator.h"
-#include "ns3/mobility-model-notifier.h"
-#include <iostream>
-
-using namespace ns3;
-
-static void
-CourseChange (Ptr<const MobilityModel> position)
-{
- Position pos = position->Get ();
- std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
- << ", z=" << pos.z << std::endl;
-}
-
-int main (int argc, char *argv[])
-{
- std::vector<Ptr<Object> > objects;
- while (argc > 0)
- {
- if (strncmp (*argv, "--n=", strlen ("--n=")) == 0)
- {
- uint32_t n = atoi (*argv + strlen ("--n="));
- for (uint32_t i = 0; i < n; i++)
- {
- Ptr<MobilityModelNotifier> notifier = CreateObject<MobilityModelNotifier> ();
- notifier->RegisterListener (MakeCallback (&CourseChange));
- objects.push_back (notifier);
- }
- }
- else if (strncmp (*argv, "--ns2-topology=",
- strlen ("--ns2-topology=")) == 0)
- {
- const char *filename = *argv + strlen ("--ns2-topology=");
- Ns2MobilityFileTopology topology (filename);
- topology.Layout (objects.begin (), objects.end ());
- }
- argc--;
- argv++;
- }
-
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
--- a/utils/mobility-visualizer-model.cc Fri Jun 19 12:38:01 2009 +0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-
-#include <vector>
-
-#include "ns3/ptr.h"
-#include "ns3/mobility-model.h"
-#include "ns3/mobility-model-notifier.h"
-#include "ns3/position-allocator.h"
-#include "ns3/default-value.h"
-#include "ns3/command-line.h"
-#include "ns3/command-line.h"
-#include "ns3/simulator.h"
-#include "ns3/nstime.h"
-#include "ns3/node.h"
-#include "ns3/node-list.h"
-#include "ns3/rectangle-default-value.h"
-#include "ns3/type-id-default-value.h"
-#include "ns3/mobility-helper.h"
-
-#include "mobility-visualizer.h"
-
-using namespace ns3;
-
-static Time g_sampleInterval = Seconds (SAMPLE_INTERVAL);
-static uint32_t g_numNodes = 10;
-
-template <typename T>
-static const T* DefaultValueListGet (const std::string &name)
-{
- for (DefaultValueList::Iterator iter = DefaultValueList::Begin ();
- iter != DefaultValueList::End (); iter++)
- {
- const DefaultValueBase *value = *iter;
- if (value->GetName () == name)
- {
- return dynamic_cast<const T*> (value);
- }
- }
- return NULL;
-}
-
-
-
-static void
-Sample ()
-{
-
- ViewUpdateData *data = new ViewUpdateData;
- for (NodeList::Iterator nodeIter = NodeList::Begin (); nodeIter != NodeList::End (); nodeIter++)
- {
- Ptr<Node> node = *nodeIter;
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- Vector pos = mobility->GetPosition ();
- Vector vel = mobility->GetVelocity ();
-
- NodeUpdate update;
- update.node = PeekPointer<Node> (node);
- update.x = pos.x;
- update.y = pos.y;
- update.vx = vel.x;
- update.vy = vel.y;
- data->updateList.push_back (update);
- }
- data->time = Simulator::Now ().GetSeconds ();
- view_update (data);
- Simulator::Schedule (g_sampleInterval, Sample);
-}
-
-
-
-int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2)
-{
- DefaultValue::Bind ("RandomWalk2dMode", "Time");
- DefaultValue::Bind ("RandomWalk2dTime", "5s");
- DefaultValue::Bind ("RandomWalk2dSpeed", "Constant:20.0");
- DefaultValue::Bind ("RandomDirection2dSpeed", "Uniform:10.0:20.0");
- DefaultValue::Bind ("RandomWalk2dBounds", "0:400:0:300");
- DefaultValue::Bind ("RandomDirection2dArea", "0:400:0:300");
- DefaultValue::Bind ("RandomWaypointSpeed", "Uniform:10:30");
-
-// DefaultValue::Bind ("RandomDiscPositionX", "100");
-// DefaultValue::Bind ("RandomDiscPositionY", "50");
-// DefaultValue::Bind ("RandomDiscPositionRho", "Uniform:0:30");
-
- DefaultValue::Bind ("RandomTopologyPositionType", "RandomRectanglePosition");
- DefaultValue::Bind ("RandomTopologyMobilityType", "RandomWalkMobilityModel");
-
-// CommandLine::AddArgValue ("sample-interval","sample interval", g_sampleInterval);
-// CommandLine::AddArgValue ("num-nodes","number of nodes", g_numNodes);
-
- CommandLine::Parse (argc, argv);
-
- MobilityHelper mobility;
-
- for (uint32_t i = 0; i < g_numNodes; i++)
- {
- Ptr<Node> node = CreateObject<Node> ();
- }
-
- mobility.EnableNotifier ();
- mobility.Layout (NodeList::Begin (), NodeList::End ());
-
- Simulator::Schedule (g_sampleInterval, Sample);
-
- // XXX: The following is not really going to work with the params.
-
- if (mobility.GetMobilityModelType () == "RandomWalk2dMobilityModel")
- {
- Rectangle bounds = DefaultValueListGet<RectangleDefaultValue> ("RandomWalk2dBounds")->GetValue ();
- *x1 = bounds.xMin;
- *y1 = bounds.yMin;
- *x2 = bounds.xMax;
- *y2 = bounds.yMax;
- std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " "
- << bounds.yMin << " " << bounds.yMax << std::endl;
- }
- else if (mobility.GetMobilityModelType () == "RandomDirection2dMobilityModel")
- {
- Rectangle bounds = DefaultValueListGet<RectangleDefaultValue> ("RandomDirection2dArea")->GetValue ();
- *x1 = bounds.xMin;
- *y1 = bounds.yMin;
- *x2 = bounds.xMax;
- *y2 = bounds.yMax;
- std::cout << "RECT " << bounds.xMin << " " << bounds.xMax << " "
- << bounds.yMin << " " << bounds.yMax << std::endl;
- }
- else if (mobility.GetMobilityModelType () == "RandomWaypointMobilityModel")
- {
- std::cerr << "bounds for RandomWaypointMobilityModel not implemented" << std::endl;
- //ClassId posType = DefaultValueList::Get<ClassIdDefaultValue> ("RandomWaypointPosition")->GetValue ();
- std::cout << "?" << std::endl; // too hard to represent an abstract/probabilistic model graphically
- }
- else
- {
- NS_FATAL_ERROR ("mobility type " << mobility.GetMobilityModelType () << " not supported");
- }
-
- std::cerr << g_sampleInterval << std::endl;
- return 0;
-}
--- a/utils/mobility-visualizer-view.cc Fri Jun 19 12:38:01 2009 +0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-
-#include <map>
-
-#include <goocanvas.h>
-#include <glib/gthread.h>
-
-#include "mobility-visualizer.h"
-#include <map>
-#include "ns3/simulator.h"
-
-#define MAX_QUEUE_LENGTH 100
-#define MAX_EVENTS 20
-#define LOOKAHEAD_SECONDS 10
-
-GtkWidget *g_canvas;
-
-int model_init (int argc, char *argv[]);
-
-struct Node
-{
- GooCanvasItem *m_item;
- GooCanvasItem *m_vector;
- void create ()
- {
- GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (g_canvas));
- m_item = goo_canvas_ellipse_new (root, 0, 0, 2.0, 2.0,
- "line_width", 0.5,
- "stroke_color", "black",
- "fill_color", "red",
- NULL);
-
- m_vector = goo_canvas_polyline_new (root, FALSE, 0,
- "line_width", 0.3,
- "stroke_color", "black",
- "end-arrow", TRUE,
- "arrow-length", 10.0,
- "arrow-width", 10.0,
- NULL);
-
- }
-
-
- void update (double x, double y, double vx, double vy)
- {
- g_object_set (m_item, "center_x", x, "center_y", y, NULL);
-
- if (vx == 0 && vy == 0)
- {
- GooCanvasPoints *points = goo_canvas_points_new (0);
- g_object_set (m_vector, "points", points, NULL);
- goo_canvas_points_unref (points);
- }
- else
- {
- GooCanvasPoints *points = goo_canvas_points_new (2);
-
- points->coords[0] = x;
- points->coords[1] = y;
- points->coords[2] = x + vx;
- points->coords[3] = y + vy;
-
- g_object_set (m_vector, "points", points, NULL);
- goo_canvas_points_unref (points);
- }
- }
-};
-
-std::map<void*, Node> g_nodes;
-
-GTimeVal initialTime = {-1, -1};
-gboolean firstTime = TRUE;
-double g_lookaheadTime = 0;
-GStaticMutex g_lookaheadTimeMux = G_STATIC_MUTEX_INIT;
-ViewUpdateData *g_nextData = NULL;
-
-
-GAsyncQueue *queue;
-
-#define TIME_SCALE 1
-
-double get_current_time ()
-{
- GTimeVal currTime;
- g_get_current_time (&currTime);
- GTimeVal relativeTime;
- relativeTime.tv_sec = currTime.tv_sec - initialTime.tv_sec + LOOKAHEAD_SECONDS;
- relativeTime.tv_usec = currTime.tv_usec;
- g_time_val_add (&relativeTime, -initialTime.tv_usec);
- return (relativeTime.tv_sec + 1.0e-6*relativeTime.tv_usec)*TIME_SCALE;
-}
-
-// called from the simulation thread
-void view_update (ViewUpdateData *updateData)
-{
- while ((g_static_mutex_lock (&g_lookaheadTimeMux), g_lookaheadTime) != 0 and updateData->time >= g_lookaheadTime)
- {
- g_static_mutex_unlock (&g_lookaheadTimeMux);
- g_usleep ((gulong) 10e3);
- }
- g_static_mutex_unlock (&g_lookaheadTimeMux);
- g_async_queue_push (queue, updateData);
-}
-
-void view_update_process (ViewUpdateData *updateData)
-{
- for (std::vector<NodeUpdate>::const_iterator update
- = updateData->updateList.begin ();
- update != updateData->updateList.end ();
- update++)
- {
- if (g_nodes.find (update->node) == g_nodes.end ())
- {
- g_nodes[update->node].create ();
- }
- g_nodes[update->node].update (update->x, update->y, update->vx, update->vy);
- }
- delete updateData;
-}
-
-gboolean view_update_consumer ()
-{
- if (firstTime)
- {
- firstTime = FALSE;
- g_get_current_time (&initialTime);
- }
-
- double now = get_current_time ();
- g_static_mutex_lock (&g_lookaheadTimeMux);
- g_lookaheadTime = now + LOOKAHEAD_SECONDS;
- g_static_mutex_unlock (&g_lookaheadTimeMux);
-
- if (!g_nextData)
- g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
-
- if (!g_nextData)
- return TRUE;
-
- if (g_nextData->time > now)
- return TRUE;
-
- do
- {
- view_update_process (g_nextData);
- g_nextData = (ViewUpdateData *) g_async_queue_try_pop (queue);
- }
- while (g_nextData && g_nextData->time <= now);
-
- return TRUE;
-}
-
-void zoom_changed (GtkAdjustment *adj)
-{
- goo_canvas_set_scale (GOO_CANVAS (g_canvas), gtk_adjustment_get_value (adj));
-}
-
-int main (int argc, char *argv[])
-{
- g_thread_init (NULL);
- gtk_init (&argc, &argv);
- double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
-
- model_init (argc, argv, &x1, &y1, &x2, &y2);
-
- GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
- gtk_widget_show (window);
- g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
- GtkWidget *scrolled_win = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN);
- gtk_widget_show (scrolled_win);
-
- GtkWidget *vbox = gtk_vbox_new (FALSE, 4);
- gtk_widget_show (vbox);
- gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, 1, 1, 4);
- gtk_container_add (GTK_CONTAINER (window), vbox);
-
- GtkWidget *hbox = gtk_hbox_new (FALSE, 4);
- gtk_widget_show (hbox);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 4);
-
- GtkObject *zoom = gtk_adjustment_new (3.0, 0.1, 10.0, 0.2, 1.0, 1.0);
- gtk_box_pack_start(GTK_BOX (hbox),
- GTK_WIDGET (g_object_new (GTK_TYPE_SPIN_BUTTON, "adjustment", zoom,
- "visible", true, "digits", 2, NULL)),
- false, false, 4);
-
- g_canvas = goo_canvas_new ();
- gtk_widget_set_size_request (GTK_WIDGET (g_canvas), 600, 450);
- goo_canvas_set_bounds (GOO_CANVAS (g_canvas), -500, -500, 500, 500);
- g_signal_connect (zoom, "value-changed", G_CALLBACK (zoom_changed), NULL);
- gtk_adjustment_value_changed (GTK_ADJUSTMENT (zoom));
- gtk_widget_show (g_canvas);
- gtk_container_add (GTK_CONTAINER (scrolled_win), g_canvas);
-
- goo_canvas_scroll_to (GOO_CANVAS (g_canvas), 0, 0);
-
- // create the bounds rectangle
- if (x1 != x2)
- {
- GooCanvasItem *item =
- goo_canvas_rect_new (goo_canvas_get_root_item (GOO_CANVAS (g_canvas)),
- x1, y1, x2-x1, y2-y1, NULL);
- g_object_set (item, "line-width", 1.0, "stroke-color", "grey", NULL);
- }
-
- queue = g_async_queue_new ();
-
- g_timeout_add ((guint) (SAMPLE_INTERVAL*1000), (GSourceFunc) view_update_consumer, NULL);
-
- g_thread_create (GThreadFunc (ns3::Simulator::Run), NULL, FALSE, NULL);
-
- gtk_main ();
-
- return 0;
-}
--- a/utils/mobility-visualizer.h Fri Jun 19 12:38:01 2009 +0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-#include <vector>
-
-int model_init (int argc, char *argv[], double *x1, double *y1, double *x2, double *y2);
-
-struct NodeUpdate
-{
- void *node;
- double x;
- double y;
- double vx;
- double vy;
-};
-
-struct ViewUpdateData
-{
- std::vector<NodeUpdate> updateList;
- double time;
-};
-
-void view_update (ViewUpdateData *updateData);
-
-#define SAMPLE_INTERVAL (1.0/30)
--- a/utils/wscript Fri Jun 19 12:38:01 2009 +0400
+++ b/utils/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -1,11 +1,6 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import os.path
-def configure(conf):
- conf.env['ENABLE_MOBILITY_VISUALIZER'] = conf.pkg_check_modules(
- 'MOBILITY_VISUALIZER', 'goocanvas gthread-2.0', mandatory=False)
-
-
def build(bld):
env = bld.env
@@ -25,13 +20,3 @@
['internet-stack', 'csma-cd', 'point-to-point'])
obj.source = 'print-introspected-doxygen.cc'
-# XXX: disable mobility visualizer code temporarily.
- env['ENABLE_MOBILITY_VISUALIZER'] = ''
- if env['ENABLE_MOBILITY_VISUALIZER']:
- obj = bld.create_ns3_program('mobility-visualizer',
- ['internet-stack', 'mobility'])
- obj.source = ['mobility-visualizer-model.cc', 'mobility-visualizer-view.cc']
- obj.uselib = 'MOBILITY_VISUALIZER'
- if os.path.basename(obj.env['CXX']).startswith("g++"):
- obj.env.append_value('CXXFLAGS', '-fno-strict-aliasing')
-
--- a/wscript Fri Jun 19 12:38:01 2009 +0400
+++ b/wscript Fri Jun 19 12:58:35 2009 +0400
@@ -273,7 +273,6 @@
env['WL_SONAME_SUPPORTED'] = True
conf.sub_config('src')
- conf.sub_config('utils')
conf.sub_config('bindings/python')
if Options.options.enable_modules:
@@ -498,6 +497,8 @@
lib.target = 'ns3'
if lib.env['CXX_NAME'] == 'gcc' and env['WL_SONAME_SUPPORTED']:
lib.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % ccroot.get_target_name(lib))
+ if sys.platform == 'cygwin':
+ lib.features.append('implib') # workaround for WAF bug #472
if env['NS3_ENABLED_MODULES']:
lib.add_objects = list(modules)