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
10 ### Connection functions ####
12 def connect_node_device(testbed_instance, node_guid, device_guid):
13 node = testbed_instance._elements[node_guid]
14 device = testbed_instance._elements[device_guid]
15 node.AddDevice(device)
17 def connect_queue_device(testbed_instance, queue_guid, device_guid):
18 queue = testbed_instance._elements[queue_guid]
19 device = testbed_instance._elements[device_guid]
20 device.SetQueue(queue)
22 def connect_manager_device(testbed_instance, manager_guid, device_guid):
23 manager = testbed_instance._elements[manager_guid]
24 device = testbed_instance._elements[device_guid]
25 device.SetRemoteStationManager(manager)
27 def connect_phy_device(testbed_instance, phy_guid, device_guid):
28 phy = testbed_instance._elements[phy_guid]
29 device = testbed_instance._elements[device_guid]
32 # search for the node asociated with the device
33 node_guid = testbed_instance.get_connected(device_guid, "node", "devs")
34 if len(node_guid) == 0:
35 raise RuntimeError("Can't instantiate interface %d outside netns \
37 node = testbed_instance.elements[node_guid[0]]
40 def connect_mac_device(testbed_instance, mac_guid, device_guid):
41 mac = testbed_instance._elements[mac_guid]
42 device = testbed_instance._elements[device_guid]
45 def connect_errormodel_device(testbed_instance, model_guid, device_guid):
46 model = testbed_instance._elements[model_guid]
47 device = testbed_instance._elements[device_guid]
48 device.SetReceiveErrorModel(model)
50 def connect_errormodel_phy(testbed_instance, err_guid, phy_guid):
51 err = testbed_instance._elements[err_guid]
52 phy = testbed_instance._elements[phy_guid]
53 phy.SetErrorRateModel(err)
55 def connect_channel_device(testbed_instance, channel_guid, device_guid):
56 channel = testbed_instance._elements[channel_guid]
57 device = testbed_instance._elements[device_guid]
58 device.Attach(channel)
60 def connect_simple_channel_device(testbed_instance, channel_guid, device_guid):
61 channel = testbed_instance._elements[channel_guid]
62 device = testbed_instance._elements[device_guid]
63 device.SetChannel(channel)
65 def connect_loss_channel(testbed_instance, loss_guid, channel_guid):
66 loss = testbed_instance._elements[loss_guid]
67 channel = testbed_instance._elements[channel_guid]
68 channel.SetPropagationLossModel(loss)
70 def connect_next_loss(testbed_instance, prev_guid, next_guid):
71 prev = testbed_instance._elements[prev_guid]
72 next = testbed_instance._elements[next_guid]
75 def connect_delay_channel(testbed_instance, delay_guid, channel_guid):
76 delay = testbed_instance._elements[delay_guid]
77 channel = testbed_instance._elements[channel_guid]
78 channel.SetPropagationDelayModel(delay)
80 def connect_node_application(testbed_instance, node_guid, application_guid):
81 node = testbed_instance._elements[node_guid]
82 application = testbed_instance._elements[application_guid]
83 node.AddApplication(application)
84 # works for ArpL3Protocol, Ipv4L3Protocol, UdpL4Protocol, TcpL4Protocol,
85 # NscTcpL4Protocol, MobilityModel (every subclass),
86 # RoutingProtocol (every subclass)
88 def connect_node_other(testbed_instance, node_guid, other_guid):
89 node = testbed_instance._elements[node_guid]
90 other = testbed_instance._elements[other_guid]
91 node.AggregateObject(other)
93 def connect_fd(testbed_instance, fdnd_guid, cross_data):
94 fdnd = testbed_instance._elements[fdnd_guid]
95 endpoint = fdnd.GetEndpoint()
96 # XXX: check the method StringToBuffer of ns3::FileDescriptorNetDevice
97 # to see how the address should be decoded
98 address = endpoint.replace(":", "").decode('hex')[2:]
99 testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address)
101 # Set tun standard contract attributes
102 testbed_instance.set(fdnd_guid, "tun_addr",
103 os.path.join( testbed_instance.root_directory, address ) )
104 testbed_instance.set(fdnd_guid, "tun_proto", "fd")
105 testbed_instance.set(fdnd_guid, "tun_port", 0)
106 testbed_instance.set(fdnd_guid, "tun_key", "\xfa"*32) # unimportant, fds aren't encrypted
108 ### Connector information ###
110 connector_types = dict({
112 "help": "Connector to a ns3::Node object (mandatory)",
118 "help": "Connector to network interfaces",
124 "help": "Connector to exactly two network interfaces (mandatory)",
130 "help": "Connector to exactly one network interface (mandatory)",
136 "help": "Connector to applications",
142 "help": "Connector to network stacks and protocols",
148 "help": "Connector to a channel for the device (mandatory)",
154 "help": "Connector to a queueing discipline (mandatory)",
160 "help": "Connector to an error model for the device",
166 "help": "File descriptor receptor for devices with file descriptors",
172 "help": "File descriptor provider for devices with file descriptors",
178 "help": "Connector to interconnect elements with a PHY wifi model",
184 "help": "Connector to interconnect a wifi channel with PHY wifi models",
190 "help": "Connector to interconnect a device with a MAC wifi model",
196 "help": "Connector to interconnect a wifi device with a wifi manager",
202 "help": "Connector to a delay model",
208 "help": "Connector to a loss model",
214 "help": "Connector to the previous loss model",
220 "help": "Connector to the next loss model",
226 "help": "Connector to a mobility model for the node",
235 "from": ( "ns3", "ns3::Node", "devs" ),
236 "to": ( "ns3", "ns3::BridgeNetDevice", "node" ),
237 "init_code": connect_node_device,
241 "from": ( "ns3", "ns3::Node", "devs" ),
242 "to": ( "ns3", "ns3::CsmaNetDevice", "node" ),
243 "init_code": connect_node_device,
247 "from": ( "ns3", "ns3::Node", "devs" ),
248 "to": ( "ns3", "ns3::EmuNetDevice", "node" ),
249 "init_code": connect_node_device,
253 "from": ( "ns3", "ns3::Node", "devs" ),
254 "to": ( "ns3", "ns3::PointToPointNetDevice", "node" ),
255 "init_code": connect_node_device,
259 "from": ( "ns3", "ns3::Node", "devs" ),
260 "to": ( "ns3", "ns3::SimpleNetDevice", "node" ),
261 "init_code": connect_node_device,
265 "from": ( "ns3", "ns3::Node", "devs" ),
266 "to": ( "ns3", "ns3::FileDescriptorNetDevice", "node" ),
267 "init_code": connect_node_device,
271 "from": ( "ns3", "ns3::Node", "devs" ),
272 "to": ( "ns3", "ns3::WifiNetDevice", "node" ),
273 "init_code": connect_node_device,
277 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
278 "to": ( "ns3", "ns3::CsmaNetDevice", "queue" ),
279 "init_code": connect_queue_device,
283 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
284 "to": ( "ns3", "ns3::EmuNetDevice", "queue" ),
285 "init_code": connect_queue_device,
289 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
290 "to": ( "ns3", "ns3::PointToPointNetDevice", "queue" ),
291 "init_code": connect_queue_device,
295 "from": ( "ns3", "ns3::ArfWifiManager", "dev" ),
296 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
297 "init_code": connect_manager_device,
301 "from": ( "ns3", "ns3::ConstantRateWifiManager", "dev" ),
302 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
303 "init_code": connect_manager_device,
307 "from": ( "ns3", "ns3::YansWifiPhy", "dev" ),
308 "to": ( "ns3", "ns3::WifiNetDevice", "phy" ),
309 "init_code": connect_phy_device,
313 "from": ( "ns3", "ns3::QapWifiMac", "dev" ),
314 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
315 "init_code": connect_mac_device,
319 "from": ( "ns3", "ns3::QstaWifiMac", "dev" ),
320 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
321 "init_code": connect_mac_device,
325 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
326 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
327 "init_code": connect_errormodel_device,
331 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
332 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
333 "init_code": connect_errormodel_device,
337 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
338 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
339 "init_code": connect_errormodel_device,
343 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
344 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
345 "init_code": connect_errormodel_device,
349 "from": ( "ns3", "ns3::NistErrorRateModel", "phy" ),
350 "to": ( "ns3", "ns3::YansWifiPhy", "err" ),
351 "init_code": connect_errormodel_phy,
355 "from": ( "ns3", "ns3::CsmaChannel", "devs" ),
356 "to": ( "ns3", "ns3::CsmaNetDevice", "chan" ),
357 "init_code": connect_channel_device,
361 "from": ( "ns3", "ns3::PointToPointChannel", "dev2" ),
362 "to": ( "ns3", "ns3::PointToPointNetDevice", "chan" ),
363 "init_code": connect_channel_device,
367 "from": ( "ns3", "ns3::SimpleChannel", "devs" ),
368 "to": ( "ns3", "ns3::SimpleNetDevice", "chan" ),
369 "init_code": connect_simple_channel_device,
373 "from": ( "ns3", "ns3::YansWifiChannel", "phys" ),
374 "to": ( "ns3", "ns3::YansWifiPhy", "chan" ),
375 "init_code": connect_simple_channel_device,
379 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
380 "to": ( "ns3", "ns3::YansWifiChannel", "loss" ),
381 "init_code": connect_loss_channel,
385 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
386 "to": ( "ns3", "ns3::LogDistancePropagationLossModel", "next" ),
387 "init_code": connect_next_loss,
391 "from": ( "ns3", "ns3::ConstantSpeedPropagationDelayModel", "chan" ),
392 "to": ( "ns3", "ns3::YansWifiChannel", "delay" ),
393 "init_code": connect_delay_channel,
397 "from": ( "ns3", "ns3::Node", "apps" ),
398 "to": ( "ns3", "ns3::OnOffApplication", "node" ),
399 "init_code": connect_node_application,
403 "from": ( "ns3", "ns3::Node", "apps" ),
404 "to": ( "ns3", "ns3::PacketSink", "node" ),
405 "init_code": connect_node_application,
409 "from": ( "ns3", "ns3::Node", "apps" ),
410 "to": ( "ns3", "ns3::UdpEchoClient", "node" ),
411 "init_code": connect_node_application,
415 "from": ( "ns3", "ns3::Node", "apps" ),
416 "to": ( "ns3", "ns3::UdpEchoServer", "node" ),
417 "init_code": connect_node_application,
421 "from": ( "ns3", "ns3::Node", "apps" ),
422 "to": ( "ns3", "ns3::V4Ping", "node" ),
423 "init_code": connect_node_application,
427 "from": ( "ns3", "ns3::Node", "protos" ),
428 "to": ( "ns3", "ns3::ArpL3Protocol", "node" ),
429 "init_code": connect_node_other,
433 "from": ( "ns3", "ns3::Node", "protos" ),
434 "to": ( "ns3", "ns3::Icmpv4L4Protocol", "node" ),
435 "init_code": connect_node_other,
439 "from": ( "ns3", "ns3::Node", "protos" ),
440 "to": ( "ns3", "ns3::Ipv4L3Protocol", "node" ),
441 "init_code": connect_node_other,
445 "from": ( "ns3", "ns3::Node", "protos" ),
446 "to": ( "ns3", "ns3::UdpL4Protocol", "node" ),
447 "init_code": connect_node_other,
451 "from": ( "ns3", "ns3::Node", "protos" ),
452 "to": ( "ns3", "ns3::TcpL4Protocol", "node" ),
453 "init_code": connect_node_other,
457 "from": ( "ns3", "ns3::Node", "mobility" ),
458 "to": ( "ns3", "ns3::ConstantAccelerationMobilityModel", "node" ),
459 "init_code": connect_node_other,
463 "from": ( "ns3", "ns3::Node", "mobility" ),
464 "to": ( "ns3", "ns3::ConstantPositionMobilityModel", "node" ),
465 "init_code": connect_node_other,
469 "from": ( "ns3", "ns3::Node", "mobility" ),
470 "to": ( "ns3", "ns3::ConstantVelocityMobilityModel", "node" ),
471 "init_code": connect_node_other,
475 "from": ( "ns3", "ns3::Node", "mobility" ),
476 "to": ( "ns3", "ns3::HierarchicalMobilityModel", "node" ),
477 "init_code": connect_node_other,
481 "from": ( "ns3", "ns3::Node", "mobility" ),
482 "to": ( "ns3", "ns3::RandomDirection2dMobilityModel", "node" ),
483 "init_code": connect_node_other,
487 "from": ( "ns3", "ns3::Node", "mobility" ),
488 "to": ( "ns3", "ns3::RandomWalk2dMobilityModel", "node" ),
489 "init_code": connect_node_other,
493 "from": ( "ns3", "ns3::Node", "mobility" ),
494 "to": ( "ns3", "ns3::RandomWaypointMobilityModel", "node" ),
495 "init_code": connect_node_other,
499 "from": ( "ns3", "ns3::FileDescriptorNetDevice", "->fd" ),
500 "to": ( None, None, "fd->" ),
501 "init_code": connect_fd,
508 "name": "P2PPcapTrace",
509 "help": "Trace to sniff packets from a P2P network device"
512 "name": "P2PAsciiTrace",
513 "help": "Ascii trace from a P2P network device"
515 "csmapcap_promisc": dict({
516 "name": "CsmaPromiscPcapTrace",
517 "help": "Trace to sniff packets from a Csma network device in promiscuous mode"
520 "name": "CsmaPcapTrace",
521 "help": "Trace to sniff packets from a Csma network device"
524 "name": "FileDescriptorPcapTrace",
525 "help": "Trace to sniff packets from a FileDescriptor network device"
527 "yanswifipcap": dict({
528 "name": "YansWifiPhyPcapTrace",
529 "help": "Trace to sniff packets from a Wifi network device"
533 factories_order = ["ns3::BasicEnergySource",
534 "ns3::WifiRadioEnergyModel",
535 "ns3::BSSchedulerRtps",
536 "ns3::BSSchedulerSimple",
537 "ns3::SubscriberStationNetDevice",
538 "ns3::BaseStationNetDevice",
539 "ns3::UdpTraceClient",
545 "ns3::flame::FlameProtocol",
546 "ns3::flame::FlameRtable",
547 "ns3::dot11s::AirtimeLinkMetricCalculator",
548 "ns3::dot11s::HwmpProtocol",
549 "ns3::dot11s::HwmpRtable",
550 "ns3::dot11s::PeerManagementProtocol",
551 "ns3::dot11s::PeerLink",
552 "ns3::MeshWifiInterfaceMac",
553 "ns3::MeshPointDevice",
556 "ns3::UanPhyCalcSinrDual",
557 "ns3::UanPhyPerGenDefault",
559 "ns3::UanPropModelThorp",
561 "ns3::UanNoiseModelDefault",
563 "ns3::UanPropModelIdeal",
564 "ns3::UanTransducerHd",
565 "ns3::UanPhyCalcSinrDefault",
567 "ns3::UanPhyCalcSinrFhFsk",
568 "ns3::UanPhyPerUmodem",
571 "ns3::AthstatsWifiTraceSink",
574 "ns3::NonCommunicatingNetDevice",
575 "ns3::HalfDuplexIdealPhy",
576 "ns3::AlohaNoackNetDevice",
577 "ns3::SpectrumAnalyzer",
578 "ns3::WaveformGenerator",
579 "ns3::MultiModelSpectrumChannel",
580 "ns3::SingleModelSpectrumChannel",
581 "ns3::MsduStandardAggregator",
585 "ns3::QadhocWifiMac",
586 "ns3::MinstrelWifiManager",
587 "ns3::CaraWifiManager",
588 "ns3::AarfcdWifiManager",
589 "ns3::OnoeWifiManager",
590 "ns3::AmrrWifiManager",
591 "ns3::ConstantRateWifiManager",
592 "ns3::IdealWifiManager",
593 "ns3::AarfWifiManager",
594 "ns3::ArfWifiManager",
595 "ns3::WifiNetDevice",
601 "ns3::YansWifiChannel",
603 "ns3::NistErrorRateModel",
604 "ns3::YansErrorRateModel",
605 "ns3::WaypointMobilityModel",
606 "ns3::ConstantAccelerationMobilityModel",
607 "ns3::RandomDirection2dMobilityModel",
608 "ns3::RandomWalk2dMobilityModel",
609 "ns3::SteadyStateRandomWaypointMobilityModel",
610 "ns3::RandomWaypointMobilityModel",
611 "ns3::GaussMarkovMobilityModel",
612 "ns3::ConstantVelocityMobilityModel",
613 "ns3::ConstantPositionMobilityModel",
614 "ns3::ListPositionAllocator",
615 "ns3::GridPositionAllocator",
616 "ns3::RandomRectanglePositionAllocator",
617 "ns3::RandomBoxPositionAllocator",
618 "ns3::RandomDiscPositionAllocator",
619 "ns3::UniformDiscPositionAllocator",
620 "ns3::HierarchicalMobilityModel",
621 "ns3::aodv::RoutingProtocol",
622 "ns3::UdpEchoServer",
623 "ns3::UdpEchoClient",
625 "ns3::OnOffApplication",
626 "ns3::VirtualNetDevice",
627 "ns3::FileDescriptorNetDevice",
629 "ns3::BridgeChannel",
630 "ns3::BridgeNetDevice",
633 "ns3::CsmaNetDevice",
634 "ns3::PointToPointRemoteChannel",
635 "ns3::PointToPointChannel",
636 "ns3::PointToPointNetDevice",
637 "ns3::NscTcpL4Protocol",
638 "ns3::Icmpv6L4Protocol",
639 "ns3::Ipv6OptionPad1",
640 "ns3::Ipv6OptionPadn",
641 "ns3::Ipv6OptionJumbogram",
642 "ns3::Ipv6OptionRouterAlert",
643 "ns3::Ipv6ExtensionHopByHop",
644 "ns3::Ipv6ExtensionDestination",
645 "ns3::Ipv6ExtensionFragment",
646 "ns3::Ipv6ExtensionRouting",
647 "ns3::Ipv6ExtensionLooseRouting",
648 "ns3::Ipv6ExtensionESP",
649 "ns3::Ipv6ExtensionAH",
650 "ns3::Ipv6L3Protocol",
651 "ns3::LoopbackNetDevice",
652 "ns3::Icmpv4L4Protocol",
653 "ns3::RttMeanDeviation",
654 "ns3::ArpL3Protocol",
655 "ns3::TcpL4Protocol",
656 "ns3::UdpL4Protocol",
657 "ns3::Ipv4L3Protocol",
658 "ns3::SimpleNetDevice",
659 "ns3::SimpleChannel",
661 "ns3::DropTailQueue",
663 "ns3::FriisSpectrumPropagationLossModel",
664 "ns3::Cost231PropagationLossModel",
665 "ns3::JakesPropagationLossModel",
666 "ns3::RandomPropagationLossModel",
667 "ns3::FriisPropagationLossModel",
668 "ns3::TwoRayGroundPropagationLossModel",
669 "ns3::LogDistancePropagationLossModel",
670 "ns3::ThreeLogDistancePropagationLossModel",
671 "ns3::NakagamiPropagationLossModel",
672 "ns3::FixedRssLossModel",
673 "ns3::MatrixPropagationLossModel",
674 "ns3::RangePropagationLossModel",
675 "ns3::RandomPropagationDelayModel",
676 "ns3::ConstantSpeedPropagationDelayModel",
677 "ns3::RateErrorModel",
678 "ns3::ListErrorModel",
679 "ns3::ReceiveListErrorModel",
681 "ns3::EnergySourceContainer"
684 testbed_attributes = dict({
685 "simu_impl_type": dict({
686 "name": "SimulatorImplementationType",
687 "help": "The object class to use as the simulator implementation",
688 "type": Attribute.STRING,
689 "flags": Attribute.DesignOnly,
690 "validation_function": validation.is_string
693 "name": "ChecksumEnabled",
694 "help": "A global switch to enable all checksums for all protocols",
695 "type": Attribute.BOOL,
697 "flags": Attribute.DesignOnly,
698 "validation_function": validation.is_bool
702 class VersionedMetadataInfo(metadata.VersionedMetadataInfo):
704 def connector_types(self):
705 return connector_types
708 def connections(self):
712 def attributes(self):
713 from attributes_metadata_v3_9_RC3 import attributes
721 def create_order(self):
722 return factories_order
725 def configure_order(self):
726 return factories_order
729 def factories_info(self):
730 from factories_metadata_v3_9_RC3 import factories_info
731 return factories_info
734 def testbed_attributes(self):
735 return testbed_attributes