device

package
Version: v0.0.0-...-986d81d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package device contains the structs and logic to create, configure, and maintain virtual multi-queue network devices. Each network device type is represented by a struct adhering to the included Device interface, which describes a generic multi-queue virtual network device.

Currently supported devices:

- TUN device

Index

Constants

View Source
const (
	// TUNDevice creates and manages a TUN based network device.
	TUNDevice = "tun"

	// MOCKDevice creates and manages a mocked out network device for testing.
	MOCKDevice = "mock"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	// Should return the name of the virual network device.
	Name() string

	// Read should return a formatted *common.Payload, based on the provided byte slice, off the specified device queue.
	Read(queue int, buf []byte) (*common.Payload, bool)

	// Write should handle being passed a formatted *common.Payload, and write the underlying raw data to the specified device queue.
	Write(queue int, payload *common.Payload) bool

	// Close should gracefully destroy the virtual network device.
	Close() error

	// Queues should return all underlying queue file descriptors to pass along during a rolling restart.
	Queues() []int
}

Device interface for a generic multi-queue network device.

func New

func New(deviceType string, cfg *common.Config) (Device, error)

New will generate a new Device struct based on the supplied device deviceType and user configuration

type Mock

type Mock struct {
}

Mock device struct to use for testing.

func (*Mock) Close

func (mock *Mock) Close() error

Close which is a noop.

func (*Mock) Name

func (mock *Mock) Name() string

Name of the mock device.

func (*Mock) Queues

func (mock *Mock) Queues() []int

Queues which is a noop.

func (*Mock) Read

func (mock *Mock) Read(queue int, buf []byte) (*common.Payload, bool)

Read which just returns the supplied buffer in the form of a *common.Payload.

func (*Mock) Write

func (mock *Mock) Write(queue int, payload *common.Payload) bool

Write which is a noop.

type Tun

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

Tun device struct for managing a multi-queue TUN networking device.

func (*Tun) Close

func (tun *Tun) Close() error

Close the Tun device and remove associated network configuration.

func (*Tun) Name

func (tun *Tun) Name() string

Name of the Tun device.

func (*Tun) Queues

func (tun *Tun) Queues() []int

Queues returns the underlying device queue file descriptors.

func (*Tun) Read

func (tun *Tun) Read(queue int, buf []byte) (*common.Payload, bool)

Read a packet off the specified device queue and return a *common.Payload representation of the packet.

func (*Tun) Write

func (tun *Tun) Write(queue int, payload *common.Payload) bool

Write a *common.Payload to the specified device queue.

Jump to

Keyboard shortcuts

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