tinynet

package module
v0.0.0-...-be7e1a1 Latest Latest
Warning

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

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

README

tinynet

Build Status codecov GoDoc

A lightweight instant virtual network for rapid prototyping SDN

Tinynet provides a simple network library with Go and uses for emulating any network to prototype Software Defined Networks.

Prerequisite

Open vSwitch

Installation from Debian Packages

$ sudo apt-get install openvswitch-switch

or installation from source

Install

$ go get -u github.com/John-Lin/tinynet

API Reference

https://godoc.org/github.com/John-Lin/tinynet

Features

  • Go API for creating any networks topology
  • Integrate with docker containers as a host
  • A cleanup command for removing virtual interfaces, network namespace and bridges

Example

package main

import (
	tn "github.com/John-Lin/tinynet"
	log "github.com/sirupsen/logrus"
)

// Custom topology example
// Host1 --- Switch1 --- Host2

func main() {
	// add a switch as a Switch1
	sw1, err := tn.AddSwitch("br0")
	if err != nil {
		log.Fatal("failed to AddSwitch:", err)
	}
	// setup Host1 network configuration through NewHostConfig constructor
	// parameters: name, address, interface name, MTU, isDocker, docker image
	hc1 := tn.NewHostConfig("h1", "10.0.0.102/24", "eth2", 1500, true, "library/busybox")
	// add a docker container host as a Host1
	h1, err := tn.AddHostWithConf(hc1)
	if err != nil {
		log.Fatal("failed to AddHost:", err)
	}
	// setup Host2 network configuration
	hc2 := tn.NewHostConfig("h2", "10.0.0.101/24", "eth1", 1500, true, "library/busybox")
	// add a docker container host as a Host2
	h2, err := tn.AddHostWithConf(hc2)
	if err != nil {
		log.Fatal("failed to AddHost:", err)
	}

	// add Link for Switch1 - Host1
	if err := tn.AddLink(sw1, h1); err != nil {
		log.Fatal("failed to AddLink:", err)
	}
	// add Link for Host2 - Switch1
	if err := tn.AddLink(h2, sw1); err != nil {
		log.Fatal("failed to AddLink:", err)
	}
}

more complicated example that you might see in a examples folder

Cleanup command

cleanup command to remove interfaces, network namespaces and bridges.

$ sudo python clean.py

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLink(n1, n2 interface{}) error

AddLink will add a link between switch to switch or host to switch.

func GetIPs

func GetIPs(cidr string, num int) ([]string, error)

GetIPs will get IP address from a CIDR notation Return an array with IP address. negative num for getting all IP addresses (network address and broadcast address are not included)

Types

type Host

type Host struct {
	NodeType string
	Name     string
	VethName string
	IfName   string
	Sandbox  string
	IP       string
	MAC      string
}

Host is a host instance

func AddHost

func AddHost(name string, addr string, docker bool) (*Host, error)

AddHost will add a host to topology. set docker to true can enable docker container as a host

func AddHostWithConf

func AddHostWithConf(hc HostConfig) (*Host, error)

AddHostWithConf will add a host to topology.

func NewContainer

func NewContainer(name string, imageRef string) (*Host, error)

NewContainer for creating a docker container

func NewHost

func NewHost(name string) (*Host, error)

NewHost for creating a network namespace

type HostConfig

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

HostConfig is a host network configuration

func NewHostConfig

func NewHostConfig(name, addr, ifaceName string, mtu int, docker bool, imageRef string) HostConfig

NewHostConfig is a constructor to initial host network configuration.

type OVSSwitch

type OVSSwitch struct {
	NodeType     string
	BridgeName   string
	CtrlHostPort string
	// contains filtered or unexported fields
}

OVSSwitch is a bridge instance

func AddSwitch

func AddSwitch(params ...string) (*OVSSwitch, error)

AddSwitch will add a switch to topology.

func NewOVSSwitch

func NewOVSSwitch(bridgeName string) (*OVSSwitch, error)

NewOVSSwitch for creating a ovs bridge

func (*OVSSwitch) Delete

func (sw *OVSSwitch) Delete() error

func (*OVSSwitch) SetCtrl

func (sw *OVSSwitch) SetCtrl(hostport string) error

SetCtrl for seting up OpenFlow controller for ovs bridge

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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