Skip to content

Commit

Permalink
GoLint and GoVet warnings (#143)
Browse files Browse the repository at this point in the history
This patch removes GoLint and GoVet warnings.
  • Loading branch information
ybubnov authored Oct 1, 2018
1 parent 6a58d4d commit 5f84efe
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 45 deletions.
3 changes: 2 additions & 1 deletion cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
)

// CookieJar manages storage and use of cookies in OpenFlow requests.
type CookieJar interface {
SetCookies(uint64)
Cookies() uint64
Expand Down Expand Up @@ -55,7 +56,7 @@ func NewCookieMatcher(j CookieJar) *CookieMatcher {
cookiesLow := rand.Uint32()
cookiesHigh := rand.Uint32()

cookies = uint64(cookiesHigh<<32) | uint64(cookiesLow)
cookies = (uint64(cookiesHigh) << 32) | uint64(cookiesLow)

// Set the generated cookies to the given cookie jar and also
// put this value to the matcher.
Expand Down
128 changes: 113 additions & 15 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,154 @@ import (
)

const (
// Immutable messages.
// TypeHello is used by either controller or switch during connection
// setup. It is used for version negotiation. When the connection
// is established, each side must immediately send a Hello message
// with the version field set to the highest version supported by
// the sender. If the version negotiation fails, an Error message
// is sent with type HelloFailed and code Incompatible.
TypeHello Type = iota

// TypeError can be sent by either the switch or the controller and
// indicates the failure of an operation. The simplest failure pertain
// to malformed messages or failed version negotiation, while more
// complex scenarios desbie some failure in state change at the switch.
TypeError

// TypeEchoRequest is used to exchange information about latency,
// bandwidth and liveness. Echo request timeout indicates disconnection.
TypeEchoRequest

// TypeEchoReply is used to exchange information about latency,
// bandwidth and liveness. Echo reply is sent as a response to Echo
// request.
TypeEchoReply

// TypeExperiment is a mechanism for proprietary messages within the
// protocol.
TypeExperiment

// Switch configuration messages.
// TypeFeaturesRequest is used when a transport channel (TCP, SCTP,
// TLS) is established between the switch and controller, the first
// activity is feature determination. The controller will send a
// feature request to the switch over the transport channel.
TypeFeaturesRequest

// TypeFeaturesReply is the switch's reply to the controller
// enumerating its abilities.
TypeFeaturesReply

// TypeGetConfigRequest sequence is used to query and set the
// fragmentation handling properties of the packet processing pipeline.
TypeGetConfigRequest

// TypeGetConfigReply is the switch's reply to the controller
// that acknowledges configuration requests.
TypeGetConfigReply

// TypeSetConfig is used by the controller to alter the switch's
// configuration. This message is unacknowledged.
TypeSetConfig

// Asynchronous messages.
// TypePacketIn message is a way for the switch to send a captured
// packet to the controller.
TypePacketIn

// TypeFlowRemoved is sent to the controller by the switch when a
// flow entry in a flow table is removed. It happens when a timeout
// occurs, either due to inactivity or hard timeout. An idle timeout
// happens when no packets are matched in a period of time. A hard
// timeout happens when a certain period of time elapses, regardless
// of the number of matching packets. Whether the switch sends a
// TypeFlowRemoved message after a timeout is specified by the
// TypeFlowMod. Flow entry removal with a TypeFlowMod message from
// the controller can also lead to a TypeFlowRemoved message.
TypeFlowRemoved

// TypePortStatus messages are asynchronous events sent from the
// switch to the controller indicating a change of status for the
// indicated port.
TypePortStatus

// Controller command messages.
// TypePacketOut is used by the controller to inject packets into the
// data plane of a particular switch. Such message can either carry a
// raw packet to inject into the switch, or indicate a local buffer
// on the switch containing a raw packet to release. Packets injected
// into the data plane of a switch using this method are not treated
// the same as packets that arrive on standard ports. The packet jumps
// to the action set application stage in the standard packet processing
// pipeline. If the action set indicates table processing is necessary
// then the input port id is used as the arrival port of the raw packet.
TypePacketOut

// TypeFlowMod is one of the main messages, it allows the controller
// to modify the state of switch.
TypeFlowMod

// TypeGroupMod is used by controller to modify group tables.
TypeGroupMod

// TypePortMod is used by the controller to modify the state of port.
TypePortMod

// TypeTableMod is used to determine a packet's fate when it misses
// in the table. It can be forwarded to the controller, dropped, or
// sent to the next table.
TypeTableMod

// Multipart messages
// TypeMultipartRequest is used by the controller to request the
// state of the datapath.
TypeMultipartRequest

// TypeMultipartReply are the replies from the switch to controller
// on TypeMultipartRequest messages.
TypeMultipartReply

// Barrier messages
// TypeBarrierRequest can be used by the controller to set a
// synchronization point, ensuring that all previous state messages
// are completed before the barrier response is sent back to the
// controller.
TypeBarrierRequest

// TypeBarrierReply is a response from the switch to controller
// on TypeBarrierRequest messages.
TypeBarrierReply

// Queue configuration messages.
// TypeQueueGetConfigRequest can be used by the controller to
// query the state of queues associated with various ports on switch.
TypeQueueGetConfigRequest

// TypeQueueGetConfigReply is a response from the switch to controller
// on TypeQueueGetConfigReply messages.
TypeQueueGetConfigReply

// Controller role change request messages.
// TypeRoleRequest is the message used by the controller to
// modify its role among multiple controllers on a switch.
TypeRoleRequest

// TypeRoleReply is a response from the switch to controller on
// TypeRoleRequest.
TypeRoleReply

// Asynchronous message configuration.
TypeAsynchRequest
TypeAsyncReply
// TypeGetAsyncRequest is used by the controller to request the switch
// which asynchronous events are enabled on the switch for the
// communication channel.
TypeGetAsyncRequest

// TypeGetAsyncReply is used by the switch as response to controller
// on TypeAsyncRequest messages.
TypeGetAsyncReply

// TypeSetAsync is used by the controller to set which asynchronous
// messages it should send, as well as to query the switch for which
// asynchronous messages it will send.
TypeSetAsync

// Meters and rate limiters configuration messages.
// TypeMeterMod used by the controller to modify the meter.
TypeMeterMod
)

// Type is an OpenFlow message type.
type Type uint8

func (t Type) String() string {
Expand Down Expand Up @@ -98,8 +195,8 @@ var typeText = map[Type]string{
TypeQueueGetConfigReply: "TypeQueueGetConfigReply",
TypeRoleRequest: "TypeRoleRequest",
TypeRoleReply: "TypeRoleReply",
TypeAsynchRequest: "TypeAsynchRequest",
TypeAsyncReply: "TypeAsyncReply",
TypeGetAsyncRequest: "TypeGetAsyncRequest",
TypeGetAsyncReply: "TypeGetAsyncReply",
TypeSetAsync: "TypeSetAsync",
TypeMeterMod: "TypeMeterMod",
}
Expand All @@ -122,11 +219,12 @@ type Header struct {
Transaction uint32
}

// Copy returns a copy of the request header.
func (h *Header) Copy() *Header {
return &Header{h.Version, h.Type, h.Length, h.Transaction}
}

// Length of the packet payload including header.
// Len of the packet payload including header.
func (h *Header) Len() int {
return int(h.Length)
}
Expand Down
6 changes: 1 addition & 5 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ func ReadFunc(r io.Reader, rm ReaderMaker, fn func(r io.ReaderFrom)) (int64, err

fn(reader)
}

return n, nil
}

// ReaderMaker defines factory types, used to created new exemplars
Expand Down Expand Up @@ -204,7 +202,7 @@ func (fn ReaderMakerFunc) MakeReader() (io.ReaderFrom, error) {
}

func ScanFrom(r io.Reader, v interface{}, rm ReaderMaker) (int64, error) {
// Retrieve the size of the instruction type, that preceeds
// Retrieve the size of the instruction type, that precedes
// every instruction body.
valType := reflect.TypeOf(v)
typeLen := int(valType.Elem().Size())
Expand Down Expand Up @@ -244,8 +242,6 @@ func ScanFrom(r io.Reader, v interface{}, rm ReaderMaker) (int64, error) {
return n, SkipEOF(err)
}
}

return n, nil
}

// SkipEOF returns nil of the given error caused by the
Expand Down
9 changes: 5 additions & 4 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (t TypeMatcher) Match(r *Request) bool {
}

// MultiMatcher creates a new Matcher instance that matches the request
// by all specified criterias.
// by all specified criteria.
func MultiMatcher(m ...Matcher) Matcher {
fn := func(r *Request) bool {
for _, matcher := range m {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (mux *ServeMux) Handle(m Matcher, h Handler) {
mux.handle(&muxEntry{m, h, false})
}

// Handle registers disposable handler for the given pattern.
// HandleOnce registers disposable handler for the given pattern.
//
// It is not guaranteed that handler will process the first message
// exemplar of the matching message.
Expand All @@ -110,7 +110,7 @@ func (mux *ServeMux) HandleFunc(m Matcher, h HandlerFunc) {
mux.Handle(m, h)
}

// HandleFunc registers handler function for the given message type.
// Handler returns a handler of the specified request.
func (mux *ServeMux) Handler(r *Request) Handler {
var matcher Matcher
var entry *muxEntry
Expand Down Expand Up @@ -175,6 +175,7 @@ type TypeMux struct {
mux *ServeMux
}

// NewTypeMux creates and returns a new TypeMux.
func NewTypeMux() *TypeMux {
return &TypeMux{NewServeMux()}
}
Expand All @@ -194,7 +195,7 @@ func (mux *TypeMux) HandleFunc(t Type, f HandlerFunc) {
mux.Handle(t, f)
}

// Handle returns a Handler instance for the given OpenFlow request.
// Handler returns a Handler instance for the given OpenFlow request.
func (mux *TypeMux) Handler(r *Request) Handler {
return mux.mux.Handler(r)
}
Expand Down
24 changes: 24 additions & 0 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,40 @@ import (
"time"
)

// A ConnState represents the state of a client connection to a server. It's
// used by the optional Server.ConnState hook.
type ConnState int

const (
// StateNew represents a new connection that is expected to
// send a request immediately. Connections begin at this
// state and the transition to either StateHandshake or
// StateClosed.
StateNew ConnState = iota

// StateHandshake represents a connection that has initiated
// OpenFlow handshake routine. After the request is handled,
// the state transitions to one of: StateHandshake, StateActive,
// StateIdle or StateClosed.
StateHandshake

// StateActive represents a connection that has read 1 or more
// bytes of the request. The Server.ConnState hook for StateActive
// fires before the request has been handled.
StateActive

// StateIdle represents a connection that has finished
// handling a request and is in the keep-alive state, waiting
// for a new request. Connections transition from StateIdle
// to StateHandshake, StateActive or StateClosed
StateIdle

// StateClosed represents a closed connection. This is a
// terminal state.
StateClosed
)

// String returns the string presentation of the ConnState.
func (c ConnState) String() string {
text, ok := connStateText[c]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion ofp/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type ActionOutput struct {
MaxLen uint16
}

// Type retuns the type of the action.
// Type returns the type of the action.
func (a *ActionOutput) Type() ActionType {
return ActionTypeOutput
}
Expand Down
2 changes: 1 addition & 1 deletion ofp/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TestActionCopyTTLInOut(t *testing.T) {
tests := []encodingtest.MU{
{ReadWriter: &ActionCopyTTLOut{}, Bytes: []byte{
0x00, 0xb, // Action type.
0x00, 0x08, // Action lenght.
0x00, 0x08, // Action length.
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
}},
{ReadWriter: &ActionCopyTTLIn{}, Bytes: []byte{
Expand Down
6 changes: 3 additions & 3 deletions ofp/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestIntructionWriteMetadata(t *testing.T) {
MetadataMask: 0x3ec894d841073494,
}, Bytes: []byte{
0x00, 0x02, // Instruction type.
0x00, 0x18, // Intruction length.
0x00, 0x18, // Instruction length.
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
0x50, 0x91, 0xae, 0xdc, 0x96, 0x97, 0x44, 0x5e, // Metadata.
0x3e, 0xc8, 0x94, 0xd8, 0x41, 0x07, 0x34, 0x94, // Metadata mask.
Expand All @@ -51,10 +51,10 @@ func TestInstructionApplyActions(t *testing.T) {

// Actions.
0x00, 0x16, // Action group.
0x00, 0x08, // Action lenght.
0x00, 0x08, // Action length.
0xff, 0xff, 0xff, 0xfc,
0x00, 0xb, // Action type.
0x00, 0x08, // Action lenght.
0x00, 0x08, // Action length.
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
}},
}
Expand Down
2 changes: 1 addition & 1 deletion ofp/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ const (
)

const (
// xmlen defines the length of the extention match header, it does
// xmlen defines the length of the extension match header, it does
// not include the value and mask.
xmlen = 4
)
Expand Down
2 changes: 1 addition & 1 deletion ofp/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (q QueueProps) ReadFrom(r io.Reader) (int64, error) {
// packetQueueLen defines the length of the packet queue header.
const packetQueueLen = 16

// PacketQueue decribes the packet processing queue.
// PacketQueue describes the packet processing queue.
//
// An OpenFlow switch provides limited Quality-of-Service support (QoS)
// through a simple queuing mechanism. One (or more) queues can attach
Expand Down
Loading

0 comments on commit 5f84efe

Please sign in to comment.