calc

package
v2.0.0-beta-rc1+incomp... Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2016 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

The calc package implements a calculation graph for Felix's dynamic state. The graph filters and transforms updates from the backend Syncer into a stream of host-specific updates to policies, profiles, endpoints and IP sets.

The graph is available either with a synchronous callback API or as a channel-based async API. The async version of the API is recommended because it includes and EventBuffer to efficiently batch IP set updates. In addition, it converts the callbacks into structs from the felix/proto package, which are ready to be marshaled directly to the felix front-end.

// Using the async API.
asyncCalcGraph := calc.NewAsyncCalcGraph("hostname", outputChannel)
syncer := fc.datastore.Syncer(asyncCalcGraph)
syncer.Start()
asyncCalcGraph.Start()
for event := range outputChannel {
	switch event := event.(type) {
	case *proto.XYZ:
		...
	...
}

Copyright (c) 2016 Tigera, Inc. All rights reserved.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCalculationGraph

func NewCalculationGraph(callbacks PipelineCallbacks, hostname string) (allUpdDispatcher *dispatcher.Dispatcher)

func NewTierInfo

func NewTierInfo(name string) *tierInfo

func TagIPSetID

func TagIPSetID(tagID string) string

Types

type ActiveRulesCalculator

type ActiveRulesCalculator struct {

	// Callback objects.
	RuleScanner         ruleScanner
	PolicyMatchListener PolicyMatchListener
	// contains filtered or unexported fields
}

func NewActiveRulesCalculator

func NewActiveRulesCalculator() *ActiveRulesCalculator

func (*ActiveRulesCalculator) OnUpdate

func (arc *ActiveRulesCalculator) OnUpdate(update api.Update) (filterOut bool)

func (*ActiveRulesCalculator) RegisterWith

func (arc *ActiveRulesCalculator) RegisterWith(localEndpointDispatcher, allUpdDispatcher *dispatcher.Dispatcher)

type AsyncCalcGraph

type AsyncCalcGraph struct {
	Dispatcher *dispatcher.Dispatcher
	// contains filtered or unexported fields
}

func NewAsyncCalcGraph

func NewAsyncCalcGraph(conf *config.Config, outputEvents chan<- interface{}) *AsyncCalcGraph

func (*AsyncCalcGraph) OnStatusUpdated

func (acg *AsyncCalcGraph) OnStatusUpdated(status api.SyncStatus)

func (*AsyncCalcGraph) OnUpdates

func (acg *AsyncCalcGraph) OnUpdates(updates []api.Update)

func (*AsyncCalcGraph) Start

func (acg *AsyncCalcGraph) Start()

type ConfigBatcher

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

func NewConfigBatcher

func NewConfigBatcher(hostname string, callbacks configCallbacks) *ConfigBatcher

func (*ConfigBatcher) OnDatamodelStatus

func (cb *ConfigBatcher) OnDatamodelStatus(status api.SyncStatus)

func (*ConfigBatcher) OnUpdate

func (cb *ConfigBatcher) OnUpdate(update api.Update) (filterOut bool)

func (*ConfigBatcher) RegisterWith

func (cb *ConfigBatcher) RegisterWith(allUpdDispatcher *dispatcher.Dispatcher)

type DatastoreNotReady

type DatastoreNotReady struct{}

type EventBuffer

type EventBuffer struct {
	Callback EventHandler
	// contains filtered or unexported fields
}

EventBuffer buffers and coalesces updates from the calculation graph. Its input form the graph is by the callback interface, it's output is a stream of protobuf-format events.

func NewEventBuffer

func NewEventBuffer(conf configInterface) *EventBuffer

func (*EventBuffer) Flush

func (buf *EventBuffer) Flush()

func (*EventBuffer) OnConfigUpdate

func (buf *EventBuffer) OnConfigUpdate(globalConfig, hostConfig map[string]string)

func (*EventBuffer) OnDatastoreNotReady

func (buf *EventBuffer) OnDatastoreNotReady()

func (*EventBuffer) OnEndpointTierUpdate

func (buf *EventBuffer) OnEndpointTierUpdate(endpointKey model.Key,
	endpoint interface{},
	filteredTiers []tierInfo)

func (*EventBuffer) OnHostIPRemove

func (buf *EventBuffer) OnHostIPRemove(hostname string)

func (*EventBuffer) OnHostIPUpdate

func (buf *EventBuffer) OnHostIPUpdate(hostname string, ip *net.IP)

func (*EventBuffer) OnIPAdded

func (buf *EventBuffer) OnIPAdded(setID string, ip ip.Addr)

func (*EventBuffer) OnIPRemoved

func (buf *EventBuffer) OnIPRemoved(setID string, ip ip.Addr)

func (*EventBuffer) OnIPSetAdded

func (buf *EventBuffer) OnIPSetAdded(setID string)

func (*EventBuffer) OnIPSetRemoved

func (buf *EventBuffer) OnIPSetRemoved(setID string)

func (*EventBuffer) OnPolicyActive

func (buf *EventBuffer) OnPolicyActive(key model.PolicyKey, rules *ParsedRules)

func (*EventBuffer) OnPolicyInactive

func (buf *EventBuffer) OnPolicyInactive(key model.PolicyKey)

func (*EventBuffer) OnProfileActive

func (buf *EventBuffer) OnProfileActive(key model.ProfileRulesKey, rules *ParsedRules)

func (*EventBuffer) OnProfileInactive

func (buf *EventBuffer) OnProfileInactive(key model.ProfileRulesKey)

type EventHandler

type EventHandler func(message interface{})

type FelixSender

type FelixSender interface {
	SendUpdateToFelix(update model.KVPair)
}

type HostIPPassthru

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

func NewHostIPPassthru

func NewHostIPPassthru(callbacks hostIPCallbacks) *HostIPPassthru

func (*HostIPPassthru) OnUpdate

func (h *HostIPPassthru) OnUpdate(update api.Update) (filterOut bool)

func (*HostIPPassthru) RegisterWith

func (h *HostIPPassthru) RegisterWith(dispatcher *dispatcher.Dispatcher)

type IPAddRemoveCallbacks

type IPAddRemoveCallbacks interface {
	OnIPAdded(ipSetID string, ip ip.Addr)
	OnIPRemoved(ipSetID string, ip ip.Addr)
}

type MemberCalculator

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

func NewMemberCalculator

func NewMemberCalculator() *MemberCalculator

func (*MemberCalculator) Empty

func (calc *MemberCalculator) Empty() bool

func (*MemberCalculator) MatchStarted

func (calc *MemberCalculator) MatchStarted(key model.Key, ipSetID string)

MatchStarted tells this object that an endpoint now belongs to an IP set.

func (*MemberCalculator) MatchStopped

func (calc *MemberCalculator) MatchStopped(key model.Key, ipSetID string)

MatchStopped tells this object that an endpoint no longer belongs to an IP set.

func (*MemberCalculator) OnUpdate

func (calc *MemberCalculator) OnUpdate(update api.Update) (filterOut bool)

func (*MemberCalculator) RegisterWith

func (calc *MemberCalculator) RegisterWith(allUpdDispatcher *dispatcher.Dispatcher)

type ParsedRule

type ParsedRule struct {
	Action string

	IPVersion *int

	Protocol *numorstring.Protocol

	SrcNet      *net.IPNet
	SrcPorts    []numorstring.Port
	DstNet      *net.IPNet
	DstPorts    []numorstring.Port
	ICMPType    *int
	ICMPCode    *int
	SrcIPSetIDs []string
	DstIPSetIDs []string

	NotProtocol    *numorstring.Protocol
	NotSrcNet      *net.IPNet
	NotSrcPorts    []numorstring.Port
	NotDstNet      *net.IPNet
	NotDstPorts    []numorstring.Port
	NotICMPType    *int
	NotICMPCode    *int
	NotSrcIPSetIDs []string
	NotDstIPSetIDs []string

	LogPrefix string
}

Rule is like a backend.model.Rule, except the tag and selector matches are replaced with pre-calculated ipset IDs.

type ParsedRules

type ParsedRules struct {
	InboundRules  []*ParsedRule
	OutboundRules []*ParsedRule
}

type PipelineCallbacks

type PipelineCallbacks interface {
	// contains filtered or unexported methods
}

type PolKV

type PolKV struct {
	Key   model.PolicyKey
	Value *model.Policy
}

type PolicyByOrder

type PolicyByOrder []PolKV

func (PolicyByOrder) Len

func (a PolicyByOrder) Len() int

func (PolicyByOrder) Less

func (a PolicyByOrder) Less(i, j int) bool

func (PolicyByOrder) Swap

func (a PolicyByOrder) Swap(i, j int)

type PolicyMatchListener

type PolicyMatchListener interface {
	OnPolicyMatch(policyKey model.PolicyKey, endpointKey interface{})
	OnPolicyMatchStopped(policyKey model.PolicyKey, endpointKey interface{})
}

type PolicyResolver

type PolicyResolver struct {
	Callbacks PolicyResolverCallbacks
	InSync    bool
	// contains filtered or unexported fields
}

func NewPolicyResolver

func NewPolicyResolver() *PolicyResolver

func (*PolicyResolver) OnDatamodelStatus

func (pr *PolicyResolver) OnDatamodelStatus(status api.SyncStatus)

func (*PolicyResolver) OnPolicyMatch

func (pr *PolicyResolver) OnPolicyMatch(policyKey model.PolicyKey, endpointKey interface{})

func (*PolicyResolver) OnPolicyMatchStopped

func (pr *PolicyResolver) OnPolicyMatchStopped(policyKey model.PolicyKey, endpointKey interface{})

func (*PolicyResolver) OnUpdate

func (pr *PolicyResolver) OnUpdate(update api.Update) (filterOut bool)

func (*PolicyResolver) RegisterWith

func (pr *PolicyResolver) RegisterWith(allUpdDispatcher, localEndpointDispatcher *dispatcher.Dispatcher)

type PolicyResolverCallbacks

type PolicyResolverCallbacks interface {
	OnEndpointTierUpdate(endpointKey model.Key, endpoint interface{}, filteredTiers []tierInfo)
}

type PolicySorter

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

func NewPolicySorter

func NewPolicySorter() *PolicySorter

func (*PolicySorter) OnUpdate

func (poc *PolicySorter) OnUpdate(update api.Update) (dirty bool)

func (*PolicySorter) Sorted

func (poc *PolicySorter) Sorted() *tierInfo

type RuleScanner

type RuleScanner struct {
	OnSelectorActive   func(selector selector.Selector)
	OnSelectorInactive func(selector selector.Selector)
	OnTagActive        func(tag string)
	OnTagInactive      func(tag string)

	RulesUpdateCallbacks rulesUpdateCallbacks
	// contains filtered or unexported fields
}

RuleScanner calculates the active set of selectors and tags from the current set of policies/profiles. It generates events for selectors becoming active/inactive.

func NewRuleScanner

func NewRuleScanner() *RuleScanner

func (*RuleScanner) OnPolicyActive

func (rs *RuleScanner) OnPolicyActive(key model.PolicyKey, policy *model.Policy)

func (*RuleScanner) OnPolicyInactive

func (rs *RuleScanner) OnPolicyInactive(key model.PolicyKey)

func (*RuleScanner) OnProfileActive

func (rs *RuleScanner) OnProfileActive(key model.ProfileRulesKey, profile *model.ProfileRules)

func (*RuleScanner) OnProfileInactive

func (rs *RuleScanner) OnProfileInactive(key model.ProfileRulesKey)

type StatsCollector

type StatsCollector struct {
	Callback func(StatsUpdate) error
	// contains filtered or unexported fields
}

func NewStatsCollector

func NewStatsCollector(callback func(StatsUpdate) error) *StatsCollector

func (*StatsCollector) OnStatusUpdate

func (s *StatsCollector) OnStatusUpdate(status api.SyncStatus)

func (*StatsCollector) OnUpdate

func (s *StatsCollector) OnUpdate(update api.Update) (filterOut bool)

func (*StatsCollector) RegisterWith

func (s *StatsCollector) RegisterWith(allUpdDispatcher *dispatcher.Dispatcher)

type StatsUpdate

type StatsUpdate struct {
	NumHosts             int
	NumWorkloadEndpoints int
	NumHostEndpoints     int
}

func (StatsUpdate) String

func (s StatsUpdate) String() string

type SyncerCallbacksDecoupler

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

func NewSyncerCallbacksDecoupler

func NewSyncerCallbacksDecoupler() *SyncerCallbacksDecoupler

func (*SyncerCallbacksDecoupler) OnStatusUpdated

func (a *SyncerCallbacksDecoupler) OnStatusUpdated(status api.SyncStatus)

func (*SyncerCallbacksDecoupler) OnUpdates

func (a *SyncerCallbacksDecoupler) OnUpdates(updates []api.Update)

func (*SyncerCallbacksDecoupler) SendTo

type ValidationFilter

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

func NewValidationFilter

func NewValidationFilter(sink api.SyncerCallbacks) *ValidationFilter

func (*ValidationFilter) OnStatusUpdated

func (v *ValidationFilter) OnStatusUpdated(status api.SyncStatus)

func (*ValidationFilter) OnUpdates

func (v *ValidationFilter) OnUpdates(updates []api.Update)

Jump to

Keyboard shortcuts

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