/
graphedge.go
169 lines (124 loc) · 5.55 KB
/
graphedge.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package gaia
import (
"fmt"
"github.com/mitchellh/copystructure"
"go.aporeto.io/elemental"
)
// GraphEdgeDestinationTypeValue represents the possible values for attribute "destinationType".
type GraphEdgeDestinationTypeValue string
const (
// GraphEdgeDestinationTypeExternalNetwork represents the value ExternalNetwork.
GraphEdgeDestinationTypeExternalNetwork GraphEdgeDestinationTypeValue = "ExternalNetwork"
// GraphEdgeDestinationTypeNode represents the value Node.
GraphEdgeDestinationTypeNode GraphEdgeDestinationTypeValue = "Node"
// GraphEdgeDestinationTypeProcessingUnit represents the value ProcessingUnit.
GraphEdgeDestinationTypeProcessingUnit GraphEdgeDestinationTypeValue = "ProcessingUnit"
)
// GraphEdgeSourceTypeValue represents the possible values for attribute "sourceType".
type GraphEdgeSourceTypeValue string
const (
// GraphEdgeSourceTypeExternalNetwork represents the value ExternalNetwork.
GraphEdgeSourceTypeExternalNetwork GraphEdgeSourceTypeValue = "ExternalNetwork"
// GraphEdgeSourceTypeNode represents the value Node.
GraphEdgeSourceTypeNode GraphEdgeSourceTypeValue = "Node"
// GraphEdgeSourceTypeProcessingUnit represents the value ProcessingUnit.
GraphEdgeSourceTypeProcessingUnit GraphEdgeSourceTypeValue = "ProcessingUnit"
)
// GraphEdge represents the model of a graphedge
type GraphEdge struct {
// Identifier of the edge.
ID string `json:"ID" msgpack:"ID" bson:"-" mapstructure:"ID,omitempty"`
// Number of accepted flows in the edge.
AcceptedFlows int `json:"acceptedFlows" msgpack:"acceptedFlows" bson:"-" mapstructure:"acceptedFlows,omitempty"`
// ID of the destination `GraphNode` of the edge.
DestinationID string `json:"destinationID" msgpack:"destinationID" bson:"-" mapstructure:"destinationID,omitempty"`
// Type of the destination `GraphNode` of the edge.
DestinationType GraphEdgeDestinationTypeValue `json:"destinationType" msgpack:"destinationType" bson:"-" mapstructure:"destinationType,omitempty"`
// The number of encrypted flows in the edge.
Encrypted int `json:"encrypted" msgpack:"encrypted" bson:"-" mapstructure:"encrypted,omitempty"`
// Number of accepted observed flows.
ObservedAcceptedFlows int `json:"observedAcceptedFlows" msgpack:"observedAcceptedFlows" bson:"-" mapstructure:"observedAcceptedFlows,omitempty"`
// Number of encrypted observed flows.
ObservedEncrypted int `json:"observedEncrypted" msgpack:"observedEncrypted" bson:"-" mapstructure:"observedEncrypted,omitempty"`
// Information about the observed policies that were hit in the flows
// represented by the edge.
ObservedPolicyIDs map[string]*GraphPolicyInfo `json:"observedPolicyIDs" msgpack:"observedPolicyIDs" bson:"-" mapstructure:"observedPolicyIDs,omitempty"`
// Number of rejected observed flows.
ObservedRejectedFlows int `json:"observedRejectedFlows" msgpack:"observedRejectedFlows" bson:"-" mapstructure:"observedRejectedFlows,omitempty"`
// Map of ints.
ObservedServiceIDs map[string]int `json:"observedServiceIDs" msgpack:"observedServiceIDs" bson:"-" mapstructure:"observedServiceIDs,omitempty"`
// Information about the policies that were hit in the flows represented by the
// edge.
PolicyIDs map[string]*GraphPolicyInfo `json:"policyIDs" msgpack:"policyIDs" bson:"-" mapstructure:"policyIDs,omitempty"`
// Number of rejected flows in the edge.
RejectedFlows int `json:"rejectedFlows" msgpack:"rejectedFlows" bson:"-" mapstructure:"rejectedFlows,omitempty"`
// ID of the source `GraphNode` of the edge.
SourceID string `json:"sourceID" msgpack:"sourceID" bson:"-" mapstructure:"sourceID,omitempty"`
// Type of the source `GraphNode` of the edge.
SourceType GraphEdgeSourceTypeValue `json:"sourceType" msgpack:"sourceType" bson:"-" mapstructure:"sourceType,omitempty"`
ModelVersion int `json:"-" msgpack:"-" bson:"_modelversion"`
}
// NewGraphEdge returns a new *GraphEdge
func NewGraphEdge() *GraphEdge {
return &GraphEdge{
ModelVersion: 1,
ObservedPolicyIDs: map[string]*GraphPolicyInfo{},
ObservedServiceIDs: map[string]int{},
PolicyIDs: map[string]*GraphPolicyInfo{},
}
}
// BleveType implements the bleve.Classifier Interface.
func (o *GraphEdge) BleveType() string {
return "graphedge"
}
// DeepCopy returns a deep copy if the GraphEdge.
func (o *GraphEdge) DeepCopy() *GraphEdge {
if o == nil {
return nil
}
out := &GraphEdge{}
o.DeepCopyInto(out)
return out
}
// DeepCopyInto copies the receiver into the given *GraphEdge.
func (o *GraphEdge) DeepCopyInto(out *GraphEdge) {
target, err := copystructure.Copy(o)
if err != nil {
panic(fmt.Sprintf("Unable to deepcopy GraphEdge: %s", err))
}
*out = *target.(*GraphEdge)
}
// Validate valides the current information stored into the structure.
func (o *GraphEdge) Validate() error {
errors := elemental.Errors{}
requiredErrors := elemental.Errors{}
if err := elemental.ValidateStringInList("destinationType", string(o.DestinationType), []string{"ProcessingUnit", "ExternalNetwork", "Node"}, false); err != nil {
errors = errors.Append(err)
}
for _, sub := range o.ObservedPolicyIDs {
if sub == nil {
continue
}
if err := sub.Validate(); err != nil {
errors = errors.Append(err)
}
}
for _, sub := range o.PolicyIDs {
if sub == nil {
continue
}
if err := sub.Validate(); err != nil {
errors = errors.Append(err)
}
}
if err := elemental.ValidateStringInList("sourceType", string(o.SourceType), []string{"ProcessingUnit", "ExternalNetwork", "Node"}, false); err != nil {
errors = errors.Append(err)
}
if len(requiredErrors) > 0 {
return requiredErrors
}
if len(errors) > 0 {
return errors
}
return nil
}