mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-10-29 17:54:14 +08:00
lacp: implement IEEE 802.3ad link aggregation
Dynamic link aggregation on top of the static LAGG, for RTL8372/8373: receive, selection and mux state machines (coupled mux, one aggregator per group), with "lacp show" to look inside. Each of the four trunk groups runs its own aggregator on the candidate ports assigned with "lag <n> lacp <ports>"; the engine starts with the first such group and stops with the last. LACPDUs reach the CPU through the reserved-multicast trap, so delivery needs no L2 entry and nothing written per VLAN or per PVID. The trap acts on the address before the VLAN lookup and before the ingress filters, so a LACPDU also arrives on a port that admits tagged frames only and on a port STP holds in blocking, neither of which a forwarded one reaches. A trapped frame carries no VLAN tag, so lacp_in() takes the offset of the PDU body from TRAP_RX_BODY(). The action is set with trap_rma_set(), which leaves the flags sharing that register alone, and "lacp off" puts the slow-protocols drop default back. doc/lacp.md and doc/link_aggregation.md record what was measured, including why the trap looked like a dead end at first. The web UI gets a Static/LACP mode per group on the LAG page with live status, and the startup-config validator knows the per-group syntax. A host-side sandbox for the state machines runs in the test harness together with the LAG hash check. It drives both forms of an incoming LACPDU, so the body offset of a trapped one is covered as well. The L2 table page iterated with the "next unicast" read method, so static multicast entries such as an IGMP group were invisible. It now iterates with "next address", skips L3 entries (their layout carries IP addresses where a MAC is expected), and reports the lowest member of a multicast entry's port mask, so such an entry shows up as a static entry on that port. A port taken out of LACP forgets its partner, so "lacp show" after "lacp off" no longer reports one. Applying the same candidate set to a group again, as the LAG page does on every Apply, leaves the trunk alone instead of tearing it down for a second or two. lacp_in() checks the frame length and ethertype before reading a LACPDU, so a runt or a foreign frame on the slow-protocols address cannot leave stale buffer bytes as a partner. The sandbox covers these three in T20-T22. On the LAG page, LACP mode with no ports checked sends "lag N lacp off", and the startup-config validator wants at least one port after "lacp".
This commit is contained in:
1 parent
ed069b67fd
commit
56686185ce
31 files changed
+1885
-23
No files matched your search
+77
-4
@@ -14,6 +14,7 @@
|
||||
#include "version.h"
|
||||
#include "machine.h"
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_lacp.h"
|
||||
#include "page_impl.h"
|
||||
#include "syslog.h"
|
||||
|
||||
@@ -408,14 +409,19 @@ void send_l2(uint16_t idx)
|
||||
*/
|
||||
__xdata uint16_t entry = idx & 0xfff;
|
||||
__xdata uint16_t first_entry = 0xffff; // An illegal entry index
|
||||
__xdata uint16_t mbr;
|
||||
__bit first = true;
|
||||
char_to_html('[');
|
||||
while (1) {
|
||||
entries_left--;
|
||||
uint8_t port = 0;
|
||||
uint8_t lag;
|
||||
uint8_t mc = 0;
|
||||
reg_read_m(RTL837x_TBL_DATA_0);
|
||||
REG_WRITE(RTL837x_TBL_DATA_0, sfr_data[0], sfr_data[1] & 0xfc, sfr_data[2] | (TBL_LUTREAD_NEXT_L2UC << 6), sfr_data[3]);
|
||||
// Iterate with "next address" (method 2) so static multicast entries -
|
||||
// an IGMP group entry, say - are listed too, not only learned or
|
||||
// static unicast ones.
|
||||
REG_WRITE(RTL837x_TBL_DATA_0, sfr_data[0], sfr_data[1] & 0xfc, sfr_data[2] | (TBL_LUTREAD_NEXT_ADDRESS << 6), sfr_data[3]);
|
||||
|
||||
REG_WRITE(RTL837X_TBL_CTRL, entry >> 8, entry, TBL_L2_UNICAST, TBL_EXECUTE);
|
||||
do {
|
||||
@@ -423,7 +429,7 @@ void send_l2(uint16_t idx)
|
||||
} while (sfr_data[3] & TBL_EXECUTE);
|
||||
|
||||
reg_read_m(RTL837x_L2_DATA_OUT_B);
|
||||
__bit valid = (sfr_data[0] & 0x20) != 0;
|
||||
__bit valid = (sfr_data[0] & 0x20) && !(sfr_data[0] & 0x10);
|
||||
if (valid) {
|
||||
/* separator + 74-byte worst-case entry + closing "]" */
|
||||
if (slen + 76 > TCP_OUTBUF_SIZE)
|
||||
@@ -432,6 +438,8 @@ void send_l2(uint16_t idx)
|
||||
char_to_html(',');
|
||||
first = false;
|
||||
|
||||
mc = sfr_data[2] & 0x01; // multicast MAC: member mask, no SPA/age
|
||||
|
||||
// VLAN, taken from the read above instead of reading the register twice
|
||||
slen += strtox(outbuf + slen, "{\"vlan\":\"");
|
||||
charhex_to_html(sfr_data[0] & 0x0f);
|
||||
@@ -450,12 +458,23 @@ void send_l2(uint16_t idx)
|
||||
|
||||
// type
|
||||
reg_read_m(RTL837x_L2_DATA_OUT_C);
|
||||
if (sfr_data[1] & 0x1)
|
||||
if (mc || (sfr_data[1] & 0x1))
|
||||
slen += strtox(outbuf + slen, "\",\"type\":\"s\",\"port\":");
|
||||
else
|
||||
slen += strtox(outbuf + slen, "\",\"type\":\"l\",\"port\":");
|
||||
|
||||
port |= (sfr_data[3] & 0x3) << 2;
|
||||
if (mc) {
|
||||
// Report the lowest member of the mask (an entry holding only
|
||||
// the CPU port is rendered as "CPU" by the UI)
|
||||
mbr = port | ((uint16_t)sfr_data[3] << 2);
|
||||
port = 0;
|
||||
while (mbr && !(mbr & 1)) {
|
||||
mbr >>= 1;
|
||||
port++;
|
||||
}
|
||||
} else {
|
||||
port |= (sfr_data[3] & 0x3) << 2;
|
||||
}
|
||||
itoa_html(port);
|
||||
slen += strtox(outbuf + slen, ",\"lag\":");
|
||||
lag = port_lag_of(port);
|
||||
@@ -736,6 +755,60 @@ void send_stp(void)
|
||||
slen += strtox(outbuf + slen, "]}");
|
||||
}
|
||||
|
||||
/* LACP protocol status for the LAG page ("/lacp.json"). State variables are
|
||||
* exported read-only via rtl837x_lacp.h; hardware trunk membership itself is
|
||||
* already visible through send_lag() (it reads the trunk registers). */
|
||||
void send_lacp(void)
|
||||
{
|
||||
dbg_string("send_lacp called\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
|
||||
slen += strtox(outbuf + slen, "{\"on\":");
|
||||
bool_to_html(lacpEnabled);
|
||||
/* Per-LAG section: candidate ports, elected aggregator, trunk members. */
|
||||
slen += strtox(outbuf + slen, ",\"lags\":[");
|
||||
for (uint8_t l = 0; l < LACP_NUM_LAGS; l++) {
|
||||
slen += strtox(outbuf + slen, "{\"cfg\":\"");
|
||||
byte_to_html(lacp_lag_ports[l] >> 8);
|
||||
byte_to_html(lacp_lag_ports[l]);
|
||||
slen += strtox(outbuf + slen, "\",\"aggValid\":");
|
||||
bool_to_html(lacp_agg_valid[l]);
|
||||
slen += strtox(outbuf + slen, ",\"agg\":\"");
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
byte_to_html(lacp_agg_sys[l][j]);
|
||||
slen += strtox(outbuf + slen, "\",\"members\":\"");
|
||||
byte_to_html(lacp_members_last[l] >> 8);
|
||||
byte_to_html(lacp_members_last[l]);
|
||||
slen += strtox(outbuf + slen, "\"},");
|
||||
}
|
||||
slen -= 1; // remove comma
|
||||
slen += strtox(outbuf + slen, "],\"ports\":[");
|
||||
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
|
||||
slen += strtox(outbuf + slen, "{\"p\":");
|
||||
itoa_html(machine.log_to_phys_port[i]);
|
||||
/* Which LACP LAG this port belongs to; 255 = none */
|
||||
slen += strtox(outbuf + slen, ",\"lag\":");
|
||||
itoa_html(lacp_port_lag[i]);
|
||||
slen += strtox(outbuf + slen, ",\"a\":\"");
|
||||
byte_to_html(lacp_actor_state[i]);
|
||||
slen += strtox(outbuf + slen, "\",\"pt\":\"");
|
||||
byte_to_html(lacp_partner_state[i]);
|
||||
slen += strtox(outbuf + slen, "\",\"rs\":");
|
||||
itoa_html(lacp_rx_state[i]);
|
||||
/* rx as 4-digit hex: itoa16_html() only renders values up to 9999
|
||||
* correctly (see its VLAN-ID comment), the counter goes to 65535 */
|
||||
slen += strtox(outbuf + slen, ",\"rx\":\"");
|
||||
byte_to_html(lacp_rx_count[i] >> 8);
|
||||
byte_to_html(lacp_rx_count[i]);
|
||||
slen += strtox(outbuf + slen, "\",\"psys\":\"");
|
||||
for (uint8_t j = 0; j < 6; j++)
|
||||
byte_to_html(lacp_partner_sys[i][j]);
|
||||
slen += strtox(outbuf + slen, "\"},");
|
||||
}
|
||||
slen -= 1; // remove comma
|
||||
slen += strtox(outbuf + slen, "]}");
|
||||
}
|
||||
|
||||
void send_lldp(void)
|
||||
{
|
||||
dbg_string("send_lldp called\n");
|
||||
|
||||
Reference in new issue
Block a user