Giter Site home page Giter Site logo

openflow's Introduction

openflow - The OpenFlow protocol library

Build Status Documentation

The openflow library is a pure Go implementation of the OpenFlow protocol. The ideas of the programming interface mostly borrowed from the Go standard HTTP library.

Installation

$ go get github.com/netrack/openflow

Usage

The usage is pretty similar to the handling HTTP request, but instead of routes we are using message types.

package main

import (
    of "github.com/netrack/openflow"
)

func main() {
    // Define the OpenFlow handler for hello messages.
    of.HandleFunc(of.TypeHello, func(rw of.ResponseWriter, r *of.Request) {
        // Send back hello response.
        rw.Write(&of.Header{Type: of.TypeHello}, nil)
    })

    // Start the TCP server on 6633 port.
    of.ListenAndServe(":6633", nil)
}
package main

import (
    "github.com/netrack/openflow/ofp"
    of "github.com/netrack/openflow"
)

func main() {
    pattern := of.TypeMatcher(of.TypePacketIn)

    mux := of.NewServeMux()
    mux.HandleFunc(pattern, func(rw of.ResponseWriter, r *of.Request) {
        var packet ofp.PacketIn
        packet.ReadFrom(r.Body)

        apply := &ofp.InstructionApplyActions{
            ofp.Actions{&ofp.ActionOutput{ofp.PortFlood, 0}},
        }

        // For each incoming packet-in request, create a
        // respective flow modification command.
        fmod := ofp.NewFlowMod(ofp.FlowAdd, packet)
        fmod.Instructions = ofp.Instructions{apply}

        rw.Write(&of.Header{Type: of.TypeFlowMod}, fmod)
    })

    of.ListenAndServe(":6633", mux)
}

License

The openflow library is distributed under MIT license, therefore you are free to do with code whatever you want. See the LICENSE file for full license text.

openflow's People

Contributors

codelingoteam avatar costiser avatar kent-h avatar samribeiro avatar ybubnov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openflow's Issues

Make ListenAndServe function accept address and handler.

In the current implementation ListenAndServe function does not accept any parameters. On one hand it is pretty simple, but not really useful, thus require refactoring.

The usage of the resulting function should look like the doppelganger from net/http package:

func ListenAndServe(addr string, handler Handler) error

Note, the server implementation could be required to accept nil value as handler parameter.

readTablePropXM() Shouldn't Read a Payload

Matches read as part of ofp_table_feature_prop_oxm should not include a payload.

From the spec (emphasis mine):
"The oxm_ids is the list of OXM types for the feature (see 7.2.3.2). The elements of that list are 32-bit
OXM headers for non-experimenter OXM fields or 64-bit OXM headers for experimenter OXM fields,
those OXM fields don’t include any payload."

These Matches are currently read assuming a payload, causing errors.

(Pull request WIP.)

DefaultHandler instead of DiscardHandler

Small nit but it seems intuitive to me that all references to DiscardHandler should instead be named DefaultHandler.

func DiscardHandler(rw ResponseWriter, r *Request) {}

var DefaultHandler = DiscardHandler

s/DiscardHandler/DefaultHandler

we can then override an externally visible DefaultHandler which makes more sense than overriding DiscardHandler.

Create integration tests

The library more or less is covered with unit tests, but is lack of integration tests, therefore in terms of this issue, should be introduced integration tests with Open V-Switch, that cover some scenario of communication between the data plane and control plane.

Also, the tests should require minimal configuration of the development environment. Ideally, it would be nice to describe environment using Dockerfile.

Cookie match for multipart requests

During the implementation of the integration tests notices the problem with registering disposable handler for multipart requests.

Initially, I thought to use the NewCookieMatcher to match the multipart response, but ofp.MultipartRequest header does not implement CookieJar interface, while the body of multipart request does (e.g. AggregateStatsRequest).

Need a solution how to register disposable handler for multipart responses.

consolidate package naming to either "of" or "openflow"

I suggest "openflow".
If other packages want to use a shorter name they can name the import:
of "netrack/openflow"

one strange example is "ofputil/handler.go" where it imports "openflow", but the package is defined as "of".

Identifiers should not use camel case instead of all caps

Identifiers in the match.go file should be modified to pass golint validations:

ofp.v13/match.go:162:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:165:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:177:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:180:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:183:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:186:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:189:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:192:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:195:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:198:2: don't use ALL_CAPS in Go names; use CamelCase
ofp.v13/match.go:201:2: don't use ALL_CAPS in Go names; use CamelCase

Table features generated messages seems incorrect

I was expecting the following to work. But it does not. =(

ofp.TableFeatures{
		Table:      0,
		Name:       "Table0",
		MaxEntries: 1000,
		Properties: []ofp.TableProp{
			ofp.TableProp(&ofp.TablePropInstructions{
				Instructions: ofp.Instructions{
					ofp.Instruction(&ofp.InstructionApplyActions{}),
				},
			}),
		},
},

The generated packet has extra junk after InstructionApplyActions{}.

The shortest workaround is to prevent the extra fields from being serialized. Example:

type InstructionApplyActions struct{ ofp.InstructionApplyActions }

func (i *InstructionApplyActions) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, i.Type(), uint16(4))
}

The workaround is feasible but expensive. Any alternative option? This issue is consistent with most if not all of the fields used in TablePropInstructions.

Create a uniform function to align the messages

The OpenFlow specification mentions about the message padding, that forces some
of the structures with variable size to be aligned up to 8-byte boundary. Currently the
ofp package does not have any uniform approach to deal with it, instead it contains
copy-pasted snippets, like this one below:

padding := make([]byte, (header.Len+7)/8*8-header.Len)
nn, err := encoding.ReadFrom(r, padding)

Therefore, it would be better to refactor this part and introduce a new function as part of
the encoding package, that will handle this automatically (e.g. ReadFullFrom(r, &values, 8)).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.