Skip to content

Commit c910586

Browse files
authored
Merge pull request #10 from digitalocean/mdl-readme
README: add ovs, ovsdb examples
2 parents dada971 + d769a77 commit c910586

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,72 @@
11
go-openvswitch [![Build Status](https://travis-ci.org/digitalocean/go-openvswitch.svg?branch=master)](https://travis-ci.org/digitalocean/go-openvswitch) [![GoDoc](https://godoc.org/github.com/digitalocean/go-openvswitch?status.svg)](https://godoc.org/github.com/digitalocean/go-openvswitch) [![Go Report Card](https://goreportcard.com/badge/github.com/digitalocean/go-openvswitch)](https://goreportcard.com/report/github.com/digitalocean/go-openvswitch)
22
==============
33

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.
55

66
- `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.
78
- `ovsnl`: Package ovsnl enables interaction with the Linux Open vSwitch generic netlink interface.
89

910
ovs
1011
---
1112

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+
```
1364

1465
ovsnl
1566
-----
1667

1768
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.
1970

2071
```go
2172
// Dial a generic netlink connection and create a *ovsnl.Client.

0 commit comments

Comments
 (0)