Adding vlanlist support into http_sim so it's easier to work on

Also improving vlan.json to mirror the real output
This commit is contained in:
Rob Emery committed 2026-10-25 09:06:30 +00:00
1 parent a18c334139
commit 1d359afba5
1 file changed
+44 -3
+44 -3
View File
@@ -19,6 +19,7 @@
#define NSFP 1 #define NSFP 1
#define N_COUNTERS 52 #define N_COUNTERS 52
#define VLAN_MAX 1
#if PORTS == 9 #if PORTS == 9
const uint8_t physToLogPort[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8}; const uint8_t physToLogPort[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8};
@@ -135,16 +136,49 @@ void send_vlan(int s, int vlan)
v = json_object_new_object(); v = json_object_new_object();
sprintf(num_buff, "0x%08x", 0x00060011); sprintf(num_buff, "0x%08x", 0x207ffff);
json_object_object_add(v, "members", json_object_new_string(num_buff)); json_object_object_add(v, "members", json_object_new_string(num_buff));
write(s, header, strlen(header)); json_object_object_add(v, "name", json_object_new_string(""));
json_object_object_add(v, "pvid", json_object_new_string("0x01ff"));
write(s, header, strlen(header));
jstring = json_object_to_json_string_ext(v, JSON_C_TO_STRING_PLAIN); jstring = json_object_to_json_string_ext(v, JSON_C_TO_STRING_PLAIN);
write(s, jstring, strlen(jstring)); write(s, jstring, strlen(jstring));
json_object_put(v); json_object_put(v);
} }
void send_vlanlist(int s)
{
struct json_object *v, *vlans, *vlan;
const char *jstring;
char *header = "HTTP/1.1 200 OK\r\n"
"Content-Type: application/json; charset=UTF-8\r\n\r\n";
v = json_object_new_object();
json_object_object_add(v, "mgmt", json_object_new_int(1));
vlans = json_object_new_array_ext(VLAN_MAX);
//foreach VLAN
for (int x=1;x<=VLAN_MAX;++x) {
vlan = json_object_new_object();
json_object_object_add(vlan, "id", json_object_new_int(x));
json_object_object_add(vlan, "name", json_object_new_string(""));
json_object_array_add(vlans, vlan);
}
json_object_object_add(v, "vlan", vlans);
write(s, header, strlen(header));
jstring = json_object_to_json_string_ext(v, JSON_C_TO_STRING_PLAIN);
write(s, jstring, strlen(jstring));
json_object_put(v);
}
void send_status(int s) void send_status(int s)
{ {
@@ -735,6 +769,13 @@ void launch(struct Server *server)
else else
send_vlan(new_socket, vlan); send_vlan(new_socket, vlan);
goto done; goto done;
} else if (!strncmp(&buffer[4], "/vlanlist", 9)) {
printf("request for vlan list");
if (!authenticated)
send_unauthorized(new_socket);
else
send_vlanlist(new_socket);
goto done;
} else if (!strncmp(&buffer[4], "/lldp.json", 10)) { } else if (!strncmp(&buffer[4], "/lldp.json", 10)) {
printf("LLDP request"); printf("LLDP request");
if (!authenticated) if (!authenticated)