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
b83b67d234
commit
c3b4cc893b
31 files changed
+1885
-23
No files matched your search
+19
-6
@@ -13,6 +13,7 @@
|
||||
#include "rtl837x_port.h"
|
||||
#include "rtl837x_trap.h"
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_lacp.h"
|
||||
#include "rtl837x_igmp.h"
|
||||
#include "rtl837x_leds.h"
|
||||
#include "rtl837x_bandwidth.h"
|
||||
@@ -133,6 +134,7 @@ __xdata bool stp_enabled;
|
||||
__xdata uint8_t igmpEnabled;
|
||||
__xdata bool lldp_enabled;
|
||||
__xdata char hostname[24]; /* device hostname, default set at boot, see rtl837x_common.h */
|
||||
__xdata uint8_t lacpEnabled;
|
||||
|
||||
__code const uint16_t bit_mask[16] = {
|
||||
0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
|
||||
@@ -1059,12 +1061,18 @@ void handle_rx(void)
|
||||
print_byte(uip_buf[3]); print_byte(uip_buf[4]); print_byte(uip_buf[5]); write_char('\n');
|
||||
print_string(" MGMT-VLAN: "); print_short(management_vlan); write_char('\n');
|
||||
#endif
|
||||
if (stp_enabled && uip_buf[0] == 0x01 && uip_buf[1] == 0x80 && uip_buf[2] == 0xc2 // STP packet?
|
||||
&& uip_buf[3] == 0x00 && uip_buf[4] == 0x00 && uip_buf[5] == 0x00) {
|
||||
stp_in();
|
||||
if (uip_len) {
|
||||
print_string("STP TX\n");
|
||||
tcpip_output();
|
||||
if ((stp_enabled || lacpEnabled) && uip_buf[0] == 0x01 && uip_buf[1] == 0x80
|
||||
&& uip_buf[2] == 0xc2 && uip_buf[3] == 0x00 && uip_buf[4] == 0x00) { // 01:80:C2:00:00:0x
|
||||
if (stp_enabled && uip_buf[5] == 0x00) { // STP/RSTP BPDU
|
||||
stp_in();
|
||||
if (uip_len) {
|
||||
print_string("STP TX\n");
|
||||
tcpip_output();
|
||||
}
|
||||
} else if (lacpEnabled && uip_buf[5] == 0x02) { // LACPDU (slow protocols)
|
||||
lacp_in();
|
||||
if (uip_len)
|
||||
tcpip_output();
|
||||
}
|
||||
} else if (igmpEnabled && uip_buf[0] == 0x01 && uip_buf[1] == 0x00 && uip_buf[2] == 0x5e // IPv4-MC packet?
|
||||
&& igmp_packet_handler()) {
|
||||
@@ -1290,6 +1298,9 @@ static void handle_tick(void)
|
||||
stp_timers();
|
||||
}
|
||||
}
|
||||
// If LACP enabled, drive its machines (own tick divider lives in the banked module)
|
||||
if (lacpEnabled)
|
||||
lacp_timers();
|
||||
health_phase(HEALTH_PH_STP);
|
||||
lldp_tick();
|
||||
health_phase(HEALTH_LLDP);
|
||||
@@ -1792,6 +1803,8 @@ void main(void)
|
||||
#endif
|
||||
stp_enabled = 0;
|
||||
stp_defaults(); /* 802.1D/w default config before any "stp ..." replay */
|
||||
lacpEnabled = 0;
|
||||
lacp_init(); /* clear per-LAG state (port->LAG map = NONE) before any config replay */
|
||||
nic_setup();
|
||||
REG_SET(RTL837X_NIC_INT_MSK, NIC_INT_RXIE);
|
||||
trap_init();
|
||||
|
||||
Reference in new issue
Block a user