ogo

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

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

Go to latest
Published: Jun 26, 2018 License: GPL-3.0 Imports: 12 Imported by: 6

README

Ogo

An OpenFlow Network Controller written in Go.
This repo has some hot fixes and also ability to work with JSON configs.

A Basic Application

Register

To process OpenFlow messages register a function that returns a pointer to an existing or new Application struct.

func NewDemoInstance() interface{} {
  return &DemoInstance{}
}
controller.RegisterApplication(NewDemoInstance)
Receive

To receive OpenFlow messages, applications should implement the interfaces found in protocol/ofp10/interface.go or protocol/ofp13/interface.go.

func (b *DemoInstance) ConnectionUp(dpid net.HardwareAddr) {
  log.Println("Switch connected:", dpid)
}

func (b *DemoInstance) ConnectionDown(dpid net.HardwareAddr) {
  log.Println("Switch disconnected:", dpid)
}

func (b *DemoInstance) PacketIn(dpid net.HardwareAddr, pkt *ofp10.PacketIn) {
  log.Println("PacketIn message received from:", dpid)
}
Send

Any struct that implements util.Message can be sent to the switch. Only OpenFlow messages should be sent using OFSwitch.Send(m util.Message).

req := ofp10.NewEchoRequest()

// If switch dpid is known, returns its OFPSwitch struct. The
// switch is not guaranteed to have an active connection.
if sw, ok := ogo.Switch(dpid string); ok {
  sw.Send(req)
}

Documentation

Index

Constants

This section is empty.

Variables

Functions

func NewInstance

func NewInstance() interface{}

OgoInstance generator.

func NewSwitch

func NewSwitch(stream *MessageStream, msg ofp10.SwitchFeatures)

Builds and populates a Switch struct then starts listening for OpenFlow messages on conn.

Types

type ApplicationInstanceGenerator

type ApplicationInstanceGenerator func() interface{}

type BufferPool

type BufferPool struct {
	Empty chan *bytes.Buffer
	Full  chan *bytes.Buffer
}

func NewBufferPool

func NewBufferPool() *BufferPool

type Controller

type Controller struct{}

func NewController

func NewController() *Controller

func (*Controller) Listen

func (c *Controller) Listen(port string)

func (*Controller) RegisterApplication

func (c *Controller) RegisterApplication(fn ApplicationInstanceGenerator)

Setup OpenFlow Message chans for each message type.

type Link struct {
	DPID      net.HardwareAddr
	Port      uint16
	Latency   time.Duration
	Bandwidth int
}

Internal representation of a network link. Can be used to describe the state of the link. Each switch maintains its own set of links.

type LinkDiscovery

type LinkDiscovery struct {
	SrcDPID net.HardwareAddr
	Nsec    int64 /* Number of nanoseconds elapsed since Jan 1, 1970. */
	// contains filtered or unexported fields
}

func NewLinkDiscovery

func NewLinkDiscovery() *LinkDiscovery

func (*LinkDiscovery) Len

func (d *LinkDiscovery) Len() uint16

func (*LinkDiscovery) MarshalBinary

func (d *LinkDiscovery) MarshalBinary() (data []byte, err error)

func (*LinkDiscovery) UnmarshalBinary

func (d *LinkDiscovery) UnmarshalBinary(data []byte) error

type MessageStream

type MessageStream struct {

	// OpenFlow Version
	Version uint8
	// Channel on which to publish connection errors
	Error chan error
	// Channel on which to publish inbound messages
	Inbound chan util.Message
	// Channel on which to receive outbound messages
	Outbound chan util.Message
	// Channel on which to receive a shutdown command
	Shutdown chan bool
	// contains filtered or unexported fields
}

func NewMessageStream

func NewMessageStream(conn *net.TCPConn) *MessageStream

Returns a pointer to a new MessageStream. Used to parse OpenFlow messages from conn.

func (*MessageStream) GetAddr

func (m *MessageStream) GetAddr() net.Addr

type Network

type Network struct {
	sync.RWMutex
	Switches map[string]*OFSwitch
}

A map from DPIDs to all Switches that have connected since Ogo started.

func NewNetwork

func NewNetwork() *Network

type OFSwitch

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

func Switch

func Switch(dpid net.HardwareAddr) (*OFSwitch, bool)

Returns a pointer to the Switch mapped to dpid.

func Switches

func Switches() []*OFSwitch

Returns a slice of *OFPSwitches for operations across all switches.

func (*OFSwitch) AddInstance

func (sw *OFSwitch) AddInstance(inst interface{})

func (*OFSwitch) DPID

func (s *OFSwitch) DPID() net.HardwareAddr

Returns the dpid of Switch s.

func (s *OFSwitch) Link(dpid net.HardwareAddr) (l Link, ok bool)

Returns the link between Switch s and the Switch dpid.

func (s *OFSwitch) Links() []Link

Returns a slice of all links connected to Switch s.

func (*OFSwitch) MarshalJSON

func (sw *OFSwitch) MarshalJSON() ([]byte, error)

func (*OFSwitch) Port

func (sw *OFSwitch) Port(portNo uint16) (port ofp10.PhyPort, ok bool)

Returns a pointer to the OfpPhyPort at port number from Switch s.

func (*OFSwitch) Ports

func (s *OFSwitch) Ports() []ofp10.PhyPort

Returns a slice of all the ports from Switch s.

func (*OFSwitch) Send

func (s *OFSwitch) Send(req util.Message)

Sends an OpenFlow message to this Switch.

func (*OFSwitch) SetPort

func (sw *OFSwitch) SetPort(portNo uint16, port ofp10.PhyPort)

type OgoInstance

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

func (*OgoInstance) ConnectionDown

func (o *OgoInstance) ConnectionDown(dpid net.HardwareAddr)

func (*OgoInstance) ConnectionUp

func (o *OgoInstance) ConnectionUp(dpid net.HardwareAddr)

func (*OgoInstance) EchoReply

func (o *OgoInstance) EchoReply(dpid net.HardwareAddr)

func (*OgoInstance) EchoRequest

func (o *OgoInstance) EchoRequest(dpid net.HardwareAddr)

func (*OgoInstance) FeaturesReply

func (o *OgoInstance) FeaturesReply(dpid net.HardwareAddr, features *ofp10.SwitchFeatures)

func (*OgoInstance) PacketIn

func (o *OgoInstance) PacketIn(dpid net.HardwareAddr, msg *ofp10.PacketIn)

Directories

Path Synopsis
example
l2
protocol
arp
eth
ofp
ofp10
OpenFlow Wire Protocol 0x01 Package ofp10 provides OpenFlow 1.0 structs along with Read and Write methods for each.
OpenFlow Wire Protocol 0x01 Package ofp10 provides OpenFlow 1.0 structs along with Read and Write methods for each.
ofpxx
Package ofpxx defines OpenFlow message types that are version independent.
Package ofpxx defines OpenFlow message types that are version independent.
tcp
udp

Jump to

Keyboard shortcuts

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