Revision a256629c

View differences:

utils/cpu-counter.sh
1
#!/bin/bash
2

  
3
# This script can be used to count the number of cpus reserved
4
# After setting up the environment, copy it in the cpu_info dir and execute it.
5

  
6
tot=0
7

  
8
for f in `ls node*`
9
do
10
  cpu=`cat $f | json_pp | grep "ansible_processor_vcpus" | cut -d ":" -f2 | cut -d"," -f1 | cut -d " " -f2`
11
  tot=$((tot + cpu))  
12
done
13
echo $tot
utils/gen-destinations.py
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)
utils/get_random_nodes.py
1
#!/usr/bin/env python
2

  
3
# This script selects an arbitrary number of random nodes from a
4
# topology graph. It has been used to select the nodes originating
5
# a change in the network in the "Elmokashfi" simulations.
6

  
7
from networkx import *
8
from argparse import ArgumentParser
9
from random import randint
10

  
11
if __name__ == "__main__":
12
    parser = ArgumentParser()
13

  
14
    parser.add_argument("-g", "--graph", dest="graph",required=True,
15
                        default="", action="store",
16
                        help="Graphml file")
17
    parser.add_argument("-t", "--type", dest="type", default="", action="store",
18
                        help = "Node type. Can be either T, M, CP, or C.")
19
    parser.add_argument("-n", "--num", dest="num", default=5, action="store",
20
                        help="Number of AS to extract")
21
    parser.add_argument("-l", "--leaf", dest="leaf", required=False, action = "store_true",
22
                        help = "Forces the selected node to be a leaf")
23

  
24

  
25
    args = parser.parse_args()
26

  
27
    graph = read_graphml(args.graph)
28

  
29
    num = int(args.num)
30

  
31
    if args.leaf and args.type != "C":
32
        print("Only C nodes can be leafs.")
33
        exit()
34
    if num < 1:
35
        print("Number of AS to extract too low")
36
        exit()
37

  
38
    nodes_num = graph.number_of_nodes()
39
    nodes_list = list(graph.nodes(data=True))
40

  
41
    extracted_nodes = 0
42
    while extracted_nodes < num:
43
        r = randint(0,nodes_num-1)
44

  
45
        if args.type == "":
46
            print("ID: {}".format(r))
47
            extracted_nodes += 1
48
        else:
49
            t = nodes_list[r][1]['type']
50
            #print(t)
51
            if t != args.type:
52
                continue
53
            if args.leaf:
54
                # Need to be a leaf
55
                deg = graph.degree[nodes_list[r][0]]
56
                #print(deg)
57
                if deg != 1:
58
                    continue
59
                else:
60
                    print("ID: {}".format(r))
61
                    extracted_nodes += 1
62
            else:
63
                print("ID: {}".format(r))
64
                extracted_nodes += 1
65

  

Also available in: Unified diff