Skip to content

Commit b563528

Browse files
authored
Merge pull request #63 from andrewsykim/ofproto-trace-support
add initial support for ovs-appctl ofproto/trace
2 parents 2fbc32e + d9cc74a commit b563528

File tree

10 files changed

+1025
-30
lines changed

10 files changed

+1025
-30
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22
go:
3-
- 1.x
3+
- 1.11
44
os:
55
- linux
66
sudo: required
@@ -9,13 +9,11 @@ before_install:
99
- sudo apt install openvswitch-switch
1010
- sudo ovs-vsctl add-br ovsbr0
1111
- go get github.com/golang/lint/golint
12-
- go get honnef.co/go/tools/cmd/staticcheck
1312
- go get -d ./...
1413
script:
1514
- ./scripts/licensecheck.sh
1615
- go build -tags=gofuzz ./...
1716
- go vet ./...
18-
- staticcheck ./...
1917
- ./scripts/gofmt.sh
2018
- ./scripts/golint.sh
2119
- go test -race ./...

ovs/action.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ var (
2626
// errCTNoArguments is returned when no arguments are passed to ActionCT.
2727
errCTNoArguments = errors.New("no arguments for connection tracking")
2828

29+
// errInvalidIPv6Label is returned when an input IPv6 label is out of
30+
// range. It should only use the first 20 bits of the 32 bit field.
31+
errInvalidIPv6Label = errors.New("IPv6 label must only use 20 bits")
32+
33+
// errInvalidARPOP is returned when an input ARP OP is out of
34+
// range. It should be in the range 1-4.
35+
errInvalidARPOP = errors.New("ARP OP must in the range 1-4")
36+
2937
// errInvalidVLANVID is returned when an input VLAN VID is out of range
3038
// for a valid VLAN VID.
3139
errInvalidVLANVID = errors.New("VLAN VID must be between 0 and 4095")
3240

41+
// errInvalidVLANVIDPCP is returned when an input VLAN PCP is out of range
42+
// for a valid VLAN PCP.
43+
errInvalidVLANPCP = errors.New("VLAN PCP must be between 0 and 7")
44+
3345
// errOutputNegativePort is returned when Output is called with a
3446
// negative integer port.
3547
errOutputNegativePort = errors.New("output port number must not be negative")
@@ -557,8 +569,26 @@ func (a *setTunnelAction) MarshalText() ([]byte, error) {
557569
return bprintf("set_tunnel:%#x", a.tunnelID), nil
558570
}
559571

572+
// validARPOP indicates if an ARP OP is out of range. It should be in the range
573+
// 1-4.
574+
func validARPOP(op uint16) bool {
575+
return 1 <= op && op <= 4
576+
}
577+
578+
// validIPv6Label indicates if an IPv6 label is out of range. It should only
579+
// use the first 20 bits of the 32 bit field.
580+
func validIPv6Label(label uint32) bool {
581+
return (label & 0xfff00000) == 0x00000000
582+
}
583+
560584
// validVLANVID indicates if a VLAN VID falls within the valid range
561585
// for a VLAN VID.
562586
func validVLANVID(vid int) bool {
563587
return vid >= 0x000 && vid <= 0xfff
564588
}
589+
590+
// validVLANVPCP indicates if a VLAN VID falls within the valid range
591+
// for a VLAN VID.
592+
func validVLANPCP(pcp int) bool {
593+
return pcp >= 0 && pcp <= 7
594+
}

ovs/app.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2017 DigitalOcean.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package ovs
16+
17+
import (
18+
"strings"
19+
)
20+
21+
// AppService runs commands that are available from ovs-appctl
22+
type AppService struct {
23+
c *Client
24+
}
25+
26+
// ProtoTrace runs ovs-appctl ofproto/trace on the given bridge and match flow
27+
// and returns a *ProtoTrace. Also returns err if there is any error parsing the
28+
// output from ovs-appctl ofproto/trace.
29+
func (a *AppService) ProtoTrace(bridge string, matches []Match) (*ProtoTrace, error) {
30+
matchFlows := []string{}
31+
for _, match := range matches {
32+
matchFlow, err := match.MarshalText()
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
matchFlows = append(matchFlows, string(matchFlow))
38+
}
39+
40+
matchArg := strings.Join(matchFlows, ",")
41+
out, err := a.exec("ofproto/trace", bridge, matchArg)
42+
if err != nil {
43+
return nil, err
44+
}
45+
46+
pt := &ProtoTrace{}
47+
err = pt.UnmarshalText(out)
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
return pt, nil
53+
}
54+
55+
// exec executes 'ovs-appctl' + args passed in
56+
func (a *AppService) exec(args ...string) ([]byte, error) {
57+
return a.c.exec("ovs-appctl", args...)
58+
}

ovs/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type Client struct {
3030
// OpenFlow wraps functionality of the 'ovs-ofctl' binary.
3131
OpenFlow *OpenFlowService
3232

33+
// App wraps functionality of the 'ovs-appctl' binary
34+
App *AppService
35+
3336
// VSwitch wraps functionality of the 'ovs-vsctl' binary.
3437
VSwitch *VSwitchService
3538

@@ -232,6 +235,11 @@ func New(options ...OptionFunc) *Client {
232235
}
233236
c.OpenFlow = ofs
234237

238+
app := &AppService{
239+
c: c,
240+
}
241+
c.App = app
242+
235243
return c
236244
}
237245

0 commit comments

Comments
 (0)