Skip to content

Commit

Permalink
add some constants and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Feb 20, 2021
1 parent 1688d7d commit 018684b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
36 changes: 36 additions & 0 deletions constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ovs

// Some linux commands.
var (
IPCmd = "ip"
OfctlCmd = "ovs-ofctl"
VsctlCmd = "ovs-vsctl"
)

// L2 Data-Link Protocol Number
const (
ARP = 0x0806
IPv4 = 0x0800
IPv6 = 0x86dd
)

// L3 IP Protocol Number
const (
ICMP = 1
TCP = 6
UDP = 17
GRE = 47
)

// OVS Actions
const (
DROP = "drop"
LOCAL = "local"
FLOOD = "flood"
NORMAL = "normal"
)

// MAC address
const (
BroadcastMac = "ff:ff:ff:ff:ff:ff"
)
16 changes: 8 additions & 8 deletions ovs_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func GetAllFlows(bridge string, isName, isStats bool) (flows []string, err error
var out string
if isName {
if isStats {
out, err = exec.Outputs("ovs-ofctl", "--names", "--stats", "dump-flows", bridge)
out, err = exec.Outputs(OfctlCmd, "--names", "--stats", "dump-flows", bridge)
} else {
out, err = exec.Outputs("ovs-ofctl", "--names", "--no-stats", "dump-flows", bridge)
out, err = exec.Outputs(OfctlCmd, "--names", "--no-stats", "dump-flows", bridge)
}
} else {
if isStats {
out, err = exec.Outputs("ovs-ofctl", "--no-names", "--stats", "dump-flows", bridge)
out, err = exec.Outputs(OfctlCmd, "--no-names", "--stats", "dump-flows", bridge)
} else {
out, err = exec.Outputs("ovs-ofctl", "--no-names", "--no-stats", "dump-flows", bridge)
out, err = exec.Outputs(OfctlCmd, "--no-names", "--no-stats", "dump-flows", bridge)
}
}

Expand All @@ -70,7 +70,7 @@ func GetAllFlows(bridge string, isName, isStats bool) (flows []string, err error
// AddFlows adds the flows.
func AddFlows(bridge string, flows ...string) (err error) {
for _, flow := range flows {
if err = exec.Executes("ovs-ofctl", "add-flow", bridge, flow); err != nil {
if err = exec.Executes(OfctlCmd, "add-flow", bridge, flow); err != nil {
return
}
}
Expand All @@ -80,7 +80,7 @@ func AddFlows(bridge string, flows ...string) (err error) {
// DelFlows deletes the flows.
func DelFlows(bridge string, matches ...string) (err error) {
for _, match := range matches {
if err = exec.Executes("ovs-ofctl", "del-flows", bridge, match); err != nil {
if err = exec.Executes(OfctlCmd, "del-flows", bridge, match); err != nil {
return
}
}
Expand All @@ -91,7 +91,7 @@ func DelFlows(bridge string, matches ...string) (err error) {
func DelFlowsStrict(bridge string, priority int, matches ...string) (err error) {
for _, match := range matches {
match = fmt.Sprintf("priority=%d,%s", priority, match)
err = exec.Executes("ovs-ofctl", "--strict", "del-flows", bridge, match)
err = exec.Executes(OfctlCmd, "--strict", "del-flows", bridge, match)
if err != nil {
return
}
Expand Down Expand Up @@ -153,6 +153,6 @@ func SendARPRequest(bridge, output, inPort, srcMac, srcIP, dstIP string,
}

pkt := fmt.Sprintf(arpPacket, srcmac, vlan, srcmac, srcIP, dstIP)
exec.Execute("ovs-ofctl", "packet-out", bridge, inPort, output, pkt)
exec.Execute(OfctlCmd, "packet-out", bridge, inPort, output, pkt)
return
}

0 comments on commit 018684b

Please sign in to comment.