blob: 98b66f28d7a89e5661d804e430a036b06315ed53 [file] [log] [blame]
TamasBakaid38feb62019-02-28 09:06:19 +00001#!/usr/bin/env python3
2import argparse
3import sys
TamasBakaid38feb62019-02-28 09:06:19 +00004import subprocess
5import ipaddress
6import time
7
8parser = argparse.ArgumentParser()
9parser.add_argument(
10 '--bootstrap',
11 help='Bootstrapping the system',
12)
13
14parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000015 '--trigger',
16 help='Trigger one single VES event from each simulator',
17)
18
TamasBakai34a6f112019-04-15 08:38:51 +000019
20parser.add_argument(
21 '--triggerstart',
22 help='Trigger only a subset of the simulators (note --triggerend)',
23)
24
25parser.add_argument(
26 '--triggerend',
27 help='Last instance to trigger',
28)
29
TamasBakaib59bffb2019-03-22 09:52:03 +000030parser.add_argument(
TamasBakaibab325b2019-03-26 09:20:16 +000031 '--urlves',
32 help='URL of the VES collector',
TamasBakaid38feb62019-02-28 09:06:19 +000033)
34
35parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000036 '--ipfileserver',
37 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
38)
39
40parser.add_argument(
RehanRaza4b50bdd2019-05-03 14:28:39 +000041 '--typefileserver',
42 help='Type of the file server (SFTP/FTPS) to be included in the VES event',
43)
44
45parser.add_argument(
TamasBakaid38feb62019-02-28 09:06:19 +000046 '--ipstart',
47 help='IP address range beginning',
48)
49
50parser.add_argument(
51 '--clean',
52 action='store_true',
53 help='Cleaning work-dirs',
54)
55
56parser.add_argument(
57 '--start',
58 help='Starting instances',
59)
60
61parser.add_argument(
62 '--status',
63 help='Status',
64)
65
66parser.add_argument(
67 '--stop',
68 help='Stopping instances',
69)
70
71args = parser.parse_args()
72
TamasBakaibab325b2019-03-26 09:20:16 +000073if args.bootstrap and args.ipstart and args.urlves:
TamasBakaid38feb62019-02-28 09:06:19 +000074 print("Bootstrap:")
75
TamasBakaib59bffb2019-03-22 09:52:03 +000076 start_port=2000
TamasBakaie781c7c2019-07-11 11:26:20 +000077 ftps_pasv_port_start=8000
78 ftps_pasv_port_num_of_ports=10
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010079
TamasBakaie781c7c2019-07-11 11:26:20 +000080 ftps_pasv_port_end=ftps_pasv_port_start + ftps_pasv_port_num_of_ports
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010081
TamasBakaib59bffb2019-03-22 09:52:03 +000082
TamasBakaid38feb62019-02-28 09:06:19 +000083 for i in range(int(args.bootstrap)):
84 print("PNF simulator instance: " + str(i) + ".")
85
86 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
87 print("\tIp Subnet:" + str(ip_subnet))
88 # The IP ranges are in distance of 16 compared to each other.
89 # This is matching the /28 subnet mask used in the dockerfile inside.
90
91 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
92 print("\tIP Gateway:" + str(ip_gw))
93
94 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
95 print("\tIp Pnf SIM:" + str(IpPnfSim))
96
TamasBakaib59bffb2019-03-22 09:52:03 +000097 IpFileServer = args.ipfileserver
RehanRaza4b50bdd2019-05-03 14:28:39 +000098 TypeFileServer = args.typefileserver
TamasBakaib59bffb2019-03-22 09:52:03 +000099
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100100
TamasBakaib59bffb2019-03-22 09:52:03 +0000101 PortSftp=start_port +1
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100102 PortFtps=start_port +2
TamasBakaib59bffb2019-03-22 09:52:03 +0000103 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +0000104 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
105 print("\tUrl Ftps: " + str(UrlFtps))
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100106
TamasBakaibab325b2019-03-26 09:20:16 +0000107 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
108 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +0000109
110 foldername = "pnf-sim-lw-" + str(i)
111 completed = subprocess.run('mkdir ' + foldername, shell=True)
112 print('\tCreating folder:', completed.stdout)
113 completed = subprocess.run(
114 'cp -r pnf-sim-lightweight/* ' +
115 foldername,
116 shell=True)
117 print('\tCloning folder:', completed.stdout)
118
TamasBakaibab325b2019-03-26 09:20:16 +0000119 composercmd = "./simulator.sh compose " + \
120 str(ip_gw) + " " + \
121 str(ip_subnet) + " " + \
122 str(i) + " " + \
123 str(args.urlves) + " " + \
124 str(IpPnfSim) + " " + \
125 str(IpFileServer) + " " + \
RehanRaza4b50bdd2019-05-03 14:28:39 +0000126 str(TypeFileServer) + " " + \
TamasBakaibab325b2019-03-26 09:20:16 +0000127 str(PortSftp) + " " + \
128 str(PortFtps) + " " + \
129 str(UrlFtps) + " " + \
TamasBakaie781c7c2019-07-11 11:26:20 +0000130 str(UrlSftp) + " " + \
131 str(ftps_pasv_port_start) + " " + \
132 str(ftps_pasv_port_end)
TamasBakaid38feb62019-02-28 09:06:19 +0000133
134 completed = subprocess.run(
135 'set -x; cd ' +
136 foldername +
137 '; ' +
138 composercmd,
139 shell=True)
140 print('Cloning:', completed.stdout)
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100141
TamasBakaie781c7c2019-07-11 11:26:20 +0000142 ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
143 ftps_pasv_port_end += ftps_pasv_port_num_of_ports +1
TamasBakaid38feb62019-02-28 09:06:19 +0000144
TamasBakaibab325b2019-03-26 09:20:16 +0000145 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
146 print("Build docker image: ", completed.stdout)
147
TamasBakaid38feb62019-02-28 09:06:19 +0000148 sys.exit()
149
150if args.clean:
151 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
152 print('Deleting:', completed.stdout)
153 sys.exit()
154
155if args.start:
156
157 for i in range(int(args.start)):
158 foldername = "pnf-sim-lw-" + str(i)
159
160 completed = subprocess.run(
161 'set -x ; cd ' +
162 foldername +
163 "; bash -x ./simulator.sh start",
164 shell=True)
165 print('Starting:', completed.stdout)
166
167 time.sleep(5)
168
169if args.status:
170
171 for i in range(int(args.status)):
172 foldername = "pnf-sim-lw-" + str(i)
173
174 completed = subprocess.run(
175 'cd ' +
176 foldername +
177 "; ./simulator.sh status",
178 shell=True)
179 print('Status:', completed.stdout)
180
181if args.stop:
182 for i in range(int(args.stop)):
183 foldername = "pnf-sim-lw-" + str(i)
184
185 completed = subprocess.run(
186 'cd ' +
187 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000188 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000189 shell=True)
190 print('Stopping:', completed.stdout)
191
TamasBakaib59bffb2019-03-22 09:52:03 +0000192
193if args.trigger:
194 print("Triggering VES sending:")
195
196 for i in range(int(args.trigger)):
197 foldername = "pnf-sim-lw-" + str(i)
198
199 completed = subprocess.run(
200 'cd ' +
201 foldername +
202 "; ./simulator.sh trigger-simulator",
203 shell=True)
204 print('Status:', completed.stdout)
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100205
TamasBakai34a6f112019-04-15 08:38:51 +0000206if args.triggerstart and args.triggerend:
207 print("Triggering VES sending by a range of simulators:")
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100208
TamasBakai34a6f112019-04-15 08:38:51 +0000209 for i in range(int(args.triggerstart), int(args.triggerend)+1):
210 foldername = "pnf-sim-lw-" + str(i)
211 print("Instance being processed:" + str(i))
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100212
TamasBakai34a6f112019-04-15 08:38:51 +0000213 completed = subprocess.run(
214 'cd ' +
215 foldername +
216 "; ./simulator.sh trigger-simulator",
217 shell=True)
218 print('Status:', completed.stdout)
TamasBakaid38feb62019-02-28 09:06:19 +0000219else:
220 print("No instruction was defined")
221 sys.exit()