blob: e150e66e89cbd3841b6854fa628dace979352c19 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3import optparse
4
5def parse_args():
6 usage="""Usage: generate_mesh num_nodes [template_file]
7 Generates template_file with a full mesh topology with num_nodes
8 If no template_file is given, will write to default
9 file miniccnx.conf in the current directory.
10 """
11
12 parser = optparse.OptionParser(usage)
13
14 _, arg = parser.parse_args()
15
16 if len(arg) > 2:
17 print parser.usage
18 quit()
19 elif len(arg) == 0:
20 print parser.usage
21 quit()
22 elif len(arg) == 1:
23 num_nodes = int(parser.parse_args()[1][0])
24 temp_file = ''
25 else:
26 print parser.parse_args()
27 num_nodes,temp_file = int(parser.parse_args()[1][0]), parser.parse_args()[1][1]
28
29 return num_nodes, temp_file
30
31if __name__ == '__main__':
32
33 n_nodes, t_file = parse_args()
34
35 if t_file == '':
36 t_file = 'miniccnx.conf'
37
38 temp_file = open(t_file,'w')
39
40 temp_file.write('[hosts]\n')
41
42 temp_file.write('[routers]\n')
43
44 for i in range(n_nodes):
45 temp_file.write('s' + str(i) + ':\n')
46
47 temp_file.write('[links]\n')
48
49 for i in range(n_nodes):
50 peer = i + 1
51 for j in range(peer,n_nodes):
52 temp_file.write('s' + str(i) + ':s' + str(j) + '\n')
53
54 temp_file.close()
55
56
57