Пример #1
0
    def test_port_down_with_cost_as_string(self):
        sw_alpha = make_datapath_id(1)
        sw_beta = make_datapath_id(2)
        isl_alpha_beta = model.InterSwitchLink(
            model.NetworkEndpoint(sw_alpha, 2),
            model.NetworkEndpoint(sw_beta, 2), None)
        self.assertTrue(share.exec_isl_discovery(isl_alpha_beta))

        with neo4j_connect.begin() as tx:
            isl_utils.set_props(tx, isl_alpha_beta, {"cost": "10"})

        self.assertTrue(make_port_down(isl_alpha_beta.source))
Пример #2
0
    def test_isl_without_life_cycle_fields(self):
        sw_alpha = share.make_datapath_id(1)
        sw_beta = share.make_datapath_id(2)
        isl_alpha_beta = model.InterSwitchLink(
                model.IslPathNode(sw_alpha, 2),
                model.IslPathNode(sw_beta, 2), None)

        self.assertTrue(make_switch_add(sw_alpha))
        self.assertTrue(make_switch_add(sw_beta))

        self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))

        with neo4j_connect.begin() as tx:
            neo4j_connect.pull(isl_utils.fetch(tx, isl_alpha_beta))
            isl_utils.set_props(
                    tx, isl_alpha_beta,
                    {'time_create': None, 'time_modify': None})

        self.assertTrue(share.feed_isl_discovery(isl_alpha_beta))
Пример #3
0
    def create_isl(self):
        """
        Two parts to creating an ISL:
        (1) create the relationship itself
        (2) add any link properties, if they exist.

        NB: The query used for (2) is the same as in the TER
        TODO: either share the same query as library in python, or handle in java

        :return: success or failure (boolean)
        """
        path = self.payload['path']
        latency = int(self.payload['latency_ns'])
        a_switch = path[0]['switch_id']
        a_port = int(path[0]['port_no'])
        b_switch = path[1]['switch_id']
        b_port = int(path[1]['port_no'])
        speed = int(self.payload['speed'])
        available_bandwidth = int(self.payload['available_bandwidth'])

        isl = model.InterSwitchLink.new_from_isl_data(self.payload)
        isl.ensure_path_complete()

        logger.info('ISL %s create request', isl)
        with graph.begin() as tx:
            flow_utils.precreate_switches(
                tx, isl.source.dpid, isl.dest.dpid)
            isl_utils.create_if_missing(tx, self.timestamp, isl)
            isl_utils.set_props(tx, isl, {
                'latency': latency,
                'speed': speed,
                'max_bandwidth': available_bandwidth,
                'actual': 'active'})

            isl_utils.update_status(tx, isl, mtime=self.timestamp)
            isl_utils.resolve_conflicts(tx, isl)

            life_cycle = isl_utils.get_life_cycle_fields(tx, isl)
            self.update_payload_lifecycle(life_cycle)

        #
        # Now handle the second part .. pull properties from link_props if they exist
        #

        src_sw, src_pt, dst_sw, dst_pt = a_switch, a_port, b_switch, b_port  # use same names as TER code
        query = 'MATCH (src:switch)-[i:isl]->(dst:switch) '
        query += ' WHERE i.src_switch = "%s" ' \
                 ' AND i.src_port = %s ' \
                 ' AND i.dst_switch = "%s" ' \
                 ' AND i.dst_port = %s ' % (src_sw, src_pt, dst_sw, dst_pt)
        query += ' MATCH (lp:link_props) '
        query += ' WHERE lp.src_switch = "%s" ' \
                 ' AND lp.src_port = %s ' \
                 ' AND lp.dst_switch = "%s" ' \
                 ' AND lp.dst_port = %s ' % (src_sw, src_pt, dst_sw, dst_pt)
        query += ' SET i += lp '
        graph.run(query)

        #
        # Finally, update the available_bandwidth..
        #
        flow_utils.update_isl_bandwidth(src_sw, src_pt, dst_sw, dst_pt)

        logger.info('ISL %s have been created/updated', isl)

        return True