4 from subprocess import *
5 from subprocess import STDOUT
10 parser = argparse.ArgumentParser()
13 help='Bootstrapping the system',
18 help='Trigger one single VES event from each simulator',
24 help='Trigger only a subset of the simulators (note --triggerend)',
29 help='Last instance to trigger',
34 help='URL of the VES collector',
39 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
44 help='Type of the file server (SFTP/FTPS) to be included in the VES event',
49 help='IP address range beginning',
55 help='Cleaning work-dirs',
60 help='Starting instances',
70 help='Stopping instances',
73 args = parser.parse_args()
75 if args.bootstrap and args.ipstart and args.urlves:
79 ftps_pasv_port_start=8000
80 ftps_pasv_port_num_of_ports=10
82 ftps_pasv_port_end=ftps_pasv_port_start + ftps_pasv_port_num_of_ports
85 for i in range(int(args.bootstrap)):
86 print("PNF simulator instance: " + str(i) + ".")
88 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
89 print("\tIp Subnet:" + str(ip_subnet))
90 # The IP ranges are in distance of 16 compared to each other.
91 # This is matching the /28 subnet mask used in the dockerfile inside.
93 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
94 print("\tIP Gateway:" + str(ip_gw))
96 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
97 print("\tIp Pnf SIM:" + str(IpPnfSim))
99 IpFileServer = args.ipfileserver
100 TypeFileServer = args.typefileserver
103 PortSftp=start_port +1
104 PortFtps=start_port +2
106 UrlFtps = str(ipaddress.ip_address(args.ipstart) + int(3 + (i * 16)))
107 print("\tUrl Ftps: " + str(UrlFtps))
109 UrlSftp = str(ipaddress.ip_address(args.ipstart) + int(4 + (i * 16)))
110 print("\tUrl Sftp: " + str(UrlSftp))
112 foldername = "pnf-sim-lw-" + str(i)
113 completed = subprocess.run('mkdir ' + foldername, shell=True)
114 print('\tCreating folder:', completed.stdout)
115 completed = subprocess.run(
116 'cp -r pnf-sim-lightweight/* ' +
119 print('\tCloning folder:', completed.stdout)
121 composercmd = "./simulator.sh compose " + \
123 str(ip_subnet) + " " + \
125 str(args.urlves) + " " + \
126 str(IpPnfSim) + " " + \
127 str(IpFileServer) + " " + \
128 str(TypeFileServer) + " " + \
129 str(PortSftp) + " " + \
130 str(PortFtps) + " " + \
131 str(UrlFtps) + " " + \
132 str(UrlSftp) + " " + \
133 str(ftps_pasv_port_start) + " " + \
134 str(ftps_pasv_port_end)
136 completed = subprocess.run(
142 print('Cloning:', completed.stdout)
144 ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
145 ftps_pasv_port_end += ftps_pasv_port_num_of_ports +1
147 completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True)
148 print("Build docker image: ", completed.stdout)
153 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
154 print('Deleting:', completed.stdout)
159 for i in range(int(args.start)):
160 foldername = "pnf-sim-lw-" + str(i)
162 completed = subprocess.run(
165 "; bash -x ./simulator.sh start",
167 print('Starting:', completed.stdout)
173 for i in range(int(args.status)):
174 foldername = "pnf-sim-lw-" + str(i)
176 completed = subprocess.run(
179 "; ./simulator.sh status",
181 print('Status:', completed.stdout)
184 for i in range(int(args.stop)):
185 foldername = "pnf-sim-lw-" + str(i)
187 completed = subprocess.run(
190 "; ./simulator.sh stop " + str(i),
192 print('Stopping:', completed.stdout)
196 print("Triggering VES sending:")
198 for i in range(int(args.trigger)):
199 foldername = "pnf-sim-lw-" + str(i)
201 completed = subprocess.run(
204 "; ./simulator.sh trigger-simulator",
206 print('Status:', completed.stdout)
208 if args.triggerstart and args.triggerend:
209 print("Triggering VES sending by a range of simulators:")
211 for i in range(int(args.triggerstart), int(args.triggerend)+1):
212 foldername = "pnf-sim-lw-" + str(i)
213 print("Instance being processed:" + str(i))
215 completed = subprocess.run(
218 "; ./simulator.sh trigger-simulator",
220 print('Status:', completed.stdout)
225 print("No instruction was defined")