|
1 | 1 | go-openvswitch [](https://travis-ci.org/digitalocean/go-openvswitch) [](https://godoc.org/github.com/digitalocean/go-openvswitch) [](https://goreportcard.com/report/github.com/digitalocean/go-openvswitch)
|
2 | 2 | ==============
|
3 | 3 |
|
4 |
| -Go packages which enable interacting with Open vSwitch. Apache 2.0 Licensed. |
| 4 | +Go packages which enable interacting with Open vSwitch and related tools. Apache 2.0 Licensed. |
5 | 5 |
|
6 | 6 | - `ovs`: Package ovs is a client library for Open vSwitch which enables programmatic control of the virtual switch.
|
| 7 | +- `ovsdb`: Package ovsdb implements an OVSDB client, as described in RFC 7047. |
7 | 8 | - `ovsnl`: Package ovsnl enables interaction with the Linux Open vSwitch generic netlink interface.
|
8 | 9 |
|
9 | 10 | ovs
|
10 | 11 | ---
|
11 | 12 |
|
12 |
| -Not yet open source; coming soon! |
| 13 | +Package `ovs` is a wrapper around the `ovs-vsctl` and `ovs-ofctl` utilities, but |
| 14 | +in the future, it may speak OVSDB and OpenFlow directly with the same interface. |
| 15 | + |
| 16 | +```go |
| 17 | +// Create a *ovs.Client. Specify ovs.OptionFuncs to customize it. |
| 18 | +c := ovs.New( |
| 19 | + // Prepend "sudo" to all commands. |
| 20 | + ovs.Sudo(), |
| 21 | +) |
| 22 | + |
| 23 | +// $ sudo ovs-vsctl --may-exist add-br ovsbr0 |
| 24 | +if err := c.VSwitch.AddBridge("ovsbr0"); err != nil { |
| 25 | + log.Fatalf("failed to add bridge: %v", err) |
| 26 | +} |
| 27 | + |
| 28 | +// $ sudo ovs-ofctl add-flow ovsbr0 priority=100,ip,actions=drop |
| 29 | +err := c.OpenFlow.AddFlow("ovsbr0", &ovs.Flow{ |
| 30 | + Priority: 100, |
| 31 | + Protocol: ovs.ProtocolIPv4, |
| 32 | + Actions: []ovs.Action{ovs.Drop()}, |
| 33 | +}) |
| 34 | +if err != nil { |
| 35 | + log.Fatalf("failed to add flow: %v", err) |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +ovsdb |
| 40 | +----- |
| 41 | + |
| 42 | +Package `ovsdb` allows you to communicate with an instance of `ovsdb-server` using |
| 43 | +the OVSDB protocol, specified in [RFC 7047](https://tools.ietf.org/html/rfc7047). |
| 44 | + |
| 45 | +```go |
| 46 | +// Dial an OVSDB connection and create a *ovsdb.Client. |
| 47 | +c, err := ovsdb.Dial("unix", "/var/run/openvswitch/db.sock") |
| 48 | +if err != nil { |
| 49 | + log.Fatalf("failed to dial: %v", err) |
| 50 | +} |
| 51 | +// Be sure to close the connection! |
| 52 | +defer c.Close() |
| 53 | + |
| 54 | +// Ask ovsdb-server for all of its databases. |
| 55 | +dbs, err := c.ListDatabases() |
| 56 | +if err != nil { |
| 57 | + log.Fatalf("failed to list databases: %v", err) |
| 58 | +} |
| 59 | + |
| 60 | +for _, d := range dbs { |
| 61 | + log.Println(d) |
| 62 | +} |
| 63 | +``` |
13 | 64 |
|
14 | 65 | ovsnl
|
15 | 66 | -----
|
16 | 67 |
|
17 | 68 | Package `ovsnl` allows you to utilize OvS's Linux generic netlink interface to
|
18 |
| -pull data from the kernel. Here's an example: |
| 69 | +pull data from the kernel. |
19 | 70 |
|
20 | 71 | ```go
|
21 | 72 | // Dial a generic netlink connection and create a *ovsnl.Client.
|
|
0 commit comments