Skip to content

Commit

Permalink
Add support for overlay ECMP (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhatv authored Nov 16, 2021
1 parent 6822a46 commit 5cc4358
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 9 deletions.
47 changes: 38 additions & 9 deletions go-server-server/go/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,13 +937,22 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {

pt := swsscommon.NewTable(db.swss_db, VNET_TB)
defer pt.Delete()

pt.Set(vnet_id_str, map[string]string{
"vxlan_tunnel": "default_vxlan_tunnel",
"vni": strconv.Itoa(attr.Vnid),
"guid": vars["vnet_name"],
}, "SET", "")


log.Printf("debug: vnet_id_str: "+vnet_id_str)
if strings.Compare(vars["vnet_name"], "Vnet-default") == 0 {
pt.Set(vnet_id_str, map[string]string{
"vxlan_tunnel": "default_vxlan_tunnel",
"vni": strconv.Itoa(attr.Vnid),
"guid": vars["vnet_name"],
"scope": "default",
}, "SET", "")
} else {
pt.Set(vnet_id_str, map[string]string{
"vxlan_tunnel": "default_vxlan_tunnel",
"vni": strconv.Itoa(attr.Vnid),
"guid": vars["vnet_name"],
}, "SET", "")
}
w.WriteHeader(http.StatusNoContent)
}

Expand Down Expand Up @@ -1135,7 +1144,9 @@ func ConfigVrouterVrfIdRoutesPatch(w http.ResponseWriter, r *http.Request) {
if r.IfName == "" {
if cur_route["endpoint"] != r.NextHop ||
cur_route["mac_address"] != r.MACAddress ||
cur_route["vni"] != strconv.Itoa(r.Vnid) {
cur_route["vni"] != strconv.Itoa(r.Vnid) ||
cur_route["weight"] != r.Weight ||
cur_route["profile"] != r.Profile {
/* Delete and re-add the route as it is not identical */
pt.Del(generateDBTableKey(db.separator,vnet_id_str, r.IPPrefix), "DEL", "")
} else {
Expand Down Expand Up @@ -1167,6 +1178,12 @@ func ConfigVrouterVrfIdRoutesPatch(w http.ResponseWriter, r *http.Request) {
route_map["nexthop"] = r.NextHop
}
}
if r.Weight != "" {
route_map["weight"] = r.Weight
}
if r.Profile != "" {
route_map["profile"] = r.Profile
}
pt.Set(generateDBTableKey(db.separator,vnet_id_str, r.IPPrefix), route_map, "SET", "")
}
}
Expand Down Expand Up @@ -1269,7 +1286,12 @@ func ConfigVrfVrfIdRoutesPatch(w http.ResponseWriter, r *http.Request) {
if r.IfName == "null" {
route_map["blackhole"] = "true"
}

if r.Weight != "" {
route_map["weight"] = r.Weight
}
if r.Profile != "" {
route_map["profile"] = r.Profile
}
pt.Set(generateDBTableKey(db.separator,vrf_id_str, r.IPPrefix), route_map, "SET", "")
}
}
Expand Down Expand Up @@ -1328,6 +1350,13 @@ func ConfigVrfVrfIdRoutesGet(w http.ResponseWriter, r *http.Request) {
routeModel.IfName = ifname
}

if weight, ok := kvp["weight"]; ok {
routeModel.Weight = weight
}

if profile, ok := kvp["profile"]; ok {
routeModel.Profile = profile
}
routes = append(routes, routeModel)
}

Expand Down
10 changes: 10 additions & 0 deletions go-server-server/go/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type RouteModel struct {
NextHop string `json:"nexthop"`
MACAddress string `json:"mac_address,omitempty"`
Vnid int `json:"vnid,omitempty"`
Weight string `json:"weight,omitempty"`
Profile string `json:"profile,omitempty"`
Error_code int `json:"error_code,omitempty"`
Error_msg string `json:"error_msg,omitempty"`
}
Expand Down Expand Up @@ -178,6 +180,8 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) {
NextHop *string `json:"nexthop"`
MACAddress *string `json:"mac_address"`
Vnid int `json:"vnid"`
Weight *string `json:"weight"`
Profile *string `json:"profile"`
Error string `json:"error"`
}{}

Expand Down Expand Up @@ -235,6 +239,12 @@ func (m *RouteModel) UnmarshalJSON(data []byte) (err error) {
if required.IfName != nil {
m.IfName = *required.IfName
}
if required.Weight != nil {
m.Weight = *required.Weight
}
if required.Profile != nil {
m.Profile = *required.Profile
}
return
}

Expand Down
15 changes: 15 additions & 0 deletions go-server-server/go/persistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ func SwssGetVrouterRoutes(vnet_id_str string, vnidMatch int, ipFilter string) (r
routeModel.MACAddress = mac
}

if weight, ok := kvp["weight"]; ok {
routeModel.Weight = weight
}

if profile, ok := kvp["profile"]; ok {
routeModel.Profile = profile
}

routes = append(routes, routeModel)
}

Expand All @@ -323,6 +331,13 @@ func SwssGetVrouterRoutes(vnet_id_str string, vnidMatch int, ipFilter string) (r
routeModel.IfName = ifname
}

if weight, ok := kvp["weight"]; ok {
routeModel.Weight = weight
}

if profile, ok := kvp["profile"]; ok {
routeModel.Profile = profile
}
routes = append(routes, routeModel)
}
return
Expand Down
67 changes: 67 additions & 0 deletions test/test_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ def test_post_vrouter(self, setup_restapi_client):
b'guid': b'vnet-guid-1'
}

def test_post_vrouter_default(self, setup_restapi_client):
_, _, configdb, restapi_client = setup_restapi_client
restapi_client.post_generic_vxlan_tunnel()
r = restapi_client.post_config_vrouter_vrf_id("Vnet-default", {
'vnid': 2001
})
assert r.status_code == 204

vrouter_table = configdb.hgetall(VNET_TB + '|' + VNET_NAME_PREF + '1')
assert vrouter_table == {
b'vxlan_tunnel': b'default_vxlan_tunnel',
b'vni': b'2001',
b'guid': b'Vnet-default',
b'scope': b'default'
}

def test_get_vrouter(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
restapi_client.post_generic_vrouter_and_deps()
Expand Down Expand Up @@ -633,6 +649,51 @@ def test_patch_update_routes_with_optional_args(self, setup_restapi_client):
j = json.loads(r.text)
assert sorted(j) == sorted(routes)

# Weight optional arg
route['vnid'] = 5000
route['nexthop'] = '100.3.152.32,200.3.152.32'
route['weight'] = '20,10'
route['cmd'] = 'add'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 204
route_table = db.hgetall(ROUTE_TUN_TB + ':' + VNET_NAME_PREF +str(1)+':'+route['ip_prefix'])
assert route_table == {b'endpoint' : route['nexthop'],
b'vni': str(route['vnid']),
b'mac_address' : route['mac_address'],
b'weight': route['weight']
}
del route['cmd']
routes = list()
routes.append(route)
routes.append({'nexthop': '', 'ip_prefix': '10.1.1.0/24', 'ifname': 'Vlan2'})
r = restapi_client.get_config_vrouter_vrf_id_routes("vnet-guid-1")
assert r.status_code == 200
j = json.loads(r.text)
assert sorted(j) == sorted(routes)
del route['weight']

# Profile optional arg
route['vnid'] = 5000
route['nexthop'] = '100.3.152.32,200.3.152.32'
route['profile'] = 'profile1'
route['cmd'] = 'add'
r = restapi_client.patch_config_vrouter_vrf_id_routes("vnet-guid-1", [route])
assert r.status_code == 204
route_table = db.hgetall(ROUTE_TUN_TB + ':' + VNET_NAME_PREF +str(1)+':'+route['ip_prefix'])
assert route_table == {b'endpoint' : route['nexthop'],
b'vni': str(route['vnid']),
b'mac_address' : route['mac_address'],
b'profile': route['profile']
}
del route['cmd']
routes = list()
routes.append(route)
routes.append({'nexthop': '', 'ip_prefix': '10.1.1.0/24', 'ifname': 'Vlan2'})
r = restapi_client.get_config_vrouter_vrf_id_routes("vnet-guid-1")
assert r.status_code == 200
j = json.loads(r.text)
assert sorted(j) == sorted(routes)


def test_patch_routes_drop_bm_routes_tunnel(self, setup_restapi_client):
_, _, _, restapi_client = setup_restapi_client
Expand Down Expand Up @@ -873,6 +934,12 @@ def test_vrf_routes_all_verbs(self, setup_restapi_client):
'ip_prefix':'60.1.2.0/24',
'ifname':'Ethernet8'})

routes.append({'cmd':'add',
'ip_prefix':'70.1.2.0/24',
'nexthop':'192.168.2.200,192.168.2.201,192.168.2.202',
'weight':'10,20',
'profile':'profile1'})


# Patch add
r = restapi_client.patch_config_vrf_vrf_id_routes("default", routes)
Expand Down

0 comments on commit 5cc4358

Please sign in to comment.