Skip to content

Commit 4151a95

Browse files
committed
Make MaxRoutes a struct
1 parent ceb50f2 commit 4151a95

File tree

4 files changed

+127
-17
lines changed

4 files changed

+127
-17
lines changed

go-server-server/go/default.go

+49-4
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,53 @@ func ConfigVrouterVrfIdGet(w http.ResponseWriter, r *http.Request) {
866866
WriteRequestError(w, http.StatusInternalServerError, "Internal service error, Non numeric vnid found in db", []string{}, "")
867867
return
868868
}
869-
870869
output := VnetReturnModel{
871870
VnetName: vars["vnet_name"],
872871
Attr: VnetModel{
873872
Vnid: vnid,
874-
Ipv4MaxRoutes: 0,
875873
},
876874
}
875+
var ipv4MaxRoutesNum int
876+
ipv4MaxRoutesNumStr, ok := kv["ipv4_max_routes_num"]
877+
if (ok) {
878+
ipv4MaxRoutesNum, err = strconv.Atoi(ipv4MaxRoutesNumStr)
879+
if err != nil {
880+
WriteRequestError(w, http.StatusInternalServerError, "Internal service error, Non numeric ipv4_max_routes_num found in db", []string{}, "")
881+
return
882+
}
883+
var ipv4MaxRoutesThreshold int
884+
ipv4MaxRoutesThresholdStr, ok := kv["ipv4_max_routes_threshold"]
885+
if (ok) {
886+
ipv4MaxRoutesThreshold, err = strconv.Atoi(ipv4MaxRoutesThresholdStr)
887+
if err != nil {
888+
WriteRequestError(w, http.StatusInternalServerError, "Internal service error, Non numeric ipv4_max_routes_threshold found in db", []string{}, "")
889+
return
890+
}
891+
}
892+
tmpIpv4MaxRoutes := MaxRoutesModel { ipv4MaxRoutesNum, ipv4MaxRoutesThreshold }
893+
output.Attr.Ipv4MaxRoutes = &tmpIpv4MaxRoutes
894+
}
895+
896+
var ipv6MaxRoutesNum int
897+
ipv6MaxRoutesNumStr, ok := kv["ipv6_max_routes_num"]
898+
if (ok) {
899+
ipv6MaxRoutesNum, err = strconv.Atoi(ipv6MaxRoutesNumStr)
900+
if err != nil {
901+
WriteRequestError(w, http.StatusInternalServerError, "Internal service error, Non numeric ipv6_max_routes_num found in db", []string{}, "")
902+
return
903+
}
904+
var ipv6MaxRoutesThreshold int
905+
ipv6MaxRoutesThresholdStr, ok := kv["ipv6_max_routes_threshold"]
906+
if (ok) {
907+
ipv6MaxRoutesThreshold, err = strconv.Atoi(ipv6MaxRoutesThresholdStr)
908+
if err != nil {
909+
WriteRequestError(w, http.StatusInternalServerError, "Internal service error, Non numeric ipv6_max_routes_threshold found in db", []string{}, "")
910+
return
911+
}
912+
}
913+
tmpIpv6MaxRoutes := MaxRoutesModel { ipv6MaxRoutesNum, ipv6MaxRoutesThreshold }
914+
output.Attr.Ipv6MaxRoutes = &tmpIpv6MaxRoutes
915+
}
877916

878917
WriteRequestResponse(w, output, http.StatusOK)
879918
}
@@ -935,8 +974,14 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {
935974
"vni": strconv.Itoa(attr.Vnid),
936975
"guid": vars["vnet_name"],
937976
}
938-
if (attr.Ipv4MaxRoutes != 0) {
939-
x["ipv4_max_routes"] = strconv.Itoa(attr.Ipv4MaxRoutes)
977+
978+
if (attr.Ipv4MaxRoutes != nil) {
979+
x["ipv4_max_routes_num"] = strconv.Itoa(attr.Ipv4MaxRoutes.Num)
980+
x["ipv4_max_routes_threshold"] = strconv.Itoa(attr.Ipv4MaxRoutes.Threshold)
981+
}
982+
if (attr.Ipv6MaxRoutes != nil) {
983+
x["ipv6_max_routes_num"] = strconv.Itoa(attr.Ipv6MaxRoutes.Num)
984+
x["ipv6_max_routes_threshold"] = strconv.Itoa(attr.Ipv6MaxRoutes.Threshold)
940985
}
941986
pt.Set(vnet_id_str, x, "SET", "")
942987

go-server-server/go/models.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55
"net"
66
"strconv"
7-
"fmt"
7+
"log"
88
)
99

1010
type HeartbeatReturnModel struct {
@@ -117,9 +117,15 @@ type TunnelDecapReturnModel struct {
117117
Attr TunnelDecapModel `json:"attr"`
118118
}
119119

120+
type MaxRoutesModel struct {
121+
Num int `json:"num"`
122+
Threshold int `json:"threshold"`
123+
}
124+
120125
type VnetModel struct {
121126
Vnid int `json:"vnid"`
122-
Ipv4MaxRoutes int `json:"ipv4_max_routes,omitempty"`
127+
Ipv4MaxRoutes *MaxRoutesModel `json:"ipv4_max_routes,omitempty"`
128+
Ipv6MaxRoutes *MaxRoutesModel `json:"ipv6_max_routes,omitempty"`
123129
}
124130

125131
type VnetReturnModel struct {
@@ -311,15 +317,17 @@ func (m *TunnelDecapModel) UnmarshalJSON(data []byte) (err error) {
311317
func (m *VnetModel) UnmarshalJSON(data []byte) (err error) {
312318
required := struct {
313319
Vnid *int `json:"vnid"`
314-
Ipv4MaxRoutes *int `json:"ipv4_max_routes,omitempty"`
320+
Ipv4MaxRoutes **MaxRoutesModel `json:"ipv4_max_routes,omitempty"`
321+
Ipv6MaxRoutes **MaxRoutesModel `json:"ipv6_max_routes,omitempty"`
315322
}{}
316-
317323
err = json.Unmarshal(data, &required)
318-
319324
if err != nil {
320325
return
321326
}
322-
327+
log.Printf(
328+
"debug: UnmarshalJSON: VnetModel: %v",
329+
required,
330+
)
323331
if required.Vnid == nil {
324332
err = &MissingValueError{"vnid"}
325333
return
@@ -332,7 +340,13 @@ func (m *VnetModel) UnmarshalJSON(data []byte) (err error) {
332340

333341
m.Vnid = *required.Vnid
334342
if required.Ipv4MaxRoutes != nil {
335-
m.Ipv4MaxRoutes = *required.Ipv4MaxRoutes
343+
tmp := MaxRoutesModel {(*(*required.Ipv4MaxRoutes)).Num, (*required.Ipv4MaxRoutes).Threshold}
344+
m.Ipv4MaxRoutes = &tmp
345+
}
346+
347+
if required.Ipv6MaxRoutes != nil {
348+
tmp := MaxRoutesModel {(*(*required.Ipv6MaxRoutes)).Num, (*required.Ipv6MaxRoutes).Threshold}
349+
m.Ipv6MaxRoutes = &tmp
336350
}
337351

338352
return

sonic_api.yaml

+13-4
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,15 @@ definitions:
13331333
ip_addr:
13341334
type: string
13351335
description: tunnel local termination IP address
1336+
MaxRoutesEntry:
1337+
type: object
1338+
properties:
1339+
num:
1340+
description: maximum routes which can advertised
1341+
type: integer
1342+
threshold:
1343+
description: after what threshold should a warning be generated (1-100)
1344+
type: integer
13361345
VnetEntry:
13371346
type: object
13381347
required:
@@ -1343,10 +1352,10 @@ definitions:
13431352
type: integer
13441353
format: int32
13451354
description: vnid
1346-
max_routes:
1347-
type: integer
1348-
format: int32
1349-
description: maximum routes per vrf
1355+
ipv4_max_routes:
1356+
$ref: '#/definitions/MaxRoutesEntry'
1357+
ipv6_max_routes:
1358+
$ref: '#/definitions/MaxRoutesEntry'
13501359
VlanEntry:
13511360
type: object
13521361
properties:

test/apitest.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,60 @@ def test_post_vrouter_with_max_routes(self):
449449
self.post_generic_vxlan_tunnel()
450450
r = self.post_config_vrouter_vrf_id("vnet-guid-1", {
451451
'vnid': 1001,
452-
'ipv4_max_routes': 1000
452+
'ipv4_max_routes': {
453+
'num': 1000,
454+
'threshold': 80,
455+
},
456+
'ipv6_max_routes': {
457+
'num': 2000,
458+
'threshold': 80,
459+
},
453460
})
454461
self.assertEqual(r.status_code, 204)
455462

456463
vrouter_table = self.configdb.hgetall(VNET_TB + '|' + VNET_NAME_PREF + '1')
457464
self.assertEqual(vrouter_table, {
458465
b'vxlan_tunnel': b'default_vxlan_tunnel',
459466
b'vni': b'1001',
460-
b'ipv4_max_routes': b'1000',
467+
b'ipv4_max_routes_num': b'1000',
468+
b'ipv4_max_routes_threshold': b'80',
469+
b'ipv6_max_routes_num': b'2000',
470+
b'ipv6_max_routes_threshold': b'80',
461471
b'guid': b'vnet-guid-1'
462472
})
463473

474+
def test_get_vrouter_with_max_routes(self):
475+
self.post_generic_vxlan_tunnel()
476+
r = self.post_config_vrouter_vrf_id("vnet-guid-1", {
477+
'vnid': 1001,
478+
'ipv4_max_routes': {
479+
'num': 1000,
480+
'threshold': 80,
481+
},
482+
'ipv6_max_routes': {
483+
'num': 2000,
484+
'threshold': 80,
485+
},
486+
})
487+
self.assertEqual(r.status_code, 204)
488+
r = self.get_config_vrouter_vrf_id("vnet-guid-1")
489+
self.assertEqual(r.status_code, 200)
490+
j = json.loads(r.text)
491+
self.assertEqual(j, {
492+
'vnet_id': "vnet-guid-1",
493+
'attr': {
494+
'vnid': 1001,
495+
'ipv4_max_routes': {
496+
'num': 1000,
497+
'threshold': 80,
498+
},
499+
'ipv6_max_routes': {
500+
'num': 2000,
501+
'threshold': 80,
502+
},
503+
}
504+
})
505+
464506
# Vlan
465507
def test_vlan_wo_ippref_vnetid_all_verbs(self):
466508
# post

0 commit comments

Comments
 (0)