-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_semantics.go
125 lines (110 loc) · 4.5 KB
/
list_semantics.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
/*
Copyright 2023 Alexander Bartolomey ([email protected])
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.
*/
package ipfix
// ListSemantic is the type capturing the IANA-assigned list semantics as defined by RFC 6313
type ListSemantic uint8
const (
// The "noneOf" structured data type semantic specifies that none of the
// elements are actual properties of the Data Record.
//
// For example, a mediator might want to report to a Collector that a
// specific Flow is suspicious, but that it checked already that this
// Flow does not belong to the attack type 1, attack type 2, or attack
// type 3. So this Flow might need some further inspection. In such a
// case, the mediator would report the Flow Record with a basicList
// composed of (attack type 1, attack type 2, attack type 3) and the
// respective structured data type semantic of "noneOf".
SemanticNoneOf ListSemantic = 0
// The "exactlyOneOf" structured data type semantic specifies that only
// a single element from the structured data is an actual property of
// the Data Record. This is equivalent to a logical XOR operation.
SemanticExactlyOneOf ListSemantic = 1
// The "oneOrMoreOf" structured data type semantic specifies that one or
// more elements from the list in the structured data are actual
// properties of the Data Record. This is equivalent to a logical OR
// operation.
SemanticOneOrMoreOf ListSemantic = 2
// The "allOf" structured data type semantic specifies that all of the
// list elements from the structured data are actual properties of the
// Data Record.
//
// For example, if a Record contains a basicList of outgoing interfaces
// with the "allOf" semantic, then the observed Flow is typically a
// multicast Flow where each packet in the Flow has been replicated to
// each outgoing interface in the basicList.
SemanticAllOf ListSemantic = 3
// The "ordered" structured data type semantic specifies that elements
// from the list in the structured data are ordered.
//
// For example, an Exporter might want to export the AS10 AS20 AS30 AS40
// BGP AS-PATH. In such a case, the Exporter would report a basicList
// composed of (AS10, AS20, AS30, AS40) and the respective structured
// data type semantic of "ordered".
SemanticOrdered ListSemantic = 4
// The "undefined" structured data type semantic specifies that the
// semantic of list elements is not specified and that, if a semantic
// exists, then it is up to the Collecting Process to draw its own
// conclusions. The "undefined" structured data type semantic, which is
// the default value, is used when no other structured data type
// semantic applies.
// For example, a mediator that wants to translate IPFIX [RFC5101] into
// the export of structured data according to the specifications in this
// document doesn't know what the semantic is; it can only guess, as the
// IPFIX specifications [RFC5101] does not contain any semantic.
// Therefore, the mediator should use the "undefined" semantic.
SemanticUndefined ListSemantic = 255
)
func (s ListSemantic) String() string {
switch s {
case SemanticNoneOf:
return "noneOf"
case SemanticExactlyOneOf:
return "exactlyOneOf"
case SemanticOneOrMoreOf:
return "oneOrMoreOf"
case SemanticAllOf:
return "allOf"
case SemanticOrdered:
return "ordered"
case SemanticUndefined:
return "undefined"
default:
return "unassigned"
}
}
// MarshalText implements encoding.Marshaler to convert a ListSemantic
// instance into a string representation
func (s ListSemantic) MarshalText() ([]byte, error) {
return []byte(s.String()), nil
}
// UnmarshalText implements encoding.Unmarshaler to convert the string
// representation of a ListSemantic into its proper type
func (s *ListSemantic) UnmarshalText(in []byte) error {
st := string(in)
switch st {
case "noneOf":
*s = SemanticNoneOf
case "exactlyOneOf":
*s = SemanticExactlyOneOf
case "oneOrMoreOf":
*s = SemanticOneOrMoreOf
case "allOf":
*s = SemanticAllOf
case "ordered":
*s = SemanticOrdered
case "undefined":
*s = SemanticUndefined
default:
}
return nil
}