forked from Juniper/contrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgpaa_service_parameters_type.go
35 lines (28 loc) · 1.05 KB
/
bgpaa_service_parameters_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package models
import (
"math"
"github.com/pkg/errors"
)
// BGP constants.
const (
DefaultPortRangeStart = 50000
DefaultPortRangeEnd = 50512
)
// ValidatePortRange checks if ports specified are valid and if start < end.
func (ports *BGPaaServiceParametersType) ValidatePortRange() error {
if (ports.PortStart > ports.PortEnd) || (ports.PortStart <= 0) || (ports.PortEnd > math.MaxUint16) {
return errors.Errorf("Invalid Port range specified (%d : %d)", ports.PortStart, ports.PortEnd)
}
return nil
}
// GetDefaultBGPaaServiceParameters creates BGPaaService parameters with a default port range.
func GetDefaultBGPaaServiceParameters() *BGPaaServiceParametersType {
return &BGPaaServiceParametersType{PortStart: DefaultPortRangeStart, PortEnd: DefaultPortRangeEnd}
}
// EnclosesRange checks if port range includes the other one.
func (ports *BGPaaServiceParametersType) EnclosesRange(other *BGPaaServiceParametersType) bool {
if ports != nil && other != nil {
return ports.PortStart <= other.PortStart && ports.PortEnd >= other.PortEnd
}
return false
}