Beispiel #1
0
    def print_db_delta(self, key, our_kv_pub_db, value, other_val):
        ''' print db delta '''

        if key.startswith(Consts.PREFIX_DB_MARKER):
            prefix_db = deserialize_thrift_object(value.value,
                                                  lsdb_types.PrefixDatabase)
            other_prefix_db = deserialize_thrift_object(
                other_val.value, lsdb_types.PrefixDatabase)
            other_prefix_set = {}
            utils.update_global_prefix_db(other_prefix_set, other_prefix_db)
            lines = utils.sprint_prefixes_db_delta(other_prefix_set, prefix_db)

        elif key.startswith(Consts.ADJ_DB_MARKER):
            adj_db = deserialize_thrift_object(value.value,
                                               lsdb_types.AdjacencyDatabase)
            other_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase)
            lines = utils.sprint_adj_db_delta(adj_db, other_adj_db)

        else:
            lines = None

        if lines != []:
            print_publication_delta(
                "Key: {} difference".format(key),
                utils.sprint_pub_update(our_kv_pub_db, key, other_val),
                "\n".join(lines) if lines else "")
Beispiel #2
0
    def print_adj_delta(self, key, value, delta, global_adj_db,
                        global_publication_db):
        _, reported_node_name = key.split(":", 1)
        new_adj_db = serializer.deserialize_thrift_object(
            value.value, lsdb_types.AdjacencyDatabase)
        if delta:
            old_adj_db = global_adj_db.get(new_adj_db.thisNodeName, None)
            if old_adj_db is None:
                lines = ("ADJ_DB_ADDED: {}\n".format(new_adj_db.thisNodeName) +
                         utils.sprint_adj_db_full(global_adj_db, new_adj_db,
                                                  False)[1])
            else:
                lines = utils.sprint_adj_db_delta(new_adj_db, old_adj_db)
                lines = "\n".join(lines)
        else:
            _, lines = utils.sprint_adj_db_full(global_adj_db, new_adj_db,
                                                False)

        if lines:
            self.print_timestamp()
            self.print_publication_delta(
                "{}'s adjacencies".format(reported_node_name),
                utils.sprint_pub_update(global_publication_db, key, value),
                lines,
            )

        utils.update_global_adj_db(global_adj_db, new_adj_db)
Beispiel #3
0
    def print_adj_delta(
        self,
        key: str,
        value: openr_types.Value,
        delta: bool,
        global_adj_db: Dict,
        global_publication_db: Dict,
    ):
        new_adj_db = serializer.deserialize_thrift_object(
            value.value, openr_types.AdjacencyDatabase)
        if delta:
            old_adj_db = global_adj_db.get(new_adj_db.thisNodeName, None)
            if old_adj_db is None:
                lines = "ADJ_DB_ADDED: {}\n".format(
                    new_adj_db.thisNodeName) + utils.sprint_adj_db_full(
                        global_adj_db, new_adj_db, False)
            else:
                lines = utils.sprint_adj_db_delta(new_adj_db, old_adj_db)
                lines = "\n".join(lines)
        else:
            lines = utils.sprint_adj_db_full(global_adj_db, new_adj_db, False)

        if lines:
            self.print_publication_delta(
                "{}'s adjacencies".format(new_adj_db.thisNodeName),
                utils.sprint_pub_update(global_publication_db, key, value),
                lines,
                timestamp=True,
            )

        utils.update_global_adj_db(global_adj_db, new_adj_db)
Beispiel #4
0
    def print_db_delta(self, key, value, kvstore_adj_node_names,
                       kvstore_prefix_node_names, decision_adj_dbs,
                       decision_prefix_dbs):
        if key.startswith(Consts.ADJ_DB_MARKER):
            kvstore_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase)
            node_name = kvstore_adj_db.thisNodeName
            kvstore_adj_node_names.add(node_name)
            if node_name not in decision_adj_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s adj db is missing in Decision".format(
                            node_name)
                    ]]))
                return
            decision_adj_db = decision_adj_dbs[node_name]
            lines = utils.sprint_adj_db_delta(kvstore_adj_db, decision_adj_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s adj db in Decision out of sync with KvStore's"
                        .format(node_name)
                    ]]))
                print("\n".join(lines))
            return

        if key.startswith(Consts.PREFIX_DB_MARKER):
            kvstore_prefix_db = deserialize_thrift_object(
                value.value, lsdb_types.PrefixDatabase)
            node_name = kvstore_prefix_db.thisNodeName
            kvstore_prefix_node_names.add(node_name)
            if node_name not in decision_prefix_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db is missing in Decision".format(
                            node_name)
                    ]]))
                return
            decision_prefix_db = decision_prefix_dbs[node_name]
            decision_prefix_set = {}
            utils.update_global_prefix_db(decision_prefix_set,
                                          decision_prefix_db)
            lines = utils.sprint_prefixes_db_delta(decision_prefix_set,
                                                   kvstore_prefix_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db in Decision out of sync with KvStore's"
                        .format(node_name)
                    ]]))
                print("\n".join(lines))
            return
Beispiel #5
0
    def print_db_delta_adj(
        self, key, value, kvstore_adj_node_names, decision_adj_dbs, json
    ):
        """ Returns status code. 0 = success, 1 = failure"""

        kvstore_adj_db = deserialize_thrift_object(
            value.value, lsdb_types.AdjacencyDatabase
        )
        node_name = kvstore_adj_db.thisNodeName
        kvstore_adj_node_names.add(node_name)
        if node_name not in decision_adj_dbs:
            print(
                printing.render_vertical_table(
                    [["node {}'s adj db is missing in Decision".format(node_name)]]
                )
            )
            return 1
        decision_adj_db = decision_adj_dbs[node_name]

        return_code = 0
        if json:
            tags = ("in_decision", "in_kvstore", "changed_in_decision_and_kvstore")
            adj_list_deltas = utils.find_adj_list_deltas(
                decision_adj_db.adjacencies, kvstore_adj_db.adjacencies, tags=tags
            )
            deltas_json, return_code = utils.adj_list_deltas_json(
                adj_list_deltas, tags=tags
            )
            if return_code:
                utils.print_json(deltas_json)
        else:
            lines = utils.sprint_adj_db_delta(kvstore_adj_db, decision_adj_db)
            if lines:
                print(
                    printing.render_vertical_table(
                        [
                            [
                                "node {}'s adj db in Decision out of sync with "
                                "KvStore's".format(node_name)
                            ]
                        ]
                    )
                )
                print("\n".join(lines))
                return_code = 1

        return return_code
Beispiel #6
0
    def print_db_delta(self, key, value, kvstore_adj_node_names,
                       kvstore_prefix_node_names, decision_adj_dbs,
                       decision_prefix_dbs, json):
        ''' Returns status code. 0 = success, 1 = failure'''

        if key.startswith(Consts.ADJ_DB_MARKER):
            kvstore_adj_db = deserialize_thrift_object(
                value.value, lsdb_types.AdjacencyDatabase)
            node_name = kvstore_adj_db.thisNodeName
            kvstore_adj_node_names.add(node_name)
            if node_name not in decision_adj_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s adj db is missing in Decision".format(
                            node_name)
                    ]]))
                return 1
            decision_adj_db = decision_adj_dbs[node_name]

            return_code = 0
            if json:
                tags = ('in_decision', 'in_kvstore',
                        'changed_in_decision_and_kvstore')
                adj_list_deltas = utils.find_adj_list_deltas(
                    decision_adj_db.adjacencies,
                    kvstore_adj_db.adjacencies,
                    tags=tags)
                deltas_json, return_code = utils.adj_list_deltas_json(
                    adj_list_deltas, tags=tags)
                if return_code:
                    utils.print_json(deltas_json)
            else:
                lines = utils.sprint_adj_db_delta(kvstore_adj_db,
                                                  decision_adj_db)
                if lines:
                    print(
                        printing.render_vertical_table([[
                            "node {}'s adj db in Decision out of sync with KvStore's"
                            .format(node_name)
                        ]]))
                    print("\n".join(lines))
                    return_code = 1

            return return_code

        if key.startswith(Consts.PREFIX_DB_MARKER):
            kvstore_prefix_db = deserialize_thrift_object(
                value.value, lsdb_types.PrefixDatabase)
            node_name = kvstore_prefix_db.thisNodeName
            kvstore_prefix_node_names.add(node_name)
            if node_name not in decision_prefix_dbs:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db is missing in Decision".format(
                            node_name)
                    ]]))
                return 1
            decision_prefix_db = decision_prefix_dbs[node_name]
            decision_prefix_set = {}
            utils.update_global_prefix_db(decision_prefix_set,
                                          decision_prefix_db)
            lines = utils.sprint_prefixes_db_delta(decision_prefix_set,
                                                   kvstore_prefix_db)
            if lines:
                print(
                    printing.render_vertical_table([[
                        "node {}'s prefix db in Decision out of sync with KvStore's"
                        .format(node_name)
                    ]]))
                print("\n".join(lines))
                return 1

            return 0