Skip to content

[CLI] Add script null_route_helper#1737

Merged
bingwang-ms merged 1 commit intosonic-net:masterfrom
bingwang-ms:null_route_helper_master
Aug 3, 2021
Merged

[CLI] Add script null_route_helper#1737
bingwang-ms merged 1 commit intosonic-net:masterfrom
bingwang-ms:null_route_helper_master

Conversation

@bingwang-ms
Copy link
Copy Markdown
Contributor

Signed-off-by: bingwang bingwang@microsoft.com

What I did

This PR introduced a new helper script null_route_helper.

null_route_helper is a utility for blocking and unblocking traffic from given source ip_prefix on ACL tables.
The block operation will insert a DENY rule at the top of the table. The unblock operation will remove an existing DENY rule that has been created by the block operation (i.e. it does NOT insert an ALLOW rule, only removes DENY rules).
Since SONiC supports multi ACL rules share the same priority, all ACL rules created by null_route_helper will use the highest priority(9999).

Example:

Block traffic from 10.2.3.4:
./null_route_helper block acl_table_name 10.2.3.4

Unblock all traffic from 10.2.3.4:
./null_route_helper unblock acl_table_name 10.2.3.4

List all acl rules added by this script
./null_route_helper list acl_table_name

How I did it

The feature is implemented with applying ACL rules.

How to verify it

Verified with both unit test and traffic test.

tests/null_route_helper_test.py::test_ip_validation PASSED                                                                                                                                      [ 59%]
tests/null_route_helper_test.py::test_confirm_required_table_existence PASSED                                                                                                                   [ 59%]
tests/null_route_helper_test.py::test_build_rule PASSED                                                                                                                                         [ 59%]
tests/null_route_helper_test.py::test_get_rule PASSED                                                                                                                                           [ 59%]
tests/null_route_helper_test.py::test_run_when_table_absent PASSED                                                                                                                              [ 59%]
tests/null_route_helper_test.py::test_run_with_invalid_ip PASSED                                                                                                                                [ 59%]
tests/null_route_helper_test.py::test_block PASSED                                                                                                                                              [ 60%]
tests/null_route_helper_test.py::test_unblock PASSED                                                                                                                                            [ 60%]
tests/null_route_helper_test.py::test_list PASSED          
Name                                                Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------
scripts/null_route_helper                             123      4     34      3    96%

Traffic verification will be done in sonic-mgmt
sonic-net/sonic-mgmt#3812

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

Signed-off-by: bingwang <bingwang@microsoft.com>
@bingwang-ms bingwang-ms merged commit 394e2fb into sonic-net:master Aug 3, 2021
@qiluo-msft
Copy link
Copy Markdown
Contributor

This PR could not cleanly cherry-picked to 201911 branch. Please submit another PR.

judyjoseph pushed a commit that referenced this pull request Sep 19, 2021
Signed-off-by: bingwang <bingwang@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants