2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
6 from nepi.util.tunchannel_impl import \
7 crossconnect_tunchannel_peer_init, \
8 crossconnect_tunchannel_peer_compl
10 ### Connection functions ####
12 def connect_dummy(testbed_instance, guid1, guid2):
15 def connect_node_device(testbed_instance, node_guid, device_guid):
16 node = testbed_instance._elements[node_guid]
17 device = testbed_instance._elements[device_guid]
18 node.AddDevice(device)
20 def connect_queue_device(testbed_instance, queue_guid, device_guid):
21 queue = testbed_instance._elements[queue_guid]
22 device = testbed_instance._elements[device_guid]
23 device.SetQueue(queue)
25 def connect_manager_device(testbed_instance, manager_guid, device_guid):
26 manager = testbed_instance._elements[manager_guid]
27 device = testbed_instance._elements[device_guid]
28 device.SetRemoteStationManager(manager)
30 def connect_phy_device(testbed_instance, phy_guid, device_guid):
31 phy = testbed_instance._elements[phy_guid]
32 device = testbed_instance._elements[device_guid]
35 # search for the node asociated with the device
36 node_guid = testbed_instance.get_connected(device_guid, "node", "devs")
37 if len(node_guid) == 0:
38 raise RuntimeError("Can't instantiate interface %d outside netns \
40 node = testbed_instance.elements[node_guid[0]]
43 def connect_mac_device(testbed_instance, mac_guid, device_guid):
44 mac = testbed_instance._elements[mac_guid]
45 device = testbed_instance._elements[device_guid]
48 def connect_errormodel_device(testbed_instance, model_guid, device_guid):
49 model = testbed_instance._elements[model_guid]
50 device = testbed_instance._elements[device_guid]
51 device.SetReceiveErrorModel(model)
53 def connect_errormodel_phy(testbed_instance, err_guid, phy_guid):
54 err = testbed_instance._elements[err_guid]
55 phy = testbed_instance._elements[phy_guid]
56 phy.SetErrorRateModel(err)
58 def connect_channel_device(testbed_instance, channel_guid, device_guid):
59 channel = testbed_instance._elements[channel_guid]
60 device = testbed_instance._elements[device_guid]
61 device.Attach(channel)
63 def connect_simple_channel_device(testbed_instance, channel_guid, device_guid):
64 channel = testbed_instance._elements[channel_guid]
65 device = testbed_instance._elements[device_guid]
66 device.SetChannel(channel)
68 def connect_loss_channel(testbed_instance, loss_guid, channel_guid):
69 loss = testbed_instance._elements[loss_guid]
70 channel = testbed_instance._elements[channel_guid]
71 channel.SetPropagationLossModel(loss)
73 def connect_next_loss(testbed_instance, prev_guid, next_guid):
74 prev = testbed_instance._elements[prev_guid]
75 next = testbed_instance._elements[next_guid]
78 def connect_delay_channel(testbed_instance, delay_guid, channel_guid):
79 delay = testbed_instance._elements[delay_guid]
80 channel = testbed_instance._elements[channel_guid]
81 channel.SetPropagationDelayModel(delay)
83 def connect_node_application(testbed_instance, node_guid, application_guid):
84 node = testbed_instance._elements[node_guid]
85 application = testbed_instance._elements[application_guid]
86 node.AddApplication(application)
87 # works for ArpL3Protocol, Ipv4L3Protocol, UdpL4Protocol, TcpL4Protocol,
88 # NscTcpL4Protocol, MobilityModel (every subclass),
89 # RoutingProtocol (every subclass)
91 def connect_node_other(testbed_instance, node_guid, other_guid):
92 node = testbed_instance._elements[node_guid]
93 other = testbed_instance._elements[other_guid]
94 node.AggregateObject(other)
96 def connect_station_sflow(testbed_instance, station_guid, sflow_guid):
97 station = testbed_instance._elements[station_guid]
98 sflow = testbed_instance._elements[sflow_guid]
99 station.AddServiceFlow(sflow)
101 def connect_bstation_linksched(testbed_instance, bstation_guid, linksched_guid):
102 bstation = testbed_instance._elements[bstation_guid]
103 linksched = testbed_instance._elements[linksched_guid]
104 linksched.SetBs(bstation)
106 def connect_classifier_sflow(testbed_instance, classifier_guid, sflow_guid):
107 classifier = testbed_instance._elements[classifier_guid]
108 sflow = testbed_instance._elements[sflow_guid]
109 csparam = testbed_instance.ns3.CsParameters(testbed_instance.ns3.CsParameters.ADD, classifier)
110 sflow.SetConvergenceSublayerParam (csparam);
112 def connect_fd(testbed_instance, fdnd_guid, cross_data):
113 fdnd = testbed_instance._elements[fdnd_guid]
114 endpoint = fdnd.GetEndpoint()
115 # XXX: check the method StringToBuffer of ns3::FileDescriptorNetDevice
116 # to see how the address should be decoded
117 address = endpoint.replace(":", "").decode('hex')[2:]
118 testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address)
120 # If it's a non-abstract socket, add the path
121 if not address.startswith('\x00'):
122 address = os.path.join( testbed_instance.root_directory, address )
124 # Set tun standard contract attributes
125 testbed_instance.set(fdnd_guid, "tun_addr", address )
126 testbed_instance.set(fdnd_guid, "tun_proto", "fd")
127 testbed_instance.set(fdnd_guid, "tun_port", 0)
128 testbed_instance.set(fdnd_guid, "tun_key", "\xfa"*32) # unimportant, fds aren't encrypted
130 def connect_tunchannel_fd(testbed_instance, tun_guid, fdnd_guid):
131 fdnd = testbed_instance._elements[fdnd_guid]
132 tun = testbed_instance._elements[tun_guid]
134 # XXX: check the method StringToBuffer of ns3::FileDescriptorNetDevice
135 # to see how the address should be decoded
136 endpoint = fdnd.GetEndpoint()
137 address = endpoint.replace(":", "").decode('hex')[2:]
138 testbed_instance.set(fdnd_guid, "LinuxSocketAddress", address)
140 # Create socket pair to connect the FDND and the TunChannel with it
142 sock1, sock2 = socket.socketpair(
143 socket.AF_UNIX, socket.SOCK_SEQPACKET)
145 # Send one endpoint to the FDND
148 sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
149 sock.connect(address)
150 passfd.sendfd(sock, sock1.fileno(), '0')
152 # Store a reference to the endpoint to keep the socket alive
153 fdnd._endpoint_socket = sock1
155 # Send the other endpoint to the TUN channel
156 tun.tun_socket = sock2
158 # With this kind of tun_socket, NS3 will expect a PI header
159 # (sockets don't support the TUNGETIFF ioctl, so it will assume
160 # the default presence of PI headers)
164 ### Connector information ###
166 connector_types = dict({
168 "help": "Connector to a ns3::Node object (mandatory)",
174 "help": "Connector to network interfaces",
180 "help": "Connector to exactly two network interfaces (mandatory)",
186 "help": "Connector to exactly one network interface (mandatory)",
192 "help": "Connector to applications",
198 "help": "Connector to network stacks and protocols",
204 "help": "Connector to a channel for the device (mandatory)",
210 "help": "Connector to a queueing discipline (mandatory)",
216 "help": "Connector to an error model for the device",
222 "help": "Connector for file descriptor reception for devices with file descriptors",
228 "help": "Connector for file descriptor providing for devices with file descriptors",
234 "help": "Connector to a PHY wifi model",
240 "help": "Connector to a wifi channel with PHY wifi models",
246 "help": "Connector to a MAC wifi model",
252 "help": "Connector to a wifi manager",
258 "help": "Connector to a delay model",
264 "help": "Connector to a loss model",
270 "help": "Connector to the previous loss model",
276 "help": "Connector to the next loss model",
282 "help": "Connector to a mobility model",
288 "help": "Connector for ip-ip tunneling over TCP link",
294 "help": "Connector for ip-ip tunneling over UDP datagrams",
300 "help": "Connector to service flows",
306 "help": "Connector to a uplink scheduler",
312 "help": "Connector to a dowlink scheduler",
318 "help": "Connector to a classifier recod",
324 "help": "Connector to a service flow",
333 "from": ( "ns3", "ns3::Node", "devs" ),
334 "to": ( "ns3", "ns3::BridgeNetDevice", "node" ),
335 "init_code": connect_node_device,
339 "from": ( "ns3", "ns3::Node", "devs" ),
340 "to": ( "ns3", "ns3::CsmaNetDevice", "node" ),
341 "init_code": connect_node_device,
345 "from": ( "ns3", "ns3::Node", "devs" ),
346 "to": ( "ns3", "ns3::EmuNetDevice", "node" ),
347 "init_code": connect_node_device,
351 "from": ( "ns3", "ns3::Node", "devs" ),
352 "to": ( "ns3", "ns3::PointToPointNetDevice", "node" ),
353 "init_code": connect_node_device,
357 "from": ( "ns3", "ns3::Node", "devs" ),
358 "to": ( "ns3", "ns3::SimpleNetDevice", "node" ),
359 "init_code": connect_node_device,
363 "from": ( "ns3", "ns3::Node", "devs" ),
364 "to": ( "ns3", "ns3::FileDescriptorNetDevice", "node" ),
365 "init_code": connect_node_device,
369 "from": ( "ns3", "ns3::Node", "devs" ),
370 "to": ( "ns3", "ns3::WifiNetDevice", "node" ),
371 "init_code": connect_node_device,
375 "from": ( "ns3", "ns3::Node", "devs" ),
376 "to": ( "ns3", "ns3::SubscriberStationNetDevice", "node" ),
377 "init_code": connect_dummy,
381 "from": ( "ns3", "ns3::Node", "devs" ),
382 "to": ( "ns3", "ns3::BaseStationNetDevice", "node" ),
383 "init_code": connect_dummy,
387 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
388 "to": ( "ns3", "ns3::CsmaNetDevice", "queue" ),
389 "init_code": connect_queue_device,
393 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
394 "to": ( "ns3", "ns3::EmuNetDevice", "queue" ),
395 "init_code": connect_queue_device,
399 "from": ( "ns3", "ns3::DropTailQueue", "dev" ),
400 "to": ( "ns3", "ns3::PointToPointNetDevice", "queue" ),
401 "init_code": connect_queue_device,
405 "from": ( "ns3", "ns3::ArfWifiManager", "dev" ),
406 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
407 "init_code": connect_manager_device,
411 "from": ( "ns3", "ns3::ConstantRateWifiManager", "dev" ),
412 "to": ( "ns3", "ns3::WifiNetDevice", "manager" ),
413 "init_code": connect_manager_device,
417 "from": ( "ns3", "ns3::YansWifiPhy", "dev" ),
418 "to": ( "ns3", "ns3::WifiNetDevice", "phy" ),
419 "init_code": connect_phy_device,
423 "from": ( "ns3", "ns3::SimpleOfdmWimaxPhy", "dev" ),
424 "to": ( "ns3", "ns3::SubscriberStationNetDevice", "phy" ),
425 "init_code": connect_phy_device,
429 "from": ( "ns3", "ns3::SimpleOfdmWimaxPhy", "dev" ),
430 "to": ( "ns3", "ns3::BaseStationNetDevice", "phy" ),
431 "init_code": connect_phy_device,
435 "from": ( "ns3", "ns3::QapWifiMac", "dev" ),
436 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
437 "init_code": connect_mac_device,
441 "from": ( "ns3", "ns3::QstaWifiMac", "dev" ),
442 "to": ( "ns3", "ns3::WifiNetDevice", "mac" ),
443 "init_code": connect_mac_device,
447 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
448 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
449 "init_code": connect_errormodel_device,
453 "from": ( "ns3", "ns3::RateErrorModel", "dev" ),
454 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
455 "init_code": connect_errormodel_device,
459 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
460 "to": ( "ns3", "ns3::CsmaNetDevice", "err" ),
461 "init_code": connect_errormodel_device,
465 "from": ( "ns3", "ns3::ListErrorModel", "dev" ),
466 "to": ( "ns3", "ns3::PointToPointNetDevice", "err" ),
467 "init_code": connect_errormodel_device,
471 "from": ( "ns3", "ns3::NistErrorRateModel", "phy" ),
472 "to": ( "ns3", "ns3::YansWifiPhy", "err" ),
473 "init_code": connect_errormodel_phy,
477 "from": ( "ns3", "ns3::CsmaChannel", "devs" ),
478 "to": ( "ns3", "ns3::CsmaNetDevice", "chan" ),
479 "init_code": connect_channel_device,
483 "from": ( "ns3", "ns3::PointToPointChannel", "dev2" ),
484 "to": ( "ns3", "ns3::PointToPointNetDevice", "chan" ),
485 "init_code": connect_channel_device,
489 "from": ( "ns3", "ns3::SimpleChannel", "devs" ),
490 "to": ( "ns3", "ns3::SimpleNetDevice", "chan" ),
491 "init_code": connect_simple_channel_device,
495 "from": ( "ns3", "ns3::SimpleOfdmWimaxChannel", "devs" ),
496 "to": ( "ns3", "ns3::SubscriberStationNetDevice", "chan" ),
497 "init_code": connect_channel_device,
501 "from": ( "ns3", "ns3::SimpleOfdmWimaxChannel", "devs" ),
502 "to": ( "ns3", "ns3::BaseStationNetDevice", "chan" ),
503 "init_code": connect_channel_device,
507 "from": ( "ns3", "ns3::YansWifiChannel", "phys" ),
508 "to": ( "ns3", "ns3::YansWifiPhy", "chan" ),
509 "init_code": connect_simple_channel_device,
513 "from": ( "ns3", "ns3::YansWifiChannel", "phys" ),
514 "to": ( "ns3", "ns3::YansWifiPhy", "chan" ),
515 "init_code": connect_simple_channel_device,
519 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
520 "to": ( "ns3", "ns3::YansWifiChannel", "loss" ),
521 "init_code": connect_loss_channel,
525 "from": ( "ns3", "ns3::LogDistancePropagationLossModel", "prev" ),
526 "to": ( "ns3", "ns3::LogDistancePropagationLossModel", "next" ),
527 "init_code": connect_next_loss,
531 "from": ( "ns3", "ns3::ConstantSpeedPropagationDelayModel", "chan" ),
532 "to": ( "ns3", "ns3::YansWifiChannel", "delay" ),
533 "init_code": connect_delay_channel,
537 "from": ( "ns3", "ns3::Node", "apps" ),
538 "to": ( "ns3", "ns3::OnOffApplication", "node" ),
539 "init_code": connect_node_application,
543 "from": ( "ns3", "ns3::Node", "apps" ),
544 "to": ( "ns3", "ns3::PacketSink", "node" ),
545 "init_code": connect_node_application,
549 "from": ( "ns3", "ns3::Node", "apps" ),
550 "to": ( "ns3", "ns3::UdpEchoClient", "node" ),
551 "init_code": connect_node_application,
555 "from": ( "ns3", "ns3::Node", "apps" ),
556 "to": ( "ns3", "ns3::UdpEchoServer", "node" ),
557 "init_code": connect_node_application,
561 "from": ( "ns3", "ns3::Node", "apps" ),
562 "to": ( "ns3", "ns3::UdpClient", "node" ),
563 "init_code": connect_node_application,
567 "from": ( "ns3", "ns3::Node", "apps" ),
568 "to": ( "ns3", "ns3::UdpServer", "node" ),
569 "init_code": connect_node_application,
572 "from": ( "ns3", "ns3::Node", "apps" ),
573 "to": ( "ns3", "ns3::V4Ping", "node" ),
574 "init_code": connect_node_application,
578 "from": ( "ns3", "ns3::Node", "protos" ),
579 "to": ( "ns3", "ns3::ArpL3Protocol", "node" ),
580 "init_code": connect_node_other,
584 "from": ( "ns3", "ns3::Node", "protos" ),
585 "to": ( "ns3", "ns3::Icmpv4L4Protocol", "node" ),
586 "init_code": connect_node_other,
590 "from": ( "ns3", "ns3::Node", "protos" ),
591 "to": ( "ns3", "ns3::Icmpv6L4Protocol", "node" ),
592 "init_code": connect_node_other,
596 "from": ( "ns3", "ns3::Node", "protos" ),
597 "to": ( "ns3", "ns3::Ipv4L3Protocol", "node" ),
598 "init_code": connect_node_other,
602 "from": ( "ns3", "ns3::Node", "protos" ),
603 "to": ( "ns3", "ns3::Ipv6L3Protocol", "node" ),
604 "init_code": connect_node_other,
608 "from": ( "ns3", "ns3::Node", "protos" ),
609 "to": ( "ns3", "ns3::UdpL4Protocol", "node" ),
610 "init_code": connect_node_other,
614 "from": ( "ns3", "ns3::Node", "protos" ),
615 "to": ( "ns3", "ns3::TcpL4Protocol", "node" ),
616 "init_code": connect_node_other,
620 "from": ( "ns3", "ns3::Node", "mobility" ),
621 "to": ( "ns3", "ns3::ConstantAccelerationMobilityModel", "node" ),
622 "init_code": connect_node_other,
626 "from": ( "ns3", "ns3::Node", "mobility" ),
627 "to": ( "ns3", "ns3::ConstantPositionMobilityModel", "node" ),
628 "init_code": connect_node_other,
632 "from": ( "ns3", "ns3::Node", "mobility" ),
633 "to": ( "ns3", "ns3::ConstantVelocityMobilityModel", "node" ),
634 "init_code": connect_node_other,
638 "from": ( "ns3", "ns3::Node", "mobility" ),
639 "to": ( "ns3", "ns3::HierarchicalMobilityModel", "node" ),
640 "init_code": connect_node_other,
644 "from": ( "ns3", "ns3::Node", "mobility" ),
645 "to": ( "ns3", "ns3::RandomDirection2dMobilityModel", "node" ),
646 "init_code": connect_node_other,
650 "from": ( "ns3", "ns3::Node", "mobility" ),
651 "to": ( "ns3", "ns3::RandomWalk2dMobilityModel", "node" ),
652 "init_code": connect_node_other,
656 "from": ( "ns3", "ns3::Node", "mobility" ),
657 "to": ( "ns3", "ns3::RandomWaypointMobilityModel", "node" ),
658 "init_code": connect_node_other,
662 "from": ( "ns3", "ns3::SubscriberStationNetDevice", "sflows" ),
663 "to": ( "ns3", "ns3::ServiceFlow", "dev" ),
664 "init_code": connect_station_sflow,
668 "from": ( "ns3", "ns3::BaseStationNetDevice", "sflows" ),
669 "to": ( "ns3", "ns3::ServiceFlow", "dev" ),
670 "init_code": connect_station_sflow,
674 "from": ( "ns3", "ns3::BaseStationNetDevice", "uplnk" ),
675 "to": ( "ns3", "ns3::UplinkSchedulerSimple", "dev" ),
676 "init_code": connect_bstation_linksched,
680 "from": ( "ns3", "ns3::BaseStationNetDevice", "uplnk" ),
681 "to": ( "ns3", "ns3::UplinkSchedulerRtps", "dev" ),
682 "init_code": connect_bstation_linksched,
686 "from": ( "ns3", "ns3::BaseStationNetDevice", "dwnlnk" ),
687 "to": ( "ns3", "ns3::BSSchedulerSimple", "dev" ),
688 "init_code": connect_bstation_linksched,
692 "from": ( "ns3", "ns3::BaseStationNetDevice", "dwnlnk" ),
693 "to": ( "ns3", "ns3::BSSchedulerRtps", "dev" ),
694 "init_code": connect_bstation_linksched,
698 "from": ( "ns3", "ns3::IpcsClassifierRecord", "sflow" ),
699 "to": ( "ns3", "ns3::ServiceFlow", "classif" ),
700 "init_code": connect_classifier_sflow,
704 "from": ( "ns3", "ns3::FileDescriptorNetDevice", "->fd" ),
705 "to": ( None, None, "fd->" ),
706 "init_code": connect_fd,
710 "from": ( "ns3", "ns3::Nepi::TunChannel", "fd->" ),
711 "to": ( "ns3", "ns3::FileDescriptorNetDevice", "->fd" ),
712 "init_code": connect_tunchannel_fd,
716 "from": ( "ns3", "ns3::Nepi::TunChannel", "tcp"),
717 "to": (None, None, "tcp"),
718 "init_code": functools.partial(crossconnect_tunchannel_peer_init,"tcp"),
719 "compl_code": functools.partial(crossconnect_tunchannel_peer_compl,"tcp"),
723 "from": ( "ns3", "ns3::Nepi::TunChannel", "udp"),
724 "to": (None, None, "udp"),
725 "init_code": functools.partial(crossconnect_tunchannel_peer_init,"udp"),
726 "compl_code": functools.partial(crossconnect_tunchannel_peer_compl,"udp"),