flowstats

package
v0.0.0-...-dcb2eba Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package flowstats implements the main functions to process and store flow statistics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flow

type Flow struct {
	Id          string
	Service     string
	DomainName  string
	ServiceIP   string
	LocalIP     string
	Protocol    string
	LocalPort   string
	ServicePort string

	Cntrs []counters.Counter
}

Flow is a general flow structure that contains flow information as well as the counters it needs to collect

func CreateFlow

func CreateFlow() *Flow

func (*Flow) AddPacket

func (f *Flow) AddPacket(pkt *network.Packet) error

AddPacket updates the flow states based on the packet pkt

func (*Flow) Clear

func (f *Flow) Clear() error

Clear the flow statistics

func (*Flow) Collect

func (f *Flow) Collect() []byte

Collect converts a flow into JSON form

func (*Flow) Reset

func (f *Flow) Reset() error

Reset resets the flow statistics

type FlowCache

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

FlowCache is a cache used to store flows' statistics

func NewFlowCache

func NewFlowCache(t string, serviceMap *servicemap.ServiceMap, evictTime, cleanupTime time.Duration, shardsCount uint32, anonymize bool) (*FlowCache, error)

NewFlowCache initiates a new FlowCache. t specifies the cache type. Possible cache types:

- "ConcurrentCacheMap": Concurrent Map with periodic eviction of expired entries. Currently the only supported cache type

- "BigCache": (NOT IMPLEMENTED) modified version of https://github.com/allegro/bigcache

- "CacheMap": (NOT IMPLEMENTED) a simple map with no concurrency support

- "Map": (NOT IMPLEMENTED) a simple map with no concurrency support

func (*FlowCache) AddServices

func (fc *FlowCache) AddServices(services []Service) error

func (*FlowCache) Dump

func (fc *FlowCache) Dump() map[string]Flow

Dump copies the entire cache int a map.

func (*FlowCache) DumpToChannel

func (fc *FlowCache) DumpToChannel(c chan Flow)

DumpToChannel copies the entire cache int a channel, entry by entry.

func (*FlowCache) DumpToString

func (fc *FlowCache) DumpToString() []json.RawMessage

Dump copies the entire cache int a map.

func (*FlowCache) ProcessPacket

func (fc *FlowCache) ProcessPacket(pkt *network.Packet) error

ProcessPacket processes incoming packets. If the flow is already in the cache, it updates its counters. If not, it creates it based on the DNS type and inserts it into the cache.

type OutCounter

type OutCounter struct {
	CType string
	Data  json.RawMessage
}

type OutFlow

type OutFlow struct {
	Id          string
	Service     string
	DomainName  string
	ServiceIP   string
	LocalIP     string
	Protocol    string
	LocalPort   string
	ServicePort string

	Cntrs []OutCounter
}

type Service

type Service struct {
	// Name of the service
	Name string
	// Collect is the list of counters to collect in string format
	Collect []string
}

type TupleFlow

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

TupleFlow is a special flow that includes the 4-tuple consisting of the network and transport flows src and dst are IP addresses, src2 and dst2 are port numbers

func NewTupleFlow

func NewTupleFlow(src, dst, src2, dst2 []byte) (f TupleFlow)

NewTupleFlow generates a TupleFlow given the 4-tuple

func (TupleFlow) FastHash

func (f TupleFlow) FastHash() (h uint64)

FastHash is a special version of gopacket's fasthash as we incorporate a 4-tuple rather than only 2 endpoints The hash must be symmetric srcIP,srcPort->dstIP,dstPort must collide with dstIP,dstPort->srcIP,srcPort

Jump to

Keyboard shortcuts

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