예제 #1
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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
0
파일: main.go 프로젝트: Cepave/lvs-metrics
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)
	}
}