This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
/
flowsets.go
74 lines (62 loc) · 1.6 KB
/
flowsets.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
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2021 Intel Corporation
package flowsets
import (
flowapi "github.com/smart-edge-open/intel-ethernet-operator/pkg/flowconfig/rpc/v1/flow"
)
type FlowCreateRecord struct {
FlowID uint32
FlowRule *flowapi.RequestFlowCreate
}
func newFlowCreateRecord(id uint32, rule *flowapi.RequestFlowCreate) *FlowCreateRecord {
return &FlowCreateRecord{
FlowID: id,
FlowRule: rule,
}
}
type FlowSets struct {
data map[string]*FlowCreateRecord
}
func (s *FlowSets) Add(key string, id uint32, rule *flowapi.RequestFlowCreate) *FlowSets {
if s.data == nil {
s.data = make(map[string]*FlowCreateRecord)
}
if _, ok := s.data[key]; !ok {
s.data[key] = newFlowCreateRecord(id, rule)
}
return s
}
func (s *FlowSets) Delete(key string) {
delete(s.data, key)
}
func (s *FlowSets) Has(key string) bool {
_, ok := s.data[key]
return ok
}
func (s *FlowSets) Size() int {
return len(s.data)
}
// GetCompliments returns a list of flowRecords with keys that are not in the list of keys given in the parameter
// Calling GetCompliments() with empty key slice will return all items in the flowSets
func (s *FlowSets) GetCompliments(keys []string) map[string]*FlowCreateRecord {
flowRecs := make(map[string]*FlowCreateRecord)
for setKey := range s.data {
found := false
for _, k := range keys {
if setKey == k {
found = true
break
}
}
if !found {
flowRecs[setKey] = s.data[setKey]
}
}
return flowRecs
}
// newFlowSets return an instacne of FlowSets
func NewFlowSets() *FlowSets {
return &FlowSets{
data: map[string]*FlowCreateRecord{},
}
}