Skip to content

Commit 2054680

Browse files
authored
[subinterface] Fix route add command to accept subinterface as dev (sonic-net#2180)
* [subinterface]Fixing static route add command to accept subinterface as dev
1 parent 5383e92 commit 2054680

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

config/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,6 +5053,7 @@ def add_route(ctx, command_str):
50535053
if (not route['ifname'] in config_db.get_keys('VLAN_INTERFACE') and
50545054
not route['ifname'] in config_db.get_keys('INTERFACE') and
50555055
not route['ifname'] in config_db.get_keys('PORTCHANNEL_INTERFACE') and
5056+
not route['ifname'] in config_db.get_keys('VLAN_SUB_INTERFACE') and
50565057
not route['ifname'] == 'null'):
50575058
ctx.fail('interface {} doesn`t exist'.format(route['ifname']))
50585059

doc/Command-Reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8431,6 +8431,7 @@ This command is used to add a static route. Note that prefix /nexthop vrf`s and
84318431
84328432
```
84338433
admin@sonic:~$ config route add prefix 2.2.3.4/32 nexthop 30.0.0.9
8434+
admin@sonic:~$ config route add prefix 4.0.0.0/24 nexthop dev Ethernet32.10
84348435
```
84358436
84368437
It also supports ECMP, and adding a new nexthop to the existing prefix will complement it and not overwrite them.

tests/mock_tables/config_db.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,16 @@
373373
"VLAN_SUB_INTERFACE|Ethernet0.10": {
374374
"admin_status": "up"
375375
},
376+
"VLAN_SUB_INTERFACE|Ethernet0.10|10.11.12.13/24": {
377+
"NULL" : "NULL"
378+
},
376379
"VLAN_SUB_INTERFACE|Eth32.10": {
377380
"admin_status": "up",
378381
"vlan": "100"
379382
},
383+
"VLAN_SUB_INTERFACE|Eth32.10|32.10.11.12/24": {
384+
"NULL" : "NULL"
385+
},
380386
"ACL_RULE|NULL_ROUTE_V4|DEFAULT_RULE": {
381387
"PACKET_ACTION": "DROP",
382388
"PRIORITY": "1"

tests/static_routes_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,37 @@ def test_del_entire_ECMP_static_route(self):
372372
print(result.exit_code, result.output)
373373
assert not '14.2.3.4/32' in db.cfgdb.get_table('STATIC_ROUTE')
374374

375+
def test_static_route_nexthop_subinterface(self):
376+
db = Db()
377+
runner = CliRunner()
378+
obj = {'config_db':db.cfgdb}
379+
380+
# config route add prefix 2.2.3.5/32 nexthop dev Ethernet0.10
381+
result = runner.invoke(config.config.commands["route"].commands["add"], \
382+
["prefix", "2.2.3.5/32", "nexthop", "dev", "Ethernet0.10"], obj=obj)
383+
print(result.exit_code, result.output)
384+
assert ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE')
385+
assert db.cfgdb.get_entry('STATIC_ROUTE', '2.2.3.5/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Ethernet0.10', 'nexthop-vrf': ''}
386+
387+
# config route del prefix 2.2.3.5/32 nexthop dev Ethernet0.10
388+
result = runner.invoke(config.config.commands["route"].commands["del"], \
389+
["prefix", "2.2.3.5/32", "nexthop", "dev", "Ethernet0.10"], obj=obj)
390+
print(result.exit_code, result.output)
391+
assert not ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE')
392+
393+
# config route add prefix 2.2.3.5/32 nexthop dev Eth32.10
394+
result = runner.invoke(config.config.commands["route"].commands["add"], \
395+
["prefix", "2.2.3.5/32", "nexthop", "dev", "Eth32.10"], obj=obj)
396+
print(result.exit_code, result.output)
397+
assert ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE')
398+
assert db.cfgdb.get_entry('STATIC_ROUTE', '2.2.3.5/32') == {'nexthop': '', 'blackhole': 'false', 'distance': '0', 'ifname': 'Eth32.10', 'nexthop-vrf': ''}
399+
400+
# config route del prefix 2.2.3.5/32 nexthop dev Eth32.10
401+
result = runner.invoke(config.config.commands["route"].commands["del"], \
402+
["prefix", "2.2.3.5/32", "nexthop", "dev", "Eth32.10"], obj=obj)
403+
print(result.exit_code, result.output)
404+
assert not ('2.2.3.5/32') in db.cfgdb.get_table('STATIC_ROUTE')
405+
375406
@classmethod
376407
def teardown_class(cls):
377408
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)