Ejemplo n.º 1
0
    def send_cmd_to_prefix_mgr(self,
                               cmd,
                               prefixes=None,
                               prefix_type="BREEZE",
                               forwarding_type="IP"):
        """ Send the given cmd to prefix manager and return resp """

        PREFIX_TYPE_TO_VALUES = network_types.PrefixType._NAMES_TO_VALUES
        if prefix_type not in PREFIX_TYPE_TO_VALUES:
            raise Exception("Unknown type {}. Use any of {}".format(
                prefix_type, ", ".join(PREFIX_TYPE_TO_VALUES.keys())))

        FORWARDING_TYPE_TO_VALUES = lsdb_types.PrefixForwardingType._NAMES_TO_VALUES
        if forwarding_type not in FORWARDING_TYPE_TO_VALUES:
            raise Exception("Unknown forwarding type {}. Use any of {}".format(
                forwarding_type, ", ".join(FORWARDING_TYPE_TO_VALUES.keys())))

        req_msg = prefix_mgr_types.PrefixManagerRequest()
        req_msg.cmd = cmd
        req_msg.type = PREFIX_TYPE_TO_VALUES[prefix_type]
        req_msg.prefixes = []
        if prefixes is not None:
            for prefix in prefixes:
                req_msg.prefixes.append(
                    lsdb_types.PrefixEntry(
                        prefix=ipnetwork.ip_str_to_prefix(prefix),
                        type=PREFIX_TYPE_TO_VALUES[prefix_type],
                        forwardingType=FORWARDING_TYPE_TO_VALUES[
                            forwarding_type],
                    ))

        return self.send_and_recv_thrift_obj(
            req_msg, prefix_mgr_types.PrefixManagerResponse)
Ejemplo n.º 2
0
    def send_cmd_to_prefix_mgr(self, cmd, prefixes=None, prefix_type='BREEZE'):
        ''' Send the given cmd to prefix manager and return resp '''

        TYPE_TO_VALUES = lsdb_types.PrefixType._NAMES_TO_VALUES
        if prefix_type not in TYPE_TO_VALUES:
            raise Exception('Unknown type {}. Use any of {}'.format(
                prefix_type, ', '.join(TYPE_TO_VALUES.keys())))

        req_msg = prefix_mgr_types.PrefixManagerRequest()
        req_msg.cmd = cmd
        req_msg.type = TYPE_TO_VALUES[prefix_type]
        req_msg.prefixes = []
        if prefixes is not None:
            for prefix in prefixes:
                req_msg.prefixes.append(
                    lsdb_types.PrefixEntry(prefix=ip_str_to_prefix(prefix),
                                           type=TYPE_TO_VALUES[prefix_type]))

        self._prefix_mgr_cmd_socket.send_thrift_obj(req_msg)

        return self._prefix_mgr_cmd_socket.recv_thrift_obj(
            prefix_mgr_types.PrefixManagerResponse)