Exemplo 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())
	if *controllertype == "master" {
		routing.InstallMasterC(h, bh.Persistent(1))
	} else if *controllertype == "area1" {
		routing.InstallR1(h, bh.Persistent(1))
	} else {
		routing.InstallR2(h, bh.Persistent(1))
	}

	// routing.InstallLoadBalancer(h, bh.Persistent(1))
	// routing.InstallRouterIP(h,  bh.Persistent(1))
	h.Start()
}
Exemplo n.º 2
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 {
			glog.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	opts := []bh.AppOption{bh.Persistent(*replFactor)}
	if *random {
		rp := bh.RandomPlacement{
			Rand: rand.New(rand.NewSource(time.Now().UnixNano())),
		}
		opts = append(opts, bh.Placement(rp))
	}
	a := bh.NewApp("kvstore", opts...)
	kv := &store.KVStore{
		Hive:    bh.DefaultHive,
		Buckets: uint64(*buckets),
	}
	a.Handle(store.Put{}, kv)
	a.Handle(store.Get(""), kv)
	a.Handle(store.Del(""), kv)
	a.HandleHTTP("/{key}", kv)

	bh.Start()
}
Exemplo n.º 3
0
// RegisterTaskQ registers the TaskQ application and all its handler in the
// hive.
func RegisterTaskQ(h beehive.Hive, opts ...Option) error {
	if !flag.Parsed() {
		flag.Parse()
	}

	proto, err := NewProtoHandler(addr.Get(opts))
	if err != nil {
		return err
	}

	r := rate.Get(opts)
	taskq := h.NewApp("taskq", beehive.Persistent(repl.Get(opts)),
		beehive.OutRate(bucket.Rate(r), 2*r))
	taskq.Handle(Enque{}, EnQHandler{})
	taskq.Handle(Deque{}, DeQHandler{})
	taskq.Handle(Ack{}, AckHandler{})
	taskq.Handle(Timeout{}, TimeoutHandler{
		ExpDur: 60 * time.Second,
	})

	ah := &AckHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/{id:[0-9]+}", ah).Methods("DELETE")
	dh := &DeQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks/deque", dh).Methods("POST")
	eh := &EnQHTTPHandler{Hive: h}
	taskq.HandleHTTP("/{queue}/tasks", eh).Methods("POST")

	taskq.Detached(beehive.NewTimer(30*time.Second, func() {
		h.Emit(Timeout(time.Now()))
	}))
	taskq.Detached(proto)

	return nil
}
Exemplo n.º 4
0
func Example_hTTP() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloHTTP{}, beehive.RuntimeMap(RcvfHTTP), RcvfHTTP)
	// Register the HTTP handler for the hello world application.
	app.HandleHTTP("/{name}", &HelloHTTPHandler{}).Methods("POST")
	// Start the DefaultHive.
	beehive.Start()
}
Exemplo n.º 5
0
func Example_detached() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloDetached{},
		beehive.RuntimeMap(RcvfDetached), RcvfDetached)
	// Register the detached handler for the hello world listener.
	app.Detached(NewHelloListener())
	// Start the DefaultHive.
	beehive.Start()
}
Exemplo n.º 6
0
func main() {
	shouldPing := flag.Bool("ping", false, "Whether to ping.")
	shouldPong := flag.Bool("pong", false, "Whether to pong.")

	pingApp := bh.NewApp("Ping", bh.Persistent(2))
	pingApp.Handle(pong{}, &pinger{})

	pongApp := bh.NewApp("Pong", bh.Persistent(2))
	pongApp.Handle(ping{}, &ponger{})

	if *shouldPing {
		bh.Emit(ping{})
	}

	if *shouldPong {
		bh.Emit(pong{})
	}

	bh.Start()
}
Exemplo n.º 7
0
func main() {
	app := bh.NewApp("HelloWorld", bh.Persistent(1))
	app.HandleFunc(string(""), mapf, rcvf)

	name1 := "1st name"
	name2 := "2nd name"
	for i := 0; i < 3; i++ {
		go bh.Emit(name1)
		go bh.Emit(name2)
	}

	bh.Start()
}
Exemplo n.º 8
0
func Example() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(Hello{}, beehive.RuntimeMap(Rcvf), Rcvf)
	// Emit simply emits a message, here a
	// string of your name.
	go beehive.Emit(Hello{Name: "your name"})
	// Emit another message with the same name
	// to test the counting feature.
	go beehive.Emit(Hello{Name: "your name"})
	// Start the DefualtHive.
	beehive.Start()
}
func main() {
	logger.InitDefault()
	logger.Trace.Println("[main] Init beehive app")
	// Create the application and
	beehiveApp := beehive.NewApp("beehive-app", beehive.Persistent(0))
	// Register the handler for MessageToBee messages.
	beehiveApp.HandleFunc(
		MessageToBee{},
		beehive.RuntimeMap(BeeHandler),
		BeeHandler)

	initHTTPHandler(beehiveApp)

	logger.Trace.Println("[main] Start beehive")
	beehive.Start()
}
Exemplo n.º 10
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()
}
Exemplo n.º 11
0
func Example_reply() {
	// Create the hello world application and make sure .
	app := beehive.NewApp("hello-world", beehive.Persistent(1))
	// Register the handler for Hello messages.
	app.HandleFunc(HelloReply{}, beehive.RuntimeMap(RcvfReply), RcvfReply)

	// Start the default hive.
	go beehive.Start()
	defer beehive.Stop()

	name := "your name"
	for i := 0; i < 2; i++ {
		// Sync sends the Hello message and waits until it receives the reply.
		res, err := beehive.Sync(context.TODO(), HelloReply{Name: name})
		if err != nil {
			glog.Fatalf("error in sending Hello: %v", err)
		}
		cnt := res.(int)
		fmt.Printf("hello %s (%d)!\n", name, cnt)
	}
}
Exemplo n.º 12
0
func RegisterNOMController(h bh.Hive) {
	app := h.NewApp("NOMController", bh.Persistent(3))

	app.Handle(nom.NodeConnected{}, nodeConnectedHandler{})
	app.Handle(nom.NodeDisconnected{}, nodeDisconnectedHandler{})
	app.Handle(nom.PortStatusChanged{}, portStatusHandler{})

	app.Handle(nom.AddFlowEntry{}, addFlowHandler{})
	app.Handle(nom.DelFlowEntry{}, delFlowHandler{})

	app.Handle(nom.FlowStatsQuery{}, queryHandler{})

	app.Handle(nom.PacketOut{}, pktOutHandler{})

	app.Handle(nom.AddTrigger{}, addTriggerHandler{})

	app.Handle(nom.FlowStatsQueryResult{}, Consolidator{})
	app.Handle(nom.Pong{}, HealthChecker{})
	app.Handle(poll{}, Poller{})
	app.Detached(bh.NewTimer(1*time.Second, func() {
		h.Emit(poll{})
	}))
}
Exemplo n.º 13
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()
}