def hierarchy(root, layers, bottom, hosts, label='s', num=False): """Build a hierarchical fat tree. ARGS: root: number of aggregating switches at the root of the tree, connected to all the switches of the next layer layers: [(groups, aggregators)], in order from closest to root to farthest. At each layer, groups defines the number of divisions of the tree, and aggregators the number of aggregator switches connected to all the switches of that group in the next layer down. This multiplies going downwards, so [(2, 2), (2, 2)] has 4 aggregator switches total on the first layer, and 8 on the next, with 4 groups total at the bottom. bottom: the number of switches per group at the last layer of switches hosts: the number of hosts per switch at the bottom. Numbering: groups are hierarchical, so a given switch has a sequence of numbers as follows: * group numbers in order from the root (none of these for the root) * sequential number to distinguish between switches/hosts in the group. Bottom layer nodes are treated as if they were all in group 0 of the previous layer. """ topo = NXTopo() if len(layers) > 0: layer = layers[0] next_layer = hierarchy_add_layer(topo, [], layer, layers[1:], bottom, hosts, label=label, num=num) else: next_layer = hierarchy_bottom(topo, [0], bottom, hosts, label=label, num=num) for i in range(root): s_id = make_id(label, i, num=num) topo.add_switch(s_id) for s in next_layer: topo.add_link(s_id, s) return topo
def grid(m, n, diagonal=False, label='s', num=False): """Produce an m by n grid of nodes. Diagonal links are not included unles diagonal=True is set. """ topo = NXTopo() # add nodes for i in range(m): for j in range(n): topo.add_switch(make_id(label, i, j, num=num)) # add links for i in range(m): for j in range(n): if i+1 < m: topo.add_link(make_id(label, i, j, num=num), make_id(label, i+1, j, num=num)) if j+1 < n: topo.add_link(make_id(label, i, j, num=num), make_id(label, i, j+1, num=num)) if diagonal: if i+1 < m and j+1 < n: topo.add_link(make_id(label, i, j, num=num), make_id(label, i+1, j+1, num=num)) if i-1 >= 0 and j+1 < n: topo.add_link(make_id(label, i, j, num=num), make_id(label, i-1, j+1, num=num)) return topo