blob: 898cd650f7b568e739edd7fdb5eb3fd01fd003bf [file] [log] [blame]
TamasBakaid38feb62019-02-28 09:06:19 +00001#!/usr/bin/env python3
2import argparse
3import sys
4from subprocess import *
5from subprocess import STDOUT
6import subprocess
7import ipaddress
8import time
9
10parser = argparse.ArgumentParser()
11parser.add_argument(
12 '--bootstrap',
13 help='Bootstrapping the system',
14)
15
16parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000017 '--trigger',
18 help='Trigger one single VES event from each simulator',
19)
20
21parser.add_argument(
TamasBakaid38feb62019-02-28 09:06:19 +000022 '--ipves',
23 help='IP of the VES collector',
24)
25
26parser.add_argument(
TamasBakaib59bffb2019-03-22 09:52:03 +000027 '--ipfileserver',
28 help='Visible IP of the file server (SFTP/FTPS) to be included in the VES event',
29)
30
31parser.add_argument(
TamasBakaid38feb62019-02-28 09:06:19 +000032 '--ipstart',
33 help='IP address range beginning',
34)
35
36parser.add_argument(
37 '--clean',
38 action='store_true',
39 help='Cleaning work-dirs',
40)
41
42parser.add_argument(
43 '--start',
44 help='Starting instances',
45)
46
47parser.add_argument(
48 '--status',
49 help='Status',
50)
51
52parser.add_argument(
53 '--stop',
54 help='Stopping instances',
55)
56
57args = parser.parse_args()
58
59if args.bootstrap and args.ipstart and args.ipves:
60 print("Bootstrap:")
61
TamasBakaib59bffb2019-03-22 09:52:03 +000062 start_port=2000
63
TamasBakaid38feb62019-02-28 09:06:19 +000064 for i in range(int(args.bootstrap)):
65 print("PNF simulator instance: " + str(i) + ".")
66
67 ip_subnet = ipaddress.ip_address(args.ipstart) + int(0 + (i * 16))
68 print("\tIp Subnet:" + str(ip_subnet))
69 # The IP ranges are in distance of 16 compared to each other.
70 # This is matching the /28 subnet mask used in the dockerfile inside.
71
72 ip_gw = ipaddress.ip_address(args.ipstart) + int(1 + (i * 16))
73 print("\tIP Gateway:" + str(ip_gw))
74
75 IpPnfSim = ipaddress.ip_address(args.ipstart) + int(2 + (i * 16))
76 print("\tIp Pnf SIM:" + str(IpPnfSim))
77
TamasBakaib59bffb2019-03-22 09:52:03 +000078 IpFileServer = args.ipfileserver
79
80
81 PortSftp=start_port +1
82 PortFtps=start_port +2
83 start_port +=2
TamasBakaid38feb62019-02-28 09:06:19 +000084 IpFtps = ipaddress.ip_address(args.ipstart) + int(3 + (i * 16))
85 print("\tIp Ftps: " + str(IpFtps))
TamasBakaib59bffb2019-03-22 09:52:03 +000086
TamasBakaid38feb62019-02-28 09:06:19 +000087 IpSftp = ipaddress.ip_address(args.ipstart) + int(4 + (i * 16))
88 print("\tIp Sftp:" + str(IpSftp))
89
90 foldername = "pnf-sim-lw-" + str(i)
91 completed = subprocess.run('mkdir ' + foldername, shell=True)
92 print('\tCreating folder:', completed.stdout)
93 completed = subprocess.run(
94 'cp -r pnf-sim-lightweight/* ' +
95 foldername,
96 shell=True)
97 print('\tCloning folder:', completed.stdout)
98
99 composercmd = "./simulator.sh compose " +\
100 str(ip_gw) + " " +\
101 str(ip_subnet) + " " +\
102 str(i) + " " +\
103 str(args.ipves) + " " +\
104 str(IpPnfSim) + " " +\
TamasBakaib59bffb2019-03-22 09:52:03 +0000105 str(IpFileServer) + " " +\
106 str(PortSftp) + " " +\
107 str(PortFtps) + " " +\
TamasBakaid38feb62019-02-28 09:06:19 +0000108 str(IpFtps) + " " +\
109 str(IpSftp)
110
111 completed = subprocess.run(
112 'set -x; cd ' +
113 foldername +
114 '; ' +
115 composercmd,
116 shell=True)
117 print('Cloning:', completed.stdout)
118
119 sys.exit()
120
121if args.clean:
122 completed = subprocess.run('rm -rf ./pnf-sim-lw-*', shell=True)
123 print('Deleting:', completed.stdout)
124 sys.exit()
125
126if args.start:
127
128 for i in range(int(args.start)):
129 foldername = "pnf-sim-lw-" + str(i)
130
131 completed = subprocess.run(
132 'set -x ; cd ' +
133 foldername +
134 "; bash -x ./simulator.sh start",
135 shell=True)
136 print('Starting:', completed.stdout)
137
138 time.sleep(5)
139
140if args.status:
141
142 for i in range(int(args.status)):
143 foldername = "pnf-sim-lw-" + str(i)
144
145 completed = subprocess.run(
146 'cd ' +
147 foldername +
148 "; ./simulator.sh status",
149 shell=True)
150 print('Status:', completed.stdout)
151
152if args.stop:
153 for i in range(int(args.stop)):
154 foldername = "pnf-sim-lw-" + str(i)
155
156 completed = subprocess.run(
157 'cd ' +
158 foldername +
RehanRaza48f92042019-03-20 08:12:55 +0000159 "; ./simulator.sh stop " + str(i),
TamasBakaid38feb62019-02-28 09:06:19 +0000160 shell=True)
161 print('Stopping:', completed.stdout)
162
TamasBakaib59bffb2019-03-22 09:52:03 +0000163
164if args.trigger:
165 print("Triggering VES sending:")
166
167 for i in range(int(args.trigger)):
168 foldername = "pnf-sim-lw-" + str(i)
169
170 completed = subprocess.run(
171 'cd ' +
172 foldername +
173 "; ./simulator.sh trigger-simulator",
174 shell=True)
175 print('Status:', completed.stdout)
176
TamasBakaid38feb62019-02-28 09:06:19 +0000177else:
178 print("No instruction was defined")
179 sys.exit()