forked from sonic-net/sonic-mgmt-framework
-
Notifications
You must be signed in to change notification settings - Fork 15
/
sonic_sflow.go
40 lines (33 loc) · 1.08 KB
/
sonic_sflow.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
36
37
38
39
package custom_validation
import (
"net"
util "cvl/internal/util"
)
//Validate ip address of sflow collector ip
func (t *CustomValidation) ValidateCollectorIp(vc *CustValidationCtxt) CVLErrorInfo {
if (vc.CurCfg.VOp == OP_DELETE) {
return CVLErrorInfo{ErrCode: CVL_SUCCESS}
}
ip := net.ParseIP(vc.YNodeVal)
if ip == nil {
errStr:= "Sflow collector IP is not valid"
util.CVL_LEVEL_LOG(util.ERROR,"%s",errStr)
return CVLErrorInfo{
ErrCode: CVL_SYNTAX_INVALID_INPUT_DATA,
TableName: "SFLOW_COLLECTOR",
CVLErrDetails : errStr,
ConstraintErrMsg : errStr,
}
}
if ip.IsUnspecified() || ip.Equal(net.IPv4bcast) || ip.IsMulticast() {
errStr:= "Sflow collector IP is not valid, IP is either reserved, unspecified, or broadcast"
util.CVL_LEVEL_LOG(util.ERROR,"%s",errStr)
return CVLErrorInfo{
ErrCode: CVL_SYNTAX_INVALID_INPUT_DATA,
TableName: "SFLOW_COLLECTOR",
CVLErrDetails : errStr,
ConstraintErrMsg : errStr,
}
}
return CVLErrorInfo{ErrCode: CVL_SUCCESS}
}