Skip to content

Commit c093efd

Browse files
authored
chore: improve bandwidth (#202)
1 parent 2463a2c commit c093efd

File tree

4 files changed

+72
-41
lines changed

4 files changed

+72
-41
lines changed

.changelog/202.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
`edgegateway` - Add array var of supported bandwidth values depending on the service class of the Tier0.
3+
```

v1/cloudavenue_t0.go

+33-20
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,33 @@ type (
3636
)
3737

3838
const (
39-
// ClassServiceVRFStandard - VRF Standard.
40-
ClassServiceVRFStandard ClassService = "VRF_STANDARD"
41-
// ClassServiceVRFPremium - VRF Premium.
42-
ClassServiceVRFPremium ClassService = "VRF_PREMIUM"
43-
// ClassServiceVRFDedicatedMedium - VRF Dedicated Medium.
44-
ClassServiceVRFDedicatedMedium ClassService = "VRF_DEDICATED_MEDIUM"
45-
// ClassServiceVRFDedicatedLarge - VRF Dedicated Large.
46-
ClassServiceVRFDedicatedLarge ClassService = "VRF_DEDICATED_LARGE"
39+
// TOClassServiceVRFStandard - VRF Standard.
40+
T0ClassServiceVRFStandard ClassService = "VRF_STANDARD"
41+
// T0ClassServiceVRFPremium - VRF Premium.
42+
T0ClassServiceVRFPremium ClassService = "VRF_PREMIUM"
43+
// T0ClassServiceVRFDedicatedMedium - VRF Dedicated Medium.
44+
T0ClassServiceVRFDedicatedMedium ClassService = "VRF_DEDICATED_MEDIUM"
45+
// T0ClassServiceVRFDedicatedLarge - VRF Dedicated Large.
46+
T0ClassServiceVRFDedicatedLarge ClassService = "VRF_DEDICATED_LARGE"
4747
)
4848

49+
var T0ClassesServices = map[ClassService]struct {
50+
TotalBandwidth int
51+
}{
52+
T0ClassServiceVRFStandard: {
53+
TotalBandwidth: 300,
54+
},
55+
T0ClassServiceVRFPremium: {
56+
TotalBandwidth: 1000,
57+
},
58+
T0ClassServiceVRFDedicatedMedium: {
59+
TotalBandwidth: 3500,
60+
},
61+
T0ClassServiceVRFDedicatedLarge: {
62+
TotalBandwidth: 10000,
63+
},
64+
}
65+
4966
// * T0
5067

5168
// GetTier0ClassService - Returns the Tier0ClassService.
@@ -94,22 +111,22 @@ func (t *T0Service) GetVLANID() any {
94111

95112
// IsVRFStandard - Returns true if the ClassService is VRFStandard.
96113
func (c ClassService) IsVRFStandard() bool {
97-
return c == ClassServiceVRFStandard
114+
return c == T0ClassServiceVRFStandard
98115
}
99116

100117
// IsVRFPremium - Returns true if the ClassService is VRFPremium.
101118
func (c ClassService) IsVRFPremium() bool {
102-
return c == ClassServiceVRFPremium
119+
return c == T0ClassServiceVRFPremium
103120
}
104121

105122
// IsVRFDedicatedMedium - Returns true if the ClassService is VRFDedicatedMedium.
106123
func (c ClassService) IsVRFDedicatedMedium() bool {
107-
return c == ClassServiceVRFDedicatedMedium
124+
return c == T0ClassServiceVRFDedicatedMedium
108125
}
109126

110127
// IsVRFDedicatedLarge - Returns true if the ClassService is VRFDedicatedLarge.
111128
func (c ClassService) IsVRFDedicatedLarge() bool {
112-
return c == ClassServiceVRFDedicatedLarge
129+
return c == T0ClassServiceVRFDedicatedLarge
113130
}
114131

115132
// * List
@@ -172,13 +189,9 @@ func (t *Tier0) GetT0(t0 string) (response *T0, err error) {
172189

173190
// GetBandwidthCapacity - Returns the Bandwidth Capacity of the T0 in Mbps.
174191
func (t *T0) GetBandwidthCapacity() (bandwidthCapacity int, err error) {
175-
switch t.GetClassService() {
176-
case ClassServiceVRFStandard:
177-
bandwidthCapacity = 300
178-
case ClassServiceVRFPremium:
179-
bandwidthCapacity = 1000
180-
default:
181-
err = fmt.Errorf("unknown class service: %s", t.GetClassService())
192+
if v, ok := T0ClassesServices[t.GetClassService()]; ok {
193+
return v.TotalBandwidth, nil
182194
}
183-
return
195+
196+
return 0, fmt.Errorf("unknown class service: %s", t.GetClassService())
184197
}

v1/edgegw.go

+5-20
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
type (
2727
EdgeGateway struct{}
28-
Bandwidth int
2928
OwnerType string
3029
)
3130

@@ -71,32 +70,18 @@ func (v *EdgeGateway) List() (response *EdgeGateways, err error) {
7170
return r.Result().(*EdgeGateways), nil
7271
}
7372

74-
var (
75-
allowedRateLimitVRFStandard = []int{5, 25, 50, 75, 100, 150, 200, 250, 300} // 5, 25, 50, 75, 100, 150, 200, 250, 300
76-
allowedRateLimitVRFPremium = append(allowedRateLimitVRFStandard, []int{400, 500, 600, 700, 800, 900, 1000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000
77-
allowedRateLimitVRFDedicatedMedium = append(allowedRateLimitVRFPremium, []int{2000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000
78-
allowedRateLimitVRFDedicatedLarge = append(allowedRateLimitVRFDedicatedMedium, []int{3000, 4000, 5000, 6000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000
79-
)
80-
8173
// GetAllowedBandwidthValues - Returns the allowed rate limit value.
8274
func (v *EdgeGateway) GetAllowedBandwidthValues(t0VrfName string) (allowedValues []int, err error) {
8375
t0, err := (&Tier0{}).GetT0(t0VrfName)
8476
if err != nil {
8577
return
8678
}
8779

88-
switch t0.GetClassService() {
89-
case ClassServiceVRFPremium:
90-
allowedValues = allowedRateLimitVRFPremium
91-
case ClassServiceVRFStandard:
92-
allowedValues = allowedRateLimitVRFStandard
93-
case ClassServiceVRFDedicatedMedium:
94-
allowedValues = allowedRateLimitVRFDedicatedMedium
95-
case ClassServiceVRFDedicatedLarge:
96-
allowedValues = allowedRateLimitVRFDedicatedLarge
80+
if v, ok := EdgeGatewayAllowedBandwidth[t0.GetClassService()]; ok {
81+
return v.T1AllowedBandwidth, nil
9782
}
9883

99-
return
84+
return nil, fmt.Errorf("failed to get allowed bandwidth values. The service class %s does not exist", t0.GetClassService())
10085
}
10186

10287
// GetBandwidthCapacityRemaining - Returns the bandwidth capacity remaining in Mbps.
@@ -113,7 +98,7 @@ func (e *EdgeGateways) GetBandwidthCapacityRemaining(t0VrfName string) (response
11398

11499
for _, edgeGateway := range *e {
115100
if edgeGateway.GetT0() == t0VrfName {
116-
t0BandwidthCapacity -= int(edgeGateway.GetBandwidth())
101+
t0BandwidthCapacity -= edgeGateway.GetBandwidth()
117102
}
118103
}
119104

@@ -292,7 +277,7 @@ func (e *EdgeGatewayType) Delete() (job *commoncloudavenue.JobStatus, err error)
292277
// * Bandwidth
293278

294279
// GetBandwidth - Returns the rate limit.
295-
func (e *EdgeGatewayType) GetBandwidth() Bandwidth {
280+
func (e *EdgeGatewayType) GetBandwidth() int {
296281
return e.Bandwidth
297282
}
298283

v1/edgegw_types.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type (
2828
OwnerType OwnerType `json:"ownerType"`
2929
OwnerName string `json:"ownerName"`
3030
Description string `json:"description"`
31-
Bandwidth Bandwidth `json:"rateLimit"`
31+
Bandwidth int `json:"rateLimit"`
3232
}
3333

3434
EdgeClient struct {
@@ -45,6 +45,36 @@ type (
4545
}
4646
)
4747

48+
var (
49+
// Source : https://wiki.cloudavenue.orange-business.com/wiki/Network
50+
EdgeGatewayAllowedBandwidth = map[ClassService]struct {
51+
T0TotalBandwidth int
52+
T1AllowedBandwidth []int
53+
}{
54+
T0ClassServiceVRFStandard: {
55+
T0TotalBandwidth: T0ClassesServices[T0ClassServiceVRFStandard].TotalBandwidth,
56+
T1AllowedBandwidth: allowedBandwidthVRFStandard,
57+
},
58+
T0ClassServiceVRFPremium: {
59+
T0TotalBandwidth: T0ClassesServices[T0ClassServiceVRFPremium].TotalBandwidth,
60+
T1AllowedBandwidth: allowedBandwidthVRFPremium,
61+
},
62+
T0ClassServiceVRFDedicatedMedium: {
63+
T0TotalBandwidth: T0ClassesServices[T0ClassServiceVRFDedicatedMedium].TotalBandwidth,
64+
T1AllowedBandwidth: allowedBandwidthVRFDedicatedMedium,
65+
},
66+
T0ClassServiceVRFDedicatedLarge: {
67+
T0TotalBandwidth: T0ClassesServices[T0ClassServiceVRFDedicatedLarge].TotalBandwidth,
68+
T1AllowedBandwidth: allowedBandwidthVRFDedicatedLarge,
69+
},
70+
}
71+
72+
allowedBandwidthVRFStandard = []int{5, 25, 50, 75, 100, 150, 200, 250, 300} // 5, 25, 50, 75, 100, 150, 200, 250, 300
73+
allowedBandwidthVRFPremium = append(allowedBandwidthVRFStandard, []int{400, 500, 600, 700, 800, 900, 1000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000
74+
allowedBandwidthVRFDedicatedMedium = append(allowedBandwidthVRFPremium, []int{2000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000
75+
allowedBandwidthVRFDedicatedLarge = append(allowedBandwidthVRFDedicatedMedium, []int{3000, 4000, 5000, 6000}...) // 5, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000
76+
)
77+
4878
// * Getters
4979

5080
// GetTier0VrfID - Returns the Tier0VrfID.

0 commit comments

Comments
 (0)