From f5aab753964bb2bafd2354bda1e347dfeed423eb Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 20 May 2022 01:19:32 +0000 Subject: [PATCH 1/2] [subinterface]Fixing static route add command to accept subinterface as dev Signed-off-by: Sudharsan Dhamal Gopalarathnam --- config/main.py | 1 + tests/mock_tables/config_db.json | 6 ++++++ tests/static_routes_test.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/config/main.py b/config/main.py index 924364ba11..84d851b639 100644 --- a/config/main.py +++ b/config/main.py @@ -4931,6 +4931,7 @@ def add_route(ctx, command_str): if (not route['ifname'] in config_db.get_keys('VLAN_INTERFACE') and not route['ifname'] in config_db.get_keys('INTERFACE') and not route['ifname'] in config_db.get_keys('PORTCHANNEL_INTERFACE') and + not route['ifname'] in config_db.get_keys('VLAN_SUB_INTERFACE') and not route['ifname'] == 'null'): ctx.fail('interface {} doesn`t exist'.format(route['ifname'])) diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 9a037bb587..e073937f70 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -373,10 +373,16 @@ "VLAN_SUB_INTERFACE|Ethernet0.10": { "admin_status": "up" }, + "VLAN_SUB_INTERFACE|Ethernet0.10|10.11.12.13/24": { + "NULL" : "NULL" + }, "VLAN_SUB_INTERFACE|Eth32.10": { "admin_status": "up", "vlan": "100" }, + "VLAN_SUB_INTERFACE|Eth32.10|32.10.11.12/24": { + "NULL" : "NULL" + }, "ACL_RULE|NULL_ROUTE_V4|DEFAULT_RULE": { "PACKET_ACTION": "DROP", "PRIORITY": "1" diff --git a/tests/static_routes_test.py b/tests/static_routes_test.py index 5704844aef..4d60c3ef0c 100644 --- a/tests/static_routes_test.py +++ b/tests/static_routes_test.py @@ -372,6 +372,37 @@ def test_del_entire_ECMP_static_route(self): print(result.exit_code, result.output) assert not '14.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE') + def test_static_route_nexthop_subinterface(self): + db = Db() + runner = CliRunner() + obj = {'config_db':db.cfgdb} + + # config route add prefix 2.2.3.5/32 nexthop dev Ethernet0.10 + result = runner.invoke(config.config.commands["route"].commands["add"], \ + ["prefix", "2.2.3.5/32", "nexthop", "dev", "Ethernet0.10"], obj=obj) + print(result.exit_code, result.output) + assert ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE') + assert db.cfgdb.get_entry('STATIC_ROUTE', '2.2.3.5/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Ethernet0.10', 'nexthop-vrf': ''} + + # config route del prefix 2.2.3.5/32 nexthop dev Ethernet0.10 + result = runner.invoke(config.config.commands["route"].commands["del"], \ + ["prefix", "2.2.3.5/32", "nexthop", "dev", "Ethernet0.10"], obj=obj) + print(result.exit_code, result.output) + assert not ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE') + + # config route add prefix 2.2.3.5/32 nexthop dev Eth32.10 + result = runner.invoke(config.config.commands["route"].commands["add"], \ + ["prefix", "2.2.3.5/32", "nexthop", "dev", "Eth32.10"], obj=obj) + print(result.exit_code, result.output) + assert ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE') + assert db.cfgdb.get_entry('STATIC_ROUTE', '2.2.3.5/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Eth32.10', 'nexthop-vrf': ''} + + # config route del prefix 2.2.3.5/32 nexthop dev Eth32.10 + result = runner.invoke(config.config.commands["route"].commands["del"], \ + ["prefix", "2.2.3.5/32", "nexthop", "dev", "Eth32.10"], obj=obj) + print(result.exit_code, result.output) + assert not ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE') + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" From cece19e0aea131a7998cc668e9d0905fc58a39d0 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 20 May 2022 01:26:37 +0000 Subject: [PATCH 2/2] Updating command reference to add an example for subinterface as nexthop for a route --- doc/Command-Reference.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 4beef0cafa..ebba414a53 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -8431,6 +8431,7 @@ This command is used to add a static route. Note that prefix /nexthop vrf`s and ``` admin@sonic:~$ config route add prefix 2.2.3.4/32 nexthop 30.0.0.9 + admin@sonic:~$ config route add prefix 4.0.0.0/24 nexthop dev Ethernet32.10 ``` It also supports ECMP, and adding a new nexthop to the existing prefix will complement it and not overwrite them.