Skip to content

Commit eda6a11

Browse files
added env variables and load test files
1 parent dadbe7a commit eda6a11

File tree

3 files changed

+207
-0
lines changed

3 files changed

+207
-0
lines changed

.env-example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
GF_SECURITY_ADMIN_USER=admin
44
GF_SECURITY_ADMIN_PASSWORD=admin
55

6+
# Clickhouse Environment Variables
7+
# These should be updated to more secure values.
8+
GRAFANA_CLICKHOUSE_PASSWORD=CHANGE_ME
9+
OTEL_COLLECTOR_CLICKHOUSE_PASSWORD="CHANGE_ME"
10+
HOSTNAME="localhost"
11+
612
# Optional Parameters Required for metrics export to F5 DataFabric
713
SENSOR_SECRET_TOKEN="YOUR_TOKEN"
814
SENSOR_ID="YOUR_ID"

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright 2024 F5 Networks
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
.PHONY: test-certs
18+
test-certs:
19+
@echo "Generating self-signed certificates..."
20+
@mkdir -p ./services/otel_collector/ssl
21+
@openssl genpkey -algorithm RSA -out ./services/otel_collector/ssl/key.pem
22+
@openssl req -new -key ./services/otel_collector/ssl/key.pem -out ./services/otel_collector/ssl/cert.csr -subj "/CN=localhost"
23+
@openssl x509 -req -in ./services/otel_collector/ssl/cert.csr -signkey ./services/otel_collector/ssl/key.pem -out ./services/otel_collector/ssl/cert.pem
24+
@openssl genpkey -algorithm RSA -out ./services/otel_collector/ssl/ca.key
25+
@openssl req -x509 -new -key ./services/otel_collector/ssl/ca.key -out ./services/otel_collector/ssl/ca.pem -days 365 -subj "/CN=Test CA"
26+
@rm -f ./services/otel_collector/ssl/ca.key ./services/otel_collector/ssl/cert.csr
27+
@echo "Certificates generated at ./services/otel_collector/ssl/"

load_test.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import socket, ssl
2+
import time
3+
import datetime
4+
import random
5+
6+
7+
INITIAL_RATE = 100 # initial messages per second
8+
INCREASE_RATE = 100 # increase rate every interval
9+
INTERVAL = 300 # seconds to increase the rate
10+
HOST = "localhost"
11+
PORT = 6514
12+
13+
14+
print(f"Connecting to {HOST}:{PORT}...")
15+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16+
ctx = ssl.create_default_context()
17+
ctx.check_hostname = False
18+
ctx.verify_mode = ssl.CERT_NONE
19+
# require a certificate from the server
20+
conn = ctx.wrap_socket(socket.socket(socket.AF_INET),
21+
server_hostname=HOST)
22+
conn.connect((HOST, PORT))
23+
print("Done.")
24+
25+
26+
FLOW_IDS = [
27+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test_accessProfile:Common:a1c76511",
28+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test_accessProfile:Common:a1c76512",
29+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test_accessProfile:Common:a1c76513",
30+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test_accessProfile:Common:a1c76514",
31+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test_accessProfile:Common:a1c76515",
32+
"/Common/blah-blah.app/blah-blah_accessProfile:Common:a1c76511",
33+
"/Common/blah-blah.app/blah-blah_accessProfile:Common:a1c76512",
34+
"/Common/blah-blah.app/blah-blah_accessProfile:Common:a1c76513",
35+
"/Common/blah-blah.app/blah-blah_accessProfile:Common:a1c76514",
36+
"/Common/blah-blah.app/blah-blah_accessProfile:Common:a1c76515",
37+
"/Common/foo.app/foo_accessProfile:Common:a1c76511",
38+
"/Common/foo.app/foo_accessProfile:Common:a1c76512",
39+
"/Common/foo.app/foo_accessProfile:Common:a1c76513",
40+
"/Common/foo.app/foo_accessProfile:Common:a1c76514",
41+
"/Common/foo.app/foo_accessProfile:Common:a1c76515"
42+
]
43+
44+
45+
DST_IPS = [
46+
"192.168.1.1:443",
47+
"192.168.1.2:443",
48+
"192.168.1.3:443",
49+
"192.168.1.4:443",
50+
"192.168.1.5:443",
51+
"192.168.100.101:22",
52+
"192.168.100.102:22",
53+
"192.168.100.103:22",
54+
"192.168.100.104:22",
55+
"192.168.100.105:22",
56+
"192.168.200.201:443",
57+
"192.168.200.202:443",
58+
"192.168.200.203:443",
59+
"192.168.200.204:443",
60+
"192.168.200.205:443",
61+
]
62+
63+
SSL_CHOICES = [
64+
"TLSv1.3 ECDHE-RSA-AES128-GCM-SHA256",
65+
"TLSv1.1 ECDHE-RSA-AES128-GCM-SHA256",
66+
"TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384",
67+
"TLSv1.1 ECDHE-RSA-AES128-GCM-SHA256",
68+
"TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384",
69+
"TLSv1.1 ECDHE-RSA-AES128-GCM-SHA256",
70+
"TLSv1.1 ECDHE-RSA-AES128-GCM-SHA256",
71+
"TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384",
72+
"TLSv1.1 ECDHE-RSA-AES128-GCM-SHA256",
73+
"TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384",
74+
"TLSv1.2 ECDHE-ECDSA-AES256-SHA384",
75+
"TLSv1.2 ECDHE-ECDSA-AES256-SHA384",
76+
"TLSv1.3 ECDHE-ECDSA-AES256-SHA384",
77+
"TLSv1.3 ECDHE-ECDSA-AES256-SHA384",
78+
"TLSv1.3 ECDHE-ECDSA-AES256-SHA384",
79+
]
80+
81+
def get_data_to_send():
82+
hostnames = [x for x in [
83+
"sslo-hsl-test.example.com",
84+
"blah.example.com",
85+
"foo.app"
86+
] for _ in range(5)]
87+
88+
vips = [x for x in [
89+
"/Common/sslo_sslo-hsl-test.app/sslo_sslo-hsl-test-in-t-4",
90+
"/Common/blah-blah.app/blah-blah-in-t-4",
91+
"/Common/foo.app/foo-in-t-4"
92+
] for _ in range(5)]
93+
l7_choices = [x for x in ["https", "ssh", "https"] for _ in range(5)]
94+
decrypted_choices = [x for x in ["decrypted", "bypassed", "unencrypted"] for _ in range(5)]
95+
service_paths = [x for x in ["ssloSC_all_services", "ssloSC_some_services", "ssloSC_no_services"] for _ in range(5)]
96+
reset_causes = [x for x in ["NA","solar-flare","coffe_spilled_on_session"] for _ in range(5)]
97+
policy_choices = [x for x in ["All Traffic", "Some Traffic", "Most Traffic"] for _ in range(5)]
98+
url_choices = [x for x in ["/Common/Information_Technology", "/Common/Another_One", "/Common/Something"] for _ in range(5)]
99+
ingress_choices = [x for x in ["_loopback", "ifEth1.1", "ifEth2.1"] for _ in range(5)]
100+
egress_choices = [x for x in ["/Common/outbound-vlan", "/Common/outbound-vlan2", "/Common/outbound-vlan3"] for _ in range(5)]
101+
102+
# tcp 10.1.10.50:52336 -> 93.184.215.14:443 clientSSL: TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 serverSSL: TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 L7 https (www.example.com) decryption-status: decrypted duration: 57 msec service-path: ssloSC_all_services client-bytes-in: 1358 client-bytes-out: 4717 server-bytes-in: 5691 server-bytes-out: 962 client-tls-handshake: completed server-tls-handshake: completed reset-cause: 'NA' policy-rule: 'All Traffic' url-category: /Common/Information_Technology ingress: _loopback egress: /Common/outbound-vlan
103+
104+
numbers = list(range(15))
105+
weights = [i+1 for i in range(15)]
106+
ret_data = []
107+
for _ in range(10000):
108+
rand_idx = random.choices(numbers, weights=weights, k=1)[0]
109+
ret_data.append("%s %s Traffic summary - %s %s -> %s clientSSL: %s serverSSL: %s L7 %s (%s) decryption-status: %s duration: %d msec service-path: %s client-bytes-in: %d client-bytes-out: %d server-bytes-in: %d server-bytes-out: %d client-tls-handshake: %s server-tls-handshake: %s reset-cause: '%s' policy-rule: '%s' url-category: %s ingress: %s egress: %s\n" % (
110+
FLOW_IDS[rand_idx],
111+
vips[rand_idx],
112+
random.choice(["tcp", "udp"]),
113+
f"10.1.{random.randint(0,255)}.{random.randint(0,255)}:{random.randint(49152,65535)}",
114+
DST_IPS[rand_idx],
115+
SSL_CHOICES[rand_idx],
116+
SSL_CHOICES[rand_idx],
117+
l7_choices[rand_idx],
118+
hostnames[rand_idx],
119+
decrypted_choices[rand_idx],
120+
random.randint(1, 500),
121+
service_paths[rand_idx],
122+
random.randint(500, 5000),
123+
random.randint(1000, 10000),
124+
random.randint(500, 5000),
125+
random.randint(1000, 10000),
126+
random.choice(["completed", "not-completed", "some-other-status"]),
127+
random.choice(["completed", "not-completed", "some-other-status"]),
128+
reset_causes[rand_idx],
129+
policy_choices[rand_idx],
130+
url_choices[rand_idx],
131+
ingress_choices[rand_idx],
132+
egress_choices[rand_idx]
133+
))
134+
return ret_data
135+
136+
137+
try:
138+
count = 0
139+
start = time.time()
140+
send_data = get_data_to_send()
141+
current_rate = INITIAL_RATE
142+
next_increase_time = start + INTERVAL
143+
batch_count = 0
144+
nowish = f"{datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0).isoformat().replace('+00:00','')}Z"
145+
while True:
146+
for data in send_data:
147+
count +=1
148+
batch_count += 1
149+
send = str.encode(f"<118>1 {nowish} 17-1-demo.f5kc.com F5-API-Discovery - - - {data}")
150+
conn.send(send)
151+
if count % 100000 == 0 or batch_count >= current_rate:
152+
nowish = f"{datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0).isoformat().replace('+00:00','')}Z"
153+
if batch_count >= current_rate:
154+
time.sleep(1)
155+
batch_count = 0
156+
now = time.time()
157+
rate = count / (now-start)
158+
print(f'Now: {now} Sent: {count} messages ({rate} msg/sec)')
159+
send_data = get_data_to_send()
160+
if now >= next_increase_time:
161+
start = time.time()
162+
count = 0
163+
if current_rate < 10000:
164+
current_rate = current_rate * INCREASE_RATE
165+
else:
166+
current_rate += 5000
167+
next_increase_time = now + INTERVAL
168+
print(f'Increased rate to: {current_rate} msg/sec')
169+
break
170+
except KeyboardInterrupt:
171+
print("Interrupted by user. Shutting down...")
172+
finally:
173+
conn.shutdown(socket.SHUT_RDWR)
174+
conn.close()

0 commit comments

Comments
 (0)