Statistics
| Branch: | Revision:

iof-tools / gen_complete_graph.py @ 204eb1d4

History | View | Annotate | Download (1.36 KB)

1
#!/usr/bin/env python
2
from argparse import ArgumentParser
3
import networkx as nx
4
from chain_gadget import VALID_NODE_TYPES, VALID_EDGE_TYPES, ATTR_NODE_TYPE, \
5
    ATTR_EDGE_TYPE
6

    
7
parser = ArgumentParser()
8
parser.add_argument("-n", "--nodes", dest="nodes", required=True, type=int,
9
                    action="store", help="Total number of ASes")
10
parser.add_argument("-t", "--type", dest="type", default="T", action="store",
11
                    help="Node type. Can be either T, M, CP, or C.")
12
parser.add_argument("-w", "--write-to", dest="writeto",
13
                    default="complete_graph.graphml", action="store",
14
                    help="Output graphml file where the graph will be written "
15
                         "to")
16
args = parser.parse_args()
17

    
18
nodes = args.nodes
19
node_type = args.type
20
edge_type = "peer"
21
output_file = args.writeto
22

    
23
if nodes < 2:
24
    print("The number of nodes (ASes) must be at least 2")
25
    exit(1)
26
if node_type not in VALID_NODE_TYPES:
27
    print("The node type must be one of {}".format(", ".join(VALID_NODE_TYPES)))
28
    exit(1)
29
if edge_type not in VALID_EDGE_TYPES:
30
    print("The edge type must be one of {}".format(", ".join(VALID_EDGE_TYPES)))
31
    exit(1)
32

    
33
g = nx.complete_graph(nodes, create_using=nx.DiGraph())
34
nx.set_node_attributes(g, node_type, ATTR_NODE_TYPE)
35
nx.set_edge_attributes(g, edge_type, ATTR_EDGE_TYPE)
36
nx.write_graphml(g, output_file)