Esempio n. 1
0
    def __init__(self, port_data=PORT_DATA, port_ctrl=PORT_CTRL):

        # Unique object ID:
        self.id = uid()

        self.logger = twiggy.log.name('manage %s' % self.id)
        self.port_data = port_data
        self.port_ctrl = port_ctrl

        # Set up a router socket to communicate with other topology
        # components; linger period is set to 0 to prevent hanging on
        # unsent messages when shutting down:
        self.zmq_ctx = zmq.Context()
        self.sock_ctrl = self.zmq_ctx.socket(zmq.ROUTER)
        self.sock_ctrl.setsockopt(zmq.LINGER, LINGER_TIME)
        self.sock_ctrl.bind("tcp://*:%i" % self.port_ctrl)

        # Set up a poller for detecting acknowledgements to control messages:
        self.ctrl_poller = zmq.Poller()
        self.ctrl_poller.register(self.sock_ctrl, zmq.POLLIN)

        # Data structures for instances of objects that correspond to processes
        # keyed on object IDs (bidicts are used to enable retrieval of
        # broker/module IDs from object instances):
        self.brokers = bidict.bidict()
        self.modules = bidict.bidict()

        # Set up a dynamic table to contain the routing table:
        self.routing_table = RoutingTable()

        # Number of emulation steps to run:
        self.steps = np.inf
Esempio n. 2
0
 def __init__(self, dpid, vid):
     self.hosts = {}
     self.dpid = dpid
     self.vid = vid
     self.rt = RoutingTable(self.dpid, self.vid)
     # port_no - neighbor_switch
     self.neighbors = {}
     self.host_forwarding_table = {}
Esempio n. 3
0
 def __init__(self, dpid, vid):
       self.dpid = dpid
       self.vid = vid
       self.L = VidAddr.L
       self.routingTable = RoutingTable(vid, dpid)
       self.rdvStore = RdvStore()
       self.liveNbrs = {}
       self.portNbrs = {} # mapping of Nbrs = port #
       self.rdvRequestTracker = cl.defaultdict(dict)
    def __init__(self, my_node, querier, bootstrap_nodes):
        self.my_node = my_node
        self.querier = querier
        #Copy the bootstrap list
        self.bootstrap_nodes = [n for n in bootstrap_nodes]

        self.main = RoutingTable(my_node, NODES_PER_BUCKET)
        self.replacement = RoutingTable(my_node, NODES_PER_BUCKET)
        self.ping_msg = message.OutgoingPingQuery(my_node.id)
        self.find_node_msg = message.OutgoingFindNodeQuery(
            my_node.id, my_node.id)
        self.mode = BOOTSTRAP_MODE
        self.num_concurrent_refresh_msgs = 0
        #This must be called by an external party: self.do_bootstrap()
        #After initializing callbacks

        # Add myself to the routing table
        rnode = self.main.add(my_node)
        self._reset_refresh_task(rnode)
Esempio n. 5
0
    def spawn(self):
        """
        Spawn MPI processes for and execute each of the managed targets.
        """

        if self._is_parent:
            # Find the path to the mpi_backend.py script (which should be in the
            # same directory as this module:
            parent_dir = os.path.dirname(__file__)
            mpi_backend_path = os.path.join(parent_dir, 'mpi_backend.py')

            # Spawn processes:
            self._intercomm = MPI.COMM_SELF.Spawn(sys.executable,
                                                  args=[mpi_backend_path],
                                                  maxprocs=len(self))

            # First, transmit twiggy logging emitters to spawned processes so
            # that they can configure their logging facilities:
            for i in self._targets.keys():
                self._intercomm.send(twiggy.emitters, i)

            # Next, serialize the routing table ONCE and then transmit it to all
            # of the child nodes:
            try:
                routing_table = self.routing_table
            except:
                routing_table = RoutingTable()
                self.log_warning(
                    'Routing Table is null, using empty routing table.')

            self._intercomm.bcast(routing_table, root=MPI.ROOT)

            # Transmit class to instantiate, globals required by the class, and
            # the constructor arguments; the backend will wait to receive
            # them and then start running the targets on the appropriate nodes.
            req = MPI.Request()
            r_list = []
            for i in self._targets.keys():
                target_globals = all_global_vars(self._targets[i])

                # Serializing atexit with dill appears to fail in virtualenvs
                # sometimes if atexit._exithandlers contains an unserializable function:
                if 'atexit' in target_globals:
                    del target_globals['atexit']
                data = (self._targets[i], target_globals, self._kwargs[i])
                r_list.append(self._intercomm.isend(data, i))

                # Need to clobber data to prevent all_global_vars from
                # including it in its output:
                del data
            req.Waitall(r_list)
Esempio n. 6
0
    def _handle_ViroSwitchUp(self, event):
        """ Local VIRO switch is connecting to the local controller
    We set the controller Id to our local VIRO controller """
        log.debug("Connection %s %s" %
                  (event.connection, dpidToStr(event.dpid)))

        self.sw.dpid = event.dpid
        self.sw.connection = event.connection

        self.routing.dpid = event.dpid
        self.routing.routingTable.dpid = event.dpid

        # Guobao added 02/05/2015
        #self.previousRoutingTable = copy.deepcopy(self.routing.routingTable)
        self.previousRoutingTable = RoutingTable(None, None)

        # Turn on ability to specify table in flow_mods
        msg = nx.nx_flow_mod_table_id()
        self.sw.connection.send(msg)

        msg = msgFactory.ofpControllerId(LocalViro.CONTROLLER_ID)
        self.sw.connection.send(msg)

        msg = msgFactory.ctrlPktsLocalViroPacketIn(
            LocalViro.CONTROLLER_ID)  # set the rule for Viro Packets
        self.sw.connection.send(msg)

        msg_ip = msgFactory.IPv4LocalViroPacketIn(
            LocalViro.CONTROLLER_ID)  # set the rule for IP Packets
        self.sw.connection.send(msg_ip)

        # Guobao -- Fallback rule for Table 0
        msg = msgFactory.FallBack(1)
        self.sw.connection.send(msg)

        # Start periodic function of the local controller
        # 1. Neighbor discovery
        # 2. Routing table rounds
        # 3. Failure discovery
        # We don't use recurring timers to avoid function call overlaps in case of delays
        # So, we call the timer function after the end of the callback function
        Timer(LocalViro.DISCOVER_TIME, self.neibghoorDiscoverCallback)
        #Timer(LocalViro.FAILURE_TIME, self.discoveryFailureCallback) # comment here

        self.round = 1
        Timer(LocalViro.UPDATE_RT_TIME, self.startRoundCallback)

        # Sync RT Table every UPDATE_RT_TIME?
        Timer(LocalViro.UPDATE_RT_TIME, self.pushRTHelper)
Esempio n. 7
0
 def __init__(self, my_node, bootstrap_nodes, msg_f):
     self.my_node = my_node
     self.bootstrapper = bootstrap.OverlayBootstrapper(
         my_node.id, bootstrap_nodes, msg_f)
     self.msg_f = msg_f
     self.table = RoutingTable(my_node, NODES_PER_BUCKET)
     # maintenance variables
     self._next_stale_maintenance_index = 0
     self._maintenance_mode = BOOTSTRAP_MODE
     self._replacement_queue = _ReplacementQueue(self.table)
     self._query_received_queue = _QueryReceivedQueue(self.table)
     self._found_nodes_queue = _FoundNodesQueue(self.table)
     self._maintenance_tasks = [
         self._ping_a_staled_rnode,
         self._ping_a_query_received_node,
         self._ping_a_found_node,
         self._ping_a_replacement_node,
     ]
     self._num_pending_filling_lookups = NUM_FILLING_LOOKUPS
Esempio n. 8
0
    def __init__(self,
                 loop,
                 id=None,
                 listen_host='0.0.0.0',
                 listen_port=6633,
                 bootstrap=False):
        self.loop = loop

        if id == None:
            id = str(uuid.uuid4())

        self.id = id

        self.listen_host = listen_host
        self.listen_port = listen_port
        self.bootstrap = bootstrap

        # routing table
        self.rt = RoutingTable()

        # default protocol_commands
        self.protocol_commands = {}

        protocol_command = PingProtocolCommand(self, 1, 0, 0)
        self.add_protocol_command(protocol_command)

        protocol_command = DiscoverProtocolCommand(self, 1, 0, 1)
        self.add_protocol_command(protocol_command)

        # socket
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.bind((self.listen_host, self.listen_port))

        self.recv_buffer = {
        }  # {(remote_host: remote_port): [socket_data, ...]}
        self.recv_packs = {}  # {msg_id: {pack_index: pack_data}}
        self.loop.add_reader(self.sock, self.rect_sock_data)

        # tasks
        self.loop.call_soon(self.check_recv_buffer)
        self.loop.call_soon(self.remove_dead_contacts)
Esempio n. 9
0
    def __init__(self, alpha=3, k=20, identifier=None):

        # Initialiaze DatagramRPCProtocol
        super(KademliaNode, self).__init__()

        # TODO: Make the node id a function of node's public key
        # Just like Bitcoin wallet IDs use HASH160
        if identifier is None:
            identifier = random_id()

        self.identifier = identifier

        # Constants from the kademlia protocol
        self.k = k
        self.alpha = alpha

        # Each node has their own dictionary
        self.storage = {}

        # The k-bucket based kademlia routing table
        self.routing_table = RoutingTable(self.identifier, k=self.k)
Esempio n. 10
0
    def __init__(self,
                 required_args=[
                     'sel', 'sel_in', 'sel_out', 'sel_gpot', 'sel_spike'
                 ],
                 ctrl_tag=CTRL_TAG):
        super(Manager, self).__init__(ctrl_tag)

        # Required constructor args:
        self.required_args = required_args

        # One-to-one mapping between MPI rank and module ID:
        self.rank_to_id = bidict.bidict()

        # Unique object ID:
        self.id = uid()

        # Set up a dynamic table to contain the routing table:
        self.routing_table = RoutingTable()

        # Number of emulation steps to run:
        self.steps = np.inf

        # Variables for timing run loop:
        self.start_time = 0.0
        self.stop_time = 0.0

        # Variables for computing throughput:
        self.counter = 0
        self.total_sync_time = 0.0
        self.total_sync_nbytes = 0.0
        self.received_data = {}

        # Average step synchronization time:
        self._average_step_sync_time = 0.0

        # Computed throughput (only updated after an emulation run):
        self._average_throughput = 0.0
        self._total_throughput = 0.0
        self.log_info('manager instantiated')
Esempio n. 11
0
 def __init__(self, router_num, N, protocol):
     self._router_num = router_num
     self._N = N
     self._neighbors = {}
     self._routing_table = RoutingTable(N, self._router_num, protocol)