Statistics
| Branch: | Revision:

iof-tools / utils / gen-destinations.py @ a256629c

History | View | Annotate | Download (1.16 KB)

1
#!/usr/bin/env python
2

    
3
# This script adds destinations to a graphml file.
4
# The destinations are taken from the 100.0.0.0/8 netblock. 
5
# The destinations will be added to all the nodes, excluded the
6
# Tier-1 nodes.
7
#
8
from networkx import *
9
from argparse import ArgumentParser
10
import ipaddress
11

    
12

    
13
if __name__ == "__main__":
14
    parser = ArgumentParser()
15

    
16
    parser.add_argument("-g", "--graph", dest="graph",required=True,
17
                        default="", action="store",
18
                        help="Graphml file")
19
    parser.add_argument("-o","--out", dest="outgraph",required=True,
20
                        default="output.graphml", action="store",
21
                        help="Graphml output filename")
22

    
23
    args = parser.parse_args()
24

    
25
    graph = read_graphml(args.graph)
26

    
27
    node_networks = list(ipaddress.ip_network(u'100.0.0.0/8').subnets(new_prefix=24))
28

    
29
    i = 0
30
    for n in graph.nodes(data=True):
31
        if n[1]['type'] == 'C' or n[1]['type'] == 'CP' or n[1]['type'] == 'M':
32
            n[1]['destinations'] = str(node_networks[i])
33
        i += 1
34

    
35
    #for n in graph.nodes(data=True):
36
    #    print(n[1]['destinations'])
37

    
38
    nx.write_graphml(graph, args.outgraph)