/
validate.go
101 lines (85 loc) · 2.96 KB
/
validate.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2017 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// These are validation routines intended to verify correctness of the config
// individual fields.
package core
import (
"fmt"
"github.com/ligato/sfc-controller/controller/model/controller"
)
func (sfcCtrlPlugin *SfcControllerPluginHandler) validateRamCache() error {
for _, ee := range sfcCtrlPlugin.ramConfigCache.EEs {
if err := sfcCtrlPlugin.validateEE(&ee); err != nil {
return err
}
}
for _, he := range sfcCtrlPlugin.ramConfigCache.HEs {
if err := sfcCtrlPlugin.validateHE(&he); err != nil {
return err
}
}
for _, sfc := range sfcCtrlPlugin.ramConfigCache.SFCs {
if err := sfcCtrlPlugin.validateSFC(&sfc); err != nil {
return err
}
}
return nil
}
// validate the External Router, TODO: perform better/complete validation
func (sfcCtrlPlugin *SfcControllerPluginHandler) validateEE(ee *controller.ExternalEntity) error {
if ee.Name == "" {
err := fmt.Errorf("Missing entity name")
return err
} else if ee.MgmntIpAddress == "" { //|| !validIpAddress(ee.MgmntIpAddress) {
err := fmt.Errorf("Invalid mgmt_ip_address: '%s'", ee.MgmntIpAddress)
return err
}
return nil
}
// validate the Host Entity, TODO: perform better/complete validation
func (sfcCtrlPlugin *SfcControllerPluginHandler) validateHE(he *controller.HostEntity) error {
if he.Name == "" {
err := fmt.Errorf("Missing entity name")
return err
}
return nil
}
// validate the SFC, TODO: perform better/complete validation
func (sfcCtrlPlugin *SfcControllerPluginHandler) validateSFC(sfc *controller.SfcEntity) error {
if sfc.Name == "" {
err := fmt.Errorf("Missing entity name")
return err
}
numSfcElements := len(sfc.GetElements())
if numSfcElements <= 0 {
return nil
}
log.Debugf("validateSFC: sfc=", sfc)
//for i, sfcChainElement := range sfc.GetElements() {
// log.Debugf("validateSFC: sfc_chain_element[%d]=", i, sfcChainElement)
// if sfcChainElement.Type == controller.SfcElementType_EXTERNAL_ENTITY {
// if i > 0 && i < numSfcElements-1 {
// err := fmt.Errorf("External entity cannot be inside the chain: i='%d', sfcElement:'%s'",
// i, sfcChainElement.Container)
// return err
// }
// if _, exists := sfcCtrlPlugin.ramConfigCache.EEs[sfcChainElement.Container]; !exists {
// err := fmt.Errorf("External entity in chain does not exist, chain: i='%d', sfcElement:'%s'",
// i, sfcChainElement.Container)
// return err
// }
// }
//}
return nil
}