2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import metadata
6 from nepi.core.attributes import Attribute
7 from nepi.util import validation
11 from nepi.util.tunchannel_impl import \
12 crossconnect_tunchannel_peer_init, \
13 crossconnect_tunchannel_peer_compl
16 ### Connection functions ####
18 def connect_node_device(testbed_instance, node_guid, device_guid):
19 node = testbed_instance._elements[node_guid]
20 device = testbed_instance._elements[device_guid]
21 node.AddDevice(device)
23 def connect_queue_device(testbed_instance, queue_guid, device_guid):
24 queue = testbed_instance._elements[queue_guid]
25 device = testbed_instance._elements[device_guid]
26 device.SetQueue(queue)
28 def connect_manager_device(testbed_instance, manager_guid, device_guid):
29 manager = testbed_instance._elements[manager_guid]
30 device = testbed_instance._elements[device_guid]
31 device.SetRemoteStationManager(manager)
33 def connect_phy_device(testbed_instance, phy_guid, device_guid):
34 phy = testbed_instance._elements[phy_guid]
35 device = testbed_instance._elements[device_guid]
38 # search for the node asociated with the device
39 node_guid = testbed_instance.get_connected(device_guid, "node", "devs")
40 if len(node_guid) == 0:
41 raise RuntimeError("Can't instantiate interface %d outside netns \
43 node = testbed_instance.elements[node_guid[0]]
46 def connect_mac_device(testbed_instance, mac_guid, device_guid):
47 mac = testbed_instance._elements[mac_guid]
48 device = testbed_instance._elements[device_guid]
51 def connect_errormodel_device(testbed_instance, model_guid, device_guid):
52 model = testbed_instance._elements[model_guid]
53 device = testbed_instance._elements[device_guid]
54 device.SetReceiveErrorModel(model)
56 def connect_errormodel_phy(testbed_instance, err_guid, phy_guid):
57 err = testbed_instance._elements[err_guid]
58 phy = testbed_instance._elements[phy_guid]
59 phy.SetErrorRateModel(err)
61 def connect_channel_device(testbed_instance, channel_guid, device_guid):
62 channel = testbed_instance._elements[channel_guid]
63 device = testbed_instance._elements[device_guid]
64 device.Attach(channel)
66 def connect_simple_channel_device(testbed_instance, channel_guid, device_guid):
67 channel = testbed_instance._elements[channel_guid]
68 device = testbed_instance._elements[device_guid]
69 device.SetChannel(channel)
71 def connect_loss_channel(testbed_instance, loss_guid, channel_guid):
72 loss = testbed_instance._elements[loss_guid]
73 channel = testbed_instance._elements[channel_guid]
74 channel.SetPropagationLossModel(loss)
76 def connect_next_loss(testbed_instance, prev_guid, next_guid):
77 prev = testbed_instance._elements[prev_guid]
78 next = testbed_instance._elements[next_guid]
81 def connect_delay_channel(testbed_instance, delay_guid, channel_guid):
82 delay = testbed_instance._elements[delay_guid]
83 channel = testbed_instance._elements[channel_guid]
84 channel.SetPropagationDelayModel(delay)
86 def connect_node_application(testbed_instance, node_guid, application_guid):
87 node = testbed_instance._elements[node_guid]
88 application = testbed_instance._elements[application_guid]
89 node.AddApplication(application)
90 # works for ArpL3Protocol, Ipv4L3Protocol, UdpL4Protocol, TcpL4Protocol,
91 # NscTcpL4Protocol, MobilityModel (every subclass),
92 # RoutingProtocol (every subclass)
94 def connect_node_other(testbed_instance, node_guid, other_guid):
95 node = testbed_instance._elements[node_guid]
96 other = testbed_instance._elements[other_guid]
97 node.AggregateObject(other)
99 def connect_fd(testbed_instance, fdnd_guid, cross_data):
100 fdnd = testbed_instance._elements[fdnd_guid]
101 endpoint = fdnd.GetEndpoint()
102 # XXX: check the method StringToBuffer of ns3::FileDescriptorNetDevice
103 # to see how the address should be decoded
104 address = endpoint.replace(":", "").decode('hex')[2:]
105 testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address)
107 # If it's a non-abstract socket, add the path
108 if not address.startswith('\x00'):
109 address = os.path.join( testbed_instance.root_directory, address )
111 # Set tun standard contract attributes
112 testbed_instance.set(fdnd_guid, "tun_addr", address )
113 testbed_instance.set(fdnd_guid, "tun_proto", "fd")
114 testbed_instance.set(fdnd_guid, "tun_port", 0)
115 testbed_instance.set(fdnd_guid, "tun_key", "\xfa"*32) # unimportant, fds aren't encrypted
117 def connect_tunchannel_fd(testbed_instance, tun_guid, fdnd_guid):
118 fdnd = testbed_instance._elements[fdnd_guid]
119 tun = testbed_instance._elements[tun_guid]
121 # XXX: check the method StringToBuffer of ns3::FileDescriptorNetDevice
122 # to see how the address should be decoded
123 endpoint = fdnd.GetEndpoint()
124 address = endpoint.replace(":", "").decode('hex')[2:]
125 testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address)
127 # Create socket pair to connect the FDND and the TunChannel with it
129 sock1, sock2 = socket.socketpair(
130 socket.AF_UNIX, socket.SOCK_SEQPACKET)
132 # Send one endpoint to the FDND
135 sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
136 sock.connect(address)
137 passfd.sendfd(sock, sock1.fileno(), '0')
139 # Store a reference to the endpoint to keep the socket alive
140 fdnd._endpoint_socket = sock1
142 # Send the other endpoint to the TUN channel
143 tun.tun_socket = sock2
145 # With this kind of tun_socket, NS3 will expect a PI header
146 # (sockets don't support the TUNGETIFF ioctl, so it will assume
147 # the default presence of PI headers)
151 ### Connector information ###
153 connector_types = dict({
155 "help": "Connector to a ns3::Node object (mandatory)",
161 "help": "Connector to network interfaces",
167 "help": "Connector to exactly two network interfaces (mandatory)",
173 "help": "Connector to exactly one network interface (mandatory)",
179 "help": "Connector to applications",
185 "help": "Connector to network stacks and protocols",
191 "help": "Connector to a channel for the device (mandatory)",
197 "help": "Connector to a queueing discipline (mandatory)",
203 "help": "Connector to an error model for the device",
209 "help": "File descriptor receptor for devices with file descriptors",
215 "help": "File descriptor provider for devices with file descriptors",
221 "help": "Connector to interconnect elements with a PHY wifi model",
227 "help": "Connector to interconnect a wifi channel with PHY wifi models",
233 "help": "Connector to interconnect a device with a MAC wifi model",
239 "help": "Connector to interconnect a wifi device with a wifi manager",
245 "help": "Connector to a delay model",
251 "help": "Connector to a loss model",
257 "help": "Connector to the previous loss model",
263 "help": "Connector to the next loss model",
269 "help": "Connector to a mobility model for the node",
275 "help": "ip-ip tunneling over TCP link",
281 "help": "ip-ip tunneling over UDP datagrams",
290 "from": ( "ns3", "ns3::Node", "devs" ),
291 "to": ( "ns3", "ns3::BridgeNetDevice", "node" ),
292 "init_code": connect_node_device,
296 "from": ( "ns3", "ns3::Node", "devs" ),
297 "to": ( "ns3", "ns3::CsmaNetDevice", "node" ),
298 "init_code": connect_node_device,
302 "from": ( "ns3", "ns3::Node", "devs" ),
303 "to": ( "ns3", "ns3::EmuNetDevice", "node" ),
304 "init_code": connect_node_device,
308 "from": ( "ns3", "ns3::Node", "devs" ),
309 "to": ( "ns3", "ns3::PointToPointNetDevice", "node" ),
310 "init_code": connect_node_device,
314 "from": ( "ns3", "ns3::Node", "devs" ),
315 "to": ( "ns3", "ns3::SimpleNetDevice", "node" ),
316 "init_code": connect_node_device,
320 "from": ( "ns3", "ns3::Node", "devs" ),
321 "to": ( "ns3", "ns3::FileDescriptorNetDevice", "node" ),
322 "init_code": connect_node_device,
326 "from": ( "ns3", "ns3::Node", "devs" ),
327 "to": ( "ns3", "ns3::WifiNetDevice", "node" ),
328 "init_code": connect_node_device,
332 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
333 "to": ( "ns3", "ns3::CsmaNetDevice", "queue" ),
334 "init_code": connect_queue_device,
338 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
339 "to": ( "ns3", "ns3::EmuNetDevice", "queue" ),
340 "init_code": connect_queue_device,
344 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
345 "to": ( "ns3", "ns3::PointToPointNetDevice", "queue" ),
346 "init_code": connect_queue_device,
350 "from": ( "ns3", "ns3::ArfWifiManager", "dev" ),
351 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
352 "init_code": connect_manager_device,
356 "from": ( "ns3", "ns3::ConstantRateWifiManager", "dev" ),
357 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
358 "init_code": connect_manager_device,
362 "from": ( "ns3", "ns3::YansWifiPhy", "dev" ),
363 "to": ( "ns3", "ns3::WifiNetDevice", "phy" ),
364 "init_code": connect_phy_device,
368 "from": ( "ns3", "ns3::QapWifiMac", "dev" ),
369 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
370 "init_code": connect_mac_device,
374 "from": ( "ns3", "ns3::QstaWifiMac", "dev" ),
375 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
376 "init_code": connect_mac_device,
380 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
381 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
382 "init_code": connect_errormodel_device,
386 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
387 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
388 "init_code": connect_errormodel_device,
392 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
393 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
394 "init_code": connect_errormodel_device,
398 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
399 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
400 "init_code": connect_errormodel_device,
404 "from": ( "ns3", "ns3::NistErrorRateModel", "phy" ),
405 "to": ( "ns3", "ns3::YansWifiPhy", "err" ),
406 "init_code": connect_errormodel_phy,
410 "from": ( "ns3", "ns3::CsmaChannel", "devs" ),
411 "to": ( "ns3", "ns3::CsmaNetDevice", "chan" ),
412 "init_code": connect_channel_device,
416 "from": ( "ns3", "ns3::PointToPointChannel", "dev2" ),
417 "to": ( "ns3", "ns3::PointToPointNetDevice", "chan" ),
418 "init_code": connect_channel_device,
422 "from": ( "ns3", "ns3::SimpleChannel", "devs" ),
423 "to": ( "ns3", "ns3::SimpleNetDevice", "chan" ),
424 "init_code": connect_simple_channel_device,
428 "from": ( "ns3", "ns3::YansWifiChannel", "phys" ),
429 "to": ( "ns3", "ns3::YansWifiPhy", "chan" ),
430 "init_code": connect_simple_channel_device,
434 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
435 "to": ( "ns3", "ns3::YansWifiChannel", "loss" ),
436 "init_code": connect_loss_channel,
440 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
441 "to": ( "ns3", "ns3::LogDistancePropagationLossModel", "next" ),
442 "init_code": connect_next_loss,
446 "from": ( "ns3", "ns3::ConstantSpeedPropagationDelayModel", "chan" ),
447 "to": ( "ns3", "ns3::YansWifiChannel", "delay" ),
448 "init_code": connect_delay_channel,
452 "from": ( "ns3", "ns3::Node", "apps" ),
453 "to": ( "ns3", "ns3::OnOffApplication", "node" ),
454 "init_code": connect_node_application,
458 "from": ( "ns3", "ns3::Node", "apps" ),
459 "to": ( "ns3", "ns3::PacketSink", "node" ),
460 "init_code": connect_node_application,
464 "from": ( "ns3", "ns3::Node", "apps" ),
465 "to": ( "ns3", "ns3::UdpEchoClient", "node" ),
466 "init_code": connect_node_application,
470 "from": ( "ns3", "ns3::Node", "apps" ),
471 "to": ( "ns3", "ns3::UdpEchoServer", "node" ),
472 "init_code": connect_node_application,
476 "from": ( "ns3", "ns3::Node", "apps" ),
477 "to": ( "ns3", "ns3::V4Ping", "node" ),
478 "init_code": connect_node_application,
482 "from": ( "ns3", "ns3::Node", "protos" ),
483 "to": ( "ns3", "ns3::ArpL3Protocol", "node" ),
484 "init_code": connect_node_other,
488 "from": ( "ns3", "ns3::Node", "protos" ),
489 "to": ( "ns3", "ns3::Icmpv4L4Protocol", "node" ),
490 "init_code": connect_node_other,
494 "from": ( "ns3", "ns3::Node", "protos" ),
495 "to": ( "ns3", "ns3::Icmpv6L4Protocol", "node" ),
496 "init_code": connect_node_other,
500 "from": ( "ns3", "ns3::Node", "protos" ),
501 "to": ( "ns3", "ns3::Ipv4L3Protocol", "node" ),
502 "init_code": connect_node_other,
506 "from": ( "ns3", "ns3::Node", "protos" ),
507 "to": ( "ns3", "ns3::Ipv6L3Protocol", "node" ),
508 "init_code": connect_node_other,
512 "from": ( "ns3", "ns3::Node", "protos" ),
513 "to": ( "ns3", "ns3::UdpL4Protocol", "node" ),
514 "init_code": connect_node_other,
518 "from": ( "ns3", "ns3::Node", "protos" ),
519 "to": ( "ns3", "ns3::TcpL4Protocol", "node" ),
520 "init_code": connect_node_other,
524 "from": ( "ns3", "ns3::Node", "mobility" ),
525 "to": ( "ns3", "ns3::ConstantAccelerationMobilityModel", "node" ),
526 "init_code": connect_node_other,
530 "from": ( "ns3", "ns3::Node", "mobility" ),
531 "to": ( "ns3", "ns3::ConstantPositionMobilityModel", "node" ),
532 "init_code": connect_node_other,
536 "from": ( "ns3", "ns3::Node", "mobility" ),
537 "to": ( "ns3", "ns3::ConstantVelocityMobilityModel", "node" ),
538 "init_code": connect_node_other,
542 "from": ( "ns3", "ns3::Node", "mobility" ),
543 "to": ( "ns3", "ns3::HierarchicalMobilityModel", "node" ),
544 "init_code": connect_node_other,
548 "from": ( "ns3", "ns3::Node", "mobility" ),
549 "to": ( "ns3", "ns3::RandomDirection2dMobilityModel", "node" ),
550 "init_code": connect_node_other,
554 "from": ( "ns3", "ns3::Node", "mobility" ),
555 "to": ( "ns3", "ns3::RandomWalk2dMobilityModel", "node" ),
556 "init_code": connect_node_other,
560 "from": ( "ns3", "ns3::Node", "mobility" ),
561 "to": ( "ns3", "ns3::RandomWaypointMobilityModel", "node" ),
562 "init_code": connect_node_other,
566 "from": ( "ns3", "ns3::FileDescriptorNetDevice", "->fd" ),
567 "to": ( None, None, "fd->" ),
568 "init_code": connect_fd,
572 "from": ( "ns3", "ns3::Nepi::TunChannel", "fd->" ),
573 "to": ( "ns3", "ns3::FileDescriptorNetDevice", "->fd" ),
574 "init_code": connect_tunchannel_fd,
578 "from": ( "ns3", "ns3::Nepi::TunChannel", "tcp"),
579 "to": (None, None, "tcp"),
580 "init_code": functools.partial(crossconnect_tunchannel_peer_init,"tcp"),
581 "compl_code": functools.partial(crossconnect_tunchannel_peer_compl,"tcp"),
585 "from": ( "ns3", "ns3::Nepi::TunChannel", "udp"),
586 "to": (None, None, "udp"),
587 "init_code": functools.partial(crossconnect_tunchannel_peer_init,"udp"),
588 "compl_code": functools.partial(crossconnect_tunchannel_peer_compl,"udp"),
595 "name": "P2PPcapTrace",
596 "help": "Trace to sniff packets from a P2P network device"
599 "name": "P2PAsciiTrace",
600 "help": "Ascii trace from a P2P network device"
602 "csmapcap_promisc": dict({
603 "name": "CsmaPromiscPcapTrace",
604 "help": "Trace to sniff packets from a Csma network device in promiscuous mode"
607 "name": "CsmaPcapTrace",
608 "help": "Trace to sniff packets from a Csma network device"
611 "name": "FileDescriptorPcapTrace",
612 "help": "Trace to sniff packets from a FileDescriptor network device"
614 "yanswifipcap": dict({
615 "name": "YansWifiPhyPcapTrace",
616 "help": "Trace to sniff packets from a Wifi network device"
620 factories_order = ["ns3::BasicEnergySource",
621 "ns3::WifiRadioEnergyModel",
622 "ns3::BSSchedulerRtps",
623 "ns3::BSSchedulerSimple",
624 "ns3::SubscriberStationNetDevice",
625 "ns3::BaseStationNetDevice",
626 "ns3::UdpTraceClient",
632 "ns3::flame::FlameProtocol",
633 "ns3::flame::FlameRtable",
634 "ns3::dot11s::AirtimeLinkMetricCalculator",
635 "ns3::dot11s::HwmpProtocol",
636 "ns3::dot11s::HwmpRtable",
637 "ns3::dot11s::PeerManagementProtocol",
638 "ns3::dot11s::PeerLink",
639 "ns3::MeshWifiInterfaceMac",
640 "ns3::MeshPointDevice",
643 "ns3::UanPhyCalcSinrDual",
644 "ns3::UanPhyPerGenDefault",
646 "ns3::UanPropModelThorp",
648 "ns3::UanNoiseModelDefault",
650 "ns3::UanPropModelIdeal",
651 "ns3::UanTransducerHd",
652 "ns3::UanPhyCalcSinrDefault",
654 "ns3::UanPhyCalcSinrFhFsk",
655 "ns3::UanPhyPerUmodem",
658 "ns3::AthstatsWifiTraceSink",
661 "ns3::NonCommunicatingNetDevice",
662 "ns3::HalfDuplexIdealPhy",
663 "ns3::AlohaNoackNetDevice",
664 "ns3::SpectrumAnalyzer",
665 "ns3::WaveformGenerator",
666 "ns3::MultiModelSpectrumChannel",
667 "ns3::SingleModelSpectrumChannel",
668 "ns3::MsduStandardAggregator",
672 "ns3::QadhocWifiMac",
673 "ns3::MinstrelWifiManager",
674 "ns3::CaraWifiManager",
675 "ns3::AarfcdWifiManager",
676 "ns3::OnoeWifiManager",
677 "ns3::AmrrWifiManager",
678 "ns3::ConstantRateWifiManager",
679 "ns3::IdealWifiManager",
680 "ns3::AarfWifiManager",
681 "ns3::ArfWifiManager",
682 "ns3::WifiNetDevice",
688 "ns3::YansWifiChannel",
690 "ns3::NistErrorRateModel",
691 "ns3::YansErrorRateModel",
692 "ns3::WaypointMobilityModel",
693 "ns3::ConstantAccelerationMobilityModel",
694 "ns3::RandomDirection2dMobilityModel",
695 "ns3::RandomWalk2dMobilityModel",
696 "ns3::SteadyStateRandomWaypointMobilityModel",
697 "ns3::RandomWaypointMobilityModel",
698 "ns3::GaussMarkovMobilityModel",
699 "ns3::ConstantVelocityMobilityModel",
700 "ns3::ConstantPositionMobilityModel",
701 "ns3::ListPositionAllocator",
702 "ns3::GridPositionAllocator",
703 "ns3::RandomRectanglePositionAllocator",
704 "ns3::RandomBoxPositionAllocator",
705 "ns3::RandomDiscPositionAllocator",
706 "ns3::UniformDiscPositionAllocator",
707 "ns3::HierarchicalMobilityModel",
708 "ns3::aodv::RoutingProtocol",
709 "ns3::UdpEchoServer",
710 "ns3::UdpEchoClient",
712 "ns3::OnOffApplication",
713 "ns3::VirtualNetDevice",
714 "ns3::FileDescriptorNetDevice",
715 "ns3::Nepi::TunChannel",
717 "ns3::BridgeChannel",
718 "ns3::BridgeNetDevice",
721 "ns3::CsmaNetDevice",
722 "ns3::PointToPointRemoteChannel",
723 "ns3::PointToPointChannel",
724 "ns3::PointToPointNetDevice",
725 "ns3::NscTcpL4Protocol",
726 "ns3::Icmpv6L4Protocol",
727 "ns3::Ipv6OptionPad1",
728 "ns3::Ipv6OptionPadn",
729 "ns3::Ipv6OptionJumbogram",
730 "ns3::Ipv6OptionRouterAlert",
731 "ns3::Ipv6ExtensionHopByHop",
732 "ns3::Ipv6ExtensionDestination",
733 "ns3::Ipv6ExtensionFragment",
734 "ns3::Ipv6ExtensionRouting",
735 "ns3::Ipv6ExtensionLooseRouting",
736 "ns3::Ipv6ExtensionESP",
737 "ns3::Ipv6ExtensionAH",
738 "ns3::Ipv6L3Protocol",
739 "ns3::LoopbackNetDevice",
740 "ns3::Icmpv4L4Protocol",
741 "ns3::RttMeanDeviation",
742 "ns3::ArpL3Protocol",
743 "ns3::TcpL4Protocol",
744 "ns3::UdpL4Protocol",
745 "ns3::Ipv4L3Protocol",
746 "ns3::SimpleNetDevice",
747 "ns3::SimpleChannel",
749 "ns3::DropTailQueue",
751 "ns3::FriisSpectrumPropagationLossModel",
752 "ns3::Cost231PropagationLossModel",
753 "ns3::JakesPropagationLossModel",
754 "ns3::RandomPropagationLossModel",
755 "ns3::FriisPropagationLossModel",
756 "ns3::TwoRayGroundPropagationLossModel",
757 "ns3::LogDistancePropagationLossModel",
758 "ns3::ThreeLogDistancePropagationLossModel",
759 "ns3::NakagamiPropagationLossModel",
760 "ns3::FixedRssLossModel",
761 "ns3::MatrixPropagationLossModel",
762 "ns3::RangePropagationLossModel",
763 "ns3::RandomPropagationDelayModel",
764 "ns3::ConstantSpeedPropagationDelayModel",
765 "ns3::RateErrorModel",
766 "ns3::ListErrorModel",
767 "ns3::ReceiveListErrorModel",
769 "ns3::EnergySourceContainer"
772 testbed_attributes = dict({
773 "simu_impl_type": dict({
774 "name": "SimulatorImplementationType",
775 "help": "The object class to use as the simulator implementation",
776 "type": Attribute.STRING,
777 "flags": Attribute.DesignOnly,
778 "validation_function": validation.is_string
781 "name": "ChecksumEnabled",
782 "help": "A global switch to enable all checksums for all protocols",
783 "type": Attribute.BOOL,
785 "flags": Attribute.DesignOnly,
786 "validation_function": validation.is_bool
790 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
792 def connector_types(self):
793 return connector_types
796 def connections(self):
800 def attributes(self):
801 from attributes_metadata_v3_9_RC3 import attributes
809 def create_order(self):
810 return factories_order
813 def configure_order(self):
814 return factories_order
817 def factories_info(self):
818 from factories_metadata_v3_9_RC3 import factories_info
819 return factories_info
822 def testbed_attributes(self):
823 return testbed_attributes