cache

package
v0.0.0-...-792cabc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContivRuleCache

type ContivRuleCache struct {
	Deps
	// contains filtered or unexported fields
}

ContivRuleCache implements ContivRuleCacheAPI.

func (*ContivRuleCache) AllInterfaces

func (crc *ContivRuleCache) AllInterfaces() InterfaceSet

AllInterfaces returns a set of all known interfaces (already updated configuration).

func (*ContivRuleCache) Init

func (crc *ContivRuleCache) Init() error

Init initializes the ContivRule Cache.

func (*ContivRuleCache) LookupByInterface

func (crc *ContivRuleCache) LookupByInterface(ifName string) (ingress, egress *ContivRuleList)

LookupByInterface returns rules assigned to a given interface grouped into lists by the traffic direction. Interfaces with equal ingress and/or egress configuration will share the same lists (same IDs).

func (*ContivRuleCache) NewTxn

func (crc *ContivRuleCache) NewTxn(resync bool) Txn

NewTxn starts a new transaction. The rendering executes only after Commit() is called. If <resync> is enabled, the supplied configuration will completely replace the existing one, otherwise interfaces not mentioned in the transaction are left unchanged.

type ContivRuleCacheAPI

type ContivRuleCacheAPI interface {
	// NewTxn starts a new transaction. The rendering executes only after
	// Commit() is called.
	// If <resync> is enabled, the supplied configuration will completely
	// replace the existing one, otherwise interfaces not mentioned
	// in the transaction are left unchanged.
	NewTxn(resync bool) Txn

	// LookupByInterface returns rules assigned to a given interface grouped
	// into lists by the traffic direction. Interfaces with equal ingress and/or
	// egress configuration will share the same lists (same IDs).
	LookupByInterface(ifName string) (ingress, egress *ContivRuleList)

	// AllInterfaces returns  set of all known interfaces (already updated
	// configuration).
	AllInterfaces() InterfaceSet
}

ContivRuleCacheAPI defines API of a cache used to store Contiv Rules as *lists*. The cache allows renderer to easily calculate the minimal set of changes that need to be applied in a given transaction. Furthermore, the cache automatically groups ingress/egress rules per-interface into lists (see ContivRuleList) with auto-generated IDs that are shared between interfaces with equivalent configuration. If supported by the destination network stack, the renderer may install a list of ingress/egress rules only once and share it among multiple associated interfaces.

type ContivRuleCacheTxn

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

ContivRuleCacheTxn represents a single transaction of ContivRuleCache.

func (*ContivRuleCacheTxn) Changes

func (crct *ContivRuleCacheTxn) Changes() (ingress, egress []*TxnChange)

Changes calculates a minimalistic set of changes prepared in the transaction up to this point. Must be run before Commit().

func (*ContivRuleCacheTxn) Commit

func (crct *ContivRuleCacheTxn) Commit() error

Commit applies the changes into the underlying cache.

func (*ContivRuleCacheTxn) Update

func (crct *ContivRuleCacheTxn) Update(ifName string, ingress []*renderer.ContivRule, egress []*renderer.ContivRule) error

Update changes the list of ingress and egress rules for a given interface. The change is applied into the cache during commit. Run Changes() before Commit() to learn the set of pending updates (merged to minimal diff).

type ContivRuleList

type ContivRuleList struct {
	// ID is generated by the cache to uniquely identify the list among all
	// ingress and egress lists.
	ID string

	// Rules applied on the ingress or the egress side for one or multiple
	// interfaces. For a given ContivRuleList, Rules are always the same.
	Rules []*renderer.ContivRule

	// Set of all interfaces associated with this list.
	// Empty for removed list.
	Interfaces InterfaceSet

	// Private can be used by renderer to store the configuration of rules from
	// the list in the format used by the destination network stack.
	Private interface{}
}

ContivRuleList is a grouping of all rules applied on one or shared by multiple interfaces on the ingress or egress side. Rules are not mutable. Only the list of associated interfaces may change.

func (*ContivRuleList) String

func (crl *ContivRuleList) String() string

String converts ContivRuleList (pointer) into a human-readable string representation.

type ContivRuleLists

type ContivRuleLists struct {
	Log logging.Logger
	// contains filtered or unexported fields
}

ContivRuleLists is an ordered list of Contiv Rule lists with efficient operations (apart from Remove() and RemoveByPredicate() all with logarithmic or constant complexity).

API:

Insert(ruleList)
Remove(ruleList)
RemoveByIdx(idx)
RemoveByPredicate(func(ruleList) -> bool)
LookupByID(ID) -> ruleList
LookupByRules() -> ruleList
LookupByInterface(ifName) -> ruleList
AssignInterface(ruleList, ifName)
UnassignInterface(ruleList/nil, ifName)

func NewContivRuleLists

func NewContivRuleLists(logger logging.Logger, dummy bool) *ContivRuleLists

NewContivRuleLists is a constructor for ContivRuleLists.

func (*ContivRuleLists) AssignInterface

func (crls *ContivRuleLists) AssignInterface(ruleList *ContivRuleList, ifName string)

AssignInterface assigns interface into a list.

func (*ContivRuleLists) Insert

func (crls *ContivRuleLists) Insert(ruleList *ContivRuleList) bool

Insert ContivRuleList into the list.

func (*ContivRuleLists) LookupByID

func (crls *ContivRuleLists) LookupByID(id string) *ContivRuleList

LookupByID searches for ContivRuleList by ID.

func (*ContivRuleLists) LookupByInterface

func (crls *ContivRuleLists) LookupByInterface(ifname string) *ContivRuleList

LookupByInterface searches for ContivRuleList by an assigned interface.

func (*ContivRuleLists) LookupByRules

func (crls *ContivRuleLists) LookupByRules(rules []*renderer.ContivRule) *ContivRuleList

LookupByRules searches for ContivRuleList by rules.

func (*ContivRuleLists) Remove

func (crls *ContivRuleLists) Remove(ruleList *ContivRuleList) bool

Remove ContivRuleList from the list.

func (*ContivRuleLists) RemoveByIdx

func (crls *ContivRuleLists) RemoveByIdx(idx int) bool

RemoveByIdx removes ContivRuleList under a given index from the list.

func (*ContivRuleLists) RemoveByPredicate

func (crls *ContivRuleLists) RemoveByPredicate(predicate func(ruleList *ContivRuleList) bool) int

RemoveByPredicate removes ContivRuleLists that satisfy a given predicate.

func (*ContivRuleLists) UnassignInterface

func (crls *ContivRuleLists) UnassignInterface(ruleList *ContivRuleList, ifName string)

UnassignInterface removes previous assignment of an interface from a list. <ruleList> may be nil to match any list.

type Deps

type Deps struct {
	Log logging.Logger
}

Deps lists dependencies of ContivRuleCache.

type InterfaceSet

type InterfaceSet map[string]struct{}

InterfaceSet is a set of interface names.

func NewInterfaceSet

func NewInterfaceSet(ifNames ...string) InterfaceSet

NewInterfaceSet creates InterfaceSet with given items.

func (InterfaceSet) Add

func (set InterfaceSet) Add(ifName string)

Add adds new interface into the set.

func (InterfaceSet) Copy

func (set InterfaceSet) Copy() InterfaceSet

Copy returns deep copy of the set.

func (InterfaceSet) Equals

func (set InterfaceSet) Equals(set2 InterfaceSet) bool

Equals compares two sets for equality.

func (InterfaceSet) Has

func (set InterfaceSet) Has(ifName string) bool

Has returns true if the set contains given interface name.

func (InterfaceSet) Join

func (set InterfaceSet) Join(set2 InterfaceSet)

Join merges <set2> into this set.

func (InterfaceSet) Remove

func (set InterfaceSet) Remove(ifName string) bool

Remove removes interface name from the set if it is there.

func (InterfaceSet) String

func (set InterfaceSet) String() string

String returns a human-readable string representation of the set.

type Txn

type Txn interface {
	// Update changes the list of rules for a given interface.
	// The change is applied into the cache during commit.
	// Run Changes() before Commit() to learn the set of pending updates (merged
	// to minimal diff).
	Update(ifName string, ingress []*renderer.ContivRule, egress []*renderer.ContivRule) error

	// Changes calculates a minimalistic set of changes prepared in the
	// transaction up to this point.
	// Must be run before Commit().
	Changes() (ingress, egress []*TxnChange)

	// Commit applies the changes into the underlying cache.
	Commit() error
}

Txn defines API of ContivRuleCache transaction.

type TxnChange

type TxnChange struct {
	// List of rules that have been been affected by the transaction.
	// Possible changes:
	//   - new list
	//   - removed list
	//   - changed assignment of interfaces
	// List content itself is not mutable. Different content is treated
	// as a new list (and the original list may loose some interfaces
	// or all of them and get removed)
	List *ContivRuleList

	// Set of interfaces previously assigned to the list.
	// Empty for newly added list.
	PreviousInterfaces InterfaceSet
}

TxnChange represents change in the ContivRuleCache to be performed by a transaction.

func (*TxnChange) String

func (tch *TxnChange) String() string

String converts TxnChange (pointer) into a human-readable string representation.

Jump to

Keyboard shortcuts

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