-
Notifications
You must be signed in to change notification settings - Fork 42
Add STP loop guard support #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
salahadell
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
salahadell:adding-loop-guard-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -295,6 +295,11 @@ void stpmgr_disable_port(STP_CLASS *stp_class, PORT_ID port_number) | |
| stptimer_stop(&stp_port_class->root_protect_timer); | ||
| } | ||
|
|
||
| if (stp_port_class->loop_guard_active) | ||
| { | ||
| stp_port_class->loop_guard_active = false; | ||
| } | ||
|
|
||
| clear_mask_bit(stp_class->enable_mask, port_number); | ||
| configuration_update(stp_class); | ||
| port_state_selection(stp_class); | ||
|
|
@@ -1249,6 +1254,20 @@ bool stpmgr_config_root_protect(PORT_ID port_id, bool enable) | |
| return true; | ||
| } | ||
|
|
||
| /*****************************************************************************/ | ||
| /* stpmgr_config_loop_protect: enables/disables loop-guard feature on the */ | ||
| /* input port. */ | ||
| /*****************************************************************************/ | ||
| static bool stpmgr_config_loop_protect(PORT_ID port_id, bool enable) | ||
| { | ||
| if (enable) | ||
| set_mask_bit(stp_global.loop_protect_mask, port_id); | ||
| else | ||
| clear_mask_bit(stp_global.loop_protect_mask, port_id); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /*****************************************************************************/ | ||
| /* stpmgr_config_root_protect_timeout: configures the timeout in seconds for */ | ||
| /* which the violated stp port is kept in blocking state. */ | ||
|
|
@@ -1717,9 +1736,9 @@ static void stpmgr_process_intf_config_msg(void *msg) | |
| return; | ||
| } | ||
|
|
||
| STP_LOG_INFO("op:%d, intf:%s, enable:%d, root_grd:%d, bpdu_grd:%d , do_dis:%d, cost:%d, pri:%d, portfast:%d, uplink_fast:%d, count:%d", | ||
| pmsg->opcode, pmsg->intf_name, pmsg->enabled, pmsg->root_guard, pmsg->bpdu_guard, | ||
| pmsg->bpdu_guard_do_disable, pmsg->path_cost, pmsg->priority, | ||
| STP_LOG_INFO("op:%d, intf:%s, enable:%d, root_grd:%d, loop_grd:%d, bpdu_grd:%d , do_dis:%d, cost:%d, pri:%d, portfast:%d, uplink_fast:%d, count:%d", | ||
| pmsg->opcode, pmsg->intf_name, pmsg->enabled, pmsg->root_guard, pmsg->loop_guard, pmsg->bpdu_guard, | ||
| pmsg->bpdu_guard_do_disable, pmsg->path_cost, pmsg->priority, | ||
| pmsg->portfast, pmsg->uplink_fast, pmsg->count); | ||
|
|
||
| port_id = stp_intf_get_port_id_by_name(pmsg->intf_name); | ||
|
|
@@ -1771,8 +1790,9 @@ static void stpmgr_process_intf_config_msg(void *msg) | |
| if (pmsg->enabled) | ||
| { | ||
| stpmgr_config_root_protect(port_id, pmsg->root_guard); | ||
| stpmgr_config_loop_protect(port_id, pmsg->loop_guard); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR currently implements only PVST. Could we consider implementing MSTP support as well? |
||
| stpmgr_config_protect(port_id, pmsg->bpdu_guard, pmsg->bpdu_guard_do_disable); | ||
|
|
||
| stpmgr_config_fastspan(port_id, pmsg->portfast); | ||
| stpmgr_config_fastuplink(port_id, pmsg->uplink_fast); | ||
| } | ||
|
|
@@ -1788,6 +1808,7 @@ static void stpmgr_process_intf_config_msg(void *msg) | |
| if (pmsg->opcode == STP_DEL_COMMAND || !pmsg->enabled) | ||
| { | ||
| stpmgr_config_root_protect(port_id, false); | ||
| stpmgr_config_loop_protect(port_id, false); | ||
| stpmgr_config_protect(port_id, false, false); | ||
|
|
||
| stpmgr_config_fastspan(port_id, true); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -498,6 +498,27 @@ static bool stputil_root_protect_violation(STP_CLASS *stp_class, PORT_ID port_nu | |
| return true; | ||
| } | ||
|
|
||
|
|
||
| /*****************************************************************************/ | ||
| /* stputil_loop_guard_bpdu_recovery: called when a BPDU is received on a */ | ||
| /* loop-inconsistent port. clears the loop guard active flag, logs recovery, */ | ||
| /* and marks the port state as modified. */ | ||
| /*****************************************************************************/ | ||
| static void stputil_loop_guard_bpdu_recovery(STP_CLASS *stp_class, PORT_ID port_number) | ||
| { | ||
| STP_PORT_CLASS *stp_port; | ||
|
|
||
| stp_port = GET_STP_PORT_CLASS(stp_class, port_number); | ||
|
|
||
| STP_SYSLOG("STP: Loop Guard interface %s, VLAN %u consistent (BPDU received)", | ||
| stp_intf_get_port_name(port_number), stp_class->vlan_id); | ||
|
|
||
| stp_port->loop_guard_active = false; | ||
| stp_port->loop_guard_synced = false; | ||
| SET_BIT(stp_port->modified_fields, STP_PORT_CLASS_LOOP_PROTECT_BIT); | ||
| SET_BIT(stp_port->modified_fields, STP_PORT_CLASS_MEMBER_PORT_STATE_BIT); | ||
| } | ||
|
|
||
| /*****************************************************************************/ | ||
| /* stputil_root_protect_validate: routine validates the bpdu to see that it */ | ||
| /* is conforming to the root protect configuration. */ | ||
|
|
@@ -779,6 +800,16 @@ void stputil_process_bpdu(STP_INDEX stp_index, PORT_ID port_number, void *buffer | |
| return; | ||
| } | ||
|
|
||
| // Loop Guard: if port is in loop-inconsistent state and receives a BPDU, recover | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What BPDU qualifies for recovery? Any BPDU? |
||
| if (STP_IS_LOOP_PROTECT_CONFIGURED(port_number)) | ||
| { | ||
| STP_PORT_CLASS *stp_port_lg = GET_STP_PORT_CLASS(stp_class, port_number); | ||
| if (stp_port_lg->loop_guard_active) | ||
| { | ||
| stputil_loop_guard_bpdu_recovery(stp_class, port_number); | ||
| } | ||
| } | ||
|
|
||
| last_bpdu_rx_time = stp_class->last_bpdu_rx_time; | ||
| current_time = sys_get_seconds(); | ||
| stp_class->last_bpdu_rx_time = current_time; | ||
|
|
@@ -898,7 +929,12 @@ void stptimer_sync_port_class(STP_CLASS *stp_class, STP_PORT_CLASS * stp_port) | |
| if(timer_value != 0 && stp_port->state == BLOCKING) | ||
| strcpy(stp_vlan_intf.port_state, "ROOT-INC"); | ||
| else | ||
| strcpy(stp_vlan_intf.port_state, l2_port_state_to_string(stp_port->state, stp_port->port_id.number)); | ||
| { | ||
| if(stp_port->loop_guard_active && stp_port->state == BLOCKING) | ||
| strcpy(stp_vlan_intf.port_state, "LOOP-INC"); | ||
| else | ||
| strcpy(stp_vlan_intf.port_state, l2_port_state_to_string(stp_port->state, stp_port->port_id.number)); | ||
| } | ||
|
|
||
| if (stp_port->state == DISABLED) | ||
| { | ||
|
|
@@ -965,6 +1001,16 @@ void stptimer_sync_port_class(STP_CLASS *stp_class, STP_PORT_CLASS * stp_port) | |
| stp_vlan_intf.root_protect_timer = -1; | ||
| } | ||
|
|
||
| if(IS_BIT_SET(stp_port->modified_fields, STP_PORT_CLASS_LOOP_PROTECT_BIT)) | ||
| { | ||
| stp_vlan_intf.loop_guard_active = stp_port->loop_guard_active ? 1 : 0; | ||
| stp_port->loop_guard_synced = true; | ||
| } | ||
| else | ||
| { | ||
| stp_vlan_intf.loop_guard_active = -1; | ||
| } | ||
|
|
||
| if(IS_BIT_SET(stp_port->modified_fields, STP_PORT_CLASS_CLEAR_STATS_BIT)) | ||
| { | ||
| stp_vlan_intf.clear_stats = 1; | ||
|
|
@@ -1120,7 +1166,10 @@ void stputil_sync_port_counters(STP_CLASS *stp_class, STP_PORT_CLASS * stp_port) | |
|
|
||
| if (is_timer_active(&stp_port->root_protect_timer)) | ||
| SET_BIT(stp_port->modified_fields, STP_PORT_CLASS_ROOT_PROTECT_BIT); | ||
|
|
||
|
|
||
| if (stp_port->loop_guard_active && !stp_port->loop_guard_synced) | ||
| SET_BIT(stp_port->modified_fields, STP_PORT_CLASS_LOOP_PROTECT_BIT); | ||
|
|
||
| stptimer_sync_port_class(stp_class, stp_port); | ||
| } | ||
|
|
||
|
|
@@ -1302,23 +1351,36 @@ void stptimer_update(STP_CLASS *stp_class) | |
| (stp_port_class->root_protect_timer.active && !STP_IS_ROOT_PROTECT_CONFIGURED(port_number))) | ||
| { | ||
| stp_port_class->root_protect_timer.active = false; | ||
| stputil_root_protect_timer_expired(stp_class, port_number); | ||
| stputil_root_protect_timer_expired(stp_class, port_number); | ||
|
|
||
| if (debugGlobal.stp.enabled) | ||
| { | ||
| if (STP_DEBUG_VP(stp_class->vlan_id, port_number)) | ||
| { | ||
| STP_LOG_INFO("I:%lu P:%u V:%u Ev:%d",GET_STP_INDEX(stp_class),port_number, | ||
| STP_LOG_INFO("I:%lu P:%u V:%u Ev:%d",GET_STP_INDEX(stp_class),port_number, | ||
| stp_class->vlan_id,STP_RAS_ROOT_PROTECT_TIMER_EXPIRY); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| STP_LOG_INFO("I:%lu P:%u V:%u Ev:%d",GET_STP_INDEX(stp_class),port_number, | ||
| STP_LOG_INFO("I:%lu P:%u V:%u Ev:%d",GET_STP_INDEX(stp_class),port_number, | ||
| stp_class->vlan_id,STP_RAS_ROOT_PROTECT_TIMER_EXPIRY); | ||
| } | ||
| } | ||
|
|
||
| /* Loop guard config can be removed while the port is already loop-inconsistent. | ||
| * In that case, clear loop-guard state and run the same recovery path used on | ||
| * message-age expiry so the port can be re-evaluated immediately. */ | ||
| if (stp_port_class->loop_guard_active && !STP_IS_LOOP_PROTECT_CONFIGURED(port_number)) | ||
| { | ||
| stp_port_class->loop_guard_active = false; | ||
| stp_port_class->loop_guard_synced = false; | ||
| SET_BIT(stp_port_class->modified_fields, STP_PORT_CLASS_LOOP_PROTECT_BIT); | ||
| SET_BIT(stp_port_class->modified_fields, STP_PORT_CLASS_MEMBER_PORT_STATE_BIT); | ||
|
|
||
| message_age_timer_expiry(stp_class, port_number); | ||
| } | ||
|
|
||
| port_number = port_mask_get_next_port(stp_class->enable_mask, port_number); | ||
| } | ||
|
|
||
|
|
@@ -1441,4 +1503,3 @@ void sys_assert(int status) | |
| { | ||
| assert(status); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a port has both loop_guard_active AND root_protect_timer active simultaneously? How does that being handled?