Skip to content

Commit 5f84efe

Browse files
authored
GoLint and GoVet warnings (#143)
This patch removes GoLint and GoVet warnings.
1 parent 6a58d4d commit 5f84efe

File tree

16 files changed

+168
-45
lines changed

16 files changed

+168
-45
lines changed

cookie.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"reflect"
1010
)
1111

12+
// CookieJar manages storage and use of cookies in OpenFlow requests.
1213
type CookieJar interface {
1314
SetCookies(uint64)
1415
Cookies() uint64
@@ -55,7 +56,7 @@ func NewCookieMatcher(j CookieJar) *CookieMatcher {
5556
cookiesLow := rand.Uint32()
5657
cookiesHigh := rand.Uint32()
5758

58-
cookies = uint64(cookiesHigh<<32) | uint64(cookiesLow)
59+
cookies = (uint64(cookiesHigh) << 32) | uint64(cookiesLow)
5960

6061
// Set the generated cookies to the given cookie jar and also
6162
// put this value to the matcher.

header.go

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,154 @@ import (
99
)
1010

1111
const (
12-
// Immutable messages.
12+
// TypeHello is used by either controller or switch during connection
13+
// setup. It is used for version negotiation. When the connection
14+
// is established, each side must immediately send a Hello message
15+
// with the version field set to the highest version supported by
16+
// the sender. If the version negotiation fails, an Error message
17+
// is sent with type HelloFailed and code Incompatible.
1318
TypeHello Type = iota
19+
20+
// TypeError can be sent by either the switch or the controller and
21+
// indicates the failure of an operation. The simplest failure pertain
22+
// to malformed messages or failed version negotiation, while more
23+
// complex scenarios desbie some failure in state change at the switch.
1424
TypeError
25+
26+
// TypeEchoRequest is used to exchange information about latency,
27+
// bandwidth and liveness. Echo request timeout indicates disconnection.
1528
TypeEchoRequest
29+
30+
// TypeEchoReply is used to exchange information about latency,
31+
// bandwidth and liveness. Echo reply is sent as a response to Echo
32+
// request.
1633
TypeEchoReply
34+
35+
// TypeExperiment is a mechanism for proprietary messages within the
36+
// protocol.
1737
TypeExperiment
1838

19-
// Switch configuration messages.
39+
// TypeFeaturesRequest is used when a transport channel (TCP, SCTP,
40+
// TLS) is established between the switch and controller, the first
41+
// activity is feature determination. The controller will send a
42+
// feature request to the switch over the transport channel.
2043
TypeFeaturesRequest
44+
45+
// TypeFeaturesReply is the switch's reply to the controller
46+
// enumerating its abilities.
2147
TypeFeaturesReply
48+
49+
// TypeGetConfigRequest sequence is used to query and set the
50+
// fragmentation handling properties of the packet processing pipeline.
2251
TypeGetConfigRequest
52+
53+
// TypeGetConfigReply is the switch's reply to the controller
54+
// that acknowledges configuration requests.
2355
TypeGetConfigReply
56+
57+
// TypeSetConfig is used by the controller to alter the switch's
58+
// configuration. This message is unacknowledged.
2459
TypeSetConfig
2560

26-
// Asynchronous messages.
61+
// TypePacketIn message is a way for the switch to send a captured
62+
// packet to the controller.
2763
TypePacketIn
64+
65+
// TypeFlowRemoved is sent to the controller by the switch when a
66+
// flow entry in a flow table is removed. It happens when a timeout
67+
// occurs, either due to inactivity or hard timeout. An idle timeout
68+
// happens when no packets are matched in a period of time. A hard
69+
// timeout happens when a certain period of time elapses, regardless
70+
// of the number of matching packets. Whether the switch sends a
71+
// TypeFlowRemoved message after a timeout is specified by the
72+
// TypeFlowMod. Flow entry removal with a TypeFlowMod message from
73+
// the controller can also lead to a TypeFlowRemoved message.
2874
TypeFlowRemoved
75+
76+
// TypePortStatus messages are asynchronous events sent from the
77+
// switch to the controller indicating a change of status for the
78+
// indicated port.
2979
TypePortStatus
3080

31-
// Controller command messages.
81+
// TypePacketOut is used by the controller to inject packets into the
82+
// data plane of a particular switch. Such message can either carry a
83+
// raw packet to inject into the switch, or indicate a local buffer
84+
// on the switch containing a raw packet to release. Packets injected
85+
// into the data plane of a switch using this method are not treated
86+
// the same as packets that arrive on standard ports. The packet jumps
87+
// to the action set application stage in the standard packet processing
88+
// pipeline. If the action set indicates table processing is necessary
89+
// then the input port id is used as the arrival port of the raw packet.
3290
TypePacketOut
91+
92+
// TypeFlowMod is one of the main messages, it allows the controller
93+
// to modify the state of switch.
3394
TypeFlowMod
95+
96+
// TypeGroupMod is used by controller to modify group tables.
3497
TypeGroupMod
98+
99+
// TypePortMod is used by the controller to modify the state of port.
35100
TypePortMod
101+
102+
// TypeTableMod is used to determine a packet's fate when it misses
103+
// in the table. It can be forwarded to the controller, dropped, or
104+
// sent to the next table.
36105
TypeTableMod
37106

38-
// Multipart messages
107+
// TypeMultipartRequest is used by the controller to request the
108+
// state of the datapath.
39109
TypeMultipartRequest
110+
111+
// TypeMultipartReply are the replies from the switch to controller
112+
// on TypeMultipartRequest messages.
40113
TypeMultipartReply
41114

42-
// Barrier messages
115+
// TypeBarrierRequest can be used by the controller to set a
116+
// synchronization point, ensuring that all previous state messages
117+
// are completed before the barrier response is sent back to the
118+
// controller.
43119
TypeBarrierRequest
120+
121+
// TypeBarrierReply is a response from the switch to controller
122+
// on TypeBarrierRequest messages.
44123
TypeBarrierReply
45124

46-
// Queue configuration messages.
125+
// TypeQueueGetConfigRequest can be used by the controller to
126+
// query the state of queues associated with various ports on switch.
47127
TypeQueueGetConfigRequest
128+
129+
// TypeQueueGetConfigReply is a response from the switch to controller
130+
// on TypeQueueGetConfigReply messages.
48131
TypeQueueGetConfigReply
49132

50-
// Controller role change request messages.
133+
// TypeRoleRequest is the message used by the controller to
134+
// modify its role among multiple controllers on a switch.
51135
TypeRoleRequest
136+
137+
// TypeRoleReply is a response from the switch to controller on
138+
// TypeRoleRequest.
52139
TypeRoleReply
53140

54-
// Asynchronous message configuration.
55-
TypeAsynchRequest
56-
TypeAsyncReply
141+
// TypeGetAsyncRequest is used by the controller to request the switch
142+
// which asynchronous events are enabled on the switch for the
143+
// communication channel.
144+
TypeGetAsyncRequest
145+
146+
// TypeGetAsyncReply is used by the switch as response to controller
147+
// on TypeAsyncRequest messages.
148+
TypeGetAsyncReply
149+
150+
// TypeSetAsync is used by the controller to set which asynchronous
151+
// messages it should send, as well as to query the switch for which
152+
// asynchronous messages it will send.
57153
TypeSetAsync
58154

59-
// Meters and rate limiters configuration messages.
155+
// TypeMeterMod used by the controller to modify the meter.
60156
TypeMeterMod
61157
)
62158

159+
// Type is an OpenFlow message type.
63160
type Type uint8
64161

65162
func (t Type) String() string {
@@ -98,8 +195,8 @@ var typeText = map[Type]string{
98195
TypeQueueGetConfigReply: "TypeQueueGetConfigReply",
99196
TypeRoleRequest: "TypeRoleRequest",
100197
TypeRoleReply: "TypeRoleReply",
101-
TypeAsynchRequest: "TypeAsynchRequest",
102-
TypeAsyncReply: "TypeAsyncReply",
198+
TypeGetAsyncRequest: "TypeGetAsyncRequest",
199+
TypeGetAsyncReply: "TypeGetAsyncReply",
103200
TypeSetAsync: "TypeSetAsync",
104201
TypeMeterMod: "TypeMeterMod",
105202
}
@@ -122,11 +219,12 @@ type Header struct {
122219
Transaction uint32
123220
}
124221

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

129-
// Length of the packet payload including header.
227+
// Len of the packet payload including header.
130228
func (h *Header) Len() int {
131229
return int(h.Length)
132230
}

internal/encoding/encoding.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ func ReadFunc(r io.Reader, rm ReaderMaker, fn func(r io.ReaderFrom)) (int64, err
175175

176176
fn(reader)
177177
}
178-
179-
return n, nil
180178
}
181179

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

206204
func ScanFrom(r io.Reader, v interface{}, rm ReaderMaker) (int64, error) {
207-
// Retrieve the size of the instruction type, that preceeds
205+
// Retrieve the size of the instruction type, that precedes
208206
// every instruction body.
209207
valType := reflect.TypeOf(v)
210208
typeLen := int(valType.Elem().Size())
@@ -244,8 +242,6 @@ func ScanFrom(r io.Reader, v interface{}, rm ReaderMaker) (int64, error) {
244242
return n, SkipEOF(err)
245243
}
246244
}
247-
248-
return n, nil
249245
}
250246

251247
// SkipEOF returns nil of the given error caused by the

mux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (t TypeMatcher) Match(r *Request) bool {
3131
}
3232

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

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

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

178+
// NewTypeMux creates and returns a new TypeMux.
178179
func NewTypeMux() *TypeMux {
179180
return &TypeMux{NewServeMux()}
180181
}
@@ -194,7 +195,7 @@ func (mux *TypeMux) HandleFunc(t Type, f HandlerFunc) {
194195
mux.Handle(t, f)
195196
}
196197

197-
// Handle returns a Handler instance for the given OpenFlow request.
198+
// Handler returns a Handler instance for the given OpenFlow request.
198199
func (mux *TypeMux) Handler(r *Request) Handler {
199200
return mux.mux.Handler(r)
200201
}

net.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,40 @@ import (
99
"time"
1010
)
1111

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

1416
const (
17+
// StateNew represents a new connection that is expected to
18+
// send a request immediately. Connections begin at this
19+
// state and the transition to either StateHandshake or
20+
// StateClosed.
1521
StateNew ConnState = iota
22+
23+
// StateHandshake represents a connection that has initiated
24+
// OpenFlow handshake routine. After the request is handled,
25+
// the state transitions to one of: StateHandshake, StateActive,
26+
// StateIdle or StateClosed.
1627
StateHandshake
28+
29+
// StateActive represents a connection that has read 1 or more
30+
// bytes of the request. The Server.ConnState hook for StateActive
31+
// fires before the request has been handled.
1732
StateActive
33+
34+
// StateIdle represents a connection that has finished
35+
// handling a request and is in the keep-alive state, waiting
36+
// for a new request. Connections transition from StateIdle
37+
// to StateHandshake, StateActive or StateClosed
1838
StateIdle
39+
40+
// StateClosed represents a closed connection. This is a
41+
// terminal state.
1942
StateClosed
2043
)
2144

45+
// String returns the string presentation of the ConnState.
2246
func (c ConnState) String() string {
2347
text, ok := connStateText[c]
2448
if !ok {

ofp/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ type ActionOutput struct {
229229
MaxLen uint16
230230
}
231231

232-
// Type retuns the type of the action.
232+
// Type returns the type of the action.
233233
func (a *ActionOutput) Type() ActionType {
234234
return ActionTypeOutput
235235
}

ofp/action_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestActionCopyTTLInOut(t *testing.T) {
1010
tests := []encodingtest.MU{
1111
{ReadWriter: &ActionCopyTTLOut{}, Bytes: []byte{
1212
0x00, 0xb, // Action type.
13-
0x00, 0x08, // Action lenght.
13+
0x00, 0x08, // Action length.
1414
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
1515
}},
1616
{ReadWriter: &ActionCopyTTLIn{}, Bytes: []byte{

ofp/instruction_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestIntructionWriteMetadata(t *testing.T) {
2727
MetadataMask: 0x3ec894d841073494,
2828
}, Bytes: []byte{
2929
0x00, 0x02, // Instruction type.
30-
0x00, 0x18, // Intruction length.
30+
0x00, 0x18, // Instruction length.
3131
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
3232
0x50, 0x91, 0xae, 0xdc, 0x96, 0x97, 0x44, 0x5e, // Metadata.
3333
0x3e, 0xc8, 0x94, 0xd8, 0x41, 0x07, 0x34, 0x94, // Metadata mask.
@@ -51,10 +51,10 @@ func TestInstructionApplyActions(t *testing.T) {
5151

5252
// Actions.
5353
0x00, 0x16, // Action group.
54-
0x00, 0x08, // Action lenght.
54+
0x00, 0x08, // Action length.
5555
0xff, 0xff, 0xff, 0xfc,
5656
0x00, 0xb, // Action type.
57-
0x00, 0x08, // Action lenght.
57+
0x00, 0x08, // Action length.
5858
0x00, 0x00, 0x00, 0x00, // 4-byte padding.
5959
}},
6060
}

ofp/match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ const (
282282
)
283283

284284
const (
285-
// xmlen defines the length of the extention match header, it does
285+
// xmlen defines the length of the extension match header, it does
286286
// not include the value and mask.
287287
xmlen = 4
288288
)

ofp/queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (q QueueProps) ReadFrom(r io.Reader) (int64, error) {
9090
// packetQueueLen defines the length of the packet queue header.
9191
const packetQueueLen = 16
9292

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

0 commit comments

Comments
 (0)