blob: c331d24bb096b64badf8af0256bb6668a8ed61b9 [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()
Bartek Grzybowskic29b9462020-04-30 07:11:59 -07009parser.add_argument('--bootstrap', help='Bootstrap the system')
10parser.add_argument('--trigger', help='Trigger one single VES event from each simulator')
11parser.add_argument('--triggerstart', help='Trigger only a subset of the simulators (note --triggerend)')
12parser.add_argument('--triggerend', help='Last instance to trigger')
13parser.add_argument('--urlves', help='URL of the VES collector')
14parser.add_argument('--ipfileserver', help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event')
15parser.add_argument('--typefileserver', help='Type of the file server (SFTP/FTPS) to be included in the VES event')
16parser.add_argument('--ipstart', help='IP address range beginning')
17parser.add_argument('--clean', action='store_true', help='Clean work-dirs')
18parser.add_argument('--start', help='Start instances')
19parser.add_argument('--status', help='Status')
20parser.add_argument('--stop', help='Stop instances')
TamasBakaid38feb62019-02-28 09:06:19 +000021
22args = parser.parse_args()
23
TamasBakaibab325b2019-03-26 09:20:16 +000024if args.bootstrap and args.ipstart and args.urlves:
TamasBakaid38feb62019-02-28 09:06:19 +000025 print("Bootstrap:")
26
TamasBakaib59bffb2019-03-22 09:52:03 +000027 start_port=2000
TamasBakaie781c7c2019-07-11 11:26:20 +000028 ftps_pasv_port_start=8000
29 ftps_pasv_port_num_of_ports=10
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010030
TamasBakaie781c7c2019-07-11 11:26:20 +000031 ftps_pasv_port_end=ftps_pasv_port_start + ftps_pasv_port_num_of_ports
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010032
TamasBakaib59bffb2019-03-22 09:52:03 +000033
TamasBakaid38feb62019-02-28 09:06:19 +000034 for i in range(int(args.bootstrap)):
35 print("PNF simulator instance: " + str(i) + ".")
36
37 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
38 print("\tIp Subnet:" + str(ip_subnet))
39 # The IP ranges are in distance of 16 compared to each other.
40 # This is matching the /28 subnet mask used in the dockerfile inside.
41
42 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
43 print("\tIP Gateway:" + str(ip_gw))
44
45 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
46 print("\tIp Pnf SIM:" + str(IpPnfSim))
47
TamasBakaib59bffb2019-03-22 09:52:03 +000048 IpFileServer = args.ipfileserver
RehanRaza4b50bdd2019-05-03 14:28:39 +000049 TypeFileServer = args.typefileserver
TamasBakaib59bffb2019-03-22 09:52:03 +000050
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010051
TamasBakaib59bffb2019-03-22 09:52:03 +000052 PortSftp=start_port +1
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010053 PortFtps=start_port +2
TamasBakaib59bffb2019-03-22 09:52:03 +000054 start_port +=2
TamasBakaibab325b2019-03-26 09:20:16 +000055 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
56 print("\tUrl Ftps: " + str(UrlFtps))
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010057
TamasBakaibab325b2019-03-26 09:20:16 +000058 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
59 print("\tUrl Sftp: " + str(UrlSftp))
TamasBakaid38feb62019-02-28 09:06:19 +000060
61 foldername = "pnf-sim-lw-" + str(i)
62 completed = subprocess.run('mkdir ' + foldername, shell=True)
63 print('\tCreating folder:', completed.stdout)
64 completed = subprocess.run(
65 'cp -r pnf-sim-lightweight/* ' +
66 foldername,
67 shell=True)
68 print('\tCloning folder:', completed.stdout)
69
TamasBakaibab325b2019-03-26 09:20:16 +000070 composercmd = "./simulator.sh compose " + \
71 str(ip_gw) + " " + \
72 str(ip_subnet) + " " + \
73 str(i) + " " + \
74 str(args.urlves) + " " + \
75 str(IpPnfSim) + " " + \
76 str(IpFileServer) + " " + \
RehanRaza4b50bdd2019-05-03 14:28:39 +000077 str(TypeFileServer) + " " + \
TamasBakaibab325b2019-03-26 09:20:16 +000078 str(PortSftp) + " " + \
79 str(PortFtps) + " " + \
80 str(UrlFtps) + " " + \
TamasBakaie781c7c2019-07-11 11:26:20 +000081 str(UrlSftp) + " " + \
82 str(ftps_pasv_port_start) + " " + \
83 str(ftps_pasv_port_end)
TamasBakaid38feb62019-02-28 09:06:19 +000084
85 completed = subprocess.run(
86 'set -x; cd ' +
87 foldername +
88 '; ' +
89 composercmd,
90 shell=True)
91 print('Cloning:', completed.stdout)
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +010092
TamasBakaie781c7c2019-07-11 11:26:20 +000093 ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
94 ftps_pasv_port_end += ftps_pasv_port_num_of_ports +1
TamasBakaid38feb62019-02-28 09:06:19 +000095
TamasBakaibab325b2019-03-26 09:20:16 +000096 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
97 print("Build docker image: ", completed.stdout)
98
TamasBakaid38feb62019-02-28 09:06:19 +000099 sys.exit()
100
101if args.clean:
102 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
103 print('Deleting:', completed.stdout)
104 sys.exit()
105
106if args.start:
107
108 for i in range(int(args.start)):
109 foldername = "pnf-sim-lw-" + str(i)
110
111 completed = subprocess.run(
112 'set -x ; cd ' +
113 foldername +
114 "; bash -x ./simulator.sh start",
115 shell=True)
116 print('Starting:', completed.stdout)
117
118 time.sleep(5)
119
120if args.status:
121
122 for i in range(int(args.status)):
123 foldername = "pnf-sim-lw-" + str(i)
124
125 completed = subprocess.run(
126 'cd ' +
127 foldername +
128 "; ./simulator.sh status",
129 shell=True)
130 print('Status:', completed.stdout)
131
132if args.stop:
133 for i in range(int(args.stop)):
134 foldername = "pnf-sim-lw-" + str(i)
135
136 completed = subprocess.run(
137 'cd ' +
138 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000139 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000140 shell=True)
141 print('Stopping:', completed.stdout)
142
TamasBakaib59bffb2019-03-22 09:52:03 +0000143
144if args.trigger:
145 print("Triggering VES sending:")
146
147 for i in range(int(args.trigger)):
148 foldername = "pnf-sim-lw-" + str(i)
149
150 completed = subprocess.run(
151 'cd ' +
152 foldername +
153 "; ./simulator.sh trigger-simulator",
154 shell=True)
155 print('Status:', completed.stdout)
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100156
TamasBakai34a6f112019-04-15 08:38:51 +0000157if args.triggerstart and args.triggerend:
158 print("Triggering VES sending by a range of simulators:")
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100159
TamasBakai34a6f112019-04-15 08:38:51 +0000160 for i in range(int(args.triggerstart), int(args.triggerend)+1):
161 foldername = "pnf-sim-lw-" + str(i)
162 print("Instance being processed:" + str(i))
Bartek Grzybowski3d3d3c22020-03-05 10:28:03 +0100163
TamasBakai34a6f112019-04-15 08:38:51 +0000164 completed = subprocess.run(
165 'cd ' +
166 foldername +
167 "; ./simulator.sh trigger-simulator",
168 shell=True)
169 print('Status:', completed.stdout)
TamasBakaid38feb62019-02-28 09:06:19 +0000170else:
171 print("No instruction was defined")
Bartek Grzybowskic29b9462020-04-30 07:11:59 -0700172 parser.print_usage()
TamasBakaid38feb62019-02-28 09:06:19 +0000173 sys.exit()