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

Check if number of Mac Addresses is equal to the number of NextHops being configured #116

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions go-server-server/go/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,12 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) {
}
m.NextHop = *required.NextHop
}

nexthops := strings.Split(m.NextHop, ",")
if required.NextHopMonitor != nil {
if !strings.Contains(*required.NextHopMonitor, ",") && !IsValidIPBoth(*required.NextHopMonitor) {
err = &InvalidFormatError{Field: "nexthop_monitor", Message: "Invalid IP address"}
return
}
nexthops := strings.Split(m.NextHop, ",")
nexthop_mon := strings.Split(*required.NextHopMonitor, ",")
if len(nexthops) != len(nexthop_mon) {
err = &InvalidFormatError{Field: "nexthop_monitor", Message: "there must be equal number of nexthop(s) and nexthop_monitor(s)"}
Expand All @@ -249,11 +248,19 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) {
}

if required.IfName == nil && required.MACAddress != nil {
_, err = net.ParseMAC(*required.MACAddress)
mac_addresses := strings.Split(*required.MACAddress, ",")
if len(nexthops) != len(mac_addresses) {
err = &InvalidFormatError{Field: "mac_address", Message: "there must be equal number of nexthop(s) and mac_address(es)"}
return
}

if err != nil {
err = &InvalidFormatError{Field: "mac_address", Message: "Invalid MAC address"}
return
for _, mac := range mac_addresses {
_, err = net.ParseMAC(mac)

if err != nil {
err = &InvalidFormatError{Field: "mac_address", Message: "Invalid MAC address"}
return
}
}
m.MACAddress = *required.MACAddress
}
Expand Down
4 changes: 2 additions & 2 deletions sonic_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ paths:
required: true
schema:
$ref: '#/definitions/ResetStatusEntry'
description: The value of configuration reset status. Only true or false accepted
description: The value of configuration reset status. Only "true" or "false" string values accepted
responses:
'200':
description: OK
Expand Down Expand Up @@ -2854,5 +2854,5 @@ definitions:
- reset_status
properties:
reset_status:
type: boolean
type: string
description: configuration reset status.
14 changes: 12 additions & 2 deletions test/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client):

# Mac address Optional arg
del route['vnid']
route['mac_address'] = '00:08:aa:bb:cd:ef'
route['mac_address'] = '00:08:aa:bb:cc:dd,00:08:aa:bb:cd:ef'
route['cmd'] = 'add'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 204
Expand All @@ -794,6 +794,7 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client):
assert r.status_code == 200
j = json.loads(r.text)
assert sorted(j) == sorted(routes)

# Endpoint Monitor optional arg
route['vnid'] = 5000
route['nexthop_monitor'] = '100.3.152.32,200.3.152.32'
Expand Down Expand Up @@ -1623,12 +1624,21 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client):
}
route['vnid'] = 5000
route['nexthop_monitor'] = '700.3.152.327'
route['cmd'] = 'add'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
route['nexthop_monitor'] = '100.3.152.32,200.3.152.32'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
del route['nexthop_monitor']
route['mac_address'] = '00:08:xx:bb:cc:dd'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
route['mac_address'] = '00:08:aa:bb:cc:dd,00:08:aa:bb:cd:ef'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
route['mac_address'] = '0008aabbccdd'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
del route['nexthop']
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 400
Expand Down