本文整理汇总了Golang中github.com/weaveworks/go-odp/odp.NewDpif函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDpif函数的具体用法?Golang NewDpif怎么用?Golang NewDpif使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDpif函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: listVports
func listVports(f Flags) bool {
args := f.Parse(0, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
if len(args) == 0 {
// Although vport names are global, rather than being
// scoped to a datapath, odp can only enumerate the
// vports within a datapath. So enumerating them all
// is a bit of a faff.
dps, err := dpif.EnumerateDatapaths()
if err != nil {
return printErr("%s", err)
}
for dpname, dp := range dps {
if !printVports(dpname, dp) {
return false
}
}
return true
} else {
dp, dpname := lookupDatapath(dpif, args[0])
if dp == nil {
return false
}
return printVports(dpname, *dp)
}
}
示例2: deleteVport
func deleteVport(f Flags) bool {
args := f.Parse(1, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, vport, err := dpif.LookupVportByName(args[0])
if err != nil {
if odp.IsNoSuchVportError(err) {
return printErr("Cannot find port \"%s\"", args[0])
}
return printErr("%s", err)
}
err = dp.DeleteVport(vport.ID)
if err != nil {
return printErr("%s", err)
}
return true
}
示例3: CreateDatapath
func CreateDatapath(dpname string) error {
dpif, err := odp.NewDpif()
if err != nil {
return err
}
defer dpif.Close()
_, err = dpif.CreateDatapath(dpname)
if err != nil && !odp.IsDatapathNameAlreadyExistsError(err) {
return err
}
return nil
}
示例4: AddDatapathInterface
func AddDatapathInterface(dpname string, ifname string) error {
dpif, err := odp.NewDpif()
if err != nil {
return err
}
defer dpif.Close()
dp, err := dpif.LookupDatapath(dpname)
if err != nil {
return err
}
_, err = dp.CreateVport(odp.NewNetdevVportSpec(ifname))
return err
}
示例5: listDatapaths
func listDatapaths(f Flags) bool {
f.Parse(0, 0)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dps, err := dpif.EnumerateDatapaths()
for name, dp := range dps {
fmt.Printf("%d: %s\n", dp.IfIndex(), name)
}
return true
}
示例6: listenForVports
func listenForVports(f Flags) bool {
f.Parse(0, 0)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
done := make(chan struct{})
if err := dpif.ConsumeVportEvents(vportEventsConsumer{dpif, consumer{done}}); err != nil {
return printErr("%s", err)
}
<-done
return true
}
示例7: DeleteDatapath
func DeleteDatapath(dpname string) error {
dpif, err := odp.NewDpif()
if err != nil {
return err
}
defer dpif.Close()
dp, err := dpif.LookupDatapath(dpname)
if err != nil {
if odp.IsNoSuchDatapathError(err) {
return nil
}
return err
}
return dp.Delete()
}
示例8: CreateDatapath
func CreateDatapath(dpname string) (err error, supported bool) {
dpif, err := odp.NewDpif()
if err != nil {
if odp.IsKernelLacksODPError(err) {
return nil, false
}
return err, true
}
defer dpif.Close()
dp, err := dpif.CreateDatapath(dpname)
if err != nil && !odp.IsDatapathNameAlreadyExistsError(err) {
return err, true
}
// Pick an ephemeral port number to use in probing for vxlan
// support.
udpconn, err := net.ListenUDP("udp4", nil)
if err != nil {
return err, true
}
// we leave the UDP socket open, so creating a vxlan vport on
// the same port number should fail. But that's fine: It's
// still sufficient to probe for support.
portno := uint16(udpconn.LocalAddr().(*net.UDPAddr).Port)
vpid, err := dp.CreateVport(odp.NewVxlanVportSpec(
fmt.Sprintf("vxlan-%d", portno), portno))
if nlerr, ok := err.(odp.NetlinkError); ok {
if syscall.Errno(nlerr) == syscall.EAFNOSUPPORT {
dp.Delete()
return fmt.Errorf("kernel does not have Open vSwitch VXLAN support"), false
}
}
if err == nil {
dp.DeleteVport(vpid)
}
udpconn.Close()
return nil, true
}
示例9: listFlows
func listFlows(f Flags) bool {
var showStats bool
f.BoolVar(&showStats, "stats", false, "show statistics")
args := f.Parse(1, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, dpname := lookupDatapath(dpif, args[0])
if dp == nil {
return false
}
flows, err := dp.EnumerateFlows()
if err != nil {
return printErr("%s", err)
}
for _, flow := range flows {
os.Stdout.WriteString(dpname)
err = printFlowKeys(flow.FlowKeys, *dp)
if err != nil {
return printErr("%s", err)
}
err = printFlowActions(flow.Actions, *dp)
if err != nil {
return printErr("%s", err)
}
if showStats {
fmt.Printf(": %d packets, %d bytes, used %d",
flow.Packets, flow.Bytes, flow.Used)
}
os.Stdout.WriteString("\n")
}
return true
}
示例10: addFlow
func addFlow(f Flags) bool {
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, flow, ok := flagsToFlowSpec(f, dpif)
if !ok {
return false
}
err = dp.CreateFlow(flow)
if err != nil {
return printErr("%s", err)
}
return true
}
示例11: addVport
func addVport(dpname string, spec odp.VportSpec) bool {
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, dpname := lookupDatapath(dpif, dpname)
if dp == nil {
return false
}
_, err = dp.CreateVport(spec)
if err != nil {
return printErr("%s", err)
}
return true
}
示例12: listenOnDatapath
func listenOnDatapath(f Flags) bool {
var showKeys bool
f.BoolVar(&showKeys, "keys", false, "show flow keys on reported packets")
args := f.Parse(1, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, dpname := lookupDatapath(dpif, args[0])
if dp == nil {
return false
}
pipe, err := openTcpdump()
if err != nil {
return printErr("Error starting tcpdump: %s", err)
}
miss := func(packet []byte, flowKeys odp.FlowKeys) error {
if showKeys {
os.Stdout.WriteString("[" + dpname)
if err := printFlowKeys(flowKeys, *dp); err != nil {
return err
}
os.Stdout.WriteString("]\n")
}
return writeTcpdumpPacket(pipe, time.Now(), packet)
}
done := make(chan struct{})
_, err = dp.ConsumeMisses(missConsumer{consumer{done}, miss})
if err != nil {
return printErr("%s", err)
}
<-done
return true
}
示例13: addDatapath
func addDatapath(f Flags) bool {
args := f.Parse(1, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
_, err = dpif.CreateDatapath(args[0])
if err != nil {
if odp.IsDatapathNameAlreadyExistsError(err) {
return printErr("Network device named %s already exists", args[0])
} else {
return printErr("%s", err)
}
}
return true
}
示例14: deleteDatapath
func deleteDatapath(f Flags) bool {
args := f.Parse(1, 1)
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, _ := lookupDatapath(dpif, args[0])
if dp == nil {
return false
}
err = dp.Delete()
if err != nil {
return printErr("%s", err)
}
return true
}
示例15: deleteFlow
func deleteFlow(f Flags) bool {
dpif, err := odp.NewDpif()
if err != nil {
return printErr("%s", err)
}
defer dpif.Close()
dp, flow, ok := flagsToFlowSpec(f, dpif)
if !ok {
return false
}
err = dp.DeleteFlow(flow.FlowKeys)
if err != nil {
if odp.IsNoSuchFlowError(err) {
return printErr("No such flow")
} else {
return printErr("%s", err)
}
}
return true
}