Ejemplo n.º 1
0
func main() {
	target_addr := flag.String("target", default_target, "The partner to exchange latency measurement packets with")
	local_addr := protocols.ParseServerFlags("0.0.0.0", 6060)

	server, err := NewServer(local_addr)
	golib.Checkerr(err)
	client, err := NewClientFor(*target_addr)
	golib.Checkerr(err)

	measureLatency := golib.NewLoopTask("sending latency packets", func(stop golib.StopChan) {
		err := client.SendMeasureLatency()
		if err != nil {
			log.Println("Error sending Latency packet:", err)
		}
		select {
		case <-time.After(1 * time.Second):
		case <-stop:
		}
	})

	log.Println("Listening to Latency on " + local_addr + ", sending to: " + *target_addr)
	log.Println("Press Ctrl-C to close")
	golib.NewTaskGroup(
		server, measureLatency,
		&golib.NoopTask{golib.ExternalInterrupt(), "external interrupt"},
	).WaitAndExit()
}
Ejemplo n.º 2
0
func main() {
	parseFlags()
	golib.ErrorExitHook = tasks.WaitAndExit
	startScenarios()

	if close_stdin {
		log.Println("Press Ctrl-D to interrupt")
		tasks.Add(&golib.NoopTask{golib.StdinClosed(), "stdin closed"})
	}
	if close_int {
		log.Println("Press Ctrl-C to interrupt")
		tasks.Add(&golib.NoopTask{golib.ExternalInterrupt(), "external interrupt"})
	}

	tasks.WaitAndExit()
}
Ejemplo n.º 3
0
func main() {
	payloadSize := flag.Uint("payload", 0, "Additional payload to append to Load packets")
	amp_addr := protocols.ParseServerFlags("0.0.0.0", 7770)

	proto, err := protocols.NewProtocol("AMP/Load", amp.Protocol, amp_control.Protocol, ping.Protocol, heartbeat.Protocol)
	golib.Checkerr(err)
	server, err := protocols.NewServer(amp_addr, proto)
	golib.Checkerr(err)
	loadServer, err := RegisterLoadServer(server)
	golib.Checkerr(err)
	loadServer.PayloadSize = *payloadSize

	go printErrors(server)

	log.Println("Listening:", server)
	log.Println("Press Ctrl-C to close")
	golib.NewTaskGroup(
		server,
		&golib.NoopTask{golib.ExternalInterrupt(), "external interrupt"},
	).WaitAndExit()
}
Ejemplo n.º 4
0
func main() {
	proxies.UdpProxyFlags()
	pcp_addr := protocols.ParseServerFlags("0.0.0.0", 7778)

	proto, err := protocols.NewProtocol("PCP", pcp.Protocol, ping.Protocol, heartbeat.Protocol)
	golib.Checkerr(err)
	server, err := protocols.NewServer(pcp_addr, proto)
	golib.Checkerr(err)
	proxy, err := proxies.RegisterPcpProxy(server)
	golib.Checkerr(err)

	go printPcpErrors(proxy)
	proxy.ProxyStartedCallback = proxyStarted
	proxy.ProxyStoppedCallback = proxyStopped

	log.Println("Listening:", server)
	log.Println("Press Ctrl-C to close")
	golib.NewTaskGroup(
		server,
		&golib.NoopTask{golib.ExternalInterrupt(), "external interrupt"},
	).WaitAndExit()
}
Ejemplo n.º 5
0
func main() {
	loadBackend := flag.Bool("load", false, "Use Load servers to create the streams, instead of regular AMP Media servers")
	useHeartbeat := flag.Bool("heartbeat", false, "Use heartbeat-based fault detection instead of active ping-based detection")
	_heartbeat_frequency := flag.Uint("heartbeat_frequency", 200, "Time between two heartbeats which observers will send (milliseconds)")
	_heartbeat_timeout := flag.Uint("heartbeat_timeout", 350, "Time between two heartbeats before assuming offline server (milliseconds)")
	amp_addr := protocols.ParseServerFlags("0.0.0.0", 7779)
	heartbeat_frequency := time.Duration(*_heartbeat_frequency) * time.Millisecond
	heartbeat_timeout := time.Duration(*_heartbeat_timeout) * time.Millisecond

	var detector_factory balancer.FaultDetectorFactory
	tasks := golib.NewTaskGroup()
	var heartbeatServer *heartbeat.HeartbeatServer
	if *useHeartbeat {
		var err error
		heartbeatServer, err = heartbeat.NewHeartbeatServer(heartbeat_server)
		golib.Checkerr(err)
		go printServerErrors("Heartbeat", heartbeatServer.Server)
		log.Println("Listening for Heartbeats on", heartbeatServer.LocalAddr())
		detector_factory = func(endpoint string) (protocols.FaultDetector, error) {
			return heartbeatServer.ObserveServer(endpoint, heartbeat_frequency, heartbeat_timeout)
		}
		tasks.AddNamed("heartbeat", heartbeatServer)
	} else {
		detector_factory = func(endpoint string) (protocols.FaultDetector, error) {
			detector, err := ping.DialNewFaultDetector(endpoint)
			if err != nil {
				return nil, err
			}
			detector.Start()
			return detector, nil
		}
	}

	protocol, err := protocols.NewProtocol("AMP", amp.Protocol, ping.Protocol, heartbeat.Protocol)
	golib.Checkerr(err)
	baseServer, err := protocols.NewServer(amp_addr, protocol)
	golib.Checkerr(err)
	server, err := amp_balancer.RegisterPluginServer(baseServer)
	golib.Checkerr(err)
	tasks.AddNamed("server", server)

	ampPlugin := amp_balancer.NewAmpBalancingPlugin(detector_factory)
	server.AddPlugin(ampPlugin)
	pcpPlugin := amp_balancer.NewPcpBalancingPlugin(detector_factory)
	server.AddPlugin(pcpPlugin)

	if *loadBackend {
		for _, load := range load_servers {
			err := ampPlugin.AddBackendServer(load, stateChangePrinter)
			golib.Checkerr(err)
		}
	} else {
		for _, amp := range amp_servers {
			err := ampPlugin.AddBackendServer(amp, stateChangePrinter)
			golib.Checkerr(err)
		}
	}
	for _, pcp := range pcp_servers {
		err := pcpPlugin.AddBackendServer(pcp, stateChangePrinter)
		golib.Checkerr(err)
	}

	go printServerErrors("Server", server.Server)
	server.SessionStartedCallback = printSessionStarted
	server.SessionStoppedCallback = printSessionStopped

	log.Println("Listening to AMP on " + amp_addr)
	log.Println("Press Ctrl-C to close")

	if heartbeatServer != nil {
		tasks.Add(heartbeatServer)
	}
	tasks.Add(&golib.NoopTask{golib.ExternalInterrupt(), "external interrupt"})
	tasks.WaitAndExit()
}