From 40f9f8eb17e8992f11f6489823d496a4f39d8224 Mon Sep 17 00:00:00 2001 From: "badhrinath.pa@gmail.com" Date: Mon, 21 Jun 2021 10:55:08 -0500 Subject: [PATCH] grpc server support --- backend/webui_service/webui_init.go | 56 +---------- go.sum | 2 + proto/client/gClient.go | 142 ---------------------------- proto/config.proto | 6 +- proto/sdcoreConfig/config.pb.go | 102 ++++++++++++-------- proto/server/gServer.go | 108 +++++++++++++++++++++ 6 files changed, 179 insertions(+), 237 deletions(-) delete mode 100644 proto/client/gClient.go create mode 100644 proto/server/gServer.go diff --git a/backend/webui_service/webui_init.go b/backend/webui_service/webui_init.go index 056bc88..9c062b4 100644 --- a/backend/webui_service/webui_init.go +++ b/backend/webui_service/webui_init.go @@ -3,7 +3,6 @@ package webui_service import ( "bufio" "fmt" - "log" "os/exec" "sync" @@ -23,8 +22,7 @@ import ( "github.com/free5gc/webconsole/backend/logger" "github.com/free5gc/webconsole/backend/webui_context" "github.com/omec-project/webconsole/configapi" - gClient "github.com/omec-project/webconsole/proto/client" - "google.golang.org/grpc/connectivity" + gServ "github.com/omec-project/webconsole/proto/server" ) type WEBUI struct{} @@ -55,54 +53,6 @@ func init() { initLog = logger.InitLog } -func startConfigClient() { - var confClient *gClient.ConfigClient - confClient, err := gClient.CreateChannel("nssf:9876", 10000) - if err != nil { - log.Println("create grpc channel to nssf failed. : ", err) - return - } - - var cReq gClient.ConfigReq - cReq.SuppPlmnList.PlmnIdList = make([]gClient.PlmnId, 2) - cReq.SuppPlmnList.PlmnIdList[0].MCC = "305" - cReq.SuppPlmnList.PlmnIdList[0].MNC = "11" - cReq.SuppPlmnList.PlmnIdList[1].MCC = "208" - cReq.SuppPlmnList.PlmnIdList[1].MNC = "93" - - connReady := make(chan bool) - go func() { - for { - status := confClient.Conn.GetState() - if status == connectivity.Ready { - connReady <- true - } - } - }() - - go func() { - select { - case ok := <-connReady: - if ok { - err = confClient.WriteConfig(&cReq) - if err != nil { - log.Println("write config to nssf failed : ", err) - return - } - - var cResp gClient.ConfigResp - err = confClient.ReadConfig(&cResp) - if err != nil { - log.Println("write config to nssf failed : ", err) - return - } - } - } - }() - - return -} - func (*WEBUI) GetCliCmd() (flags []cli.Flag) { return webuiCLi } @@ -124,7 +74,9 @@ func (webui *WEBUI) Initialize(c *cli.Context) { } webui.setLogLevel() - startConfigClient() + var host string = "0.0.0.0:9876" + confServ := &gServ.ConfigServer{} + go gServ.StartServer(host, confServ) } func (webui *WEBUI) setLogLevel() { diff --git a/go.sum b/go.sum index 4efffc4..215e90e 100644 --- a/go.sum +++ b/go.sum @@ -539,6 +539,8 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= +google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/proto/client/gClient.go b/proto/client/gClient.go deleted file mode 100644 index 266ca63..0000000 --- a/proto/client/gClient.go +++ /dev/null @@ -1,142 +0,0 @@ -package client - -import ( - context "context" - protos "github.com/omec-project/webconsole/proto/sdcoreConfig" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" - "log" - "time" -) - -type PlmnId struct { - MCC string - MNC string -} - -type SupportedPlmnList struct { - PlmnIdList []PlmnId -} - -type Nssai struct { - sst string - sd string -} - -type SupportedNssaiList struct { - NssaiList []Nssai -} - -type SupportedNssaiInPlmnList struct { - Plmn PlmnId - SnssaiList SupportedNssaiList -} - -type ConfigReq struct { - suppNssaiPlmnList SupportedNssaiInPlmnList - SuppPlmnList SupportedPlmnList -} - -type ConfigResp struct { - suppNssaiPlmnList SupportedNssaiInPlmnList - SuppPlmnList SupportedPlmnList -} - -type ConfigClient struct { - Client protos.ConfigServiceClient - Conn *grpc.ClientConn - Version uint32 -} - -func CreateChannel(host string, timeout uint32) (*ConfigClient, error) { - log.Println("create config client") - // Second, check to see if we can reuse the gRPC connection for a new P4RT client - conn, err := GetConnection(host) - if err != nil { - log.Println("grpc connection failed") - return nil, err - } - - client := &ConfigClient{ - Client: protos.NewConfigServiceClient(conn), - Conn: conn, - } - - return client, nil -} - -var kacp = keepalive.ClientParameters{ - Time: 20 * time.Second, // send pings every 20 seconds if there is no activity - Timeout: 2 * time.Second, // wait 1 second for ping ack before considering the connection dead - PermitWithoutStream: true, // send pings even without active streams -} - -var retryPolicy = `{ - "methodConfig": [{ - "name": [{"service": "grpc.Config"}], - "waitForReady": true, - "retryPolicy": { - "MaxAttempts": 4, - "InitialBackoff": ".01s", - "MaxBackoff": ".01s", - "BackoffMultiplier": 1.0, - "RetryableStatusCodes": [ "UNAVAILABLE" ] - }}]}` - -func GetConnection(host string) (conn *grpc.ClientConn, err error) { - /* get connection */ - log.Println("Get connection.") - conn, err = grpc.Dial(host, grpc.WithInsecure(), grpc.WithKeepaliveParams(kacp), grpc.WithDefaultServiceConfig(retryPolicy)) - if err != nil { - log.Println("grpc dial err: ", err) - return nil, err - } - //defer conn.Close() - return conn, err -} - -func (c *ConfigClient) WriteConfig(cReq *ConfigReq) error { - log.Println("Write config request") - wreq := &protos.WriteRequest{} - wcfg := &protos.Config{} - wreq.WriteConfig = wcfg - suppPlmnList := &protos.SupportedPlmnList{} - for _, pl := range cReq.SuppPlmnList.PlmnIdList { - log.Println("mcc: ", pl.MCC) - log.Println("mnc: ", pl.MNC) - plmnId := &protos.PlmnId{ - Mcc: pl.MCC, - Mnc: pl.MNC, - } - suppPlmnList.PlmnIds = append(suppPlmnList.PlmnIds, plmnId) - } - wcfg.SuppPlmnList = suppPlmnList - ret, err := c.Client.Write(context.Background(), wreq) - if ((ret != nil) && (ret.WriteStatus == protos.Status_FAILURE)) || err != nil { - return err - } - - return nil -} - -func (c *ConfigClient) ReadConfig(cRes *ConfigResp) error { - log.Println("Read request") - rreq := &protos.ReadRequest{} - rsp, err := c.Client.Read(context.Background(), rreq) - if err != nil { - return err - } - - rcfg := rsp.ReadConfig - suppPlmnList := rcfg.SuppPlmnList - for _, pl := range suppPlmnList.PlmnIds { - log.Println("mcc: ", pl.Mcc) - log.Println("mnc: ", pl.Mnc) - plmnId := PlmnId{ - MCC: pl.GetMcc(), - MNC: pl.GetMnc(), - } - cRes.SuppPlmnList.PlmnIdList = append(cRes.SuppPlmnList.PlmnIdList, plmnId) - } - return nil -} diff --git a/proto/config.proto b/proto/config.proto index 2ba18dd..c620c8d 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -40,8 +40,9 @@ message SupportedNssaiInPlmnList { } message Config { - SupportedPlmnList suppPlmnList = 1; - SupportedNssaiInPlmnList suppNssaiInPlmnList = 2; + string version = 1; + SupportedPlmnList suppPlmnList = 2; + SupportedNssaiInPlmnList suppNssaiInPlmnList = 3; } message WriteRequest { @@ -53,6 +54,7 @@ message WriteResponse { } message ReadRequest { + string version = 1; } message ReadResponse { diff --git a/proto/sdcoreConfig/config.pb.go b/proto/sdcoreConfig/config.pb.go index 6cd8818..e356cdb 100644 --- a/proto/sdcoreConfig/config.pb.go +++ b/proto/sdcoreConfig/config.pb.go @@ -330,8 +330,9 @@ type Config struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - SuppPlmnList *SupportedPlmnList `protobuf:"bytes,1,opt,name=suppPlmnList,proto3" json:"suppPlmnList,omitempty"` - SuppNssaiInPlmnList *SupportedNssaiInPlmnList `protobuf:"bytes,2,opt,name=suppNssaiInPlmnList,proto3" json:"suppNssaiInPlmnList,omitempty"` + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + SuppPlmnList *SupportedPlmnList `protobuf:"bytes,2,opt,name=suppPlmnList,proto3" json:"suppPlmnList,omitempty"` + SuppNssaiInPlmnList *SupportedNssaiInPlmnList `protobuf:"bytes,3,opt,name=suppNssaiInPlmnList,proto3" json:"suppNssaiInPlmnList,omitempty"` } func (x *Config) Reset() { @@ -366,6 +367,13 @@ func (*Config) Descriptor() ([]byte, []int) { return file_config_proto_rawDescGZIP(), []int{5} } +func (x *Config) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + func (x *Config) GetSuppPlmnList() *SupportedPlmnList { if x != nil { return x.SuppPlmnList @@ -478,6 +486,8 @@ type ReadRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` } func (x *ReadRequest) Reset() { @@ -512,6 +522,13 @@ func (*ReadRequest) Descriptor() ([]byte, []int) { return file_config_proto_rawDescGZIP(), []int{8} } +func (x *ReadRequest) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + type ReadResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -586,45 +603,48 @@ var file_config_proto_rawDesc = []byte{ 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x4e, 0x73, 0x73, 0x61, 0x69, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x0a, 0x73, 0x6e, 0x73, 0x73, 0x61, 0x69, - 0x4c, 0x69, 0x73, 0x74, 0x22, 0xa7, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, - 0x43, 0x0a, 0x0c, 0x73, 0x75, 0x70, 0x70, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x50, 0x6c, - 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x0c, 0x73, 0x75, 0x70, 0x70, 0x50, 0x6c, 0x6d, 0x6e, - 0x4c, 0x69, 0x73, 0x74, 0x12, 0x58, 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x4e, 0x73, 0x73, 0x61, - 0x69, 0x49, 0x6e, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x26, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x53, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x4e, 0x73, 0x73, 0x61, 0x69, 0x49, - 0x6e, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x13, 0x73, 0x75, 0x70, 0x70, 0x4e, - 0x73, 0x73, 0x61, 0x69, 0x49, 0x6e, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x46, - 0x0a, 0x0c, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, - 0x0a, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x47, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x73, - 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x52, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, - 0x0d, 0x0a, 0x0b, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x44, - 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, - 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x2a, 0x22, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, - 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x46, - 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x01, 0x32, 0x94, 0x01, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x42, 0x0a, 0x05, 0x57, 0x72, - 0x69, 0x74, 0x65, 0x12, 0x1a, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1b, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x57, - 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, - 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x19, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, - 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4c, 0x69, 0x73, 0x74, 0x22, 0xc1, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, + 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x43, 0x0a, 0x0c, 0x73, 0x75, 0x70, + 0x70, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1f, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, + 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, + 0x52, 0x0c, 0x73, 0x75, 0x70, 0x70, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x58, + 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x4e, 0x73, 0x73, 0x61, 0x69, 0x49, 0x6e, 0x50, 0x6c, 0x6d, + 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x73, 0x64, + 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x65, 0x64, 0x4e, 0x73, 0x73, 0x61, 0x69, 0x49, 0x6e, 0x50, 0x6c, 0x6d, 0x6e, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x13, 0x73, 0x75, 0x70, 0x70, 0x4e, 0x73, 0x73, 0x61, 0x69, 0x49, 0x6e, + 0x50, 0x6c, 0x6d, 0x6e, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x46, 0x0a, 0x0c, 0x57, 0x72, 0x69, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, 0x0a, 0x0b, 0x77, 0x72, 0x69, 0x74, + 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x52, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x22, 0x47, 0x0a, 0x0d, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x36, 0x0a, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x0b, 0x77, 0x72, + 0x69, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x27, 0x0a, 0x0b, 0x52, 0x65, 0x61, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x22, 0x44, 0x0a, 0x0c, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x34, 0x0a, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0a, 0x72, 0x65, + 0x61, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2a, 0x22, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, + 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x01, 0x32, 0x94, 0x01, 0x0a, + 0x0d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x42, + 0x0a, 0x05, 0x57, 0x72, 0x69, 0x74, 0x65, 0x12, 0x1a, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x04, 0x52, 0x65, 0x61, 0x64, 0x12, 0x19, 0x2e, 0x73, 0x64, 0x63, + 0x6f, 0x72, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/server/gServer.go b/proto/server/gServer.go new file mode 100644 index 0000000..33d2826 --- /dev/null +++ b/proto/server/gServer.go @@ -0,0 +1,108 @@ +package server + +import ( + context "context" + protos "github.com/omec-project/webconsole/proto/sdcoreConfig" + "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" + "log" + "net" + "time" +) + +type PlmnId struct { + MCC string + MNC string +} + +type SupportedPlmnList struct { + PlmnIdList []PlmnId +} + +type Nssai struct { + sst string + sd string +} + +type SupportedNssaiList struct { + NssaiList []Nssai +} + +type SupportedNssaiInPlmnList struct { + Plmn PlmnId + SnssaiList SupportedNssaiList +} + +type ServerConfig struct { + suppNssaiPlmnList SupportedNssaiInPlmnList + SuppPlmnList SupportedPlmnList +} + +type ConfigServer struct { + protos.ConfigServiceServer + serverCfg ServerConfig + Version uint32 +} + +var kaep = keepalive.EnforcementPolicy{ + MinTime: 15 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection + PermitWithoutStream: true, // Allow pings even when there are no active streams +} + +var kasp = keepalive.ServerParameters{ + Time: 30 * time.Second, // Ping the client if it is idle for 5 seconds to ensure the connection is still active + Timeout: 5 * time.Second, // Wait 1 second for the ping ack before assuming the connection is dead +} + +func StartServer(host string, confServ *ConfigServer) { + log.Println("start config server") + lis, err := net.Listen("tcp", host) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + + grpcServer := grpc.NewServer(grpc.KeepaliveEnforcementPolicy(kaep), grpc.KeepaliveParams(kasp)) + protos.RegisterConfigServiceServer(grpcServer, confServ) + if err = grpcServer.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} + +func (c *ConfigServer) Read(ctx context.Context, rReq *protos.ReadRequest) (*protos.ReadResponse, error) { + log.Println("Handle Read config request") + rResp := &protos.ReadResponse{} + rCfg := &protos.Config{} + rResp.ReadConfig = rCfg + suppPlmnList := &protos.SupportedPlmnList{} + plmnId1 := &protos.PlmnId{ + Mcc: "305", + Mnc: "11", + } + plmnId2 := &protos.PlmnId{ + Mcc: "208", + Mnc: "93", + } + suppPlmnList.PlmnIds = append(suppPlmnList.PlmnIds, plmnId1) + suppPlmnList.PlmnIds = append(suppPlmnList.PlmnIds, plmnId2) + rCfg.SuppPlmnList = suppPlmnList + return rResp, nil +} + +func (c *ConfigServer) Write(ctx context.Context, wReq *protos.WriteRequest) (*protos.WriteResponse, error) { + log.Println("Handle write request") + wResp := &protos.WriteResponse{} + wResp.WriteStatus = protos.Status_SUCCESS + + wCfg := wReq.WriteConfig + suppPlmnList := wCfg.SuppPlmnList + for _, pl := range suppPlmnList.PlmnIds { + log.Println("mcc: ", pl.Mcc) + log.Println("mnc: ", pl.Mnc) + plmnId := PlmnId{ + MCC: pl.GetMcc(), + MNC: pl.GetMnc(), + } + c.serverCfg.SuppPlmnList.PlmnIdList = append(c.serverCfg.SuppPlmnList.PlmnIdList, plmnId) + } + return wResp, nil +}