From 52fe23570c0bf94ae06b425742c09f9798c125de Mon Sep 17 00:00:00 2001 From: logicog Date: Sun, 30 Nov 2025 22:27:21 +0100 Subject: [PATCH] Add simulator for LAGs --- tools/httpd_sim.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/httpd_sim.c b/tools/httpd_sim.c index 8d45d19..3463d23 100644 --- a/tools/httpd_sim.c +++ b/tools/httpd_sim.c @@ -13,7 +13,7 @@ #define SESSION_ID "1234567890ab" #define PASSWORD "1234" -#define SESSION_TIMEOUT 20 +#define SESSION_TIMEOUT 2000 #define PORTS 6 time_t last_called; @@ -216,6 +216,31 @@ void send_mirror(int s) } +void send_lag(int s) +{ + char lag_buf[20]; + struct json_object *lags = json_object_new_array_ext(4); + struct json_object *v; + const char *jstring; + char *header = "HTTP/1.1 200 OK\r\n" + "Content-Type: application/json; charset=UTF-8\r\n\r\n"; + + for (int i = 0; i < 4; i++) { + v = json_object_new_object(); + json_object_object_add(v, "lagNum", json_object_new_int(i)); + sprintf(lag_buf, "%016b", 0x30 << (i * 2) & 0x1f8); + json_object_object_add(v, "members", json_object_new_string(lag_buf)); + json_object_object_add(v, "hash", json_object_new_string("0x7e")); + json_object_array_add(lags, v); + } + write(s, header, strlen(header)); + + jstring = json_object_to_json_string_ext(lags, JSON_C_TO_STRING_PLAIN); + write(s, jstring, strlen(jstring)); + json_object_put(lags); +} + + void send_cmd_log(int s) { char *header = "HTTP/1.1 200 OK\r\n" @@ -417,6 +442,13 @@ void launch(struct Server *server) else send_mirror(new_socket); goto done; + } else if (!strncmp(&buffer[4], "/lag.json", 9)) { + printf("LAG request\n"); + if (!authenticated) + send_unauthorized(new_socket); + else + send_lag(new_socket); + goto done; } else if (!strncmp(&buffer[4], "/vlan.json?vid=", 15)) { int vlan = atoi(&buffer[19]); printf("VLAN request for %d\n", vlan);