xgfone / go-ovs

A simple OVS flow executor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OVS Build Status GoDoc License

A simple OVS flow executor supporting Go1.18+.

Example

package main

import (
	"context"

	"github.com/xgfone/go-exec"
	"github.com/xgfone/go-ovs"
)

func main() {
	initBridge("br-ovs")
	initFlows("br-ovs")
}

func must(err error) {
	if err != nil {
		panic(err)
	}
}

func initBridge(bridge string) {
	must(exec.Execute(context.Background(),
		"ovs-vsctl", "--may-exist", "add-br", bridge,
		"--", "set-fail-mode", bridge, "secure",
	))

	must(exec.Execute(context.Background(),
		"ip", "link", "set", bridge, "up",
	))
}

func initFlows(bridge string) {
	// Table 0
	ovs.MustAddFlow(bridge, "table=0,in_port=1,actions=goto_table:1")
	ovs.MustAddFlow(bridge, "table=0,in_port=2,actions=goto_table:2")
	ovs.MustAddFlow(bridge, "table=0,in_port=3,actions=goto_table:3")
	ovs.MustAddFlow(bridge, "table=0,in_port=4,actions=goto_table:4")
	ovs.MustAddFlow(bridge, "table=0,priority=0,actions=drop")

	// TODO ...
}

About

A simple OVS flow executor.

License:Apache License 2.0


Languages

Language:Go 100.0%