Esempio n. 1
0
func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	h := bh.NewHive()
	openflow.StartOpenFlow(h)
	controller.RegisterNOMController(h)
	discovery.RegisterDiscovery(h)

	// Register a switch:
	// switching.RegisterSwitch(h, bh.Persistent(1))
	// or a hub:
	// switching.RegisterHub(h, bh.NonTransactional())

	// routing.InstallRouter(h, bh.Persistent(1))
	routing.InstallLoadBalancer(h, bh.Persistent(1))
	h.Start()
}
Esempio n. 2
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())

	h := beehive.NewHive()
	if err := server.RegisterTaskQ(h); err != nil {
		glog.Errorf("cannot register taskq: %v", err)
		os.Exit(-1)
	}
	h.Start()
}
Esempio n. 3
0
func main() {
	h := bh.NewHive()

	openflow.StartOpenFlow(h)
	controller.RegisterNOMController(h)
	discovery.RegisterDiscovery(h)
	switching.RegisterSwitch(h)
	kandoo.RegisterApps(h, *eThreshold)

	h.Start()
}
Esempio n. 4
0
func main() {
	h := bh.NewHive()
	a := h.NewApp("Calc")
	a.Handle(Op{}, &Calculator{})
	a.Detached(&Generator{})

	joinCh := make(chan bool)
	go func() {
		fmt.Println("Stage started.")
		h.Start()
		joinCh <- true
	}()

	<-joinCh
	fmt.Println("Stage stopped.")
}
Esempio n. 5
0
func createHive(addr string, paddrs []string, minDriver, maxDriver int,
	minCol, maxCol int, stickyCollector bool, lockRouter bool, joinCh chan bool) {

	h := beehive.NewHive(beehive.Addr(addr), beehive.PeerAddrs(paddrs...))
	cOps := []beehive.AppOption{}
	if stickyCollector {
		cOps = append(cOps, beehive.Sticky())
	}
	c := h.NewApp("Collector", cOps...)
	p := NewPoller(1 * time.Second)
	c.Detached(p)
	c.Handle(StatResult{}, &Collector{uint64(maxSpike * (1 - elephantProb)), p})
	c.Handle(SwitchJoined{}, &SwitchJoinHandler{p})

	r := h.NewApp("Router", beehive.Sticky())
	r.Handle(MatrixUpdate{}, &UpdateHandler{})

	d := h.NewApp("Driver", beehive.Sticky())
	driver := NewDriver(minDriver, maxDriver-minDriver)
	d.Handle(StatQuery{}, driver)
	d.Handle(FlowMod{}, driver)

	if lockRouter {
		h.Emit(MatrixUpdate{})
	}

	if maxDriver != minDriver {
		glog.Infof("Running driver from %d to %d\n", minDriver, maxDriver-1)
		d.Detached(driver)
		for i := minDriver; i < maxDriver; i++ {
			h.Emit(StatQuery{Switch(i)})
		}
	}

	if maxCol != minCol {
		glog.Infof("Running collector from %d to %d\n", minCol, maxCol-1)
		for i := minCol; i < maxCol; i++ {
			h.Emit(SwitchJoined{Switch(i)})
		}
	}

	h.RegisterMsg(SwitchStats{})
	go func() {
		h.Start()
		<-joinCh
	}()
}
Esempio n. 6
0
func BenchmarkThroughput(b *testing.B) {
	hive := bh.NewHive()
	defer os.RemoveAll(hive.Config().StatePath)

	if b.N < 1024 {
		return
	}

	b.StopTimer()
	app := hive.NewApp("kvstore", bh.Persistent(1))
	store := &KVStore{
		Hive:    hive,
		Buckets: bees,
	}
	app.Handle(Put{}, store)
	app.Handle(Get(""), store)
	go hive.Start()

	keys := make([]string, 64)
	for i, _ := range keys {
		keys[i] = fmt.Sprintf("%dkeys%d", i, i)
	}
	val := "val"

	for _, k := range keys {
		hive.Emit(Put{Key: k, Val: val})
		hive.Sync(context.Background(), Get(k))
	}

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		for _, k := range keys {
			hive.Emit(Put{Key: k, Val: val})
			i++
		}
	}

	for _, k := range keys {
		hive.Sync(context.Background(), Get(k))
	}
	b.StopTimer()
	hive.Stop()
}
Esempio n. 7
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UnixNano())
	if *quiet {
		log.SetOutput(ioutil.Discard)
	}

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			panic(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	hive := bh.NewHive()
	os.RemoveAll(hive.Config().StatePath)
	app := hive.NewApp("kvstore", bh.Persistent(*replFactor))
	kvs := &store.KVStore{
		Hive:    hive,
		Buckets: uint64(*buckets),
	}
	app.Handle(store.Put{}, kvs)
	app.Handle(store.Get(""), kvs)
	go hive.Start()

	time.Sleep(4 * time.Minute)

	keys := make([]string, *numkeys)
	reqs := make([]interface{}, *numkeys)
	val := "val"
	for i, _ := range keys {
		keys[i] = fmt.Sprintf("%dkeys%d", i, i)
		if *get {
			reqs[i] = store.Get(keys[i])
		} else {
			reqs[i] = store.Put{Key: keys[i], Val: val}
		}
	}

	for _, k := range keys {
		hive.Emit(store.Put{Key: k, Val: val})
		hive.Sync(context.Background(), store.Get(k))
	}

	ts := make([]time.Duration, *rounds)
	for i := 0; i < *rounds; i++ {
		start := time.Now()
		for j := 0; j < *tries; j++ {
			for _, r := range reqs {
				hive.Emit(r)
			}
		}
		for _, k := range keys {
			hive.Sync(context.Background(), store.Get(k))
		}
		ts[i] = time.Since(start)
	}

	hive.Stop()

	f, err := os.Create(*output)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	w := bufio.NewWriter(f)
	for _, t := range ts {
		fmt.Fprintf(w, "%v\n", uint64(t))
	}
	w.Flush()
}