Add mtu support in http server

This commit is contained in:
logicog
2025-12-22 23:28:50 +01:00
parent 67fbad38ce
commit 51345a07e6
4 changed files with 115 additions and 15 deletions
+90 -15
View File
@@ -1,3 +1,4 @@
var mtus = new Int16Array(10);
function createPortTable() { function createPortTable() {
var tbl = document.getElementById('speedtable'); var tbl = document.getElementById('speedtable');
if (tbl.rows.length <= 2 && numPorts) { if (tbl.rows.length <= 2 && numPorts) {
@@ -29,6 +30,34 @@ function createPortTable() {
td.innerHTML = button; td.innerHTML = button;
} }
} }
tbl = document.getElementById('mtutable');
if (tbl.rows.length <= 2 && numPorts) {
const mSelect = '<select name="mtu_sel" id="mtu_sel">'
+ '<option value="16383">16383</option>'
+ '<option value="1522">1522</option>'
+ '<option value="1536">1536</option>'
+ '<option value="1552">1552</option>'
+ '<option value="9216">9216</option>'
+ '</select>';
var tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
if (pIsSFP[i-1])
td.innerHTML = '<object type="image/svg+xml" data="sfp.svg", width="60"</object>'
else
td.innerHTML = '<object type="image/svg+xml" data="port.svg", width="40"</object>'
}
tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
td.innerHTML = mSelect.replaceAll("mtu_sel", "mtu_sel_" + i);
}
tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
td.innerHTML = '<button type="button" style="margin: 0 0 0 24px" onclick="applyMTU(' + i + ');">Apply</button>';
}
}
} }
function updatePortTable() { function updatePortTable() {
@@ -42,27 +71,35 @@ function updatePortTable() {
tbl.rows[i].cells[1].innerHTML = `${linkS[pState[i-1]+1]}`; tbl.rows[i].cells[1].innerHTML = `${linkS[pState[i-1]+1]}`;
var td = tbl.rows[i].cells[2]; var td = tbl.rows[i].cells[2];
var adv = pAdvertised[i-1]; var adv = pAdvertised[i-1];
console.log("pAdvertised for " + i + " is " + adv); switch(pAdvertised[i-1]) {
if (pAdvertised[i-1] == 0) case 0x20:
td.innerHTML = "None"; td.innerHTML = "2.5GBit Full Duplex"; break;
else if (adv == 0b100000) case 0x10:
td.innerHTML = "2.5GBit Full Duplex"; td.innerHTML = "1000MBit Full Duplex"; break;
else if (adv == 0b010000) case 0x2f:
td.innerHTML = "1000MBit Full Duplex"; td.innerHTML = "AUTO"; break;
else if (adv == 0b111111) case 0xc:
td.innerHTML = "AUTO"; td.innerHTML = "100MBit"; break;
else if (adv == 0b000011) case 8:
td.innerHTML = "10MBit"; td.innerHTML = "100MBit Full Duplex"; break;
else if (adv == 0b000100) case 4:
td.innerHTML = "100MBit Half Duplex"; td.innerHTML = "100MBit Half Duplex"; break;
case 3:
td.innerHTML = "10MBit"; break;
case 2:
td.innerHTML = "10MBit Full Duplex"; break;
case 1:
td.innerHTML = "10MBit Half Duplex"; break;
default:
td.innerHTML = "None"; break;
}
} }
} }
async function applySpeed(port) { async function applySpeed(port) {
var speed = document.getElementById('speed_sel_' + port).value; var speed = document.getElementById('speed_sel_' + port).value;
var duplex = document.getElementById('duplex_sel_' + port).value; var duplex = document.getElementById('duplex_sel_' + port).value;
var cmd = "port " + port + " "; var cmd = "port " + port + " " + speed;
cmd = cmd + speed;
console.log("port " + port, ", speed: " + speed, ", duplex: ", duplex); console.log("port " + port, ", speed: " + speed, ", duplex: ", duplex);
try { try {
const response = await fetch('/cmd', { const response = await fetch('/cmd', {
@@ -83,8 +120,46 @@ async function applySpeed(port) {
} }
} }
async function applyMTU(port) {
var mtu = document.getElementById('mtu_sel_' + port).value;
var cmd = "mtu " + port + " " + mtu;
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('MTU Completed!', response);
getMTUs();
} catch(err) {
console.error(`Error: ${err}`);
}
}
function getMTUs() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const s = JSON.parse(xhttp.responseText);
console.log("MTUS: ", JSON.stringify(s));
for (let i = 0; i < s.length; i++) {
p = s[i];
let n = p.portNum;
mtus[n] = parseInt(p.mtu, 16);
var mtu = document.getElementById('mtu_sel_' + n);
if (!mtu)
continue;
mtu.value = mtus[n];
clearInterval(pMTUInterval);
}
}
};
xhttp.open("GET", "/mtu.json", true);
xhttp.timeout = 1500; xhttp.send();
}
window.addEventListener("load", function() { window.addEventListener("load", function() {
const updatePortTableInterval = setInterval(updatePortTable, 1000); const updatePortTableInterval = setInterval(updatePortTable, 1000);
}); });
const pTableInterval = setInterval(createPortTable, 1000); const pTableInterval = setInterval(createPortTable, 1000);
const pMTUInterval = setInterval(getMTUs, 1200);
+2
View File
@@ -570,6 +570,8 @@ void httpd_appcall(void)
send_eee(); send_eee();
} else if (is_word(q, "/mirror.json")) { } else if (is_word(q, "/mirror.json")) {
send_mirror(); send_mirror();
} else if (is_word(q, "/mtu.json")) {
send_mtu();
} else if (is_word(q, "/lag.json")) { } else if (is_word(q, "/lag.json")) {
send_lag(); send_lag();
} else if (is_word(q, "/config")) { } else if (is_word(q, "/config")) {
+22
View File
@@ -380,6 +380,28 @@ void send_eee(void)
} }
} }
void send_mtu(void)
{
print_string("send_mtu called\n");
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
char_to_html('[');
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
slen += strtox(outbuf + slen, "{\"portNum\":");
itoa_html(machine.log_to_phys_port[i]);
slen += strtox(outbuf + slen, ",\"mtu\":\"0x");
reg_read_m(RTL8373_REG_MAC_L2_PORT_MAX_LEN + ((uint16_t) i << 8));
uint16_t mtu = SFR_DATA_U16 & 0x3fff;
byte_to_html(mtu >> 8);
byte_to_html(mtu & 0xff);
char_to_html('"');
char_to_html('}');
if (i < machine.max_port)
char_to_html(',');
else
char_to_html(']');
}
}
void send_status(void) void send_status(void)
{ {
+1
View File
@@ -7,6 +7,7 @@ void send_vlan(uint16_t vlan);
void send_basic_info(void); void send_basic_info(void);
void send_eee(void); void send_eee(void);
void send_mirror(void); void send_mirror(void);
void send_mtu(void);
void send_config(void); void send_config(void);
void send_cmd_log(void); void send_cmd_log(void);
void send_lag(void); void send_lag(void);