Test and debug interface improvements
Added functionality:
- Get all E2Nodes in subscription manager
- Get all REST subscriptions of one E2Node in Subscription manager
- Get all xApps in subscription manager
- Get all subscriptions of a xApp in Subscription manager
- Get all E2 subscriptions of a REST subscription
- Delete all subscriptions of one E2Node
- Delete all subscriptions of a xApp
To be done:
- Document update not yet done
- Testing in real environment not yet done
Change-Id: I5e270c27efa4f8b2da6283540d5fa51aa6146387
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
diff --git a/pkg/control/control.go b/pkg/control/control.go
index 1bb6af6..e13fc46 100755
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -22,9 +22,6 @@
import (
"fmt"
"net/http"
- "os"
- "strconv"
- "strings"
"sync"
"time"
@@ -35,7 +32,6 @@
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
- "github.com/gorilla/mux"
"github.com/segmentio/ksuid"
"github.com/spf13/viper"
)
@@ -158,9 +154,19 @@
c.ReadConfigParameters("")
// Register REST handler for testing support
+ xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET")
xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST")
xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET")
- xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET")
+
+ xapp.Resource.InjectRoute("/ric/v1/get_all_e2nodes", c.GetAllE2Nodes, "GET")
+ xapp.Resource.InjectRoute("/ric/v1/get_e2node_rest_subscriptions/{ranName}", c.GetAllE2NodeRestSubscriptions, "GET")
+
+ xapp.Resource.InjectRoute("/ric/v1/get_all_xapps", c.GetAllXapps, "GET")
+ xapp.Resource.InjectRoute("/ric/v1/get_xapp_rest_restsubscriptions/{xappServiceName}", c.GetAllXappRestSubscriptions, "GET")
+ xapp.Resource.InjectRoute("/ric/v1/get_e2subscriptions/{restId}", c.GetE2Subscriptions, "GET")
+
+ xapp.Resource.InjectRoute("/ric/v1/delete_all_e2node_subscriptions/{ranName}", c.DeleteAllE2nodeSubscriptions, "GET")
+ xapp.Resource.InjectRoute("/ric/v1/delete_all_xapp_subscriptions/{xappServiceName}", c.DeleteAllXappSubscriptions, "GET")
if readSubsFromDb == "true" {
// Read subscriptions from db
@@ -180,10 +186,12 @@
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
-func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) {
- xapp.Logger.Debug("GetAllRestSubscriptions() called")
- response := c.registry.GetAllRestSubscriptions()
- w.Write(response)
+func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) {
+ xapp.Logger.Debug("RESTQueryHandler() called")
+
+ c.CntRecvMsg++
+
+ return c.registry.QueryHandler()
}
//-------------------------------------------------------------------
@@ -357,7 +365,7 @@
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
-func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string) (*RESTSubscription, string, error) {
+func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) {
var restSubId string
var restSubscription *RESTSubscription
@@ -384,7 +392,7 @@
if restSubscription == nil {
restSubId = ksuid.New().String()
- restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppRmrEndpoint, p.Meid)
+ restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid)
}
} else {
// Subscription contains REST subscription Id
@@ -449,7 +457,7 @@
xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error())
}
- restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint)
+ restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host)
if err != nil {
xapp.Logger.Error("Subscription with id in REST request does not exist")
return nil, common.SubscribeNotFoundCode
@@ -839,50 +847,6 @@
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
-func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) {
- xapp.Logger.Debug("RESTQueryHandler() called")
-
- c.CntRecvMsg++
-
- return c.registry.QueryHandler()
-}
-
-func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) {
- xapp.Logger.Debug("RESTTestRestHandler() called")
-
- pathParams := mux.Vars(r)
- s := pathParams["testId"]
-
- // This can be used to delete single subscription from db
- if contains := strings.Contains(s, "deletesubid="); contains == true {
- var splits = strings.Split(s, "=")
- if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil {
- xapp.Logger.Debug("RemoveSubscriptionFromSdl() called. subId = %v", subId)
- c.RemoveSubscriptionFromSdl(uint32(subId))
- return
- }
- }
-
- // This can be used to remove all subscriptions db from
- if s == "emptydb" {
- xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called")
- c.RemoveAllSubscriptionsFromSdl()
- c.RemoveAllRESTSubscriptionsFromSdl()
- return
- }
-
- // This is meant to cause submgr's restart in testing
- if s == "restart" {
- xapp.Logger.Debug("os.Exit(1) called")
- os.Exit(1)
- }
-
- xapp.Logger.Debug("Unsupported rest command received %s", s)
-}
-
-//-------------------------------------------------------------------
-//
-//-------------------------------------------------------------------
func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) {
params := &xapp.RMRParams{}
diff --git a/pkg/control/debug_rest_if.go b/pkg/control/debug_rest_if.go
new file mode 100644
index 0000000..cc73c72
--- /dev/null
+++ b/pkg/control/debug_rest_if.go
@@ -0,0 +1,182 @@
+/*
+==================================================================================
+ Copyright (c) 2019 AT&T Intellectual Property.
+ Copyright (c) 2019 Nokia
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================================
+*/
+
+package control
+
+import (
+ "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+ "github.com/gorilla/mux"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+)
+
+func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("RESTTestRestHandler() called")
+
+ pathParams := mux.Vars(r)
+ s := pathParams["testId"]
+
+ // This can be used to delete single subscription from db
+ if contains := strings.Contains(s, "deletesubid="); contains == true {
+ var splits = strings.Split(s, "=")
+ if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil {
+ xapp.Logger.Debug("RemoveSubscriptionFromSdl() called. subId = %v", subId)
+ c.RemoveSubscriptionFromSdl(uint32(subId))
+ return
+ }
+ }
+
+ // This can be used to remove all subscriptions db from
+ if s == "emptydb" {
+ xapp.Logger.Debug("RemoveAllSubscriptionsFromSdl() called")
+ c.RemoveAllSubscriptionsFromSdl()
+ c.RemoveAllRESTSubscriptionsFromSdl()
+ return
+ }
+
+ // This is meant to cause submgr's restart in testing
+ if s == "restart" {
+ xapp.Logger.Debug("os.Exit(1) called")
+ os.Exit(1)
+ }
+
+ xapp.Logger.Debug("Unsupported rest command received %s", s)
+}
+
+//-------------------------------------------------------------------
+//
+//-------------------------------------------------------------------
+func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) {
+
+ // Get all REST Subscriptions in subscription manager
+ xapp.Logger.Debug("GetAllRestSubscriptions() called")
+ w.Write(c.registry.GetAllRestSubscriptionsJson())
+}
+
+func (c *Control) GetAllE2Nodes(w http.ResponseWriter, r *http.Request) {
+
+ // Get all E2Nodes in subscription manager
+ xapp.Logger.Debug("GetAllE2Nodes() called")
+ w.Write(c.e2IfState.GetE2NodesJson())
+}
+
+func (c *Control) GetAllE2NodeRestSubscriptions(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() called: Req= %v", r.URL.Path)
+
+ // Get all REST Subscriptions of a E2Node
+ pathParams := mux.Vars(r)
+ ranName := pathParams["ranName"]
+ xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() ranName=%s", ranName)
+ if ranName != "" {
+ w.Write(c.registry.GetAllE2NodeRestSubscriptionsJson(ranName))
+ } else {
+ xapp.Logger.Debug("GetAllE2NodeRestSubscriptions() Invalid path %s", ranName)
+ w.WriteHeader(400) // Bad request
+ }
+}
+
+func (c *Control) GetAllXapps(w http.ResponseWriter, r *http.Request) {
+
+ // Get all xApps in subscription manager
+ xapp.Logger.Debug("GetAllXapps() called: Req= %v", r.URL.Path)
+ w.Write(c.registry.GetAllXappsJson())
+}
+
+func (c *Control) GetAllXappRestSubscriptions(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("GetAllXappRestSubscriptions() called")
+
+ // Get all REST Subscriptions of a xApp
+ pathParams := mux.Vars(r)
+ xappServiceName := pathParams["xappServiceName"]
+ xapp.Logger.Debug("GetAllXappRestSubscriptions() xappServiceName=%s", xappServiceName)
+ if xappServiceName != "" {
+ w.Write(c.registry.GetAllXappRestSubscriptionsJson(xappServiceName))
+ } else {
+ xapp.Logger.Debug("GetAllXappRestSubscriptions() Invalid path %s", xappServiceName)
+ w.WriteHeader(400) // Bad request
+ }
+}
+
+func (c *Control) DeleteAllE2nodeSubscriptions(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("DeleteAllE2nodeSubscriptions() called: Req= %v", r.URL.Path)
+
+ // Delete all REST Subscriptions of a E2Node
+ pathParams := mux.Vars(r)
+ ranName := pathParams["ranName"]
+ xapp.Logger.Debug("DeleteE2nodeSubscriptions() ranName=%s", ranName)
+ if ranName == "" {
+ w.WriteHeader(400) // Bad request
+ }
+ nbIds := c.e2IfState.GetAllE2Nodes()
+ ranName, ok := nbIds[ranName]
+ if ok {
+ restSubscriptions := c.registry.GetAllE2NodeRestSubscriptions(ranName)
+ for restSubsId, _ := range restSubscriptions {
+ c.RESTSubscriptionDeleteHandler(restSubsId)
+ }
+ return
+ } else {
+ w.WriteHeader(404) // Not found
+ }
+}
+
+func (c *Control) DeleteAllXappSubscriptions(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("DeleteAllXappSubscriptions() called: Req= %v", r.URL.Path)
+
+ // Delete all REST Subscriptions of a xApp
+ pathParams := mux.Vars(r)
+ xappServiceName := pathParams["xappServiceName"]
+ xapp.Logger.Debug("DeleteAllXappSubscriptions() ranName=%s", xappServiceName)
+ if xappServiceName == "" {
+ w.WriteHeader(400) // Bad request
+ }
+ xapps := c.registry.GetAllXapps()
+ _, ok := xapps[xappServiceName]
+ if ok {
+ XappRestSubscriptions := c.registry.GetAllXappRestSubscriptions(xappServiceName)
+ for restSubsId, _ := range XappRestSubscriptions {
+ c.RESTSubscriptionDeleteHandler(restSubsId)
+ }
+ return
+ } else {
+ w.WriteHeader(404) // Not found
+ }
+ w.WriteHeader(200) // OK
+}
+
+func (c *Control) GetE2Subscriptions(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Debug("GetE2Subscriptions() called: Req= %v", r.URL.Path)
+
+ // Get all E2 subscriptions of a REST Subscription
+ pathParams := mux.Vars(r)
+ restId := pathParams["restId"]
+ xapp.Logger.Debug("GetE2Subscriptions(): restId=%s", restId)
+ if restId == "" {
+ w.WriteHeader(400) // Bad request
+ }
+
+ e2Subscriptions, err := c.registry.GetE2SubscriptionsJson(restId)
+ if err != nil {
+ w.WriteHeader(404) // Not found
+ } else {
+ w.Write(e2Subscriptions)
+ }
+}
diff --git a/pkg/control/e2if_state.go b/pkg/control/e2if_state.go
index 5259618..876dfc4 100644
--- a/pkg/control/e2if_state.go
+++ b/pkg/control/e2if_state.go
@@ -20,6 +20,7 @@
package control
import (
+ "encoding/json"
"fmt"
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
"strings"
@@ -59,6 +60,31 @@
e.SubscribeChannels()
}
+func (e *E2IfState) GetE2NodesJson() []byte {
+
+ e.mutex.Lock()
+ defer e.mutex.Unlock()
+
+ // Map contains something like this{"RAN_NAME_1":"RAN_NAME_1","RAN_NAME_11":"RAN_NAME_11","RAN_NAME_2":"RAN_NAME_2"}
+ var ranNameList []string
+ for _, ranName := range e.NbIdMap {
+ ranNameList = append(ranNameList, ranName)
+ }
+
+ e2NodesJson, err := json.Marshal(ranNameList)
+ if err != nil {
+ xapp.Logger.Error("GetE2Node() json.Marshal error: %v", err)
+ }
+ return e2NodesJson
+}
+
+func (e *E2IfState) GetAllE2Nodes() map[string]string {
+
+ e.mutex.Lock()
+ defer e.mutex.Unlock()
+ return e.NbIdMap
+}
+
func (e *E2IfState) NotificationCb(ch string, events ...string) {
xapp.Logger.Debug("SDL notification received from channel=%s, event=%v", ch, events[0])
diff --git a/pkg/control/registry.go b/pkg/control/registry.go
index 36e9b4c..3de549a 100644
--- a/pkg/control/registry.go
+++ b/pkg/control/registry.go
@@ -36,6 +36,8 @@
//-----------------------------------------------------------------------------
type RESTSubscription struct {
+ Created time.Time
+ xAppServiceName string
xAppRmrEndPoint string
Meid string
InstanceIds []uint32
@@ -107,20 +109,132 @@
}
}
-func (r *Registry) GetAllRestSubscriptions() []byte {
+func (r *Registry) GetAllRestSubscriptionsJson() []byte {
+
r.mutex.Lock()
defer r.mutex.Unlock()
restSubscriptionsJson, err := json.Marshal(r.restSubscriptions)
if err != nil {
- xapp.Logger.Error("GetAllRestSubscriptions(): %v", err)
+ xapp.Logger.Error("GetAllRestSubscriptions() json.Marshal error: %v", err)
}
return restSubscriptionsJson
}
-func (r *Registry) CreateRESTSubscription(restSubId *string, xAppRmrEndPoint *string, maid *string) *RESTSubscription {
+func (r *Registry) GetAllE2NodeRestSubscriptionsJson(ranName string) []byte {
+
+ restSubscriptions := r.GetAllE2NodeRestSubscriptions(ranName)
+ e2NodeRestSubscriptionsJson, err := json.Marshal(restSubscriptions)
+ if err != nil {
+ xapp.Logger.Error("GetE2NodeRestSubscriptions() json.Marshal error: %v", err)
+ }
+ return e2NodeRestSubscriptionsJson
+}
+
+func (r *Registry) GetAllE2NodeRestSubscriptions(ranName string) map[string]RESTSubscription {
+
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ var restSubscriptions map[string]RESTSubscription
+ restSubscriptions = make(map[string]RESTSubscription)
+ for restSubsId, restSubscription := range r.restSubscriptions {
+ if restSubscription.Meid == ranName {
+ restSubscriptions[restSubsId] = *restSubscription
+ }
+ }
+ return restSubscriptions
+}
+
+func (r *Registry) GetAllXappsJson() []byte {
+
+ r.mutex.Lock()
+ var xappList []string
+ var xappsMap map[string]string
+ xappsMap = make(map[string]string)
+ for _, restSubscription := range r.restSubscriptions {
+ _, ok := xappsMap[restSubscription.xAppServiceName]
+ if !ok {
+ xappsMap[restSubscription.xAppServiceName] = restSubscription.xAppServiceName
+ xappList = append(xappList, restSubscription.xAppServiceName)
+ }
+ }
+ r.mutex.Unlock()
+
+ xappsJson, err := json.Marshal(xappList)
+ if err != nil {
+ xapp.Logger.Error("GetXapps() json.Marshal error: %v", err)
+ }
+ return xappsJson
+}
+
+func (r *Registry) GetAllXapps() map[string]string {
+
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ var xappsMap map[string]string
+ xappsMap = make(map[string]string)
+ for _, restSubscription := range r.restSubscriptions {
+ _, ok := xappsMap[restSubscription.xAppServiceName]
+ if !ok {
+ xappsMap[restSubscription.xAppServiceName] = restSubscription.xAppServiceName
+ }
+ }
+ return xappsMap
+}
+
+func (r *Registry) GetAllXappRestSubscriptionsJson(xAppServiceName string) []byte {
+
+ xappRestSubscriptions := r.GetAllXappRestSubscriptions(xAppServiceName)
+ xappRestSubscriptionsJson, err := json.Marshal(xappRestSubscriptions)
+ if err != nil {
+ xapp.Logger.Error("GetXappRestSubscriptions() json.Marshal error: %v", err)
+ }
+ return xappRestSubscriptionsJson
+}
+
+func (r *Registry) GetAllXappRestSubscriptions(xAppServiceName string) map[string]RESTSubscription {
+
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ var xappRestSubscriptions map[string]RESTSubscription
+ xappRestSubscriptions = make(map[string]RESTSubscription)
+ for restSubsId, xappRestSubscription := range r.restSubscriptions {
+ if xappRestSubscription.xAppServiceName == xAppServiceName {
+ xappRestSubscriptions[restSubsId] = *xappRestSubscription
+ }
+ }
+ return xappRestSubscriptions
+}
+
+func (r *Registry) GetE2SubscriptionsJson(restSubsId string) ([]byte, error) {
+
+ // Get all E2 subscriptions of a REST subscription
+ restSubs, err := r.GetRESTSubscription(restSubsId, false)
+ if err != nil {
+ return nil, err
+ }
+
+ r.mutex.Lock()
+ var e2Subscriptions []Subscription
+ for _, e2SubId := range restSubs.InstanceIds {
+ e2Subscription, ok := r.register[e2SubId]
+ if ok {
+ e2Subscriptions = append(e2Subscriptions, *e2Subscription)
+ }
+ }
+ r.mutex.Unlock()
+ e2SubscriptionsJson, err := json.Marshal(e2Subscriptions)
+ if err != nil {
+ xapp.Logger.Error("GetE2Subscriptions() json.Marshal error: %v", err)
+ }
+ return e2SubscriptionsJson, nil
+}
+
+func (r *Registry) CreateRESTSubscription(restSubId *string, xappServiceName *string, xAppRmrEndPoint *string, maid *string) *RESTSubscription {
r.mutex.Lock()
defer r.mutex.Unlock()
newRestSubscription := RESTSubscription{}
+ newRestSubscription.Created = time.Now()
+ newRestSubscription.xAppServiceName = *xappServiceName
newRestSubscription.xAppRmrEndPoint = *xAppRmrEndPoint
newRestSubscription.Meid = *maid
newRestSubscription.SubReqOngoing = true
diff --git a/pkg/control/sdl_restSubsDb.go b/pkg/control/sdl_restSubsDb.go
index a0afbc0..576e6af 100644
--- a/pkg/control/sdl_restSubsDb.go
+++ b/pkg/control/sdl_restSubsDb.go
@@ -22,6 +22,7 @@
import (
"encoding/json"
"fmt"
+ "time"
sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
@@ -30,6 +31,8 @@
const restSubSdlNs = "submgr_restSubsDb"
type RESTSubscriptionInfo struct {
+ Created time.Time
+ XAppServiceName string
XAppRmrEndPoint string
Meid string
InstanceIds []uint32
@@ -46,6 +49,8 @@
func (c *Control) WriteRESTSubscriptionToSdl(restSubId string, restSubs *RESTSubscription) error {
var restSubscriptionInfo RESTSubscriptionInfo
+ restSubscriptionInfo.Created = restSubs.Created
+ restSubscriptionInfo.XAppServiceName = restSubs.xAppServiceName
restSubscriptionInfo.XAppRmrEndPoint = restSubs.xAppRmrEndPoint
restSubscriptionInfo.Meid = restSubs.Meid
restSubscriptionInfo.InstanceIds = restSubs.InstanceIds
@@ -104,6 +109,8 @@
func (c *Control) CreateRESTSubscription(restSubscriptionInfo *RESTSubscriptionInfo, jsonSubscriptionInfo *string) *RESTSubscription {
restSubs := &RESTSubscription{}
+ restSubs.Created = restSubscriptionInfo.Created
+ restSubs.xAppServiceName = restSubscriptionInfo.XAppServiceName
restSubs.xAppRmrEndPoint = restSubscriptionInfo.XAppRmrEndPoint
restSubs.Meid = restSubscriptionInfo.Meid
restSubs.InstanceIds = restSubscriptionInfo.InstanceIds
diff --git a/pkg/control/sdl_restSubsDb_test.go b/pkg/control/sdl_restSubsDb_test.go
index 3db8a2d..5e1db60 100644
--- a/pkg/control/sdl_restSubsDb_test.go
+++ b/pkg/control/sdl_restSubsDb_test.go
@@ -89,6 +89,7 @@
t.Log("TEST: Creating REST subscription")
restSubscription := &RESTSubscription{}
+ restSubscription.xAppServiceName = "localhost"
restSubscription.xAppRmrEndPoint = "localhost:13560"
restSubscription.Meid = "RAN_NAME_1"
restSubscription.SubReqOngoing = true
@@ -100,6 +101,7 @@
func PrintRESTSubscriptionData(t *testing.T, restSubs *RESTSubscription) {
t.Log("TEST: RESTSubscription data")
+ t.Logf("TEST: restSubs.xAppServiceName = %v", restSubs.xAppServiceName)
t.Logf("TEST: restSubs.xAppRmrEndPoint = %v", restSubs.xAppRmrEndPoint)
t.Logf("TEST: restSubs.Meid = %v", restSubs.Meid)
t.Logf("TEST: restSubs.InstanceIds = %v", restSubs.InstanceIds)
diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go
index 1563a00..78d9990 100644
--- a/pkg/control/ut_ctrl_submgr_test.go
+++ b/pkg/control/ut_ctrl_submgr_test.go
@@ -449,20 +449,21 @@
return retCounterMap
}
-func (mc *testingSubmgrControl) sendGetRequest(t *testing.T, addr string, path string) {
+func (mc *testingSubmgrControl) SendGetRequest(t *testing.T, addr string, path string) []byte {
mc.TestLog(t, "GET http://"+addr+"%v", path)
req, err := http.NewRequest("GET", "http://"+addr+path, nil)
if err != nil {
mc.TestError(t, "Error reading request. %v", err)
- return
+ return nil
}
- req.Header.Set("Cache-Control", "no-cache")
+
+ req.Header.Set("accept", "application/json")
client := &http.Client{Timeout: time.Second * 2}
resp, err := client.Do(req)
if err != nil {
mc.TestError(t, "Error reading response. %v", err)
- return
+ return nil
}
defer resp.Body.Close()
@@ -470,19 +471,19 @@
mc.TestLog(t, "Response Headers: %v", resp.Header)
if !strings.Contains(resp.Status, "200 OK") {
mc.TestError(t, "Wrong response status")
- return
+ return nil
}
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
mc.TestError(t, "Error reading body. %v", err)
- return
+ return nil
}
mc.TestLog(t, "%s", respBody)
- return
+ return respBody
}
-func (mc *testingSubmgrControl) sendPostRequest(t *testing.T, addr string, path string) {
+func (mc *testingSubmgrControl) SendPostRequest(t *testing.T, addr string, path string) {
mc.TestLog(t, "POST http://"+addr+"%v", path)
req, err := http.NewRequest("POST", "http://"+addr+path, nil)
@@ -490,6 +491,7 @@
mc.TestError(t, "Error reading request. %v", err)
return
}
+ req.Header.Set("accept", "application/json")
client := &http.Client{Timeout: time.Second * 2}
resp, err := client.Do(req)
if err != nil {
@@ -514,12 +516,52 @@
return
}
-//-----------------------------------------------------------------------------
-//
-//-----------------------------------------------------------------------------
+func (mc *testingSubmgrControl) SendDeleteRequest(t *testing.T, addr string, path string) {
+
+ mc.TestLog(t, "DELETE http://"+addr+"%v", path)
+ req, err := http.NewRequest("DELETE", "http://"+addr+path, nil)
+ if err != nil {
+ mc.TestError(t, "Error reading request. %v", err)
+ return
+ }
+ req.Header.Set("accept", "application/json")
+ client := &http.Client{Timeout: time.Second * 2}
+ resp, err := client.Do(req)
+ if err != nil {
+ mc.TestError(t, "Error reading response. %v", err)
+ return
+ }
+ defer resp.Body.Close()
+
+ mc.TestLog(t, "Response status: %v", resp.Status)
+ mc.TestLog(t, "Response Headers: %v", resp.Header)
+ if !strings.Contains(resp.Status, "204 No Content") {
+ mc.TestError(t, "Wrong response status")
+ return
+ }
+
+ respBody, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ mc.TestError(t, "Error reading body. %v", err)
+ return
+ }
+ mc.TestLog(t, "%s", respBody)
+ return
+}
+
func (mc *testingSubmgrControl) SetE2State(t *testing.T, ranNameState string) {
if err := mc.c.e2IfStateDb.XappRnibStoreAndPublish("RAN_CONNECTION_STATUS_CHANGE", ranNameState, "key1", "data1"); err != nil {
t.Errorf("XappRnibStoreAndPublish failed: %v", err)
}
}
+
+func (mc *testingSubmgrControl) VerifyStringExistInSlice(verifiedString string, list []string) bool {
+
+ for _, listItem := range list {
+ if listItem == verifiedString {
+ return true
+ }
+ }
+ return false
+}
diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go
index b4edc3f..3e9a51b 100644
--- a/pkg/control/ut_messaging_test.go
+++ b/pkg/control/ut_messaging_test.go
@@ -20,6 +20,7 @@
package control
import (
+ "encoding/json"
"strings"
"testing"
"time"
@@ -2632,27 +2633,315 @@
// | |
func TestGetSubscriptions(t *testing.T) {
- mainCtrl.sendGetRequest(t, "localhost:8088", "/ric/v1/subscriptions")
+ mainCtrl.SendGetRequest(t, "localhost:8088", "/ric/v1/subscriptions")
}
func TestGetSymptomData(t *testing.T) {
- mainCtrl.sendGetRequest(t, "localhost:8080", "/ric/v1/symptomdata")
+ mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/symptomdata")
}
func TestPostdeleteSubId(t *testing.T) {
- mainCtrl.sendPostRequest(t, "localhost:8080", "/ric/v1/test/deletesubid=1")
+ mainCtrl.SendPostRequest(t, "localhost:8080", "/ric/v1/test/deletesubid=1")
}
func TestPostEmptyDb(t *testing.T) {
- mainCtrl.sendPostRequest(t, "localhost:8080", "/ric/v1/test/emptydb")
+ mainCtrl.SendPostRequest(t, "localhost:8080", "/ric/v1/test/emptydb")
}
func TestGetRestSubscriptions(t *testing.T) {
- mainCtrl.sendGetRequest(t, "localhost:8080", "/ric/v1/restsubscriptions")
+ mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/restsubscriptions")
+}
+
+//-----------------------------------------------------------------------------
+// TestDelAllE2nodeSubsViaDebugIf
+//
+// stub stub stub
+// +-------+ +---------+ +---------+ +---------+
+// | xapp | | submgr | | e2term | | rtmgr |
+// +-------+ +---------+ +---------+ +---------+
+// | | | |
+// | RESTSubReq | | |
+// |---------------->| | |
+// | RESTSubResp | | |
+// |<----------------| | |
+// | | RouteCreate | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+// | | SubReq | |
+// | |------------->| |
+// | | SubResp | |
+// | |<-------------| |
+// | RESTNotif1 | | |
+// |<----------------| | |
+// | | | |
+// | REST get_all_e2nodes | |
+// |---------------->| | |
+// | OK 200 | | |
+// |<----------------| | |
+// | REST delete_all_e2node_subscriptions | ranName = RAN_NAME_1
+// |---------------->| | |
+// | OK 200 | | |
+// |<----------------| | |
+// | | SubDelReq | |
+// | |------------->| |
+// | | SubDelResp | |
+// | |<-------------| |
+// | | | |
+// | | RouteDelete | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+//
+//-----------------------------------------------------------------------------
+
+func TestDelAllE2nodeSubsViaDebugIf(t *testing.T) {
+
+ // Init counter check
+ mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+ Counter{cRestSubReqFromXapp, 1},
+ Counter{cRestSubRespToXapp, 1},
+ Counter{cSubReqToE2, 1},
+ Counter{cSubRespFromE2, 1},
+ Counter{cRestSubNotifToXapp, 1},
+ Counter{cRestSubDelReqFromXapp, 1},
+ Counter{cSubDelReqToE2, 1},
+ Counter{cSubDelRespFromE2, 1},
+ Counter{cRestSubDelRespToXapp, 1},
+ })
+
+ params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
+ restSubId := xappConn1.SendRESTSubsReq(t, params)
+ xapp.Logger.Debug("Send REST Policy subscriber request for subscriberId : %v", restSubId)
+
+ crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+ xappConn1.ExpectRESTNotification(t, restSubId)
+ e2termConn1.SendSubsResp(t, crereq1, cremsg1)
+ e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
+ xapp.Logger.Debug("REST notification received e2SubsId=%v", e2SubsId)
+
+ e2nodesJson := mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/get_all_e2nodes")
+
+ var e2nodesList []string
+ err := json.Unmarshal(e2nodesJson, &e2nodesList)
+ if err != nil {
+ t.Errorf("Unmarshal error: %s", err)
+ }
+ assert.Equal(t, true, mainCtrl.VerifyStringExistInSlice("RAN_NAME_1", e2nodesList))
+
+ e2RestSubsJson := mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/get_e2node_rest_subscriptions/RAN_NAME_1") // RAN_NAME_1 = ranName
+ var e2RestSubsMap map[string]RESTSubscription
+ err = json.Unmarshal(e2RestSubsJson, &e2RestSubsMap)
+ if err != nil {
+ t.Errorf("Unmarshal error: %s", err)
+ }
+
+ if len(e2RestSubsMap) != 1 {
+ t.Errorf("Incorrect e2RestSubsMap length %v", len(e2RestSubsMap))
+ }
+
+ // Simulate deletion through REST test and debug interface
+ mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/delete_all_e2node_subscriptions/RAN_NAME_1") // RAN_NAME_1 = ranName
+ delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+ e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+ // Wait that subs is cleaned
+ waitSubsCleanup(t, e2SubsId, 10)
+ mainCtrl.VerifyCounterValues(t)
+ mainCtrl.VerifyAllClean(t)
+}
+
+//-----------------------------------------------------------------------------
+// TestDelAllxAppSubsViaDebugIf
+//
+// stub stub stub
+// +-------+ +---------+ +---------+ +---------+
+// | xapp | | submgr | | e2term | | rtmgr |
+// +-------+ +---------+ +---------+ +---------+
+// | | | |
+// | RESTSubReq | | |
+// |---------------->| | |
+// | RESTSubResp | | |
+// |<----------------| | |
+// | | RouteCreate | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+// | | SubReq | |
+// | |------------->| |
+// | | SubResp | |
+// | |<-------------| |
+// | RESTNotif1 | | |
+// |<----------------| | |
+// | | | |
+// | REST get_all_xapps | |
+// |---------------->| | |
+// | OK 200 | | |
+// |<----------------| | |
+// | REST delete_all_xapp_subscriptions | xappServiceName = localhost
+// |---------------->| | |
+// | OK 200 | | |
+// |<----------------| | |
+// | | SubDelReq | |
+// | |------------->| |
+// | | SubDelResp | |
+// | |<-------------| |
+// | | | |
+// | | RouteDelete | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+//
+//-----------------------------------------------------------------------------
+
+func TestDelAllxAppSubsViaDebugIf(t *testing.T) {
+
+ // Init counter check
+ mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+ Counter{cRestSubReqFromXapp, 1},
+ Counter{cRestSubRespToXapp, 1},
+ Counter{cSubReqToE2, 1},
+ Counter{cSubRespFromE2, 1},
+ Counter{cRestSubNotifToXapp, 1},
+ Counter{cRestSubDelReqFromXapp, 1},
+ Counter{cSubDelReqToE2, 1},
+ Counter{cSubDelRespFromE2, 1},
+ Counter{cRestSubDelRespToXapp, 1},
+ })
+
+ params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
+ restSubId := xappConn1.SendRESTSubsReq(t, params)
+ xapp.Logger.Debug("Send REST Policy subscriber request for subscriberId : %v", restSubId)
+
+ crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+ xappConn1.ExpectRESTNotification(t, restSubId)
+ e2termConn1.SendSubsResp(t, crereq1, cremsg1)
+ e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
+ xapp.Logger.Debug("REST notification received e2SubsId=%v", e2SubsId)
+
+ xappsJson := mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/get_all_xapps")
+
+ var xappList []string
+ err := json.Unmarshal(xappsJson, &xappList)
+ if err != nil {
+ t.Errorf("Unmarshal error: %s", err)
+ }
+ assert.Equal(t, true, mainCtrl.VerifyStringExistInSlice("localhost", xappList))
+
+ // Simulate deletion through REST test and debug interface
+ mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/delete_all_xapp_subscriptions/localhost") // localhost = xappServiceName
+ delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+ e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+ // Wait that subs is cleaned
+ waitSubsCleanup(t, e2SubsId, 10)
+ mainCtrl.VerifyCounterValues(t)
+ mainCtrl.VerifyAllClean(t)
+}
+
+//-----------------------------------------------------------------------------
+// TestDelViaxAppSubsIf
+//
+// stub stub stub
+// +-------+ +---------+ +---------+ +---------+
+// | xapp | | submgr | | e2term | | rtmgr |
+// +-------+ +---------+ +---------+ +---------+
+// | | | |
+// | RESTSubReq | | |
+// |---------------->| | |
+// | RESTSubResp | | |
+// |<----------------| | |
+// | | RouteCreate | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+// | | SubReq | |
+// | |------------->| |
+// | | SubResp | |
+// | |<-------------| |
+// | RESTNotif1 | | |
+// |<----------------| | |
+// | | | |
+// | REST get_xapp_rest_restsubscriptions |
+// |---------------->| | |
+// | OK 200 | | |
+// |<----------------| | |
+// | RESTSudDel | | |
+// |---------------->| | | Via user curl command (port 8088)
+// | RESTSudDel | | |
+// |<----------------| | |
+// | | SubDelReq | |
+// | |------------->| |
+// | | SubDelResp | |
+// | |<-------------| |
+// | | | |
+// | | RouteDelete | |
+// | |--------------------------->|
+// | | RouteResponse| |
+// | |<---------------------------|
+//
+//-----------------------------------------------------------------------------
+
+func TestDelViaxAppSubsIf(t *testing.T) {
+
+ // Init counter check
+ mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+ Counter{cRestSubReqFromXapp, 1},
+ Counter{cRestSubRespToXapp, 1},
+ Counter{cSubReqToE2, 1},
+ Counter{cSubRespFromE2, 1},
+ Counter{cRestSubNotifToXapp, 1},
+ Counter{cRestSubDelReqFromXapp, 1},
+ Counter{cSubDelReqToE2, 1},
+ Counter{cSubDelRespFromE2, 1},
+ Counter{cRestSubDelRespToXapp, 1},
+ })
+
+ params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
+ restSubId := xappConn1.SendRESTSubsReq(t, params)
+ xapp.Logger.Debug("Send REST Policy subscriber request for subscriberId : %v", restSubId)
+
+ crereq1, cremsg1 := e2termConn1.RecvSubsReq(t)
+ xappConn1.ExpectRESTNotification(t, restSubId)
+ e2termConn1.SendSubsResp(t, crereq1, cremsg1)
+ e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
+ xapp.Logger.Debug("REST notification received e2SubsId=%v", e2SubsId)
+
+ restSubsListJson := mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/get_xapp_rest_restsubscriptions/localhost") // localhost = xappServiceName
+
+ var restSubsMap map[string]RESTSubscription
+ err := json.Unmarshal(restSubsListJson, &restSubsMap)
+ if err != nil {
+ t.Errorf("Unmarshal error: %s", err)
+ }
+ _, ok := restSubsMap[restSubId]
+ if !ok {
+ t.Errorf("REST subscription not found. restSubId=%s", restSubId)
+ }
+
+ var e2Subscriptions []Subscription
+ e2SubscriptionsJson := mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/get_e2subscriptions/"+restSubId)
+ err = json.Unmarshal(e2SubscriptionsJson, &e2Subscriptions)
+ if err != nil {
+ t.Errorf("Unmarshal error: %s", err)
+ }
+ if len(e2Subscriptions) != 1 {
+ t.Errorf("Incorrect e2Subscriptions length %v", len(e2Subscriptions))
+ }
+
+ // Simulate deletion through xapp REST test interface
+ mainCtrl.SendDeleteRequest(t, "localhost:8088", "/ric/v1/subscriptions/"+restSubId)
+ delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+ e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+ // Wait that subs is cleaned
+ waitSubsCleanup(t, e2SubsId, 10)
+ mainCtrl.VerifyCounterValues(t)
+ mainCtrl.VerifyAllClean(t)
}
//-----------------------------------------------------------------------------
@@ -3961,6 +4250,7 @@
// | RESTSubResp | |
// |<----------------| |
// | | SubReq |
+// | |------------->|
// | | |
// | | |
// | | SubReq |