db

package
v0.0.0-...-891f3ce Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package db is responsible for the communication between the database backends and the bgpmon daemon. It abstracts database operations through types that are named Executors. Executors allow for one off, or transactional operations, that can be timed out using a context, and can be database unware by getting the appropriate SQL statement depending what type of database exists on the back.

Index

Constants

View Source
const (
	// AnyCollector is a wild card for collectors in the DB.
	AnyCollector = "%"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Capture

type Capture struct {
	ID         string // the capture_id that together with the table makes it unique
	Timestamp  time.Time
	Origin     int // origin as
	Advertised []*net.IPNet
	Withdrawn  []*net.IPNet
	ASPath     []int
	ColIP      net.IP
	PeerIP     net.IP
	NextHop    net.IP
	// contains filtered or unexported fields
}

Capture represent a BGPCapture a row in the generated capture tables. It describes a single BGP event.

func NewCaptureFromPB

func NewCaptureFromPB(pbCap *pb.BGPCapture) (*Capture, error)

NewCaptureFromPB returns a *Capture populated from a pb.BGPCapture

func (*Capture) Scan

func (c *Capture) Scan(rows *sql.Rows) error

Scan populates this capture with data from rows.Scan

func (*Capture) Values

func (c *Capture) Values() []interface{}

Values supplies values to a SQLExecutor

type CaptureFilterOptions

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

CaptureFilterOptions contains the options to filter by capture messages.

func DefaultCaptureFilterOptions

func DefaultCaptureFilterOptions() *CaptureFilterOptions

DefaultCaptureFilterOptions returns a CaptureFilterOptions with any collector, and time.Now() as the start and end date. This is unlikely to return any captures.

func NewCaptureFilterOptions

func NewCaptureFilterOptions(collector string, start time.Time, end time.Time) *CaptureFilterOptions

NewCaptureFilterOptions returns a FilterOptions interface for filtering captures.

func (*CaptureFilterOptions) AllowAdvPrefixes

func (cfo *CaptureFilterOptions) AllowAdvPrefixes(prefs ...*net.IPNet)

AllowAdvPrefixes adds the provided prefixes to a list of prefixes to filter by. If any prefix on that list appears, the Capture will pass the filter.

func (*CaptureFilterOptions) AllowSubnets

func (cfo *CaptureFilterOptions) AllowSubnets(prefs ...*net.IPNet)

AllowSubnets will allow captures to pass this filter if they have an advertized prefix that falls under one of the provided prefixes.

func (*CaptureFilterOptions) SetOrigin

func (cfo *CaptureFilterOptions) SetOrigin(as int)

SetOrigin filters by the provided origin autonomous system (AS).

type CaptureTable

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

CaptureTable represents a row in the main table. It describes an existing table populated with BGPCaptures

type CommonMessage

type CommonMessage interface {
	// This table holds the names of all other tables created.
	GetMainTable() string

	// This holds all info on the collectors.
	GetNodeTable() string

	// This holds info on customers or anyone interested in the stored
	// BGP data.
	GetEntityTable() string

	SetMainTable(string)
	SetNodeTable(string)
	SetEntityTable(string)
}

CommonMessage is a basic interface which allows the getting and setting of the the main and node tables that are usually involved in most db operations.

type CommonReply

type CommonReply interface {
	Error() error
}

CommonReply will wrap any data that needs to be returned by a dbOp. Each CommonReply has one thing in common, the ability to return an error.

type DBer

type DBer interface {
	DB() *sql.DB
}

DBer is an interface that returns a reference to the underlying *sql.DB

type Entity

type Entity struct {
	Name          string
	Email         string
	OwnedOrigins  []int
	OwnedPrefixes []*net.IPNet
}

Entity represents a row in the entities table. It describes a party interested in particular BGP data, like the owner of a prefix.

func NewEntityFromConfig

func NewEntityFromConfig(ec *config.EntityConfig) (e *Entity, err error)

NewEntityFromConfig returns an Entity populated from an EntityConfig.

func NewEntityFromPB

func NewEntityFromPB(pbEnt *pb.Entity) (e *Entity, err error)

NewEntityFromPB returns an Entity populated from a protobuf.

func (*Entity) Scan

func (e *Entity) Scan(rows *sql.Rows) error

Scan populates this entity from a sql.Rows

func (*Entity) ToProtobuf

func (e *Entity) ToProtobuf() *pb.Entity

ToProtobuf returns a protobuf Entity with the same values as this entity

func (*Entity) Values

func (e *Entity) Values() []interface{}

Values returns an array of interfaces that can be passed to a SQLExecutor to insert this Entity

type EntityFilterOptions

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

EntityFilterOptions holds all the fields to filter entities.

func NewEntityFilterOptions

func NewEntityFilterOptions(name string) *EntityFilterOptions

NewEntityFilterOptions returns FilterOptions for an Entity

type FilterOptions

type FilterOptions interface{}

FilterOptions is an empty interface. Only the implementations of it are important.

type ReadStream

type ReadStream interface {
	Read() bool

	// Data returns an interface so each implementation of a read stream is free to choose
	// what type it returns. This should be constant for each stream, and should be documented.
	Data() interface{}
	Bytes() []byte
	Err() error
	Close()
}

ReadStream represents the different kinds of read streams that can be done on a session

type Session

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

Session represents a session to the underlying db. It holds references to the schema manager and workerpool.

func NewSession

func NewSession(conf config.SessionConfiger, id string, workers int) (*Session, error)

NewSession returns a newly allocated Session

func (*Session) Close

func (s *Session) Close() error

Close stops the schema manager and the worker pool

func (*Session) DB

func (s *Session) DB() *sql.DB

DB satisfies the DBer interface on a Session

func (*Session) GetMaxWorkers

func (s *Session) GetMaxWorkers() int

GetMaxWorkers returns the maximum amount of workers that the session supports

func (*Session) GetTimeout

func (s *Session) GetTimeout() time.Duration

GetTimeout satisfies the GetTimeouter interface on a Session so it can be a TimeoutDBer

func (*Session) OpenReadStream

func (s *Session) OpenReadStream(sType SessionType, fo FilterOptions) (ReadStream, error)

OpenReadStream opens and returns a ReadStream with the given type, or an error if no such type exists

func (*Session) OpenWriteStream

func (s *Session) OpenWriteStream(sType SessionType) (WriteStream, error)

OpenWriteStream opens and returns a WriteStream with the given type, or an error if no such type exists

type SessionExecutor

type SessionExecutor struct {
	util.SQLExecutor
	// contains filtered or unexported fields
}

SessionExecutor wraps an util.SQLExecutor with queryProvider

type SessionType

type SessionType int

SessionType describes the supported session streams.

const (
	// SessionWriteCapture is provided to a Sessioner's OpenWriteStream to open
	// a capture write stream.
	SessionWriteCapture SessionType = iota
	// SessionReadCapture is provided to a Sessioner's OpenReadStream to open a
	// read capture stream.
	SessionReadCapture
	// SessionReadPrefix is provided to a Sessioner's OpenReadStream to open a
	// read prefix stream.
	SessionReadPrefix

	// SessionWriteEntity is provided to a Sessions OpenWriteStream to open
	// an entity write stream.
	SessionWriteEntity

	// SessionReadEntity is provided to a Sessions OpenReadStream to open
	// an entity read stream.
	SessionReadEntity
)

type TimeoutDBer

type TimeoutDBer interface {
	DBer
	util.GetTimeouter
}

TimeoutDBer composes DBer and GetTimeouter to return timeout duration for dbOps

type WriteStream

type WriteStream interface {
	Write(interface{}) error
	Flush() error
	Cancel()
	Close()
}

WriteStream represents the different kind of write streams that can be done on a session

Jump to

Keyboard shortcuts

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