From fe54a1466cbd4fbd4b8f5d057e095167b47b615b Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Wed, 8 Jun 2011 18:13:23 +0200 Subject: [PATCH] Added connection ordering in testbed_impl.py _do_connect by returning CONNECTION_DELAY on the connection functions that are not ready to be executed. --- src/nepi/core/testbed_impl.py | 57 ++++++++++++------- .../testbeds/ns3/connection_metadata_v3_9.py | 3 + src/nepi/util/constants.py | 1 + 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/nepi/core/testbed_impl.py b/src/nepi/core/testbed_impl.py index a37752ea..4cc37084 100644 --- a/src/nepi/core/testbed_impl.py +++ b/src/nepi/core/testbed_impl.py @@ -12,9 +12,11 @@ from nepi.util.constants import STATUS_UNDETERMINED, TIME_NOW, \ TESTBED_STATUS_CROSS_CONNECTED, \ TESTBED_STATUS_CONFIGURED, \ TESTBED_STATUS_STARTED, \ - TESTBED_STATUS_STOPPED + TESTBED_STATUS_STOPPED,\ + CONNECTION_DELAY import collections +import copy class TestbedController(execute.TestbedController): def __init__(self, testbed_id, testbed_version): @@ -204,27 +206,38 @@ class TestbedController(execute.TestbedController): self._status = TESTBED_STATUS_CREATED def _do_connect(self, init = True): - for guid1, connections in self._connect.iteritems(): - factory1 = self._get_factory(guid1) - for connector_type_name1, connections2 in connections.iteritems(): - connector_type1 = factory1.connector_type(connector_type_name1) - for guid2, connector_type_name2 in connections2.iteritems(): - factory_id2 = self._create[guid2] - # Connections are executed in a "From -> To" direction only - # This explicitly ignores the "To -> From" (mirror) - # connections of every connection pair. - if init: - connect_code = connector_type1.connect_to_init_code( - self._testbed_id, factory_id2, - connector_type_name2, - False) - else: - connect_code = connector_type1.connect_to_compl_code( - self._testbed_id, factory_id2, - connector_type_name2, - False) - if connect_code: - connect_code(self, guid1, guid2) + unconnected = copy.deepcopy(self._connect) + + while unconnected: + for guid1, connections in unconnected.items(): + factory1 = self._get_factory(guid1) + for connector_type_name1, connections2 in connections.items(): + connector_type1 = factory1.connector_type(connector_type_name1) + for guid2, connector_type_name2 in connections2.items(): + factory_id2 = self._create[guid2] + # Connections are executed in a "From -> To" direction only + # This explicitly ignores the "To -> From" (mirror) + # connections of every connection pair. + if init: + connect_code = connector_type1.connect_to_init_code( + self._testbed_id, factory_id2, + connector_type_name2, + False) + else: + connect_code = connector_type1.connect_to_compl_code( + self._testbed_id, factory_id2, + connector_type_name2, + False) + delay = None + if connect_code: + delay = connect_code(self, guid1, guid2) + + if delay is not CONNECTION_DELAY: + del unconnected[guid1][connector_type_name1][guid2] + if not unconnected[guid1][connector_type_name1]: + del unconnected[guid1][connector_type_name1] + if not unconnected[guid1]: + del unconnected[guid1] def do_connect_init(self): self._do_connect() diff --git a/src/nepi/testbeds/ns3/connection_metadata_v3_9.py b/src/nepi/testbeds/ns3/connection_metadata_v3_9.py index b2841d95..aa16b6ec 100644 --- a/src/nepi/testbeds/ns3/connection_metadata_v3_9.py +++ b/src/nepi/testbeds/ns3/connection_metadata_v3_9.py @@ -3,6 +3,7 @@ from constants import TESTBED_ID import functools +from nepi.util.constants import CONNECTION_DELAY from nepi.util.tunchannel_impl import \ crossconnect_tunchannel_peer_init, \ crossconnect_tunchannel_peer_compl @@ -29,6 +30,8 @@ def connect_manager_device(testbed_instance, manager_guid, device_guid): def connect_phy_device(testbed_instance, phy_guid, device_guid): phy = testbed_instance._elements[phy_guid] + if phy.GetErrorRateModel() == None: + return CONNECTION_DELAY device = testbed_instance._elements[device_guid] device.SetPhy(phy) phy.SetDevice(device) diff --git a/src/nepi/util/constants.py b/src/nepi/util/constants.py index ec00adce..f5cfa110 100644 --- a/src/nepi/util/constants.py +++ b/src/nepi/util/constants.py @@ -20,6 +20,7 @@ TESTBED_STATUS_STOPPED = 7 TIME_NOW = "0s" +CONNECTION_DELAY = 0 ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP = "_nepi_testbed_environment_setup" -- 2.47.0