Skip to content

Commit cfb852a

Browse files
committed
*: create individual package READMEs
1 parent b101c8d commit cfb852a

File tree

4 files changed

+94
-86
lines changed

4 files changed

+94
-86
lines changed

README.md

+1-86
Original file line numberDiff line numberDiff line change
@@ -7,89 +7,4 @@ Go packages which enable interacting with Open vSwitch and related tools. Apache
77
- `ovsdb`: Package ovsdb implements an OVSDB client, as described in RFC 7047.
88
- `ovsnl`: Package ovsnl enables interaction with the Linux Open vSwitch generic netlink interface.
99

10-
ovs
11-
---
12-
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-
```
64-
65-
ovsnl
66-
-----
67-
68-
Package `ovsnl` allows you to utilize OvS's Linux generic netlink interface to
69-
pull data from the kernel.
70-
71-
```go
72-
// Dial a generic netlink connection and create a *ovsnl.Client.
73-
c, err := ovsnl.New()
74-
if err != nil {
75-
// If OVS generic netlink families aren't available, do nothing.
76-
if os.IsNotExist(err) {
77-
log.Printf("generic netlink OVS families not found: %v", err)
78-
return
79-
}
80-
81-
log.Fatalf("failed to create client %v", err)
82-
}
83-
// Be sure to close the generic netlink connection!
84-
defer c.Close()
85-
86-
// List available OVS datapaths.
87-
dps, err := c.Datapath.List()
88-
if err != nil {
89-
log.Fatalf("failed to list datapaths: %v", err)
90-
}
91-
92-
for _, d := range dps {
93-
log.Printf("datapath: %q, flows: %d", d.Name, d.Stats.Flows)
94-
}
95-
```
10+
See each package's README for additional information.

ovs/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ovs
2+
===
3+
4+
Package `ovs` is a client library for Open vSwitch which enables programmatic
5+
control of the virtual switch.
6+
7+
Package `ovs` is a wrapper around the `ovs-vsctl` and `ovs-ofctl` utilities, but
8+
in the future, it may speak OVSDB and OpenFlow directly with the same interface.
9+
10+
```go
11+
// Create a *ovs.Client. Specify ovs.OptionFuncs to customize it.
12+
c := ovs.New(
13+
// Prepend "sudo" to all commands.
14+
ovs.Sudo(),
15+
)
16+
17+
// $ sudo ovs-vsctl --may-exist add-br ovsbr0
18+
if err := c.VSwitch.AddBridge("ovsbr0"); err != nil {
19+
log.Fatalf("failed to add bridge: %v", err)
20+
}
21+
22+
// $ sudo ovs-ofctl add-flow ovsbr0 priority=100,ip,actions=drop
23+
err := c.OpenFlow.AddFlow("ovsbr0", &ovs.Flow{
24+
Priority: 100,
25+
Protocol: ovs.ProtocolIPv4,
26+
Actions: []ovs.Action{ovs.Drop()},
27+
})
28+
if err != nil {
29+
log.Fatalf("failed to add flow: %v", err)
30+
}
31+
```

ovsdb/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ovsdb
2+
=====
3+
4+
Package `ovsdb` implements an OVSDB client, as described in [RFC 7047](https://tools.ietf.org/html/rfc7047).
5+
6+
Package `ovsdb` allows you to communicate with an instance of `ovsdb-server` using
7+
the OVSDB protocol.
8+
9+
```go
10+
// Dial an OVSDB connection and create a *ovsdb.Client.
11+
c, err := ovsdb.Dial("unix", "/var/run/openvswitch/db.sock")
12+
if err != nil {
13+
log.Fatalf("failed to dial: %v", err)
14+
}
15+
// Be sure to close the connection!
16+
defer c.Close()
17+
18+
// Ask ovsdb-server for all of its databases, but only allow the RPC
19+
// a limited amount of time to complete before timing out.
20+
ctx, cancel := context.WithTimeout(context.Background(), 2 * time.Second)
21+
defer cancel()
22+
23+
dbs, err := c.ListDatabases(ctx)
24+
if err != nil {
25+
log.Fatalf("failed to list databases: %v", err)
26+
}
27+
28+
for _, d := range dbs {
29+
log.Println(d)
30+
}
31+
```

ovsnl/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ovsnl
2+
=====
3+
4+
Package `ovsnl` enables interaction with the Linux Open vSwitch generic
5+
netlink interface.
6+
7+
```go
8+
// Dial a generic netlink connection and create a *ovsnl.Client.
9+
c, err := ovsnl.New()
10+
if err != nil {
11+
// If OVS generic netlink families aren't available, do nothing.
12+
if os.IsNotExist(err) {
13+
log.Printf("generic netlink OVS families not found: %v", err)
14+
return
15+
}
16+
17+
log.Fatalf("failed to create client %v", err)
18+
}
19+
// Be sure to close the generic netlink connection!
20+
defer c.Close()
21+
22+
// List available OVS datapaths.
23+
dps, err := c.Datapath.List()
24+
if err != nil {
25+
log.Fatalf("failed to list datapaths: %v", err)
26+
}
27+
28+
for _, d := range dps {
29+
log.Printf("datapath: %q, flows: %d", d.Name, d.Stats.Flows)
30+
}
31+
```

0 commit comments

Comments
 (0)