當前位置: 首頁>>代碼示例>>Golang>>正文


Golang odp.NewDpif函數代碼示例

本文整理匯總了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)
	}
}
開發者ID:awh,項目名稱:go-odp,代碼行數:35,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:25,代碼來源:main.go

示例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
}
開發者ID:ravisinghsfbay,項目名稱:weave,代碼行數:15,代碼來源:odp.go

示例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
}
開發者ID:codingbunch,項目名稱:weave,代碼行數:15,代碼來源:odp.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:16,代碼來源:main.go

示例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
}
開發者ID:bboreham,項目名稱:go-odp,代碼行數:17,代碼來源:main.go

示例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()
}
開發者ID:codingbunch,項目名稱:weave,代碼行數:17,代碼來源:odp.go

示例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
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:44,代碼來源:odp.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:44,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:19,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:19,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:43,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:20,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:21,代碼來源:main.go

示例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
}
開發者ID:awh,項目名稱:go-odp,代碼行數:23,代碼來源:main.go


注:本文中的github.com/weaveworks/go-odp/odp.NewDpif函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。