blob: fbafe1cbfeb6bb3db86b214898c28c2e5d45ec1c [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3import optparse
4
5def parse_args():
6 usage="""Usage: generate_linear num_nodes [template_file] [delay]
7 Generates template_file with a linear topology with num_nodes and
8 delay in the links (10ms, 100ms, etc).If no template_file is given,
9 will write to default 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) > 3:
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 delay = ''
26 elif len(arg) == 2:
27 num_nodes, delay = int(parser.parse_args()[1][0]), parser.parse_args()[1][1]
28 temp_file = ''
29 else:
30 print parser.parse_args()
31 num_nodes,temp_file, delay = int(parser.parse_args()[1][0]), parser.parse_args()[1][1],parser.parse_args()[1][2]
32
33 return num_nodes, temp_file, delay
34
35if __name__ == '__main__':
36
37 n_nodes, t_file, delay = parse_args()
38
39 if t_file == '':
40 t_file = 'miniccnx.conf'
41
42 temp_file = open(t_file,'w')
43
44 temp_file.write('[hosts]\n')
45
46 temp_file.write('[routers]\n')
47
48 for i in range(n_nodes):
49 if i == (n_nodes - 1):
50 temp_file.write('s' + str(i) + ':\n')
51 else:
52 temp_file.write('s' + str(i) + ': ccnx:/,s' + str(i+1) + '\n')
53
54 temp_file.write('[links]\n')
55
56 for i in range(n_nodes-1):
57 peer = i + 1
58 if delay == '':
59 temp_file.write('s' + str(i) + ':s' + str(peer) + '\n')
60 else:
61 temp_file.write('s' + str(i) + ':s' + str(peer) + ' delay=' + delay +'\n')
62
63 temp_file.close()