Esempio n. 1
0
    def configure_tree_topology(self, root, degree=2, remove=False):
        """Configures the cluster's network topology as a tree.

        The tree consists of the specified root node and the nodes,
        which build the subtrees. The childrens are incrementally chosen,
        in other words, sequentially as specified in the config file.

        Arguments:
            root {integer} -- The tree's root node.

        Keyword Arguments:
            degree {integer} -- The maximum number of children (default: {2})
            remove {boolean} -- Remove the configuration (default: {False})
        """

        self.logger.info("Configuring tree topology...")
        tree = Tree()
        root_node = self.topology.get_node(root)
        tree.create_node(root_node.name, root_node.node_id)
        parent_node = root
        for nodex in self.topology.nodes:
            if nodex.node_id == root_node.node_id:
                continue
            if len(tree.children(parent_node)) >= degree:
                if parent_node == root and root != 0:
                    parent_node = 0
                elif parent_node + 1 == root:
                    parent_node += 2
                else:
                    parent_node += 1
            tree.create_node(nodex.name, nodex.node_id, parent_node)

        self.logger.info("The following tree will be configured:")
        tree.show()

        for nodex in self.topology.nodes:
            self.logger.debug("%s:", nodex.name)
            subtree = tree.subtree(nodex.node_id)
            for nodey in self.topology.nodes:
                if nodex.node_id == nodey.node_id:
                    continue
                if subtree.contains(nodey.node_id):
                    children = tree.children(nodex.node_id)
                    for child in children:
                        if (child.identifier == nodey.node_id
                                or tree.is_ancestor(child.identifier,
                                                    nodey.node_id)):
                            nodex.add_forwarding(
                                nodey,
                                self.topology.get_node(child.identifier))
                            break
                elif tree.parent(nodex.node_id) != None:
                    nodex.add_forwarding(
                        nodey,
                        self.topology.get_node(
                            tree.parent(nodex.node_id).identifier))

        if not self.testing:
            self.topology.send_forwarding_tables(remove)
Esempio n. 2
0
file = open(sys.argv[1], 'r')
line = file.readline()
d = dict()

while (line):
    m = line.split(')')
    key = m[0]
    value = m[1].strip('\n')
    if key not in d.keys():
        d.setdefault(key, [])
        d[key].append(value)
    else:
        d[key].append(value)
    line = file.readline()

tree = Tree()
tree.create_node(identifier='COM')
add_orbits(tree, 'COM', d)

grandparents = []
for node in tree.all_nodes():
    if tree.is_ancestor(node.identifier, 'YOU') and tree.is_ancestor(
            node.identifier, 'SAN'):
        grandparents.append(node.identifier)

common = grandparents[-1:]
m = tree.depth(tree.get_node(common[0]))
you = tree.depth(tree.get_node('YOU'))
san = tree.depth(tree.get_node('SAN'))
print(you - m + san - m - 2)