aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Lavor <vlavor@cisco.com>2020-10-13 13:59:25 +0200
committerVladimir Lavor <vlavor@cisco.com>2020-10-13 13:59:25 +0200
commit8d4ee12e94e634b38f1dc55c830f8e222822215f (patch)
treea83bbd7a9d18c2bda32ec9c34f769980094f050c
parent4cf5e5c04b9f9b10f9b370faf0f277ac210c4b62 (diff)
Generate VPE HTTP handler
* This should fix GoVPP build Change-Id: If53177253ad4a6616860aad50ce54e5944bbea6e Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
-rw-r--r--binapi/gen.go1
-rw-r--r--binapi/vpe/vpe_http.ba.go245
-rw-r--r--cmd/govpp/main.go2
3 files changed, 247 insertions, 1 deletions
diff --git a/binapi/gen.go b/binapi/gen.go
index eec87da..ed9eed7 100644
--- a/binapi/gen.go
+++ b/binapi/gen.go
@@ -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
index 0000000..8998c9e
--- /dev/null
+++ b/binapi/vpe/vpe_http.ba.go
@@ -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)
+}
diff --git a/cmd/govpp/main.go b/cmd/govpp/main.go
index f1ad5d8..98d5078 100644
--- a/cmd/govpp/main.go
+++ b/cmd/govpp/main.go
@@ -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)