func StartTest(hive bh.Hive) error { app := hive.NewApp("TestApp") fmt.Println("Test app is comming ... :)))") app.HandleFunc(nom.HostJoined{}, bh.RuntimeMap(hostJoinedRcvf), hostJoinedRcvf) return nil }
// RegisterDiscovery registers the discovery module for topology discovery on the hive. // you can use it's REST API in order to communicate with it. func RegisterDiscovery(h bh.Hive) { a := h.NewApp("discovery") a.Handle(nom.NodeJoined{}, &nodeJoinedHandler{}) a.Handle(nom.NodeLeft{}, &nodeLeftHandler{}) a.Handle(nom.PortUpdated{}, &portUpdateHandler{}) // TODO(soheil): Handle PortRemoved. a.Handle(nom.PacketIn{}, &lldpPktInHandler{}) a.Handle(nom.PacketIn{}, &arpPktInHandler{}) a.Handle(nom.HostConnected{}, &hostConnectedHandler{}) a.Handle(NewLink{}, &newLinkHandler{}) a.Handle(lldpTimeout{}, &timeoutHandler{}) go func() { for { h.Emit(lldpTimeout{}) time.Sleep(60 * time.Second) } }() http.NewHTTPApp(a, h).DefaultHandle() a.Handle(http.HTTPRequest{}, &httpHostListHandler{}) }
// 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 }
func RegisterIntent(h bh.Hive) { a := h.NewApp("intent") a.Handle(nom.LinkAdded{}, &discovery.GraphBuilderCentralized{}) a.Handle(nom.LinkDeleted{}, &discovery.GraphBuilderCentralized{}) http.NewHTTPApp(a, h).DefaultHandle() a.Handle(http.HTTPRequest{}, &intentHandler{}) }
// InstallRoutingOnHive install the routing application func InstallRoutingOnHive(h bh.Hive, timeout time.Duration) { app := h.NewApp("Routing") router := Router{} app.Handle(Advertisement{}, router) app.Handle(Discovery{}, router) app.Handle(Timeout{}, router) go func() { ticker := time.NewTicker(timeout) for { <-ticker.C h.Emit(Timeout{}) } }() }
// RegisterDiscovery registers the handlers for topology discovery on the hive. func RegisterDiscovery(h bh.Hive) { a := h.NewApp("discovery") a.Handle(nom.NodeJoined{}, &nodeJoinedHandler{}) a.Handle(nom.NodeLeft{}, &nodeLeftHandler{}) a.Handle(nom.PortUpdated{}, &portUpdateHandler{}) // TODO(soheil): Handle PortRemoved. a.Handle(nom.PacketIn{}, &pktInHandler{}) a.Handle(NewLink{}, &newLinkHandler{}) a.Handle(lldpTimeout{}, &timeoutHandler{}) go func() { for { h.Emit(lldpTimeout{}) time.Sleep(60 * time.Second) } }() }
// StartOpenFlow starts the OpenFlow driver on the given hive using the default // OpenFlow configuration that can be set through command line arguments. func StartOpenFlow(hive bh.Hive, options ...Option) error { app := hive.NewApp("OFDriver", bh.OutRate(bucket.Rate(*maxConnRate), 10*uint64(*maxConnRate))) l := &ofListener{ proto: *proto, addr: *addr, readBufLen: *readBufLen, } for _, opt := range options { opt(l) } app.Detached(l) glog.V(2).Infof("OpenFlow driver registered on %s:%s", l.proto, l.addr) return nil }
func defaultHTTPHandler(w http.ResponseWriter, r *http.Request, h bh.Hive) { w.Header().Set("Server", "Beehive-netctrl-HTTP-Server") vars := mux.Vars(r) submodule, ok := vars["submodule"] if !ok { /* This should not happened :) */ http.Error(w, "Invalid request", http.StatusBadRequest) return } verb, ok := vars["verb"] if !ok { /* This should not happened :) */ http.Error(w, "Invalid request", http.StatusBadRequest) return } creq := HTTPRequest{ AppName: submodule, Verb: verb, } // Read content data if available :) if r.ContentLength > 0 { data, err := ioutil.ReadAll(r.Body) if err == nil { creq.Data = data } } cres, err := h.Sync(context.TODO(), creq) if err == nil && cres != nil { w.Write(cres.(HTTPResponse).Data) w.WriteHeader(http.StatusOK) return } else { http.Error(w, err.Error(), http.StatusInternalServerError) fmt.Errorf("defaultTTPHandler: %v\n", err) return } }
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{}) })) }
// RegisterApps registers Kandoo applications on the hive, with the given // elephant flow size threshold. func RegisterApps(hive bh.Hive, threshold uint64) { ar := hive.NewApp("Reroute") ar.Handle(ElephantDetected{}, Rerouter{}) ad := hive.NewApp("Detect") ad.Handle(nom.FlowStatsQueryResult{}, Detector{}) ad.Handle(nom.NodeJoined{}, Adder{}) type poll struct{} ad.Handle(poll{}, Poller{}) ad.Detached(bh.NewTimer(1*time.Second, func() { hive.Emit(poll{}) })) }
// RegisterSwitch registers the learning switch application on the given // hive with the provided options. func RegisterSwitch(h bh.Hive, opts ...bh.AppOption) { app := h.NewApp("Switch", opts...) app.Handle(nom.PacketIn{}, LearningSwitch{}) }
// RegisterHub registers the hub application on the given // hive with the provided options. func RegisterHub(h bh.Hive, opts ...bh.AppOption) { app := h.NewApp("Hub", opts...) app.Handle(nom.PacketIn{}, Hub{}) }