Generate VPE HTTP handler 36/29436/1
authorVladimir Lavor <vlavor@cisco.com>
Tue, 13 Oct 2020 11:59:25 +0000 (13:59 +0200)
committerVladimir Lavor <vlavor@cisco.com>
Tue, 13 Oct 2020 11:59:25 +0000 (13:59 +0200)
* This should fix GoVPP build

Change-Id: If53177253ad4a6616860aad50ce54e5944bbea6e
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
binapi/gen.go
binapi/vpe/vpe_http.ba.go [new file with mode: 0644]
cmd/govpp/main.go

index eec87da..ed9eed7 100644 (file)
@@ -19,3 +19,4 @@ package binapi
 //     go generate ./binapi
 //
 //go:generate binapi-generator -input-dir=/usr/share/vpp/api -output-dir=. -gen=rpc
+//go:generate binapi-generator -input-file=/usr/share/vpp/api/core/vpe.api.json -output-dir=. -gen=http
diff --git a/binapi/vpe/vpe_http.ba.go b/binapi/vpe/vpe_http.ba.go
new file mode 100644 (file)
index 0000000..8998c9e
--- /dev/null
@@ -0,0 +1,245 @@
+// Code generated by GoVPP's binapi-generator. DO NOT EDIT.
+
+package vpe
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "net/http"
+)
+
+func HTTPHandler(rpc RPCService) http.Handler {
+       mux := http.NewServeMux()
+       mux.HandleFunc("/add_node_next", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(AddNodeNext)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.AddNodeNext(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/cli", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(Cli)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.Cli(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/cli_inband", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(CliInband)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.CliInband(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/control_ping", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(ControlPing)
+               reply, err := rpc.ControlPing(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/get_f64_endian_value", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(GetF64EndianValue)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.GetF64EndianValue(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/get_f64_increment_by_one", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(GetF64IncrementByOne)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.GetF64IncrementByOne(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/get_next_index", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(GetNextIndex)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.GetNextIndex(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/get_node_graph", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(GetNodeGraph)
+               reply, err := rpc.GetNodeGraph(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/get_node_index", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(GetNodeIndex)
+               b, err := ioutil.ReadAll(req.Body)
+               if err != nil {
+                       http.Error(w, "read body failed", http.StatusBadRequest)
+                       return
+               }
+               if err := json.Unmarshal(b, request); err != nil {
+                       http.Error(w, "unmarshal data failed", http.StatusBadRequest)
+                       return
+               }
+               reply, err := rpc.GetNodeIndex(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/show_threads", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(ShowThreads)
+               reply, err := rpc.ShowThreads(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/show_version", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(ShowVersion)
+               reply, err := rpc.ShowVersion(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       mux.HandleFunc("/show_vpe_system_time", func(w http.ResponseWriter, req *http.Request) {
+               var request = new(ShowVpeSystemTime)
+               reply, err := rpc.ShowVpeSystemTime(req.Context(), request)
+               if err != nil {
+                       http.Error(w, "request failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               rep, err := json.MarshalIndent(reply, "", "  ")
+               if err != nil {
+                       http.Error(w, "marshal failed: "+err.Error(), http.StatusInternalServerError)
+                       return
+               }
+               w.Write(rep)
+       })
+       return http.HandlerFunc(mux.ServeHTTP)
+}
index f1ad5d8..98d5078 100644 (file)
@@ -174,7 +174,7 @@ func runServer(apifiles []*vppapi.File, addr string) {
        }
 
        vpeRPC := vpe.NewServiceClient(conn)
-       c := vpe.RESTHandler(vpeRPC)
+       c := vpe.HTTPHandler(vpeRPC)
 
        http.Handle("/", c)