Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Oct 12, 2023
1 parent b9ca5d7 commit 9e6c24d
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions pkg/selectors/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ type KernelLPMTrieStringPostfix struct {
data [StringPostfixMaxLength]byte
}

var gStringMaps StringMapLists
var gStringPrefixMaps []map[KernelLPMTrieStringPrefix]struct{}
var gStringPostfixMaps []map[KernelLPMTrieStringPostfix]struct{}
type KernelSelectorMaps struct {
// stringMaps are used to populate string and char buf matches
StringMaps StringMapLists
// stringPrefixMaps are used to populate string and char buf prefix matches
StringPrefixMaps []map[KernelLPMTrieStringPrefix]struct{}
// stringPostfixMaps are used to populate string and char buf postfix matches
StringPostfixMaps []map[KernelLPMTrieStringPostfix]struct{}
}

var gMaps *KernelSelectorMaps

type KernelSelectorState struct {
off uint32 // offset into encoding
Expand All @@ -96,30 +103,19 @@ type KernelSelectorState struct {
newBinVals map[uint32]string // these should be added in the names_map

listReader ValueReader
// stringMaps are used to populate string and char buf matches
stringMaps *StringMapLists

// stringPrefixMaps are used to populate string and char buf prefix matches
stringPrefixMaps *[]map[KernelLPMTrieStringPrefix]struct{}
// stringPostfixMaps are used to populate string and char buf postfix matches
stringPostfixMaps *[]map[KernelLPMTrieStringPostfix]struct{}
maps *KernelSelectorMaps
}

func NewKernelSelectorState(listReader ValueReader, newMaps bool) *KernelSelectorState {
if newMaps {
for i := 0; i < StringMapsNumSubMaps; i++ {
gStringMaps[i] = nil
}
gStringPrefixMaps = nil
gStringPostfixMaps = nil
gMaps = &KernelSelectorMaps{}
}
return &KernelSelectorState{
matchBinaries: make(map[int]*MatchBinariesMappings),
newBinVals: make(map[uint32]string),
listReader: listReader,
stringMaps: &gStringMaps,
stringPrefixMaps: &gStringPrefixMaps,
stringPostfixMaps: &gStringPostfixMaps,
matchBinaries: make(map[int]*MatchBinariesMappings),
newBinVals: make(map[uint32]string),
listReader: listReader,
maps: gMaps,
}
}

Expand Down Expand Up @@ -179,15 +175,15 @@ func (k *KernelSelectorState) Addr6Maps() []map[KernelLPMTrie6]struct{} {
}

func (k *KernelSelectorState) StringMaps(subMap int) []map[[MaxStringMapsSize]byte]struct{} {
return k.stringMaps[subMap]
return k.maps.StringMaps[subMap]
}

func (k *KernelSelectorState) StringPrefixMaps() []map[KernelLPMTrieStringPrefix]struct{} {
return *k.stringPrefixMaps
return k.maps.StringPrefixMaps
}

func (k *KernelSelectorState) StringPostfixMaps() []map[KernelLPMTrieStringPostfix]struct{} {
return *k.stringPostfixMaps
return k.maps.StringPostfixMaps
}

// ValueMapsMaxEntries returns the maximum entries over all maps
Expand Down Expand Up @@ -226,7 +222,7 @@ func (k *KernelSelectorState) Addr6MapsMaxEntries() int {
// StringMapsMaxEntries returns the maximum entries over all maps inside a particular map of map
func (k *KernelSelectorState) StringMapsMaxEntries(subMap int) int {
maxEntries := 1
for _, vm := range k.stringMaps[subMap] {
for _, vm := range k.maps.StringMaps[subMap] {
if l := len(vm); l > maxEntries {
maxEntries = l
}
Expand All @@ -237,7 +233,7 @@ func (k *KernelSelectorState) StringMapsMaxEntries(subMap int) int {
// StringPrefixMapsMaxEntries returns the maximum entries over all maps
func (k *KernelSelectorState) StringPrefixMapsMaxEntries() int {
maxEntries := 1
for _, vm := range *k.stringPrefixMaps {
for _, vm := range k.maps.StringPrefixMaps {
if l := len(vm); l > maxEntries {
maxEntries = l
}
Expand All @@ -248,7 +244,7 @@ func (k *KernelSelectorState) StringPrefixMapsMaxEntries() int {
// StringPostfixMapsMaxEntries returns the maximum entries over all maps
func (k *KernelSelectorState) StringPostfixMapsMaxEntries() int {
maxEntries := 1
for _, vm := range *k.stringPostfixMaps {
for _, vm := range k.maps.StringPostfixMaps {
if l := len(vm); l > maxEntries {
maxEntries = l
}
Expand Down Expand Up @@ -416,8 +412,8 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S

for subMap := 0; subMap < StringMapsNumSubMaps; subMap++ {
if len(stringMaps[subMap]) > 0 {
mapid = uint32(len(gStringMaps[subMap]))
gStringMaps[subMap] = append(gStringMaps[subMap], stringMaps[subMap])
mapid = uint32(len(k.maps.StringMaps[subMap]))
k.maps.StringMaps[subMap] = append(k.maps.StringMaps[subMap], stringMaps[subMap])
} else {
mapid = 0xffffffff
}
Expand All @@ -428,13 +424,13 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S
}

func (k *KernelSelectorState) newStringPrefixMap() (uint32, map[KernelLPMTrieStringPrefix]struct{}) {
mapid := len(gStringPrefixMaps)
gStringPrefixMaps = append(gStringPrefixMaps, map[KernelLPMTrieStringPrefix]struct{}{})
return uint32(mapid), gStringPrefixMaps[mapid]
mapid := len(k.maps.StringPrefixMaps)
k.maps.StringPrefixMaps = append(k.maps.StringPrefixMaps, map[KernelLPMTrieStringPrefix]struct{}{})
return uint32(mapid), k.maps.StringPrefixMaps[mapid]
}

func (k *KernelSelectorState) newStringPostfixMap() (uint32, map[KernelLPMTrieStringPostfix]struct{}) {
mapid := len(gStringPostfixMaps)
gStringPostfixMaps = append(gStringPostfixMaps, map[KernelLPMTrieStringPostfix]struct{}{})
return uint32(mapid), gStringPostfixMaps[mapid]
mapid := len(k.maps.StringPostfixMaps)
k.maps.StringPostfixMaps = append(k.maps.StringPostfixMaps, map[KernelLPMTrieStringPostfix]struct{}{})
return uint32(mapid), k.maps.StringPostfixMaps[mapid]
}

0 comments on commit 9e6c24d

Please sign in to comment.