filtering

package
v0.0.0-...-451c034 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ByteLength defines a bit length of one byte
	ByteLength = 8
)

Variables

View Source
var AvailableEngines = Engines{
	"List":         NewList,
	"PatriciaTrie": NewPatriciaTrie,
	"SplayTree":    NewSplayTree,
	"LegacyEngine": NewLegacyEngine,
}

AvailableEngines is a map of EngineConstructor with the engine's names as keys

Functions

This section is empty.

Types

type ByteSubscriptions

type ByteSubscriptions map[string]*PartialSubscription

ByteSubscriptions contains filter string as key and PartialSubscription as value

func (ByteSubscriptions) Dump

func (bsub ByteSubscriptions) Dump() string

Dump retuns a string representation of the ByteSubscriptions

func (ByteSubscriptions) Keys

func (bsub ByteSubscriptions) Keys() []string

Keys return a slice of keys in m

type ChildFilters

type ChildFilters map[string]*FilterObject

ChildFilters contains processed filters in map with its original filter as a key

type Composition

type Composition struct {
	// contains filtered or unexported fields
}

Composition contains list of composite filters and its origins

func NewComposition

func NewComposition(filters []*FilterObject) *Composition

NewComposition constructs Composition

type Engine

type Engine interface {
	AddSubscription(Subscriptions)
	DeleteSubscription(Subscriptions)
	Dump() string
	MarshalBinary() ([]byte, error)
	Name() string
	Search(llrp.ReadEvent) (string, []string, error) // pureIdentity, reportURIs, err
	UnmarshalBinary([]byte) error
}

Engine provides interface for the filtering engines

func NewLegacyEngine

func NewLegacyEngine(sub Subscriptions) Engine

NewLegacyEngine builds a LegacyEngine

func NewList

func NewList(sub Subscriptions) Engine

NewList builds a simple list of filters from filter.ByteSubscriptions returns the pointer to the slice of ExactMatch struct

func NewPatriciaTrie

func NewPatriciaTrie(sub Subscriptions) Engine

NewPatriciaTrie builds PatriciaTrie from filter.ByteSubscriptions returns the pointer to the node

func NewSplayTree

func NewSplayTree(sub Subscriptions) Engine

NewSplayTree builds SplayTree from ByteSubscriptions returns the pointer to the node node

type EngineConstructor

type EngineConstructor func(Subscriptions) Engine

EngineConstructor is a function signature for engine constructors

type EngineFactory

type EngineFactory struct {
	// contains filtered or unexported fields
}

EngineFactory manages the FC's subscriptions and engine instances

func NewEngineFactory

func NewEngineFactory(sub Subscriptions, statInterval int, mc chan ManagementMessage) *EngineFactory

NewEngineFactory returns the pointer to a new EngineFactory instance

func (*EngineFactory) IsActive

func (ef *EngineFactory) IsActive() bool

IsActive returns false if no engine is available

func (*EngineFactory) Run

func (ef *EngineFactory) Run()

Run starts the engine factory to react with the ManagementChannel

func (*EngineFactory) Search

func (ef *EngineFactory) Search(re llrp.ReadEvent) (string, []string, error)

Search is a wrapper for Search() with the current EngineGenerator

type EngineGenerator

type EngineGenerator struct {
	FSM    *fsm.FSM
	Name   string
	Engine Engine

	CurrentThroughput float64
	EventCount        int64
	MatchedCount      int64
	// contains filtered or unexported fields
}

EngineGenerator produce an engine according to the FSM

func NewEngineGenerator

func NewEngineGenerator(name string, ec EngineConstructor, statInterval int, mc chan ManagementMessage) *EngineGenerator

NewEngineGenerator returns the pointer to a new EngineGenerator instance

func (*EngineGenerator) Search

func (eg *EngineGenerator) Search(re llrp.ReadEvent) (string, []string, error)

Search do search in the generated engine

type Engines

type Engines map[string]EngineConstructor

Engines is a map of Engne's name and its constructor

type ExactMatch

type ExactMatch struct {
	// contains filtered or unexported fields
}

ExactMatch is a raw filter directly taken from ByteSubscriptions

type FilterObject

type FilterObject struct {
	String     string // the string representation of the binary filter
	Size       int    // the bit length of the filter
	Offset     int    // the bit offset from the begginng of the entire filter
	ByteFilter []byte // the actual byte slice for the filter
	ByteMask   []byte // the corresponding byte mask for ByteFilter
	ByteOffset int    // the byte offset from the beggining of the entire filter
	ByteSize   int    // the size of ByteFilter
}

FilterObject type is a struct for filter element

func NewFilter

func NewFilter(s string, o int) *FilterObject

NewFilter constructs FilterObject

func (*FilterObject) GetByteAt

func (f *FilterObject) GetByteAt(bo int) (byte, byte, error)

GetByteAt returns a byte of ByteFilter and ByteMask at the given offset, returns error if HasByteAt(bo) is false

func (*FilterObject) HasByteAt

func (f *FilterObject) HasByteAt(bo int) bool

HasByteAt returns true if the ByteFilter covers a byte starting with the given offset

func (*FilterObject) IsTransparent

func (f *FilterObject) IsTransparent() bool

IsTransparent returns true if the filter is meaningless = any id will match with this filter

func (*FilterObject) Match

func (f *FilterObject) Match(id []byte) bool

Match returns true if the id is captured by this filter

func (*FilterObject) ToString

func (f *FilterObject) ToString() string

ToString returns a string representation of FilterObject

type LegacyEngine

type LegacyEngine struct {
	// contains filtered or unexported fields
}

LegacyEngine is a engine based-on text match

func (*LegacyEngine) AddSubscription

func (le *LegacyEngine) AddSubscription(sub Subscriptions)

AddSubscription adds a set of subscriptions if not exists yet

func (*LegacyEngine) DeleteSubscription

func (le *LegacyEngine) DeleteSubscription(sub Subscriptions)

DeleteSubscription deletes a set of subscriptions if already exist

func (*LegacyEngine) Dump

func (le *LegacyEngine) Dump() string

Dump returs a string representation of the PatriciaTrie

func (*LegacyEngine) MarshalBinary

func (le *LegacyEngine) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding LegacyEngine

func (*LegacyEngine) Name

func (le *LegacyEngine) Name() string

Name returs the name of this engine type

func (*LegacyEngine) Search

func (le *LegacyEngine) Search(re llrp.ReadEvent) (pureIdentity string, reportURIs []string, err error)

Search returns a pureIdentity of the llrp.ReadEvent if found any subscription without err

func (*LegacyEngine) UnmarshalBinary

func (le *LegacyEngine) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding LegacyEngine

type List

type List struct {
	// contains filtered or unexported fields
}

List is a slice of pointers to ExactMatch

func (*List) AddSubscription

func (list *List) AddSubscription(sub Subscriptions)

AddSubscription adds a set of subscriptions if not exists yet

func (*List) DeleteSubscription

func (list *List) DeleteSubscription(sub Subscriptions)

DeleteSubscription deletes a set of subscriptions if already exist

func (*List) Dump

func (list *List) Dump() string

Dump returs a string representation of the PatriciaTrie

func (*List) MarshalBinary

func (list *List) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *List

func (*List) Name

func (list *List) Name() string

Name returs the name of this engine type

func (*List) Search

func (list *List) Search(re llrp.ReadEvent) (pureIdentity string, reportURIs []string, err error)

Search returns a pureIdentity of the llrp.ReadEvent if found any subscription without err

func (*List) UnmarshalBinary

func (list *List) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding List

type ListFilters

type ListFilters []*ExactMatch

ListFilters contains pointers to ExactMatch

func (ListFilters) IndexOf

func (lf ListFilters) IndexOf(em *ExactMatch) int

IndexOf check the index of ExactMatch in the List returns -1 if not exist

type ManagementMessage

type ManagementMessage struct {
	Type                    ManagementMessageType
	Pattern                 string
	ReportURI               string
	EngineGeneratorInstance *EngineGenerator
	CurrentThroughput       float64
	EventCount              int64
	MatchedCount            int64
	EngineName              string
}

ManagementMessage holds management action for the EngineFactory

type ManagementMessageType

type ManagementMessageType int

ManagementMessageType is to indicate the type of ManagementMessage

const (
	AddSubscription ManagementMessageType = iota
	DeleteSubscription
	OnEngineGenerated
	DeployEngine
	TrafficStatus
	EngineStatus
	SelectedEngine
)

ManagementMessage types

type PartialSubscription

type PartialSubscription struct {
	Offset    int
	ReportURI string
	Subset    ByteSubscriptions
}

PartialSubscription contains reportURI and pValue for a filter

func (*PartialSubscription) MarshalBinary

func (psub *PartialSubscription) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *PartialSubscription

func (*PartialSubscription) UnmarshalBinary

func (psub *PartialSubscription) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *PartialSubscription

type PatriciaTrie

type PatriciaTrie struct {
	// contains filtered or unexported fields
}

PatriciaTrie struct

func (*PatriciaTrie) AddSubscription

func (pt *PatriciaTrie) AddSubscription(sub Subscriptions)

AddSubscription adds a set of subscriptions if not exists yet

func (*PatriciaTrie) DeleteSubscription

func (pt *PatriciaTrie) DeleteSubscription(sub Subscriptions)

DeleteSubscription deletes a set of subscriptions if already exist

func (*PatriciaTrie) Dump

func (pt *PatriciaTrie) Dump() string

Dump returs a string representation of the PatriciaTrie

func (*PatriciaTrie) MarshalBinary

func (pt *PatriciaTrie) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *PatriciaTrie

func (*PatriciaTrie) Name

func (pt *PatriciaTrie) Name() string

Name returs the name of this engine type

func (*PatriciaTrie) Search

func (pt *PatriciaTrie) Search(re llrp.ReadEvent) (pureIdentity string, reportURIs []string, err error)

Search returns a pureIdentity of the llrp.ReadEvent if found any subscription without err

func (*PatriciaTrie) UnmarshalBinary

func (pt *PatriciaTrie) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *PatriciaTrie

type PatriciaTrieNode

type PatriciaTrieNode struct {
	// contains filtered or unexported fields
}

PatriciaTrieNode is a node for PatriciaTrie

func (*PatriciaTrieNode) MarshalBinary

func (ptn *PatriciaTrieNode) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *PatriciaTrie

func (*PatriciaTrieNode) UnmarshalBinary

func (ptn *PatriciaTrieNode) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *PatriciaTrie

type SplayTree

type SplayTree struct {
	// contains filtered or unexported fields
}

SplayTree struct

func (*SplayTree) AddSubscription

func (st *SplayTree) AddSubscription(sub Subscriptions)

AddSubscription adds a set of subscriptions if not exists yet

func (*SplayTree) DeleteSubscription

func (st *SplayTree) DeleteSubscription(sub Subscriptions)

DeleteSubscription deletes a set of subscriptions if already exist

func (*SplayTree) Dump

func (st *SplayTree) Dump() string

Dump returs a string representation of the PatriciaTrie

func (*SplayTree) MarshalBinary

func (st *SplayTree) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *SplayTree

func (*SplayTree) Name

func (st *SplayTree) Name() string

Name returns the name of this engine

func (*SplayTree) Search

func (st *SplayTree) Search(re llrp.ReadEvent) (pureIdentity string, reportURIs []string, err error)

Search returns a pureIdentity of the llrp.ReadEvent if found any subscription without err

func (*SplayTree) UnmarshalBinary

func (st *SplayTree) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *PatriciaTrie

type SplayTreeNode

type SplayTreeNode struct {
	// contains filtered or unexported fields
}

SplayTreeNode is a node for SplayTree

func (*SplayTreeNode) MarshalBinary

func (stn *SplayTreeNode) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *SplayTreeNode

func (*SplayTreeNode) UnmarshalBinary

func (stn *SplayTreeNode) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *SplayTreeNode

type Subscriptions

type Subscriptions map[string][]string

Subscriptions contains a slice of urn:epc:pat as values and a URI to report events as keys

func LoadSubscriptionsFromCSVFile

func LoadSubscriptionsFromCSVFile(f string) Subscriptions

LoadSubscriptionsFromCSVFile takes a csv file name and returns Subscriptions

func (Subscriptions) Clone

func (sub Subscriptions) Clone() Subscriptions

Clone retuns a new copy of subscriptions

func (Subscriptions) Keys

func (sub Subscriptions) Keys() []string

Keys return a slice of keys in Subscriptions

func (Subscriptions) MarshalBinary

func (sub Subscriptions) MarshalBinary() (_ []byte, err error)

MarshalBinary overwrites the marshaller in gob encoding *Subscription

func (Subscriptions) ToByteSubscriptions

func (sub Subscriptions) ToByteSubscriptions() ByteSubscriptions

ToByteSubscriptions preprocess the subscription and convert them in bytes

func (Subscriptions) UnmarshalBinary

func (sub Subscriptions) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary overwrites the unmarshaller in gob decoding *Subscription

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL