Skip to content

Commit

Permalink
[subinterface] Fix route add command to accept subinterface as dev (#…
Browse files Browse the repository at this point in the history
…2180)

* [subinterface]Fixing static route add command to accept subinterface as dev
  • Loading branch information
dgsudharsan authored and yxieca committed Jun 15, 2022
1 parent 53ff644 commit ed97c6f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))

Expand Down
1 change: 1 addition & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions tests/static_routes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ed97c6f

Please sign in to comment.