Skip to content
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

[subinterface] Fix route add command to accept subinterface as dev #2180

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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