util

package
v0.0.0-...-be71968 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package util contains necessary type definitions and helper methods for tgc, tgen and tapp modules

Index

Constants

View Source
const (
	// PromNamespace prometheus udp namespace string
	PromNamespace = "netbat"
)

Variables

This section is empty.

Functions

func GetInterfaces

func GetInterfaces() (*types.InterfaceResponse, error)

GetInterfaces get interfaces from /etc/podinfo/annotations file

func GetMessageHeaderLength

func GetMessageHeaderLength() (int, error)

GetMessageHeaderLength get message header length

func GetNetInterfaces

func GetNetInterfaces() (map[string]string, error)

GetNetInterfaces return interfaces map[name]ipAddress

func GetPaddingPayload

func GetPaddingPayload(payloadSize int) ([]byte, error)

GetPaddingPayload get payload for the given length

func GetResolvableAddress

func GetResolvableAddress(ip string) (address string, err error)

GetResolvableAddress get resolvable address for given ip address

func GetTimestampMicroSec

func GetTimestampMicroSec() int64

GetTimestampMicroSec get timestamp in microseconds

func IsIPv4

func IsIPv4(ipAddress string) bool

IsIPv4 to check ipAddress is either ipv4 or not

func IsIPv6

func IsIPv6(ipAddress string) bool

IsIPv6 to check ipAddress is either ipv6 or not

func MicroSecToDuration

func MicroSecToDuration(msec int) time.Duration

MicroSecToDuration convert give msec into duration

func NewCounter

func NewCounter(namespace, subsystem, name, help string, labelMap map[string]string) prometheus.Counter

NewCounter API to create a new counter

func NewGauge

func NewGauge(namespace, subsystem, name, help string, labelMap map[string]string) prometheus.Gauge

NewGauge API to create a new gauge metric

func NewSummary

func NewSummary(namespace, subsystem, name, help string, labelMap map[string]string, objectives map[float64]float64) prometheus.Summary

NewSummary API to create a new summary metric

func RegisterPromHandler

func RegisterPromHandler(promPort int, reg *prometheus.Registry)

RegisterPromHandler register prometheus http handler

func SecToMicroSec

func SecToMicroSec(sec int) int

SecToMicroSec convert given seconds into microseconds

Types

type BatPair

type BatPair struct {
	Source             *Source
	Destination        *Remote
	TrafficProfile     string
	TrafficScenario    string
	PendingRequestsMap map[int64]int64
	ClientConnection   ClientImpl
}

BatPair represents the BAT traffic to be run between two entities

type ClientImpl

type ClientImpl interface {
	SetupConnection() error
	TearDownConnection()
	SocketRead()
	HandleTimeouts()
	StartPackets()
}

ClientImpl methods to be implemented by a client

type Config

type Config interface {
	SuspendTraffic() bool
	GetProfileMap() map[string]map[string]string
	GetResourceVersion() string
}

Config interface

func LoadConfig

func LoadConfig(cm *v1.ConfigMap) (Config, error)

LoadConfig parse the config map and returns Config

func ReLoadConfig

func ReLoadConfig(cm *v1.ConfigMap, c interface{}) (Config, error)

ReLoadConfig parse the config map and load the config struct

type EnvResponse

type EnvResponse struct {
	Envs map[string]string
}

EnvResponse env response

type Error

type Error struct {
	Code        int
	Description string
}

Error error associated with pair

type Message

type Message struct {
	SequenceNumber   int64
	SendTimeStamp    int64
	RespondTimeStamp int64
	ServerInfoLength int
	Length           int
}

Message to be sent and received by protocol clients

func NewMessage

func NewMessage(sequence, sendTimeStamp int64, packetSize int) *Message

NewMessage creates a new message

type PodInfo

type PodInfo struct {
	Namespace  string
	Name       string
	WorkerName string
}

PodInfo used by tapp to respond with its info to client

type ProtocolClientModule

type ProtocolClientModule interface {
	CreateClient(p *BatPair, readBufferSize int, reg *prometheus.Registry) (ClientImpl, error)
	LoadBatProfileConfig(profileMap map[string]map[string]string) error
}

ProtocolClientModule contract to create protocol clients and loading its config

type ProtocolServerModule

type ProtocolServerModule interface {
	CreateServer(namespace, podName, nodeName, ipAddress, ifName string, readBufferSize int, reg *prometheus.Registry) (ServerImpl, error)
	LoadBatProfileConfig(profileMap map[string]map[string]string) error
}

ProtocolServerModule contract to create protocol servers and loading its config

type Remote

type Remote struct {
	IsDN bool
	Name string
	IP   string
}

Remote server identifier

type Server

type Server struct {
	PodInfo   PodInfo
	IPAddress string
	Port      int
}

Server struct used by protocol server

type ServerImpl

type ServerImpl interface {
	SetupServerConnection() error
	ReadFromSocket()
	HandleIdleConnections()
	TearDownServer()
}

ServerImpl methods to be implemented by a server

type Source

type Source struct {
	Type      string `json:"type"`
	Namespace string `json:"ns"`
	Name      string `json:"name"`
	Net       string `json:"net,omitempty"`
	Interface string `json:"interface,omitempty"`
	IP        string `json:"ip,omitempty"`
}

Source represents source of the BatPair

Jump to

Keyboard shortcuts

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