Пример #1
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, isl)

            #
            # Given that we know the the src and dst exist, the following query will either
            # create the relationship if it doesn't exist, or update it if it does
            #
            isl_create_or_update = ("MERGE "
                                    "(src:switch {{name:'{}'}}) "
                                    "ON CREATE SET src.state = 'inactive' "
                                    "MERGE "
                                    "(dst:switch {{name:'{}'}}) "
                                    "ON CREATE SET dst.state = 'inactive' "
                                    "MERGE "
                                    "(src)-[i:isl {{"
                                    "src_switch: '{}', src_port: {}, "
                                    "dst_switch: '{}', dst_port: {} "
                                    "}}]->(dst) "
                                    "SET "
                                    "i.latency = {}, "
                                    "i.speed = {}, "
                                    "i.max_bandwidth = {}, "
                                    "i.actual = 'active', "
                                    "i.status = 'inactive'").format(
                                        a_switch, b_switch, a_switch, a_port,
                                        b_switch, b_port, latency, speed,
                                        available_bandwidth)
            tx.run(isl_create_or_update)

            isl_utils.update_status(tx, isl)
            isl_utils.resolve_conflicts(tx, isl)

        #
        # 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
Пример #2
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
Пример #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'])

        try:
            logger.info('ISL %s_%d create or update request: timestamp=%s',
                        a_switch, a_port, self.timestamp)

            #
            # Given that we know the the src and dst exist, the following query will either
            # create the relationship if it doesn't exist, or update it if it does
            #
            isl_create_or_update = ("MERGE "
                                    "(src:switch {{name:'{}'}}) "
                                    "ON CREATE SET src.state = 'inactive' "
                                    "MERGE "
                                    "(dst:switch {{name:'{}'}}) "
                                    "ON CREATE SET dst.state = 'inactive' "
                                    "MERGE "
                                    "(src)-[i:isl {{"
                                    "src_switch: '{}', src_port: {}, "
                                    "dst_switch: '{}', dst_port: {} "
                                    "}}]->(dst) "
                                    "SET "
                                    "i.latency = {}, "
                                    "i.speed = {}, "
                                    "i.max_bandwidth = {}, "
                                    "i.status = 'active' ").format(
                                        a_switch, b_switch, a_switch, a_port,
                                        b_switch, b_port, latency, speed,
                                        available_bandwidth)
            graph.run(isl_create_or_update)

            #
            # 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 between %s and %s updated', a_switch, b_switch)

        except Exception as e:
            logger.exception('ISL between %s and %s creation error: %s',
                             a_switch, b_switch, e.message)
            return False

        return True