本文整理汇总了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)
}
示例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
}
示例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.")
}
示例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)
}
}
示例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")
}
示例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)
}
}