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


Golang client.NCC類代碼示例

本文整理匯總了Golang中github.com/google/seesaw/ncc/client.NCC的典型用法代碼示例。如果您正苦於以下問題:Golang NCC類的具體用法?Golang NCC怎麽用?Golang NCC使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了NCC類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: routeTests

func routeTests(ncc client.NCC) {
	gateway, err := ncc.RouteDefaultIPv4()
	if err != nil {
		log.Fatalf("Failed to get IPv4 default route: %v", err)
	}
	log.Printf("Got IPv4 default route - %v", gateway)
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:7,代碼來源:main.go

示例2: lbInterface

func lbInterface(ncc client.NCC) client.LBInterface {
	iface := *testIface
	nodeIP := net.ParseIP(*nodeIPStr)
	nodeIPv6 := net.ParseIP(*nodeIPv6Str)
	if nodeIP == nil && nodeIPv6 == nil {
		log.Fatalf("Invalid node IP/IPv6 - %q/%q", *nodeIPStr, *nodeIPv6Str)
	}

	unicastVIP := net.ParseIP(*unicastVIPStr)
	if unicastVIP == nil {
		log.Fatalf("Invalid unicast VIP - %q", *unicastVIPStr)
	}
	vip := net.ParseIP(*clusterVIPStr)
	if vip == nil {
		log.Fatalf("Invalid cluster VIP - %q", *clusterVIPStr)
	}
	if *vrID < 1 || *vrID > 255 {
		log.Fatalf("Invalid VRID - %q", *vrID)
	}
	rtID := uint8(*routingTableID)
	// TODO(jsing): Change this to allow both IPv4 and IPv6 addresses.
	lbCfg := &types.LBConfig{
		ClusterVIP:     seesaw.Host{IPv4Addr: vip},
		Node:           seesaw.Host{IPv4Addr: nodeIP, IPv6Addr: nodeIPv6},
		DummyInterface: "dummy0",
		NodeInterface:  "eth0",
		RoutingTableID: rtID,
		VRID:           uint8(*vrID),
	}
	lb := ncc.NewLBInterface(iface, lbCfg)
	if err := lb.Init(); err != nil {
		log.Fatalf("Failed to initialise the LB interface: %v", err)
	}
	return lb
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:35,代碼來源:main.go

示例3: arpTests

func arpTests(ncc client.NCC) {
	// Send a gratuitous ARP message.
	vip := net.ParseIP(*clusterVIPStr)
	if vip == nil {
		log.Fatalf("Invalid cluster VIP - %q", *clusterVIPStr)
	}
	log.Print("Sending gratuitous ARP...")
	if err := ncc.ARPSendGratuitous(*testIface, vip); err != nil {
		log.Fatalf("Failed to send gratuitous ARP: %v", err)
	}
	log.Print("Done.")
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:12,代碼來源:main.go

示例4: bgpTests

func bgpTests(ncc client.NCC) {
	// Display the BGP neighbors.
	log.Print("Getting BGP neighbors...")
	neighbors, err := ncc.BGPNeighbors()
	if err != nil {
		log.Fatalf("Failed to get BGP neighbors")
	}
	for _, n := range neighbors {
		log.Printf("- BGP neighbor %v, remote AS %d, state %v, uptime %v seconds",
			n.IP, n.ASN, n.BGPState, n.Uptime.Seconds())
	}

	// Withdraw all existing network advertisements.
	log.Printf("Withdrawing all network advertisements")
	if err := ncc.BGPWithdrawAll(); err != nil {
		log.Fatalf("Failed to withdraw BGP advertisements: %v", err)
	}

	// Advertise and withdraw the test-anycast VIP.
	log.Printf("Advertising and withdrawing VIP %v", testAnycast)
	if err := ncc.BGPAdvertiseVIP(testAnycast); err != nil {
		log.Fatalf("Failed to advertise VIP %v: %v", testAnycast, err)
	}
	cfg, err := ncc.BGPConfig()
	if err != nil {
		log.Fatal("Failed to get BGP configuration")
	}
	found := false
	ns := fmt.Sprintf(" network %v/32", testAnycast)
	for _, l := range cfg {
		if l == ns {
			found = true
			break
		}
	}
	if !found {
		log.Fatal("Failed to find network statement")
	}
	if err := ncc.BGPWithdrawVIP(testAnycast); err != nil {
		log.Fatalf("Failed to withdraw VIP %v: %v", testAnycast, err)
	}
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:42,代碼來源:main.go

示例5: ipvsAddLoadTest

func ipvsAddLoadTest(ncc client.NCC, services, dests int) {
	log.Printf("Starting IPVS add load test - %d services, each with %d destinations", services, dests)

	if err := ncc.IPVSFlush(); err != nil {
		log.Fatalf("Failed to flush the IPVS table: %v", err)
	}

	done := make(chan bool)
	for i := 0; i < services; i++ {
		go ipvsAddService(done, i, dests)
	}
	for i := 0; i < services; i++ {
		<-done
	}

	if err := ncc.IPVSFlush(); err != nil {
		log.Fatalf("Failed to flush the IPVS table: %v", err)
	}

	log.Printf("Completed IPVS add load test")
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:21,代碼來源:main.go

示例6: ipvsTests

func ipvsTests(ncc client.NCC) {

	// Manipulate the IPVS table.
	if err := ncc.IPVSFlush(); err != nil {
		log.Fatalf("Failed to flush the IPVS table: %v", err)
	}

	log.Printf("Adding IPVS service %v with %d destinations", testSvc, len(testSvc.Destinations))
	if err := ncc.IPVSAddService(testSvc); err != nil {
		log.Fatalf("Failed to add IPVS service: %v", err)
	}

	svcs, err := ncc.IPVSGetServices()
	if err != nil {
		log.Fatalf("Failed to get IPVS services: %v", err)
	}
	for _, svc := range svcs {
		log.Printf("Got IPVS service %v with %d destinations",
			svc, len(svc.Destinations))
	}
	if len(svcs) != 1 {
		log.Fatalf("IPVSGetServices returned %d services, expected 1", len(svcs))
	}
	if len(svcs[0].Destinations) != len(testSvc.Destinations) {
		log.Fatalf("IPVSGetServices returned %d destinations, expected %d",
			len(svcs[0].Destinations), len(testSvc.Destinations))
	}

	dst := testSvc.Destinations[0]
	if err := ncc.IPVSDeleteDestination(testSvc, dst); err != nil {
		log.Fatalf("Failed to delete destination: %v", err)
	}

	svc, err := ncc.IPVSGetService(testSvc)
	if err != nil {
		log.Fatalf("Failed to get IPVS service: %v", err)
	}
	if len(svc.Destinations) != len(testSvc.Destinations)-1 {
		log.Fatalf("IPVSGetService returned %d destinations, expected %d",
			len(svc.Destinations), len(testSvc.Destinations)-1)
	}

	ipvsGetLoadTest(4, 10*time.Second)

	if err := ncc.IPVSDeleteService(testSvc); err != nil {
		log.Fatalf("Failed to delete IPVS service: %v", err)
	}

	ipvsAddLoadTest(ncc, 20, 50)

	// Clean up after ourselves...
	if err := ncc.IPVSFlush(); err != nil {
		log.Fatalf("Failed to flush the IPVS table: %v", err)
	}
}
開發者ID:Cepave,項目名稱:lvs-metrics,代碼行數:55,代碼來源:main.go


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