Exemplo n.º 1
0
func main() {
	retries := flag.Int("retries", 5, "retries")
	timeout := flag.Int("timeout", 100, "timeout in ms")
	strDestinationAddr := flag.String("dst", "", "destination udp urls")
	strSourceAddr := flag.String("src", "", "source udp url to callback")

	flag.Parse()

	if (timeout == nil) || (*timeout <= 0) {
		fmt.Println("Timeout must be positive")
		os.Exit(1)
	}
	if (retries == nil) || (*retries <= 0) {
		fmt.Println("Retries must be positive")
		os.Exit(1)
	}

	attempts := &pinglogic.TimedAttempts{time.Duration(*timeout) * time.Millisecond, *retries}

	if (strDestinationAddr == nil) || (*strDestinationAddr == "") {
		fmt.Println("dst must not be empty")
		os.Exit(1)
	}

	if (strSourceAddr == nil) || (*strSourceAddr == "") {
		fmt.Println("src must not be empty")
		os.Exit(1)
	}

	strTargets := strings.Split(*strDestinationAddr, ";")
	targets := make([]*net.UDPAddr, len(strTargets))

	var err error
	for i, x := range strTargets {
		if targets[i], err = net.ResolveUDPAddr("udp", x); err != nil {
			panic(err)
		}
	}

	backaddress, err := net.ResolveUDPAddr("udp", *strSourceAddr)
	if err != nil {
		fmt.Println("Error for backadress: ", err)
	}

	backchannel := make(chan *pinglogic.Backcall)
	pingconf := &pinglogic.PingConf{backaddress, backchannel, attempts}
	var wg sync.WaitGroup
	wg.Add(1)
	go func() { defer wg.Done(); pinglogic.Passive(backaddress, backchannel) }()
	elapsed, _ := pinglogic.Active(pingconf, targets)
	fmt.Println("After " + elapsed.String())
	pinglogic.StopPassive()
	wg.Wait()
	close(backchannel)
}
Exemplo n.º 2
0
func main() {
	fmt.Println("Hello World!")
	strSourceAddr := flag.String("src", "", "source udp address")
	flag.Parse()
	if (strSourceAddr == nil) || (*strSourceAddr == "") {
		panic("src must not be empty")
	}

	if ServerAddr, err := net.ResolveUDPAddr("udp", *strSourceAddr); err == nil {
		backchannel := make(chan *pinglogic.Backcall)
		go pinglogic.Passive(ServerAddr, backchannel)

		for backcall := range backchannel {
			fmt.Println("received " + backcall.Responder_msg.Msg + " from " + backcall.Responder_url)
		}
	} else {
		panic(err.Error())
	}
}
Exemplo n.º 3
0
func CreateODPdetector(landscapeupdater *Landscapeupdater, serverconfig *utilities.ServerConfig) *ODPdetector {
	odpdetector := new(ODPdetector)
	odpdetector.serverconfig = serverconfig
	odpdetector.landcsapeupdater = landscapeupdater
	odpdetector.opinion = new(utilities.DetectorOpinion)
	odpdetector.opinion.Aliveopinion = true //explicit
	odpdetector.opinion.Dcid = ""           //explicit
	odpdetector.odpconfig = &serverconfig.Odpconfig
	odpdetector.pingconf = new(pinglogic.PingConf)
	if detectoraddress, err := net.ResolveUDPAddr("udp", serverconfig.Opconfig.Odip+":"+strconv.Itoa(serverconfig.Opconfig.Pingport)); err != nil {
		panic(err.Error())
	} else {
		odpdetector.pingconf.Timingconf = &serverconfig.Odpconfig.Pingattempts
		odpdetector.pingconf.Backaddress = detectoraddress
		odpdetector.Backchannel = make(chan *pinglogic.Backcall)
		odpdetector.pingconf.Backchannel = odpdetector.Backchannel
	}
	go pinglogic.Passive(odpdetector.pingconf.Backaddress, odpdetector.Backchannel)
	return odpdetector
}