aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/datafilecollector-testharness/mr-sim/mr-sim.py
blob: 6345ab69fa954addf19f4ae9cba50272799d765e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
import argparse
import json
import os
import sys
import time
from time import sleep

from flask import Flask, render_template, request
from werkzeug import secure_filename

app = Flask(__name__)

#Server info
HOST_IP = "0.0.0.0"
HOST_PORT = 2222
HOST_PORT_TLS = 2223

sftp_hosts=[]
sftp_ports=[]
ftps_hosts=[]
ftps_ports=[]
num_ftp_servers=1

def sumList(ctrArray):
    tmp=0
    for i in range(len(ctrArray)):
        tmp=tmp+ctrArray[i];

    return str(tmp);

def sumListLength(ctrArray):
    tmp=0
    for i in range(len(ctrArray)):
        tmp=tmp+len(ctrArray[i]);

    return str(tmp);

#Test function to check server running
@app.route('/',
    methods=['GET'])
def index():
    return 'Hello world'

#Returns the list of configured groups
@app.route('/groups',
    methods=['GET'])
def group_ids():
    global configuredGroups
    return configuredGroups

#Returns the list of configured changeids
@app.route('/changeids',
    methods=['GET'])
def change_ids():
    global configuredChangeIds
    return configuredChangeIds

#Returns the list of configured fileprefixes
@app.route('/fileprefixes',
    methods=['GET'])
def fileprefixes():
    global configuredPrefixes
    return configuredPrefixes


#Returns number of polls
@app.route('/ctr_requests',
    methods=['GET'])
def counter_requests():
    global ctr_requests
    return sumList(ctr_requests)

#Returns number of polls for all groups
@app.route('/groups/ctr_requests',
    methods=['GET'])
def group_counter_requests():
    global ctr_requests
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(ctr_requests[i])
    return tmp

#Returns the total number of polls for a group
@app.route('/ctr_requests/<groupId>',
    methods=['GET'])
def counter_requests_group(groupId):
    global ctr_requests
    global groupNameIndexes
    return str(ctr_requests[groupNameIndexes[groupId]])

#Returns number of poll replies
@app.route('/ctr_responses',
    methods=['GET'])
def counter_responses():
    global ctr_responses
    return sumList(ctr_responses)

#Returns number of poll replies for all groups
@app.route('/groups/ctr_responses',
    methods=['GET'])
def group_counter_responses():
    global ctr_responses
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(ctr_responses[i])
    return tmp

#Returns the total number of poll replies for a group
@app.route('/ctr_responses/<groupId>',
    methods=['GET'])
def counter_responses_group(groupId):
    global ctr_responses
    global groupNameIndexes
    return str(ctr_responses[groupNameIndexes[groupId]])

#Returns the total number of files
@app.route('/ctr_files',
    methods=['GET'])
def counter_files():
    global ctr_files
    return sumList(ctr_files)

#Returns the total number of file for all groups
@app.route('/groups/ctr_files',
    methods=['GET'])
def group_counter_files():
    global ctr_files
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(ctr_files[i])
    return tmp

#Returns the total number of files for a group
@app.route('/ctr_files/<groupId>',
    methods=['GET'])
def counter_files_group(groupId):
    global ctr_files
    global groupNameIndexes
    return str(ctr_files[groupNameIndexes[groupId]])


#Returns number of unique files
@app.route('/ctr_unique_files',
    methods=['GET'])
def counter_uniquefiles():
    global fileMap
    return sumListLength(fileMap)

#Returns number of unique files for all groups
@app.route('/groups/ctr_unique_files',
    methods=['GET'])
def group_counter_uniquefiles():
    global fileMap
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(len(fileMap[i]))
    return tmp

#Returns the total number of unique files for a group
@app.route('/ctr_unique_files/<groupId>',
    methods=['GET'])
def counter_uniquefiles_group(groupId):
    global fileMap
    global groupNameIndexes
    return str(len(fileMap[groupNameIndexes[groupId]]))

#Returns tc info
@app.route('/tc_info',
    methods=['GET'])
def testcase_info():
    global tc_num
    return tc_num

#Returns number of events
@app.route('/ctr_events',
    methods=['GET'])
def counter_events():
    global ctr_events
    return sumList(ctr_events)

#Returns number of events for all groups
@app.route('/groups/ctr_events',
    methods=['GET'])
def group_counter_events():
    global ctr_events
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(ctr_events[i])
    return tmp

#Returns the total number of events for a group
@app.route('/ctr_events/<groupId>',
    methods=['GET'])
def counter_events_group(groupId):
    global ctr_events
    global groupNameIndexes
    return str(ctr_events[groupNameIndexes[groupId]])

#Returns execution time in mm:ss
@app.route('/execution_time',
    methods=['GET'])
def exe_time():
    global startTime

    stopTime = time.time()
    minutes, seconds = divmod(stopTime-startTime, 60)
    return "{:0>2}:{:0>2}".format(int(minutes),int(seconds))

#Returns the timestamp for first poll
@app.route('/exe_time_first_poll',
    methods=['GET'])
def exe_time_first_poll():
    global firstPollTime

    tmp = 0
    for i in range(len(groupNames)):
        if (firstPollTime[i] > tmp):
            tmp = firstPollTime[i]

    if (tmp == 0):
        return "--:--"
    minutes, seconds = divmod(time.time()-tmp, 60)
    return "{:0>2}:{:0>2}".format(int(minutes),int(seconds))

#Returns the timestamp for first poll for all groups
@app.route('/groups/exe_time_first_poll',
    methods=['GET'])
def group_exe_time_first_poll():
    global firstPollTime
    global groupNames

    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        if (firstPollTime[i] == 0):
            tmp=tmp+ "--:--"
        else:
            minutes, seconds = divmod(time.time()-firstPollTime[i], 60)
            tmp=tmp+"{:0>2}:{:0>2}".format(int(minutes),int(seconds))
    return tmp

#Returns the timestamp for first poll for a group
@app.route('/exe_time_first_poll/<groupId>',
    methods=['GET'])
def exe_time_first_poll_group(groupId):
    global ctr_requests
    global groupNameIndexes

    if (firstPollTime[groupNameIndexes[groupId]] == 0):
        return "--:--"
    minutes, seconds = divmod(time.time()-firstPollTime[groupNameIndexes[groupId]], 60)
    return "{:0>2}:{:0>2}".format(int(minutes),int(seconds))

#Starts event delivery
@app.route('/start',
    methods=['GET'])
def start():
    global runningState
    runningState="Started"
    return runningState

#Stops event delivery
@app.route('/stop',
    methods=['GET'])
def stop():
    global runningState
    runningState="Stopped"
    return runningState

#Returns the running state
@app.route('/status',
    methods=['GET'])
def status():
    global runningState
    return runningState

#Returns number of unique PNFs
@app.route('/ctr_unique_PNFs',
    methods=['GET'])
def counter_uniquePNFs():
    global pnfMap
    return sumListLength(pnfMap)

#Returns number of unique PNFs for all groups
@app.route('/groups/ctr_unique_PNFs',
    methods=['GET'])
def group_counter_uniquePNFs():
    global pnfMap
    global groupNames
    tmp=''
    for i in range(len(groupNames)):
        if (i > 0):
            tmp=tmp+','
        tmp=tmp+str(len(pnfMap[i]))
    return tmp

#Returns the unique PNFs for a group
@app.route('/ctr_unique_PNFs/<groupId>',
    methods=['GET'])
def counter_uniquePNFs_group(groupId):
    global pnfMap
    global groupNameIndexes
    return str(len(pnfMap[groupNameIndexes[groupId]]))


#Messages polling function
@app.route(
    "/events/unauthenticated.VES_NOTIFICATION_OUTPUT/<consumerGroup>/<consumerId>",
    methods=['GET'])
def MR_reply(consumerGroup, consumerId):
    global ctr_requests
    global ctr_responses
    global args
    global runningState
    global firstPollTime
    global groupNameIndexes
    global changeIds
    global filePrefixes

    groupIndex = groupNameIndexes[consumerGroup]
    print("Setting groupIndex: " + str(groupIndex))

    reqCtr = ctr_requests[groupIndex]
    changeId = changeIds[groupIndex][reqCtr%len(changeIds[groupIndex])]
    print("Setting changeid: " + changeId)
    filePrefix = filePrefixes[changeId]
    print("Setting file name prefix: " + filePrefix)

    if (firstPollTime[groupIndex] == 0):
        firstPollTime[groupIndex] = time.time()

    ctr_requests[groupIndex] = ctr_requests[groupIndex] + 1
    print("MR: poll request#: " + str(ctr_requests[groupIndex]))

    if (runningState == "Stopped"):
        ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1
        return buildOkResponse("[]")



    if args.tc100:
      return tc100(groupIndex, changeId, filePrefix, "sftp", "1MB")
    elif args.tc101:
      return tc100(groupIndex, changeId, filePrefix, "sftp", "5MB")
    elif args.tc102:
      return tc100(groupIndex, changeId, filePrefix, "sftp", "50MB")

    elif args.tc110:
      return tc110(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc111:
      return tc111(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc112:
      return tc112(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc113:
      return tc113(groupIndex, changeId, filePrefix, "sftp")

    elif args.tc120:
      return tc120(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc121:
      return tc121(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc122:
      return tc122(groupIndex, changeId, filePrefix, "sftp")

    elif args.tc1000:
      return tc1000(groupIndex, changeId, filePrefix, "sftp")
    elif args.tc1001:
      return tc1001(groupIndex, changeId, filePrefix, "sftp")

    elif args.tc1100:
      return tc1100(groupIndex, changeId, filePrefix, "sftp","1MB")
    elif args.tc1101:
      return tc1100(groupIndex, changeId, filePrefix, "sftp","50MB")
    elif args.tc1102:
      return tc1100(groupIndex, changeId, filePrefix, "sftp","50MB")
    elif args.tc1200:
      return tc1200(groupIndex, changeId, filePrefix, "sftp","1MB")
    elif args.tc1201:
      return tc1200(groupIndex, changeId, filePrefix, "sftp","5MB")
    elif args.tc1202:
      return tc1200(groupIndex, changeId, filePrefix, "sftp","50MB")
    elif args.tc1300:
      return tc1300(groupIndex, changeId, filePrefix, "sftp","1MB")
    elif args.tc1301:
      return tc1300(groupIndex, changeId, filePrefix, "sftp","5MB")
    elif args.tc1302:
      return tc1300(groupIndex, changeId, filePrefix, "sftp","50MB")

    elif args.tc1500:
      return tc1500(groupIndex, changeId, filePrefix, "sftp","1MB")

    elif args.tc500:
      return tc500(groupIndex, changeId, filePrefix, "sftp","1MB")
    elif args.tc501:
      return tc500(groupIndex, changeId, filePrefix, "sftp","5MB")
    elif args.tc502:
      return tc500(groupIndex, changeId, filePrefix, "sftp","50MB")
    elif args.tc510:
      return tc510(groupIndex, changeId, filePrefix, "sftp", "1MB")
    elif args.tc511:
      return tc511(groupIndex, changeId, filePrefix, "sftp", "1KB")

    elif args.tc550:
      return tc510(groupIndex, changeId, filePrefix, "sftp", "50MB")

    elif args.tc710:
      return tc710(groupIndex, changeId, filePrefix, "sftp")


    elif args.tc200:
      return tc100(groupIndex, changeId, filePrefix, "ftps", "1MB")
    elif args.tc201:
      return tc100(groupIndex, changeId, filePrefix, "ftps", "5MB")
    elif args.tc202:
      return tc100(groupIndex, changeId, filePrefix, "ftps", "50MB")

    elif args.tc210:
      return tc110(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc211:
      return tc111(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc212:
      return tc112(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc213:
      return tc113(groupIndex, changeId, filePrefix, "ftps")

    elif args.tc220:
      return tc120(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc221:
      return tc121(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc222:
      return tc122(groupIndex, changeId, filePrefix, "ftps")

    elif args.tc2000:
      return tc1000(groupIndex, changeId, filePrefix, "ftps")
    elif args.tc2001:
      return tc1001(groupIndex, changeId, filePrefix, "ftps")

    elif args.tc2100:
      return tc1100(groupIndex, changeId, filePrefix, "ftps","1MB")
    elif args.tc2101:
      return tc1100(groupIndex, changeId, filePrefix, "ftps","50MB")
    elif args.tc2102:
      return tc1100(groupIndex, changeId, filePrefix, "ftps","50MB")
    elif args.tc2200:
      return tc1200(groupIndex, changeId, filePrefix, "ftps","1MB")
    elif args.tc2201:
      return tc1200(groupIndex, changeId, filePrefix, "ftps","5MB")
    elif args.tc2202:
      return tc1200(groupIndex, changeId, filePrefix, "ftps","50MB")
    elif args.tc2300:
      return tc1300(groupIndex, changeId, filePrefix, "ftps","1MB")
    elif args.tc2301:
      return tc1300(groupIndex, changeId, filePrefix, "ftps","5MB")
    elif args.tc2302:
      return tc1300(groupIndex, changeId, filePrefix, "ftps","50MB")

    elif args.tc2500:
      return tc1500(groupIndex, changeId, filePrefix, "ftps","1MB")

    elif args.tc600:
      return tc500(groupIndex, changeId, filePrefix, "ftps","1MB")
    elif args.tc601:
      return tc500(groupIndex, changeId, filePrefix, "ftps","5MB")
    elif args.tc602:
      return tc500(groupIndex, changeId, filePrefix, "ftps","50MB")
    elif args.tc610:
      return tc510(groupIndex, changeId, filePrefix, "ftps", "1MB")
    elif args.tc611:
      return tc511(groupIndex, changeId, filePrefix, "ftps", "1KB")
    elif args.tc650:
      return tc510(groupIndex, changeId, filePrefix, "ftps", "50MB")
    elif args.tc810:
      return tc710(groupIndex, changeId, filePrefix, "ftps")


#### Test case functions


def tc100(groupIndex, changeId, filePrefix, ftpType, fileSize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 1):
    return buildOkResponse("[]")

  seqNr = (ctr_responses[groupIndex]-1)
  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, fileSize)
  msg = getEventHead(groupIndex, changeId, nodeName) + getEventName(fileName,ftpType,"onap","pano",nodeIndex) + getEventEnd()
  fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr
  ctr_events[groupIndex] = ctr_events[groupIndex]+1
  return buildOkResponse("["+msg+"]")

#def tc101(groupIndex, ftpType):
#  global ctr_responses
#  global ctr_events
#
#  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1
#
#  if (ctr_responses[groupIndex] > 1):
#    return buildOkResponse("[]")
#
#  seqNr = (ctr_responses[groupIndex]-1)
#  nodeName = createNodeName(0)
#  fileName = createFileName(groupIndex, nodeName, seqNr, "5MB")
#  msg = getEventHead(groupIndex, nodeName) + getEventName(fileName,ftpType,"onap","pano") + getEventEnd()
#  fileMap[groupIndex][seqNr] = seqNr
#  ctr_events[groupIndex] = ctr_events[groupIndex]+1
#  return buildOkResponse("["+msg+"]")
#
#def tc102(groupIndex, ftpType):
#  global ctr_responses
#  global ctr_events
#
#  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1
#
#  if (ctr_responses[groupIndex] > 1):
#    return buildOkResponse("[]")
#
#  seqNr = (ctr_responses[groupIndex]-1)
#  nodeName = createNodeName(0)
#  fileName = createFileName(groupIndex, nodeName, seqNr, "50MB")
#  msg = getEventHead(groupIndex, nodeName) + getEventName(fileName,ftpType,"onap","pano") + getEventEnd()
#  fileMap[groupIndex][seqNr] = seqNr
#  ctr_events[groupIndex] = ctr_events[groupIndex]+1
#  return buildOkResponse("["+msg+"]")

def tc110(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  seqNr = (ctr_responses[groupIndex]-1)
  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
  msg = getEventHead(groupIndex, changeId, nodeName) + getEventName(fileName,ftpType,"onap","pano",nodeIndex) + getEventEnd()
  fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr
  ctr_events[groupIndex] = ctr_events[groupIndex]+1
  return buildOkResponse("["+msg+"]")

def tc111(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if i != 0: msg = msg + ","
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc112(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if i != 0: msg = msg + ","
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "5MB")
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc113(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 1):
    return buildOkResponse("[]")

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = ""

  for evts in range(100):  # build 100 evts
    if (evts > 0):
      msg = msg + ","
    msg = msg + getEventHead(groupIndex, changeId, nodeName)
    for i in range(100):   # build 100 files
      seqNr = i+evts+100*(ctr_responses[groupIndex]-1)
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
      msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")


def tc120(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  if (ctr_responses[groupIndex] % 10 == 2):
    return  # Return nothing

  if (ctr_responses[groupIndex] % 10 == 3):
    return buildOkResponse("") # Return empty message

  if (ctr_responses[groupIndex] % 10 == 4):
    return buildOkResponse(getEventHead(groupIndex, changeId, nodeName)) # Return part of a json event

  if (ctr_responses[groupIndex] % 10 == 5):
    return buildEmptyResponse(404) # Return empty message with status code

  if (ctr_responses[groupIndex] % 10 == 6):
    sleep(60)


  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if i != 0: msg = msg + ","
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc121(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  fileName = ""
  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if (seqNr%10 == 0):     # Every 10th file is "missing"
      fileName = createMissingFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
    else:
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    if i != 0: msg = msg + ","
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc122(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    fileName = createFileName(groupIndex, filePrefix, nodeName, 0, "1MB")  # All files identical names
    if i != 0: msg = msg + ","
    msg = msg + getEventName(fileName,ftpType,"onap","pano", nodeIndex)

  fileMap[groupIndex][0] = 0
  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")


def tc1000(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if i != 0: msg = msg + ","
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc1001(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  nodeIndex=0
  nodeName = createNodeName(nodeIndex)
  msg = getEventHead(groupIndex, changeId, nodeName)

  for i in range(100):
    seqNr = i+(ctr_responses[groupIndex]-1)
    if i != 0: msg = msg + ","
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "5MB")
    msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

  msg = msg + getEventEnd()
  ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")


def tc1100(groupIndex, changeId, filePrefix, ftpType, filesize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  msg = ""

  batch = (ctr_responses[groupIndex]-1)%20;

  for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
    if (pnfs > 0):
      msg = msg + ","
    nodeIndex=pnfs + batch*35
    nodeName = createNodeName(nodeIndex)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(100):  # 100 files per event
      seqNr = i + int((ctr_responses[groupIndex]-1)/20);
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, filesize)
      msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
      seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc1200(groupIndex, changeId, filePrefix, ftpType, filesize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  msg = ""

  batch = (ctr_responses[groupIndex]-1)%20;

  for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
    if (pnfs > 0):
      msg = msg + ","
    nodeIndex=pnfs + batch*35
    nodeName = createNodeName(nodeIndex)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(100):  # 100 files per event, all new files
      seqNr = i+100 * int((ctr_responses[groupIndex]-1)/20);
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, filesize)
      msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
      seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")


def tc1300(groupIndex, changeId, filePrefix, ftpType, filesize):
  global ctr_responses
  global ctr_events
  global rop_counter
  global rop_timestamp

  if (rop_counter == 0):
      rop_timestamp = time.time()

  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  #Start a  event deliver for all 700 nodes every 15min
  rop = time.time()-rop_timestamp
  if ((rop < 900) & (rop_counter%20 == 0) & (rop_counter != 0)):
      return buildOkResponse("[]")
  else:
    if (rop_counter%20 == 0) & (rop_counter > 0):
        rop_timestamp = rop_timestamp+900

    rop_counter = rop_counter+1

  msg = ""

  batch = (rop_counter-1)%20;

  for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
    if (pnfs > 0):
      msg = msg + ","
    nodeIndex=pnfs + batch*35
    nodeName = createNodeName(nodeIndex)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(100):  # 100 files per event
      seqNr = i + int((rop_counter-1)/20);
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, filesize)
      msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
      seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc1500(groupIndex, changeId, filePrefix, ftpType, filesize):
  global ctr_responses
  global ctr_events
  global rop_counter
  global rop_timestamp

  if (rop_counter == 0):
      rop_timestamp = time.time()

  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] <= 2000 ):   #first 25h of event doess not care of 15min rop timer

    msg = ""

    batch = (ctr_responses[groupIndex]-1)%20;

    for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
        if (pnfs > 0):
            msg = msg + ","

        nodeIndex=pnfs + batch*35
        nodeName = createNodeName(nodeIndex)
        msg = msg + getEventHead(groupIndex, changeId, nodeName)

        for i in range(100):  # 100 files per event
            seqNr = i + int((ctr_responses[groupIndex]-1)/20);
            if i != 0: msg = msg + ","
            if (seqNr < 100):
                fileName = createMissingFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
            else:
                fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
                seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
                fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr
            msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)


        msg = msg + getEventEnd()
        ctr_events[groupIndex] = ctr_events[groupIndex]+1

        rop_counter = rop_counter+1
    return buildOkResponse("["+msg+"]")

  #Start an event delivery for all 700 nodes every 15min
  rop = time.time()-rop_timestamp
  if ((rop < 900) & (rop_counter%20 == 0) & (rop_counter != 0)):
      return buildOkResponse("[]")
  else:
    if (rop_counter%20 == 0):
        rop_timestamp = time.time()

    rop_counter = rop_counter+1

  msg = ""

  batch = (rop_counter-1)%20;

  for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
    if (pnfs > 0):
      msg = msg + ","
    nodeIndex=pnfs + batch*35
    nodeName = createNodeName(nodeIndex)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(100):  # 100 files per event
      seqNr = i + int((rop_counter-1)/20);
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, filesize)
      msg = msg + getEventName(fileName,ftpType,"onap","pano", nodeIndex)
      seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc500(groupIndex, changeId, filePrefix, ftpType, filesize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 1):
    return buildOkResponse("[]")

  msg = ""


  for pnfs in range(700):
    if (pnfs > 0):
      msg = msg + ","
    nodeName = createNodeName(pnfs)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(2):
      seqNr = i;
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, filesize)
      msg = msg + getEventName(fileName,ftpType,"onap","pano",pnfs)
      seqNr = seqNr + pnfs*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc510(groupIndex, changeId, filePrefix, ftpType, fileSize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 5):
    return buildOkResponse("[]")

  msg = ""

  for pnfs in range(700):  # build events for 700 MEs
    if (pnfs > 0):
      msg = msg + ","
    nodeName = createNodeName(pnfs)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)
    seqNr = (ctr_responses[groupIndex]-1)
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, fileSize)
    msg = msg + getEventName(fileName,ftpType,"onap","pano",pnfs)
    seqNr = seqNr + pnfs*1000000 #Create unique id for this node and file
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr
    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc511(groupIndex, changeId, filePrefix, ftpType, fileSize):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 5):
    return buildOkResponse("[]")

  msg = ""

  for pnfs in range(700):  # build events for 700 MEs
    if (pnfs > 0):
      msg = msg + ","
    nodeName = createNodeName(pnfs)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)
    seqNr = (ctr_responses[groupIndex]-1)
    fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, fileSize)
    msg = msg + getEventName(fileName,ftpType,"onap","pano",pnfs)
    seqNr = seqNr + pnfs*1000000 #Create unique id for this node and file
    fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr
    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")

def tc710(groupIndex, changeId, filePrefix, ftpType):
  global ctr_responses
  global ctr_events


  ctr_responses[groupIndex] = ctr_responses[groupIndex] + 1

  if (ctr_responses[groupIndex] > 100):
    return buildOkResponse("[]")

  msg = ""

  batch = (ctr_responses[groupIndex]-1)%20;

  for pnfs in range(35):  # build events for 35 PNFs at a time. 20 batches -> 700
    if (pnfs > 0):
      msg = msg + ","
    nodeIndex=pnfs + batch*35
    nodeName = createNodeName(nodeIndex)
    msg = msg + getEventHead(groupIndex, changeId, nodeName)

    for i in range(100):  # 100 files per event
      seqNr = i + int((ctr_responses[groupIndex]-1)/20);
      if i != 0: msg = msg + ","
      fileName = createFileName(groupIndex, filePrefix, nodeName, seqNr, "1MB")
      msg = msg + getEventName(fileName,ftpType,"onap","pano",nodeIndex)
      seqNr = seqNr + (pnfs+batch*35)*1000000 #Create unique id for this node and file
      fileMap[groupIndex][seqNr*hash(filePrefix)] = seqNr

    msg = msg + getEventEnd()
    ctr_events[groupIndex] = ctr_events[groupIndex]+1

  return buildOkResponse("["+msg+"]")


#### Functions to build json messages and respones ####

def createNodeName(index):
    return "PNF"+str(index);

def createFileName(groupIndex, filePrefix, nodeName, index, size):
    global ctr_files
    ctr_files[groupIndex] = ctr_files[groupIndex] + 1
    return filePrefix+"20000626.2315+0200-2330+0200_" + nodeName + "-" + str(index) + "-" +size + ".tar.gz";

def createMissingFileName(groupIndex, filePrefix, nodeName, index, size):
    global ctr_files
    ctr_files[groupIndex] = ctr_files[groupIndex] + 1
    return filePrefix+"MissingFile_" + nodeName + "-" + str(index) + "-" +size + ".tar.gz";


# Function to build fixed beginning of an event

def getEventHead(groupIndex, changeId, nodename):
  global pnfMap
  pnfMap[groupIndex].add(nodename)
  headStr = """
        {
          "event": {
            "commonEventHeader": {
              "startEpochMicrosec": 8745745764578,
              "eventId": "FileReady_1797490e-10ae-4d48-9ea7-3d7d790b25e1",
              "timeZoneOffset": "UTC+05.30",
              "internalHeaderFields": {
                "collectorTimeStamp": "Tue, 09 18 2018 10:56:52 UTC"
              },
              "priority": "Normal",
              "version": "4.0.1",
              "reportingEntityName": \"""" + nodename + """",
              "sequence": 0,
              "domain": "notification",
              "lastEpochMicrosec": 8745745764578,
              "eventName": "Noti_RnNode-Ericsson_FileReady",
              "vesEventListenerVersion": "7.0.1",
              "sourceName": \"""" + nodename + """"
            },
            "notificationFields": {
              "notificationFieldsVersion": "2.0",
              "changeType": "FileReady",
              "changeIdentifier": \"""" + changeId + """",
              "arrayOfNamedHashMap": [
          """
  return headStr

# Function to build the variable part of an event
def getEventName(fn,type,user,passwd, nodeIndex):
    nodeIndex=nodeIndex%num_ftp_servers
    port = sftp_ports[nodeIndex]
    ip = sftp_hosts[nodeIndex]
    if (type == "ftps"):
        port = ftps_ports[nodeIndex]
        ip = ftps_hosts[nodeIndex]

    nameStr =        """{
                  "name": \"""" + fn + """",
                  "hashMap": {
                    "fileFormatType": "org.3GPP.32.435#measCollec",
                    "location": \"""" + type + """://""" + user + """:""" + passwd + """@""" + ip + """:""" + str(port) + """/""" + fn + """",
                    "fileFormatVersion": "V10",
                    "compression": "gzip"
                  }
                } """
    return nameStr

# Function to build fixed end of an event
def getEventEnd():
    endStr =  """
              ]
            }
          }
        }
        """
    return endStr

# Function to build an OK reponse from a message string
def buildOkResponse(msg):
  response = app.response_class(
      response=str.encode(msg),
      status=200,
      mimetype='application/json')
  return response

# Function to build an empty message with status
def buildEmptyResponse(status_code):
  response = app.response_class(
      response=str.encode(""),
      status=status_code,
      mimetype='application/json')
  return response


if __name__ == "__main__":

    # IP addresses to use for ftp servers, using localhost if not env var is set
    sftp_sims = os.environ.get('SFTP_SIMS', 'localhost:1022')
    ftps_sims = os.environ.get('FTPS_SIMS', 'localhost:21')
    num_ftp_servers = int(os.environ.get('NUM_FTP_SERVERS', 1))

    print("Configured sftp sims: " + sftp_sims)
    print("Configured ftps sims: " + ftps_sims)
    print("Configured number of ftp servers: " + str(num_ftp_servers))

    tmp=sftp_sims.split(',')
    for i in range(len(tmp)):
        hp=tmp[i].split(':')
        sftp_hosts.append(hp[0])
        sftp_ports.append(hp[1])

    tmp=ftps_sims.split(',')
    for i in range(len(tmp)):
        hp=tmp[i].split(':')
        ftps_hosts.append(hp[0])
        ftps_ports.append(hp[1])

    groups = os.environ.get('MR_GROUPS', 'OpenDcae-c12:PM_MEAS_FILES')
    print("Groups detected: " + groups )
    configuredPrefixes = os.environ.get('MR_FILE_PREFIX_MAPPING', 'PM_MEAS_FILES:A')

    if (len(groups) == 0 ):
        groups='OpenDcae-c12:PM_MEAS_FILES'
        print("Using default group: " + groups)
    else:
        print("Configured groups: " + groups)

    if (len(configuredPrefixes) == 0 ):
        configuredPrefixes='PM_MEAS_FILES:A'
        print("Using default changeid to file prefix mapping: " + configuredPrefixes)
    else:
        print("Configured changeid to file prefix mapping: " + configuredPrefixes)

    #Counters
    ctr_responses = []
    ctr_requests = []
    ctr_files=[]
    ctr_events = []
    startTime = time.time()
    firstPollTime = []
    runningState = "Started"
     #Keeps all responded file names
    fileMap = []
    #Keeps all responded PNF names
    pnfMap = []
    #Handles rop periods for tests that deliveres events every 15 min
    rop_counter = 0
    rop_timestamp = time.time()

    #List of configured group names
    groupNames = []
    #Mapping between group name and index in groupNames
    groupNameIndexes = {}
    #String of configured groups
    configuredGroups = ""
    #String of configured change identifiers
    configuredChangeIds = ""
    #List of changed identifiers
    changeIds = []
    #List of filePrefixes
    filePrefixes = {}

    tmp=groups.split(',')
    for i in range(len(tmp)):
        g=tmp[i].split(':')
        for j in range(len(g)):
            g[j] = g[j].strip()
            if (j == 0):
                if (len(configuredGroups) > 0):
                    configuredGroups=configuredGroups+","
                configuredGroups=configuredGroups+g[0]
                groupNames.append(g[0])
                groupNameIndexes[g[0]] = i
                changeIds.append({})
                ctr_responses.append(0)
                ctr_requests.append(0)
                ctr_files.append(0)
                ctr_events.append(0)
                firstPollTime.append(0)
                pnfMap.append(set())
                fileMap.append({})
                if (len(configuredChangeIds) > 0):
                    configuredChangeIds=configuredChangeIds+","
            else:
                changeIds[i][j-1]=g[j]
                if (j > 1):
                    configuredChangeIds=configuredChangeIds+":"
                configuredChangeIds=configuredChangeIds+g[j]

    # Create a map between changeid and file name prefix
    tmp=configuredPrefixes.split(',')
    for i in range(len(tmp)):
        p=tmp[i].split(':')
        filePrefixes[p[0]] = p[1]

    tc_num = "Not set"
    tc_help = "Not set"

    parser = argparse.ArgumentParser()

#SFTP TCs with single ME
    parser.add_argument(
        '--tc100',
        action='store_true',
        help='TC100 - One ME, SFTP, 1 1MB file, 1 event')
    parser.add_argument(
        '--tc101',
        action='store_true',
        help='TC101 - One ME, SFTP, 1 5MB file, 1 event')
    parser.add_argument(
        '--tc102',
        action='store_true',
        help='TC102 - One ME, SFTP, 1 50MB file, 1 event')

    parser.add_argument(
        '--tc110',
        action='store_true',
        help='TC110 - One ME, SFTP, 1MB files, 1 file per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc111',
        action='store_true',
        help='TC111 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc112',
        action='store_true',
        help='TC112 - One ME, SFTP, 5MB files, 100 files per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc113',
        action='store_true',
        help='TC113 - One ME, SFTP, 1MB files, 100 files per event, 100 events. All events in one poll.')

    parser.add_argument(
        '--tc120',
        action='store_true',
        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')
    parser.add_argument(
        '--tc121',
        action='store_true',
        help='TC121 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files')
    parser.add_argument(
        '--tc122',
        action='store_true',
        help='TC122 - One ME, SFTP, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name. ')

    parser.add_argument(
        '--tc1000',
        action='store_true',
        help='TC1000 - One ME, SFTP, 1MB files, 100 files per event, endless number of events, 1 event per poll')
    parser.add_argument(
        '--tc1001',
        action='store_true',
        help='TC1001 - One ME, SFTP, 5MB files, 100 files per event, endless number of events, 1 event per poll')

# SFTP TCs with multiple MEs
    parser.add_argument(
        '--tc500',
        action='store_true',
        help='TC500 - 700 MEs, SFTP, 1MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc501',
        action='store_true',
        help='TC501 - 700 MEs, SFTP, 5MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc502',
        action='store_true',
        help='TC502 - 700 MEs, SFTP, 50MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc510',
        action='store_true',
        help='TC510 - 700 MEs, SFTP, 1MB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc511',
        action='store_true',
        help='TC511 - 700 MEs, SFTP, 1KB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc550',
        action='store_true',
        help='TC550 - 700 MEs, SFTP, 50MB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc710',
        action='store_true',
        help='TC710 - 700 MEs, SFTP, 1MB files, 100 files per event, 3500 events, 35 event per poll.')

    parser.add_argument(
        '--tc1100',
        action='store_true',
        help='TC1100 - 700 ME, SFTP, 1MB files, 100 files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc1101',
        action='store_true',
        help='TC1101 - 700 ME, SFTP, 5MB files, 100 files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc1102',
        action='store_true',
        help='TC1102 - 700 ME, SFTP, 50MB files, 100 files per event, endless number of events, 35 event per poll')

    parser.add_argument(
        '--tc1200',
        action='store_true',
        help='TC1200 - 700 ME, SFTP, 1MB files, 100 new files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc1201',
        action='store_true',
        help='TC1201 - 700 ME, SFTP, 5MB files, 100 new files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc1202',
        action='store_true',
        help='TC1202 - 700 ME, SFTP, 50MB files, 100 new files per event, endless number of events, 35 event per poll')

    parser.add_argument(
        '--tc1300',
        action='store_true',
        help='TC1300 - 700 ME, SFTP, 1MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')
    parser.add_argument(
        '--tc1301',
        action='store_true',
        help='TC1301 - 700 ME, SFTP, 5MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')
    parser.add_argument(
        '--tc1302',
        action='store_true',
        help='TC1302 - 700 ME, SFTP, 50MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')

    parser.add_argument(
        '--tc1500',
        action='store_true',
        help='TC1500 - 700 ME, SFTP, 1MB files, 100 files per event, 35 events per poll, simulating 25h backlog of decreasing number of outdated files and then 20 event polls every 15min for 1h')

# FTPS TCs with single ME
    parser.add_argument(
        '--tc200',
        action='store_true',
        help='TC200 - One ME, FTPS, 1 1MB file, 1 event')
    parser.add_argument(
        '--tc201',
        action='store_true',
        help='TC201 - One ME, FTPS, 1 5MB file, 1 event')
    parser.add_argument(
        '--tc202',
        action='store_true',
        help='TC202 - One ME, FTPS, 1 50MB file, 1 event')

    parser.add_argument(
        '--tc210',
        action='store_true',
        help='TC210 - One ME, FTPS, 1MB files, 1 file per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc211',
        action='store_true',
        help='TC211 - One ME, FTPS, 1MB files, 100 files per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc212',
        action='store_true',
        help='TC212 - One ME, FTPS, 5MB files, 100 files per event, 100 events, 1 event per poll.')
    parser.add_argument(
        '--tc213',
        action='store_true',
        help='TC213 - One ME, FTPS, 1MB files, 100 files per event, 100 events. All events in one poll.')

    parser.add_argument(
        '--tc220',
        action='store_true',
        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')
    parser.add_argument(
        '--tc221',
        action='store_true',
        help='TC221 - One ME, FTPS, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files')
    parser.add_argument(
        '--tc222',
        action='store_true',
        help='TC222 - One ME, FTPS, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name. ')

    parser.add_argument(
        '--tc2000',
        action='store_true',
        help='TC2000 - One ME, FTPS, 1MB files, 100 files per event, endless number of events, 1 event per poll')
    parser.add_argument(
        '--tc2001',
        action='store_true',
        help='TC2001 - One ME, FTPS, 5MB files, 100 files per event, endless number of events, 1 event per poll')


    parser.add_argument(
        '--tc2100',
        action='store_true',
        help='TC2100 - 700 ME, FTPS, 1MB files, 100 files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc2101',
        action='store_true',
        help='TC2101 - 700 ME, FTPS, 5MB files, 100 files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc2102',
        action='store_true',
        help='TC2102 - 700 ME, FTPS, 50MB files, 100 files per event, endless number of events, 35 event per poll')

    parser.add_argument(
        '--tc2200',
        action='store_true',
        help='TC2200 - 700 ME, FTPS, 1MB files, 100 new files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc2201',
        action='store_true',
        help='TC2201 - 700 ME, FTPS, 5MB files, 100 new files per event, endless number of events, 35 event per poll')
    parser.add_argument(
        '--tc2202',
        action='store_true',
        help='TC2202 - 700 ME, FTPS, 50MB files, 100 new files per event, endless number of events, 35 event per poll')

    parser.add_argument(
        '--tc2300',
        action='store_true',
        help='TC2300 - 700 ME, FTPS, 1MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')
    parser.add_argument(
        '--tc2301',
        action='store_true',
        help='TC2301 - 700 ME, FTPS, 5MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')
    parser.add_argument(
        '--tc2302',
        action='store_true',
        help='TC2302 - 700 ME, FTPS, 50MB files, 100 files per event, endless number of events, 35 event per poll, 20 event polls every 15min')

    parser.add_argument(
        '--tc2500',
        action='store_true',
        help='TC2500 - 700 ME, FTPS, 1MB files, 100 files per event, 35 events per poll, simulating 25h backlog of decreasing number of outdated files and then 20 event polls every 15min for 1h')

    parser.add_argument(
        '--tc600',
        action='store_true',
        help='TC600 - 700 MEs, FTPS, 1MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc601',
        action='store_true',
        help='TC601 - 700 MEs, FTPS, 5MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc602',
        action='store_true',
        help='TC602 - 700 MEs, FTPS, 50MB files, 2 new files per event, 700 events, all event in one poll.')

    parser.add_argument(
        '--tc610',
        action='store_true',
        help='TC610 - 700 MEs, FTPS, 1MB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc611',
        action='store_true',
        help='TC611 - 700 MEs, FTPS, 1KB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc650',
        action='store_true',
        help='TC610 - 700 MEs, FTPS, 50MB files, 1 file per event, 3500 events, 700 event per poll.')

    parser.add_argument(
        '--tc810',
        action='store_true',
        help='TC810 - 700 MEs, FTPS, 1MB files, 100 files per event, 3500 events, 35 event per poll.')

    args = parser.parse_args()



    if args.tc100:
        tc_num = "TC# 100"
    elif args.tc101:
        tc_num = "TC# 101"
    elif args.tc102:
        tc_num = "TC# 102"

    elif args.tc110:
        tc_num = "TC# 110"
    elif args.tc111:
        tc_num = "TC# 111"
    elif args.tc112:
        tc_num = "TC# 112"
    elif args.tc113:
        tc_num = "TC# 113"

    elif args.tc120:
        tc_num = "TC# 120"
    elif args.tc121:
        tc_num = "TC# 121"
    elif args.tc122:
        tc_num = "TC# 122"

    elif args.tc1000:
        tc_num = "TC# 1000"
    elif args.tc1001:
        tc_num = "TC# 1001"

    elif args.tc1100:
        tc_num = "TC# 1100"
    elif args.tc1101:
        tc_num = "TC# 1101"
    elif args.tc1102:
        tc_num = "TC# 1102"
    elif args.tc1200:
        tc_num = "TC# 1200"
    elif args.tc1201:
        tc_num = "TC# 1201"
    elif args.tc1202:
        tc_num = "TC# 1202"
    elif args.tc1300:
        tc_num = "TC# 1300"
    elif args.tc1301:
        tc_num = "TC# 1301"
    elif args.tc1302:
        tc_num = "TC# 1302"

    elif args.tc1500:
        tc_num = "TC# 1500"

    elif args.tc500:
        tc_num = "TC# 500"
    elif args.tc501:
        tc_num = "TC# 501"
    elif args.tc502:
        tc_num = "TC# 502"
    elif args.tc510:
        tc_num = "TC# 510"
    elif args.tc511:
        tc_num = "TC# 511"

    elif args.tc550:
        tc_num = "TC# 550"

    elif args.tc710:
        tc_num = "TC# 710"

    elif args.tc200:
        tc_num = "TC# 200"
    elif args.tc201:
        tc_num = "TC# 201"
    elif args.tc202:
        tc_num = "TC# 202"

    elif args.tc210:
        tc_num = "TC# 210"
    elif args.tc211:
        tc_num = "TC# 211"
    elif args.tc212:
        tc_num = "TC# 212"
    elif args.tc213:
        tc_num = "TC# 213"

    elif args.tc220:
        tc_num = "TC# 220"
    elif args.tc221:
        tc_num = "TC# 221"
    elif args.tc222:
        tc_num = "TC# 222"

    elif args.tc2000:
        tc_num = "TC# 2000"
    elif args.tc2001:
        tc_num = "TC# 2001"

    elif args.tc2100:
        tc_num = "TC# 2100"
    elif args.tc2101:
        tc_num = "TC# 2101"
    elif args.tc2102:
        tc_num = "TC# 2102"
    elif args.tc2200:
        tc_num = "TC# 2200"
    elif args.tc2201:
        tc_num = "TC# 2201"
    elif args.tc2202:
        tc_num = "TC# 2202"
    elif args.tc2300:
        tc_num = "TC# 2300"
    elif args.tc2301:
        tc_num = "TC# 2301"
    elif args.tc2302:
        tc_num = "TC# 2302"

    elif args.tc2500:
        tc_num = "TC# 2500"

    elif args.tc600:
        tc_num = "TC# 600"
    elif args.tc601:
        tc_num = "TC# 601"
    elif args.tc602:
        tc_num = "TC# 602"
    elif args.tc610:
        tc_num = "TC# 610"
    elif args.tc611:
        tc_num = "TC# 611"
    elif args.tc650:
        tc_num = "TC# 650"
    elif args.tc810:
        tc_num = "TC# 810"

    else:
        print("No TC was defined")
        print("use --help for usage info")
        sys.exit()

    print("TC num: " + tc_num)

    for i in range(len(sftp_hosts)):
        print("Using " + str(sftp_hosts[i]) + ":" + str(sftp_ports[i]) + " for sftp server with index " + str(i) + " for sftp server address and port in file urls.")

    for i in range(len(ftps_hosts)):
        print("Using " + str(ftps_hosts[i]) + ":" + str(ftps_ports[i]) + " for ftps server with index " + str(i) + " for ftps server address and port in file urls.")

    print("Using up to " + str(num_ftp_servers) + " ftp servers, for each protocol for PNFs.")

    def https_app(**kwargs):
        import ssl
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
        context.load_cert_chain('cert/cert.pem', 'cert/key.pem')
        app.run(ssl_context=context, **kwargs)

    from multiprocessing import Process

    kwargs = dict(host=HOST_IP)
    Process(target=https_app, kwargs=dict(kwargs, port=HOST_PORT_TLS),
            daemon=True).start()

    app.run(port=HOST_PORT, host=HOST_IP)