Refactored tests

This commit is contained in:
Nicola Guerrera
2022-06-29 11:50:29 +02:00
parent fad6ad4e68
commit 0320c9a0b8
3 changed files with 60 additions and 135 deletions

View File

@@ -1,102 +1,11 @@
Number of regex;Multi-Thread MB/s;Single-Thread MB/s 0,567.771
0;2968,44;1655,201 1,103.886
1;582,24;72,545 2,55.872
2;299,866;36,222 3,37.958
3;202,91;25,245 4,28.79
4;150,858;18,555 5,22.956
5;122,142;14,911 6,19.34
6;101,656;12,398 7,16.586
7;87,515;10,822 8,14.661
8;76,449;9,458 9,13.158
9;68,049;8,372 10,11.862
10;61,615;7,563
11;54,817;6,745
12;51,085;6,429
13;46,561;5,809
14;43,522;5,518
15;40,514;5,032
16;38,643;4,809
17;36,049;4,534
18;34,211;4,249
19;32,303;3,938
20;30,805;3,237
21;29,113;3,64
22;27,837;3,484
23;26,555;3,157
24;25,501;3,193
25;24,634;3,055
26;23,286;2,928
27;22,656;2,807
28;21,794;2,737
29;21,198;2,69
30;20,387;2,504
31;19,808;2,465
32;19,175;2,114
33;18,629;2,329
34;17,785;2,282
35;17,526;2,193
36;16,925;2,153
37;16,463;2,112
38;16,136;2,02
39;15,518;1,967
40;15,369;1,934
41;14,798;1,878
42;14,451;1,821
43;14,21;1,806
44;13,959;1,75
45;13,538;1,72
46;13,377;1,686
47;12,994;1,665
48;12,71;1,606
49;12,538;1,517
50;12,239;1,537
51;12,01;1,438
52;11,69;1,472
53;11,632;1,46
54;11,325;1,373
55;11,074;1,408
56;10,983;1,392
57;10,602;1,355
58;10,521;1,335
59;10,209;1,307
60;10,135;1,287
61;9,993;1,274
62;9,86;1,259
63;9,82;1,245
64;9,503;1,192
65;9,488;1,189
66;9,292;1,145
67;9,21;1,151
68;9,064;1,125
69;8,953;1,115
70;8,646;1,088
71;8,635;1,095
72;8,497;1,077
73;8,309;1,058
74;8,247;1,05
75;8,163;1,035
76;8,038;1,015
77;7,999;0,976
78;7,837;0,983
79;7,818;0,97
80;7,56;0,944
81;7,531;0,946
82;7,497;0,95
83;7,427;0,944
84;7,354;0,938
85;7,302;0,913
86;7,053;0,905
87;7,107;0,892
88;6,959;0,878
89;6,952;0,875
90;6,898;0,863
91;6,808;0,85
92;6,785;0,84
93;6,705;0,824
94;6,518;0,824
95;6,568;0,816
96;6,305;0,724
97;6,436;0,799
98;6,232;0,771
99;6,293;0,781
100;6,039;0,761
1 Number of regex 0 Multi-Thread MB/s 567.771 Single-Thread MB/s
2 0 1 2968,44 103.886 1655,201
3 1 2 582,24 55.872 72,545
4 2 3 299,866 37.958 36,222
5 3 4 202,91 28.79 25,245
6 4 5 150,858 22.956 18,555
7 5 6 122,142 19.34 14,911
8 6 7 101,656 16.586 12,398
9 7 8 87,515 14.661 10,822
10 8 9 76,449 13.158 9,458
11 9 10 68,049 11.862 8,372
10 61,615 7,563
11 54,817 6,745
12 51,085 6,429
13 46,561 5,809
14 43,522 5,518
15 40,514 5,032
16 38,643 4,809
17 36,049 4,534
18 34,211 4,249
19 32,303 3,938
20 30,805 3,237
21 29,113 3,64
22 27,837 3,484
23 26,555 3,157
24 25,501 3,193
25 24,634 3,055
26 23,286 2,928
27 22,656 2,807
28 21,794 2,737
29 21,198 2,69
30 20,387 2,504
31 19,808 2,465
32 19,175 2,114
33 18,629 2,329
34 17,785 2,282
35 17,526 2,193
36 16,925 2,153
37 16,463 2,112
38 16,136 2,02
39 15,518 1,967
40 15,369 1,934
41 14,798 1,878
42 14,451 1,821
43 14,21 1,806
44 13,959 1,75
45 13,538 1,72
46 13,377 1,686
47 12,994 1,665
48 12,71 1,606
49 12,538 1,517
50 12,239 1,537
51 12,01 1,438
52 11,69 1,472
53 11,632 1,46
54 11,325 1,373
55 11,074 1,408
56 10,983 1,392
57 10,602 1,355
58 10,521 1,335
59 10,209 1,307
60 10,135 1,287
61 9,993 1,274
62 9,86 1,259
63 9,82 1,245
64 9,503 1,192
65 9,488 1,189
66 9,292 1,145
67 9,21 1,151
68 9,064 1,125
69 8,953 1,115
70 8,646 1,088
71 8,635 1,095
72 8,497 1,077
73 8,309 1,058
74 8,247 1,05
75 8,163 1,035
76 8,038 1,015
77 7,999 0,976
78 7,837 0,983
79 7,818 0,97
80 7,56 0,944
81 7,531 0,946
82 7,497 0,95
83 7,427 0,944
84 7,354 0,938
85 7,302 0,913
86 7,053 0,905
87 7,107 0,892
88 6,959 0,878
89 6,952 0,875
90 6,898 0,863
91 6,808 0,85
92 6,785 0,84
93 6,705 0,824
94 6,518 0,824
95 6,568 0,816
96 6,305 0,724
97 6,436 0,799
98 6,232 0,771
99 6,293 0,781
100 6,039 0,761

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse, socket,secrets, base64, iperf3, csv import argparse, socket,secrets, base64, iperf3, csv
from time import sleep from time import sleep
from requests import Session from firegexapi import FiregexAPI
from multiprocessing import Process from multiprocessing import Process
pref = "\033[" pref = "\033["
@@ -37,31 +37,28 @@ sep()
puts(f"Benchmarking with {args.num_of_regexes} regexes will start on ", color=colors.cyan, end="") puts(f"Benchmarking with {args.num_of_regexes} regexes will start on ", color=colors.cyan, end="")
puts(f"{args.address}", color=colors.yellow) puts(f"{args.address}", color=colors.yellow)
s = Session() firegex = FiregexAPI(args.address)
#Connect to Firegex #Connect to Firegex
req = s.post(f"{args.address}api/login", json={"password":args.password}) if (firegex.login(args.password)): puts(f"Sucessfully logged in ✔", color=colors.green)
assert req.json()["status"] == "ok", f"Benchmark Failed: Unknown response or wrong passowrd {req.text}" else: puts(f"Benchmark Failed: Unknown response or wrong passowrd ", color=colors.red); exit(1)
puts(f"Sucessfully logged in ✔", color=colors.green)
if args.new_istance: if args.new_istance:
#Create new Service #Create new Service
req = s.post(f"{args.address}api/services/add" , json={"name":args.service_name,"port":args.service_port}) if (firegex.create_service(args.service_name,args.service_port)):
assert req.json()["status"] == "ok", f"Benchmark Failed: Couldn't create service {req.text}"
puts(f"Sucessfully created service {args.service_name} with public port {args.service_port}", color=colors.green) puts(f"Sucessfully created service {args.service_name} with public port {args.service_port}", color=colors.green)
service_created = True
else: puts(f"Benchmark Failed: Couldn't create service ✗", color=colors.red); exit(1)
#Find the Service #Find the Service
req = s.get(f"{args.address}api/services") service = firegex.get_service_details(args.service_name)
internal_port = service_id = None if (service):
try: internal_port= service["internal_port"]
for service in req.json():
if service["name"] == args.service_name:
service_id = service["id"] service_id = service["id"]
internal_port = service["internal_port"]
puts(f"Sucessfully received the internal port {internal_port}", color=colors.green) puts(f"Sucessfully received the internal port {internal_port}", color=colors.green)
break else: puts(f"Benchmark Failed: Coulnd't get the service internal port ✗", color=colors.red); exit_test(1)
except Exception:
puts(f"Benchmark Failed: Coulnd't get the service internal port {req.text}", color=colors.red)
exit(1)
#Start iperf3 #Start iperf3
def startServer(): def startServer():
@@ -91,9 +88,8 @@ puts(f"Baseline without proxy: ", color=colors.blue, end='')
print(f"{getReading(internal_port)} MB/s") print(f"{getReading(internal_port)} MB/s")
#Start firewall #Start firewall
req = s.get(f"{args.address}api/service/{service_id}/start") if(firegex.start(service_id)): puts(f"Sucessfully started service with id {service_id}", color=colors.green)
assert req.json()["status"] == "ok", f"Benchmark Failed: Couldn't start the service {req.text}" else: puts(f"Benchmark Failed: Coulnd't start the service ", color=colors.red); exit_test(1)
puts(f"Sucessfully started service with id {service_id}", color=colors.green)
#Hacky solution - wait a bit for the server to start #Hacky solution - wait a bit for the server to start
sleep(1) sleep(1)
@@ -107,9 +103,7 @@ print(f"{results[0]} MB/s")
#Add all the regexs #Add all the regexs
for i in range(1,args.num_of_regexes+1): for i in range(1,args.num_of_regexes+1):
regex = base64.b64encode(bytes(secrets.token_hex(16).encode())).decode() regex = base64.b64encode(bytes(secrets.token_hex(16).encode())).decode()
req = s.post(f"{args.address}api/regexes/add", if(not firegex.add_regex(service_id,regex)): puts(f"Benchmark Failed: Coulnd't add the regex ✗", color=colors.red); exit_test(1)
json={"is_blacklist":True,"is_case_sensitive":True,"service_id":service_id,"mode":"B","regex":regex})
assert req.json()["status"] == "ok", f"Test Failed: Couldn't add regex {req.text}"
puts(f"Performance with {i} regex(s): ", color=colors.red, end='') puts(f"Performance with {i} regex(s): ", color=colors.red, end='')
results.append(getReading(args.service_port)) results.append(getReading(args.service_port))
print(f"{results[i]} MB/s") print(f"{results[i]} MB/s")
@@ -123,8 +117,9 @@ puts(f"Sucessfully written results to {args.output_file} ✔", color=colors.mage
if args.new_istance: if args.new_istance:
#Delete the Service #Delete the Service
req = s.get(f"{args.address}api/service/{service_id}/delete") if(firegex.delete(service_id)):
assert req.json()["status"] == "ok", f"Benchmark Failed: Couldn't delete service {req.text}"
puts(f"Sucessfully delete service with id {service_id}", color=colors.green) puts(f"Sucessfully delete service with id {service_id}", color=colors.green)
else:
puts(f"Test Failed: Couldn't delete service ✗", color=colors.red); exit(1)
server.terminate() server.terminate()

View File

@@ -1,13 +1,34 @@
from requests import Session from requests import Session
class BearerSession():
def __init__(self):
self.s = Session()
self.headers = {}
def post(self, endpoint, json={}, data=""):
headers = self.headers
if data:
headers["Content-Type"] = "application/x-www-form-urlencoded"
return self.s.post(endpoint, json=json, data=data, headers=headers)
def get(self, endpoint, json={}):
return self.s.get(endpoint, json=json, headers=self.headers)
def setToken(self,token):
self.headers = {"Authorization": f"Bearer {token}"}
class FiregexAPI: class FiregexAPI:
def __init__(self,address): def __init__(self,address):
self.s = Session() self.s = BearerSession()
self.address = address self.address = address
def login(self,password): def login(self,password):
req = self.s.post(f"{self.address}api/login", json={"password":password}) req = self.s.post(f"{self.address}api/login", data=f"username=login&password={password}")
return req.json()["status"] == "ok" try :
self.s.setToken(req.json()["access_token"])
return True
except Exception:
return False
def logout(self): def logout(self):
req = self.s.get(f"{self.address}api/logout") req = self.s.get(f"{self.address}api/logout")