blob: c1bed8f63e2481bce91ceb28a25a29d48eb67f3c [file] [log] [blame]
TamasBakai9b780332019-02-15 08:38:16 +00001import argparse
2import os
3from werkzeug import secure_filename
4from flask import Flask, render_template, request
5from time import sleep
BjornMagnussonXAf4e18362019-04-10 13:04:08 +00006import time
TamasBakai9b780332019-02-15 08:38:16 +00007import sys
8import json
9from flask import Flask
BjornMagnussonXAf4e18362019-04-10 13:04:08 +000010
TamasBakai9b780332019-02-15 08:38:16 +000011app = Flask(__name__)
12
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000013#Server info
14HOST_IP = "0.0.0.0"
15HOST_PORT = 2222
TamasBakai9b780332019-02-15 08:38:16 +000016
BjornMagnussonXAf4e18362019-04-10 13:04:08 +000017SFTP_PORT = 1022
18FTPS_PORT = 21
19
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000020#Test function to check server running
21@app.route('/',
22 methods=['GET'])
23def index():
24 return 'Hello world'
TamasBakai9b780332019-02-15 08:38:16 +000025
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000026#Returns number of polls
27@app.route('/ctr_requests',
28 methods=['GET'])
29def counter_requests():
30 global ctr_requests
31 return str(ctr_requests)
32
33#Returns number of replies
34@app.route('/ctr_responses',
35 methods=['GET'])
36def counter_responses():
37 global ctr_responses
38 return str(ctr_responses)
39
40#Returns number of unique files
41@app.route('/ctr_unique_files',
42 methods=['GET'])
43def counter_uniquefiles():
44 global fileMap
45 return str(len(fileMap))
46
47#Returns tc info
48@app.route('/tc_info',
49 methods=['GET'])
50def testcase_info():
51 global tc_num
52 return tc_num
53
BjornMagnussonXAf4e18362019-04-10 13:04:08 +000054#Returns number of events
55@app.route('/ctr_events',
56 methods=['GET'])
57def counter_events():
58 global ctr_events
59 return str(ctr_events)
60
61#Returns number of events
62@app.route('/execution_time',
63 methods=['GET'])
64def exe_time():
65 global startTime
66
67 stopTime = time.time()
68 minutes, seconds = divmod(stopTime-startTime, 60)
69 return "{:0>2}:{:0>2}".format(int(minutes),int(seconds))
70
71#Returns number of unique PNFs
72@app.route('/ctr_unique_PNFs',
73 methods=['GET'])
74def counter_uniquePNFs():
75 global pnfMap
76 return str(len(pnfMap))
77
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000078#Messages polling function
TamasBakai9b780332019-02-15 08:38:16 +000079@app.route(
80 "/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12",
81 methods=['GET'])
82def MR_reply():
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000083 global ctr_requests
84 global args
TamasBakai9b780332019-02-15 08:38:16 +000085
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000086 ctr_requests = ctr_requests + 1
87 print("MR: poll request#: " + str(ctr_requests))
TamasBakai9b780332019-02-15 08:38:16 +000088
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000089 if args.tc100:
90 return tc100("sftp")
91 elif args.tc101:
92 return tc101("sftp")
93 elif args.tc102:
94 return tc102("sftp")
TamasBakai9b780332019-02-15 08:38:16 +000095
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +000096 elif args.tc110:
97 return tc110("sftp")
98 elif args.tc111:
99 return tc111("sftp")
100 elif args.tc112:
101 return tc112("sftp")
102 elif args.tc113:
103 return tc113("sftp")
TamasBakai9b780332019-02-15 08:38:16 +0000104
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000105 elif args.tc120:
106 return tc120("sftp")
107 elif args.tc121:
108 return tc121("sftp")
109 elif args.tc122:
110 return tc122("sftp")
TamasBakai9b780332019-02-15 08:38:16 +0000111
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000112 elif args.tc1000:
113 return tc1000("sftp")
114 elif args.tc1001:
115 return tc1001("sftp")
TamasBakai9b780332019-02-15 08:38:16 +0000116
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000117 elif args.tc510:
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000118 return tc510("sftp")
119 elif args.tc511:
120 return tc511("sftp")
121
122 elif args.tc710:
123 return tc710("sftp")
TamasBakai9b780332019-02-15 08:38:16 +0000124
125
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000126 elif args.tc200:
127 return tc200("ftps")
128 elif args.tc201:
129 return tc201("ftps")
130 elif args.tc202:
131 return tc202("ftps")
TamasBakai9b780332019-02-15 08:38:16 +0000132
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000133 elif args.tc210:
134 return tc210("ftps")
135 elif args.tc211:
136 return tc211("ftps")
137 elif args.tc212:
138 return tc212("ftps")
139 elif args.tc213:
140 return tc213("ftps")
TamasBakai9b780332019-02-15 08:38:16 +0000141
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000142 elif args.tc220:
143 return tc220("ftps")
144 elif args.tc221:
145 return tc221("ftps")
146 elif args.tc222:
147 return tc222("ftps")
148
149 elif args.tc2000:
150 return tc2000("ftps")
151 elif args.tc2001:
152 return tc2001("ftps")
153
154 elif args.tc610:
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000155 return tc510("ftps")
156 elif args.tc611:
157 return tc511("ftps")
158
159 elif args.tc810:
160 return tc710("ftps")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000161
162
163#### Test case functions
164
165
166def tc100(ftptype):
167 global ctr_responses
168 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000169 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000170
171 ctr_responses = ctr_responses + 1
172
173 if (ctr_responses > 1):
174 return buildOkResponse("[]")
175
176 seqNr = (ctr_responses-1)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000177 nodeName = createNodeName(0)
178 fileName = createFileName(nodeName, seqNr, "1MB")
179 msg = getEventHead(nodeName) + getEventName(fileName,ftptype,"onap","pano") + getEventEnd()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000180 fileMap[seqNr] = seqNr
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000181 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000182 return buildOkResponse("["+msg+"]")
183
184def tc101(ftptype):
185 global ctr_responses
186 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000187 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000188
189 ctr_responses = ctr_responses + 1
190
191 if (ctr_responses > 1):
192 return buildOkResponse("[]")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000193
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000194 seqNr = (ctr_responses-1)
195 nodeName = createNodeName(0)
196 fileName = createFileName(nodeName, seqNr, "5MB")
197 msg = getEventHead(nodeName) + getEventName(fileName,ftptype,"onap","pano") + getEventEnd()
198 fileMap[seqNr] = seqNr
199 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000200 return buildOkResponse("["+msg+"]")
201
202def tc102(ftptype):
203 global ctr_responses
204 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000205 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000206
207 ctr_responses = ctr_responses + 1
208
209 if (ctr_responses > 1):
210 return buildOkResponse("[]")
211
212 seqNr = (ctr_responses-1)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000213 nodeName = createNodeName(0)
214 fileName = createFileName(nodeName, seqNr, "50MB")
215 msg = getEventHead(nodeName) + getEventName(fileName,ftptype,"onap","pano") + getEventEnd()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000216 fileMap[seqNr] = seqNr
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000217 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000218 return buildOkResponse("["+msg+"]")
219
220def tc110(ftptype):
221 global ctr_responses
222 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000223 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000224
225 ctr_responses = ctr_responses + 1
226
227 if (ctr_responses > 100):
228 return buildOkResponse("[]")
229
230 seqNr = (ctr_responses-1)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000231 nodeName = createNodeName(0)
232 fileName = createFileName(nodeName, seqNr, "1MB")
233 msg = getEventHead(nodeName) + getEventName(fileName,ftptype,"onap","pano") + getEventEnd()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000234 fileMap[seqNr] = seqNr
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000235 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000236 return buildOkResponse("["+msg+"]")
237
238def tc111(ftptype):
239 global ctr_responses
240 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000241 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000242
243 ctr_responses = ctr_responses + 1
244
245 if (ctr_responses > 100):
246 return buildOkResponse("[]")
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000247
248 nodeName = createNodeName(0)
249 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000250
251 for i in range(100):
252 seqNr = i+(ctr_responses-1)
253 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000254 fileName = createFileName(nodeName, seqNr, "1MB")
255 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000256 fileMap[seqNr] = seqNr
257
258 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000259 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000260
261 return buildOkResponse("["+msg+"]")
262
263def tc112(ftptype):
264 global ctr_responses
265 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000266 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000267
268 ctr_responses = ctr_responses + 1
269
270 if (ctr_responses > 100):
271 return buildOkResponse("[]")
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000272
273 nodeName = createNodeName(0)
274 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000275
276 for i in range(100):
277 seqNr = i+(ctr_responses-1)
278 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000279 fileName = createFileName(nodeName, seqNr, "5MB")
280 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000281 fileMap[seqNr] = seqNr
282
283 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000284 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000285
286 return buildOkResponse("["+msg+"]")
287
288def tc113(ftptype):
289 global ctr_responses
290 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000291 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000292
293 ctr_responses = ctr_responses + 1
294
295 if (ctr_responses > 1):
296 return buildOkResponse("[]")
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000297
298 nodeName = createNodeName(0)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000299 msg = ""
300
301 for evts in range(100): # build 100 evts
302 if (evts > 0):
303 msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000304 msg = msg + getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000305 for i in range(100): # build 100 files
306 seqNr = i+evts+100*(ctr_responses-1)
307 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000308 fileName = createFileName(nodeName, seqNr, "1MB")
309 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000310 fileMap[seqNr] = seqNr
311
312 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000313 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000314
315 return buildOkResponse("["+msg+"]")
316
317
318def tc120(ftptype):
319 global ctr_responses
320 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000321 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000322
323 ctr_responses = ctr_responses + 1
324
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000325 nodeName = createNodeName(0)
326
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000327 if (ctr_responses > 100):
328 return buildOkResponse("[]")
329
330 if (ctr_responses % 10 == 2):
331 return # Return nothing
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000332
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000333 if (ctr_responses % 10 == 3):
334 return buildOkResponse("") # Return empty message
335
336 if (ctr_responses % 10 == 4):
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000337 return buildOkResponse(getEventHead(nodeName)) # Return part of a json event
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000338
339 if (ctr_responses % 10 == 5):
340 return buildEmptyResponse(404) # Return empty message with status code
341
342 if (ctr_responses % 10 == 6):
343 sleep(60)
344
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000345
346 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000347
348 for i in range(100):
349 seqNr = i+(ctr_responses-1)
350 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000351 fileName = createFileName(nodeName, seqNr, "1MB")
352 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000353 fileMap[seqNr] = seqNr
354
355 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000356 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000357
358 return buildOkResponse("["+msg+"]")
359
360def tc121(ftptype):
361 global ctr_responses
362 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000363 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000364
365 ctr_responses = ctr_responses + 1
366
367 if (ctr_responses > 100):
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000368 return buildOkResponse("[]")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000369
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000370 nodeName = createNodeName(0)
371 msg = getEventHead(nodeName)
372
373 fileName = ""
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000374 for i in range(100):
375 seqNr = i+(ctr_responses-1)
376 if (seqNr%10 == 0): # Every 10th file is "missing"
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000377 fileName = createMissingFileName(nodeName, seqNr, "1MB")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000378 else:
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000379 fileName = createFileName(nodeName, seqNr, "1MB")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000380 fileMap[seqNr] = seqNr
381
382 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000383 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000384
385 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000386 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000387
388 return buildOkResponse("["+msg+"]")
389
390def tc122(ftptype):
391 global ctr_responses
392 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000393 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000394
395 ctr_responses = ctr_responses + 1
396
397 if (ctr_responses > 100):
398 return buildOkResponse("[]")
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000399
400 nodeName = createNodeName(0)
401 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000402
403 for i in range(100):
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000404 fileName = createFileName(nodeName, 0, "1MB") # All files identical names
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000405 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000406 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000407
408 fileMap[0] = 0
409 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000410 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000411
412 return buildOkResponse("["+msg+"]")
413
414
415def tc1000(ftptype):
416 global ctr_responses
417 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000418 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000419
420 ctr_responses = ctr_responses + 1
421
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000422 nodeName = createNodeName(0)
423 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000424
425 for i in range(100):
426 seqNr = i+(ctr_responses-1)
427 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000428 fileName = createFileName(nodeName, seqNr, "1MB")
429 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000430 fileMap[seqNr] = seqNr
431
432 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000433 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000434
435 return buildOkResponse("["+msg+"]")
436
437def tc1001(ftptype):
438 global ctr_responses
439 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000440 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000441
442 ctr_responses = ctr_responses + 1
443
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000444 nodeName = createNodeName(0)
445 msg = getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000446
447 for i in range(100):
448 seqNr = i+(ctr_responses-1)
449 if i != 0: msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000450 fileName = createFileName(nodeName, seqNr, "5MB")
451 msg = msg + getEventName(fileName,ftptype,"onap","pano")
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000452 fileMap[seqNr] = seqNr
453
454 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000455 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000456
457 return buildOkResponse("["+msg+"]")
458
459def tc510(ftptype):
460 global ctr_responses
461 global ctr_unique_files
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000462 global ctr_events
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000463
464 ctr_responses = ctr_responses + 1
465
466 if (ctr_responses > 5):
467 return buildOkResponse("[]")
468
469 msg = ""
470
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000471 for pnfs in range(700): # build events for 700 MEs
472 if (pnfs > 0):
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000473 msg = msg + ","
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000474 nodeName = createNodeName(pnfs)
475 msg = msg + getEventHead(nodeName)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000476 seqNr = (ctr_responses-1)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000477 fileName = createFileName(nodeName, seqNr, "1MB")
478 msg = msg + getEventName(fileName,ftptype,"onap","pano")
479 seqNr = seqNr + pnfs*1000000 #Create unique id for this node and file
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000480 fileMap[seqNr] = seqNr
481 msg = msg + getEventEnd()
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000482 ctr_events = ctr_events+1
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000483
484 return buildOkResponse("["+msg+"]")
485
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000486def tc511(ftptype):
487 global ctr_responses
488 global ctr_unique_files
489 global ctr_events
490
491 ctr_responses = ctr_responses + 1
492
493 if (ctr_responses > 5):
494 return buildOkResponse("[]")
495
496 msg = ""
497
498 for pnfs in range(700): # build events for 700 MEs
499 if (pnfs > 0):
500 msg = msg + ","
501 nodeName = createNodeName(pnfs)
502 msg = msg + getEventHead(nodeName)
503 seqNr = (ctr_responses-1)
504 fileName = createFileName(nodeName, seqNr, "1KB")
505 msg = msg + getEventName(fileName,ftptype,"onap","pano")
506 seqNr = seqNr + pnfs*1000000 #Create unique id for this node and file
507 fileMap[seqNr] = seqNr
508 msg = msg + getEventEnd()
509 ctr_events = ctr_events+1
510
511 return buildOkResponse("["+msg+"]")
512
513def tc710(ftptype):
514 global ctr_responses
515 global ctr_unique_files
516 global ctr_events
517
518 ctr_responses = ctr_responses + 1
519
520 if (ctr_responses > 100):
521 return buildOkResponse("[]")
522
523 msg = ""
524
525 batch = (ctr_responses-1)%20;
526
527 for pnfs in range(35): # build events for 35 PNFs at a time. 20 batches -> 700
528 if (pnfs > 0):
529 msg = msg + ","
530 nodeName = createNodeName(pnfs + batch*35)
531 msg = msg + getEventHead(nodeName)
532
533 for i in range(100): # 100 files per event
534 seqNr = i + int((ctr_responses-1)/20);
535 if i != 0: msg = msg + ","
536 fileName = createFileName(nodeName, seqNr, "1MB")
537 msg = msg + getEventName(fileName,ftptype,"onap","pano")
538 seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
539 fileMap[seqNr] = seqNr
540
541 msg = msg + getEventEnd()
542 ctr_events = ctr_events+1
543
544 return buildOkResponse("["+msg+"]")
545
546
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000547#Mapping FTPS TCs
548def tc200(ftptype):
549 return tc100(ftptype)
550def tc201(ftptype):
551 return tc101(ftptype)
552def tc202(ftptype):
553 return tc102(ftptype)
554
555def tc210(ftptype):
556 return tc110(ftptype)
557def tc211(ftptype):
558 return tc111(ftptype)
559def tc212(ftptype):
560 return tc112(ftptype)
561def tc213(ftptype):
562 return tc113(ftptype)
563
564def tc220(ftptype):
565 return tc120(ftptype)
566def tc221(ftptype):
567 return tc121(ftptype)
568def tc222(ftptype):
569 return tc122(ftptype)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000570
571def tc610(ftptype):
572 return tc510(ftptype)
573def tc611(ftptype):
574 return tc511(ftptype)
575
576def tc810(ftptype):
577 return tc710(ftptype)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000578
579def tc2000(ftptype):
580 return tc1000(ftptype)
581def tc2001(ftptype):
582 return tc1001(ftptype)
583
584#### Functions to build json messages and respones ####
585
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000586def createNodeName(index):
587 return "PNF"+str(index);
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000588
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000589def createFileName(nodeName, index, size):
590 return "A20000626.2315+0200-2330+0200_" + nodeName + "-" + str(index) + "-" +size + ".tar.gz";
591
592def createMissingFileName(nodeName, index, size):
593 return "AMissingFile_" + nodeName + "-" + str(index) + "-" +size + ".tar.gz";
594
595
596# Function to build fixed beginning of an event
597
598def getEventHead(nodename):
599 global pnfMap
600 pnfMap.add(nodename)
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000601 headStr = """
602 {
TamasBakai9b780332019-02-15 08:38:16 +0000603 "event": {
604 "commonEventHeader": {
605 "startEpochMicrosec": 8745745764578,
606 "eventId": "FileReady_1797490e-10ae-4d48-9ea7-3d7d790b25e1",
607 "timeZoneOffset": "UTC+05.30",
608 "internalHeaderFields": {
609 "collectorTimeStamp": "Tue, 09 18 2018 10:56:52 UTC"
610 },
611 "priority": "Normal",
612 "version": "4.0.1",
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000613 "reportingEntityName": \"""" + nodename + """",
TamasBakai9b780332019-02-15 08:38:16 +0000614 "sequence": 0,
615 "domain": "notification",
616 "lastEpochMicrosec": 8745745764578,
617 "eventName": "Noti_RnNode-Ericsson_FileReady",
618 "vesEventListenerVersion": "7.0.1",
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000619 "sourceName": \"""" + nodename + """"
TamasBakai9b780332019-02-15 08:38:16 +0000620 },
621 "notificationFields": {
622 "notificationFieldsVersion": "2.0",
623 "changeType": "FileReady",
624 "changeIdentifier": "PM_MEAS_FILES",
625 "arrayOfNamedHashMap": [
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000626 """
627 return headStr
628
629# Function to build the variable part of an event
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000630def getEventName(fn,type,user,passwd):
631 port = SFTP_PORT
632 ip = sftp_ip
633 if (type == "ftps"):
634 port = FTPS_PORT
635 ip = ftps_ip
636
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000637 nameStr = """{
638 "name": \"""" + fn + """",
TamasBakai9b780332019-02-15 08:38:16 +0000639 "hashMap": {
640 "fileFormatType": "org.3GPP.32.435#measCollec",
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000641 "location": \"""" + type + """://""" + user + """:""" + passwd + """@""" + ip + """:""" + str(port) + """/""" + fn + """",
TamasBakai9b780332019-02-15 08:38:16 +0000642 "fileFormatVersion": "V10",
643 "compression": "gzip"
644 }
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000645 } """
646 return nameStr
647
648# Function to build fixed end of an event
649def getEventEnd():
650 endStr = """
TamasBakai9b780332019-02-15 08:38:16 +0000651 ]
652 }
653 }
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000654 }
655 """
656 return endStr
TamasBakai9b780332019-02-15 08:38:16 +0000657
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000658# Function to build an OK reponse from a message string
659def buildOkResponse(msg):
660 response = app.response_class(
661 response=str.encode(msg),
662 status=200,
663 mimetype='application/json')
664 return response
TamasBakai9b780332019-02-15 08:38:16 +0000665
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000666# Function to build an empty message with status
667def buildEmptyResponse(status_code):
668 response = app.response_class(
669 response=str.encode(""),
670 status=status_code,
671 mimetype='application/json')
672 return response
TamasBakai9b780332019-02-15 08:38:16 +0000673
674
675if __name__ == "__main__":
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000676
677 # IP addresses to use for ftp servers, using localhost if not env var is set
678 sftp_ip = os.environ.get('SFTP_SIM_IP', 'localhost')
679 ftps_ip = os.environ.get('FTPS_SIM_IP', 'localhost')
680
681
682
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000683 #Counters
684 ctr_responses = 0
685 ctr_requests = 0
686 ctr_unique_files = 0
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000687 ctr_events = 0
688 startTime = time.time()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000689
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000690 #Keeps all responded file names
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000691 fileMap = {}
692
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000693 #Keeps all responded PNF names
694 pnfMap = set()
695
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000696 tc_num = "Not set"
697 tc_help = "Not set"
TamasBakai9b780332019-02-15 08:38:16 +0000698
699 parser = argparse.ArgumentParser()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000700
701#SFTP TCs with single ME
TamasBakai9b780332019-02-15 08:38:16 +0000702 parser.add_argument(
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000703 '--tc100',
TamasBakai9b780332019-02-15 08:38:16 +0000704 action='store_true',
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000705 help='TC100 - One ME, SFTP, 1 1MB file, 1 event')
TamasBakai9b780332019-02-15 08:38:16 +0000706 parser.add_argument(
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000707 '--tc101',
TamasBakai9b780332019-02-15 08:38:16 +0000708 action='store_true',
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000709 help='TC101 - One ME, SFTP, 1 5MB file, 1 event')
TamasBakai9b780332019-02-15 08:38:16 +0000710 parser.add_argument(
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000711 '--tc102',
TamasBakai9b780332019-02-15 08:38:16 +0000712 action='store_true',
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000713 help='TC102 - One ME, SFTP, 1 50MB file, 1 event')
714
TamasBakai9b780332019-02-15 08:38:16 +0000715 parser.add_argument(
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000716 '--tc110',
TamasBakai9b780332019-02-15 08:38:16 +0000717 action='store_true',
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000718 help='TC110 - One ME, SFTP, 1MB files, 1 file per event, 100 events, 1 event per poll.')
719 parser.add_argument(
720 '--tc111',
721 action='store_true',
722 help='TC111 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll.')
723 parser.add_argument(
724 '--tc112',
725 action='store_true',
726 help='TC112 - One ME, SFTP, 5MB files, 100 files per event, 100 events, 1 event per poll.')
727 parser.add_argument(
728 '--tc113',
729 action='store_true',
730 help='TC113 - One ME, SFTP, 1MB files, 100 files per event, 100 events. All events in one poll.')
731
732 parser.add_argument(
733 '--tc120',
734 action='store_true',
735 help='TC120 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% of replies each: no response, empty message, slow response, 404-error, malformed json')
736 parser.add_argument(
737 '--tc121',
738 action='store_true',
739 help='TC121 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files')
740 parser.add_argument(
741 '--tc122',
742 action='store_true',
743 help='TC122 - One ME, SFTP, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name. ')
744
745 parser.add_argument(
746 '--tc1000',
747 action='store_true',
748 help='TC1000 - One ME, SFTP, 1MB files, 100 files per event, endless number of events, 1 event per poll')
749 parser.add_argument(
750 '--tc1001',
751 action='store_true',
752 help='TC1001 - One ME, SFTP, 5MB files, 100 files per event, endless number of events, 1 event per poll')
753
754# SFTP TCs with multiple MEs
755 parser.add_argument(
756 '--tc510',
757 action='store_true',
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000758 help='TC510 - 700 MEs, SFTP, 1MB files, 1 file per event, 3500 events, 700 event per poll.')
759
760 parser.add_argument(
761 '--tc511',
762 action='store_true',
763 help='TC511 - 700 MEs, SFTP, 1KB files, 1 file per event, 3500 events, 700 event per poll.')
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000764
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000765 parser.add_argument(
766 '--tc710',
767 action='store_true',
768 help='TC710 - 700 MEs, SFTP, 1MB files, 100 files per event, 3500 events, 35 event per poll.')
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000769
770# FTPS TCs with single ME
771 parser.add_argument(
772 '--tc200',
773 action='store_true',
774 help='TC200 - One ME, FTPS, 1 1MB file, 1 event')
775 parser.add_argument(
776 '--tc201',
777 action='store_true',
778 help='TC201 - One ME, FTPS, 1 5MB file, 1 event')
779 parser.add_argument(
780 '--tc202',
781 action='store_true',
782 help='TC202 - One ME, FTPS, 1 50MB file, 1 event')
783
784 parser.add_argument(
785 '--tc210',
786 action='store_true',
787 help='TC210 - One ME, FTPS, 1MB files, 1 file per event, 100 events, 1 event per poll.')
788 parser.add_argument(
789 '--tc211',
790 action='store_true',
791 help='TC211 - One ME, FTPS, 1MB files, 100 files per event, 100 events, 1 event per poll.')
792 parser.add_argument(
793 '--tc212',
794 action='store_true',
795 help='TC212 - One ME, FTPS, 5MB files, 100 files per event, 100 events, 1 event per poll.')
796 parser.add_argument(
797 '--tc213',
798 action='store_true',
799 help='TC213 - One ME, FTPS, 1MB files, 100 files per event, 100 events. All events in one poll.')
800
801 parser.add_argument(
802 '--tc220',
803 action='store_true',
804 help='TC220 - One ME, FTPS, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% of replies each: no response, empty message, slow response, 404-error, malformed json')
805 parser.add_argument(
806 '--tc221',
807 action='store_true',
808 help='TC221 - One ME, FTPS, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files')
809 parser.add_argument(
810 '--tc222',
811 action='store_true',
812 help='TC222 - One ME, FTPS, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name. ')
813
814 parser.add_argument(
815 '--tc2000',
816 action='store_true',
817 help='TC2000 - One ME, FTPS, 1MB files, 100 files per event, endless number of events, 1 event per poll')
818 parser.add_argument(
819 '--tc2001',
820 action='store_true',
821 help='TC2001 - One ME, FTPS, 5MB files, 100 files per event, endless number of events, 1 event per poll')
822
823 parser.add_argument(
824 '--tc610',
825 action='store_true',
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000826 help='TC610 - 700 MEs, FTPS, 1MB files, 1 file per event, 3500 events, 700 event per poll.')
827
828 parser.add_argument(
829 '--tc611',
830 action='store_true',
831 help='TC611 - 700 MEs, FTPS, 1KB files, 1 file per event, 3500 events, 700 event per poll.')
832
833 parser.add_argument(
834 '--tc810',
835 action='store_true',
836 help='TC810 - 700 MEs, FTPS, 1MB files, 100 files per event, 3500 events, 35 event per poll.')
TamasBakai9b780332019-02-15 08:38:16 +0000837
838 args = parser.parse_args()
839
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000840
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000841
842 if args.tc100:
843 tc_num = "TC# 100"
844 elif args.tc101:
845 tc_num = "TC# 101"
846 elif args.tc102:
847 tc_num = "TC# 102"
848
849 elif args.tc110:
850 tc_num = "TC# 110"
851 elif args.tc111:
852 tc_num = "TC# 111"
853 elif args.tc112:
854 tc_num = "TC# 112"
855 elif args.tc113:
856 tc_num = "TC# 113"
857
858 elif args.tc120:
859 tc_num = "TC# 120"
860 elif args.tc121:
861 tc_num = "TC# 121"
862 elif args.tc122:
863 tc_num = "TC# 122"
864
865 elif args.tc1000:
866 tc_num = "TC# 1000"
867 elif args.tc1001:
868 tc_num = "TC# 1001"
869
870 elif args.tc510:
871 tc_num = "TC# 510"
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000872 elif args.tc511:
873 tc_num = "TC# 511"
874
875 elif args.tc710:
876 tc_num = "TC# 710"
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000877
878 elif args.tc200:
879 tc_num = "TC# 200"
880 elif args.tc201:
881 tc_num = "TC# 201"
882 elif args.tc202:
883 tc_num = "TC# 202"
884
885 elif args.tc210:
886 tc_num = "TC# 210"
887 elif args.tc211:
888 tc_num = "TC# 211"
889 elif args.tc212:
890 tc_num = "TC# 212"
891 elif args.tc213:
892 tc_num = "TC# 213"
893
894 elif args.tc220:
895 tc_num = "TC# 220"
896 elif args.tc221:
897 tc_num = "TC# 221"
898 elif args.tc222:
899 tc_num = "TC# 222"
900
901 elif args.tc2000:
902 tc_num = "TC# 2000"
903 elif args.tc2001:
904 tc_num = "TC# 2001"
905
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000906
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000907 elif args.tc610:
908 tc_num = "TC# 610"
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000909 elif args.tc611:
910 tc_num = "TC# 611"
911
912 elif args.tc810:
913 tc_num = "TC# 810"
TamasBakai9b780332019-02-15 08:38:16 +0000914
915 else:
916 print("No TC was defined")
917 print("use --help for usage info")
918 sys.exit()
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000919
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000920 print("TC num: " + tc_num)
921
922
923 print("Using " + sftp_ip + " for sftp server address in file urls.")
924 print("Using " + ftps_ip + " for ftps server address in file urls.")
925
BjornMagnussonXAf8b34f02019-03-22 09:48:38 +0000926 app.run(port=HOST_PORT, host=HOST_IP)
BjornMagnussonXAf4e18362019-04-10 13:04:08 +0000927