Skip to content

99cloud/VRRP-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VRRP-go

由golang实现的VRRP-v3, 点击超链接获取关于VRRP的信息。 VRRP-v3 implemented by golang,click hyperlink get details about VRRP

example

package main

import (
	"VRRP/VRRP"
	"flag"
	"fmt"
	"time"
)

var (
	VRID int
	Priority int
)

func init(){
	flag.IntVar(&VRID,"vrid",233,"virtual router ID")
	flag.IntVar(&Priority,"pri",100,"router priority")
}

func main() {
	flag.Parse()
	var vr = VRRP.NewVirtualRouter(byte(VRID), "ens33", false, VRRP.IPv4)
	vr.SetPriorityAndMasterAdvInterval(byte(Priority),time.Millisecond*800)
	vr.Enroll(VRRP.Backup2Master, func() {
		fmt.Println("init to master")
	})
	vr.Enroll(VRRP.Master2Init, func() {
		fmt.Println("master to init")
	})
	vr.Enroll(VRRP.Master2Backup, func() {
		fmt.Println("master to backup")
	})
	go func() {
		time.Sleep(time.Minute * 5)
		vr.Stop()
	}()
	vr.StartWithEventSelector()

}
GOOS=linux go build -o vr test.go
#execute on host1
./vr -vrid=200 -pri=150
#execute on host2
./vr -vrid=200 -pri=230

To-DO

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%