// This source code is part of the near-RT RIC (RAN Intelligent Controller)
// platform project (RICP).
-
package clients
import (
"e2mgr/models"
"encoding/json"
"fmt"
- "io/ioutil"
"net/http"
)
body := bytes.NewBuffer(marshaled)
c.logger.Infof("[E2M -> Routing Manager] #RoutingManagerClient.AddE2TInstance - request body: %+v", body)
- url := c.config.RoutingManagerBaseUrl + AddE2TInstanceApiSuffix
+ url := c.config.RoutingManager.BaseUrl + AddE2TInstanceApiSuffix
resp, err := c.httpClient.Post(url, "application/json", body)
if err != nil {
+ c.logger.Errorf("#RoutingManagerClient.AddE2TInstance - failed sending request. error: %s", err)
return e2managererrors.NewRoutingManagerError(err)
}
defer resp.Body.Close()
- respBody, err := ioutil.ReadAll(resp.Body)
-
- if err != nil {
- return e2managererrors.NewRoutingManagerError(err)
- }
-
- if resp.StatusCode != http.StatusOK { // TODO: shall we check for != 201?
- c.logger.Errorf("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - failure. http status code: %d, response body: %s", resp.StatusCode, string(respBody))
- return e2managererrors.NewRoutingManagerError(fmt.Errorf("Invalid data")) // TODO: which error shall we return?
+ if resp.StatusCode == http.StatusCreated {
+ c.logger.Infof("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - success. http status code: %d", resp.StatusCode)
+ return nil
}
- c.logger.Infof("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - success. http status code: %d, response body: %s", resp.StatusCode, string(respBody))
- return nil
+ c.logger.Errorf("[Routing Manager -> E2M] #RoutingManagerClient.AddE2TInstance - failure. http status code: %d", resp.StatusCode)
+ return e2managererrors.NewRoutingManagerError(fmt.Errorf("invalid data"))
}
// This source code is part of the near-RT RIC (RAN Intelligent Controller)
// platform project (RICP).
-
package clients
import (
+ "bytes"
"e2mgr/configuration"
"e2mgr/logger"
"e2mgr/mocks"
+ "e2mgr/models"
+ "encoding/json"
+ "github.com/pkg/errors"
+ "github.com/stretchr/testify/assert"
+ "io/ioutil"
+ "net/http"
"testing"
)
func initRoutingManagerClientTest(t *testing.T) (*RoutingManagerClient, *mocks.HttpClientMock, *configuration.Configuration) {
logger := initLog(t)
- config := &configuration.Configuration{
- RoutingManagerBaseUrl: "http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/",
- }
+ config := &configuration.Configuration{}
+ config.RoutingManager.BaseUrl = "http://iltlv740.intl.att.com:8080/ric/v1/handles/"
httpClientMock := &mocks.HttpClientMock{}
rmClient := NewRoutingManagerClient(logger, config, httpClientMock)
return rmClient, httpClientMock, config
}
-//func TestAddE2TInstanceSuccess(t *testing.T) {
-// rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
-//
-// data := models.NewRoutingManagerE2TData(E2TAddress)
-// marshaled, _ := json.Marshal(data)
-// body := bytes.NewBuffer(marshaled)
-// url := config.RoutingManagerBaseUrl + "e2t"
-// httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 200}, nil)
-// err := rmClient.AddE2TInstance(E2TAddress)
-// assert.Nil(t, err)
-//}
-//
-//func TestAddE2TInstanceFailure(t *testing.T) {
-// rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
-//
-// data := models.NewRoutingManagerE2TData(E2TAddress)
-// marshaled, _ := json.Marshal(data)
-// body := bytes.NewBuffer(marshaled)
-// url := config.RoutingManagerBaseUrl + "e2t"
-// httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: 400}, nil)
-// err := rmClient.AddE2TInstance(E2TAddress)
-// assert.NotNil(t, err)
-//}
+func TestAddE2TInstanceSuccess(t *testing.T) {
+ rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
+
+ data := models.NewRoutingManagerE2TData(E2TAddress)
+ marshaled, _ := json.Marshal(data)
+ body := bytes.NewBuffer(marshaled)
+ url := config.RoutingManager.BaseUrl + "e2t"
+ respBody := ioutil.NopCloser(bytes.NewBufferString(""))
+ httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: http.StatusCreated, Body: respBody}, nil)
+ err := rmClient.AddE2TInstance(E2TAddress)
+ assert.Nil(t, err)
+}
+
+func TestAddE2TInstanceHttpPostFailure(t *testing.T) {
+ rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
+
+ data := models.NewRoutingManagerE2TData(E2TAddress)
+ marshaled, _ := json.Marshal(data)
+ body := bytes.NewBuffer(marshaled)
+ url := config.RoutingManager.BaseUrl + "e2t"
+ httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{}, errors.New("error"))
+ err := rmClient.AddE2TInstance(E2TAddress)
+ assert.NotNil(t, err)
+}
+
+func TestAddE2TInstanceFailure(t *testing.T) {
+ rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
+
+ data := models.NewRoutingManagerE2TData(E2TAddress)
+ marshaled, _ := json.Marshal(data)
+ body := bytes.NewBuffer(marshaled)
+ url := config.RoutingManager.BaseUrl + "e2t"
+ respBody := ioutil.NopCloser(bytes.NewBufferString(""))
+ httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: http.StatusBadRequest, Body:respBody}, nil)
+ err := rmClient.AddE2TInstance(E2TAddress)
+ assert.NotNil(t, err)
+}
// TODO: extract to test_utils
func initLog(t *testing.T) *logger.Logger {
Port int
MaxMsgSize int
}
+ RoutingManager struct {
+ BaseUrl string
+ }
NotificationResponseBuffer int
BigRedButtonTimeoutSec int
MaxConnectionAttempts int
RnibRetryIntervalMs int
KeepAliveResponseTimeoutMs int
KeepAliveDelayMs int
- RoutingManagerBaseUrl string
}
func ParseConfiguration() *Configuration {
}
config := Configuration{}
- config.fillRmrConfig(viper.Sub("rmr"))
- config.fillHttpConfig(viper.Sub("http"))
- config.fillLoggingConfig(viper.Sub("logging"))
-
+ config.populateRmrConfig(viper.Sub("rmr"))
+ config.populateHttpConfig(viper.Sub("http"))
+ config.populateLoggingConfig(viper.Sub("logging"))
+ config.populateRoutingManagerConfig(viper.Sub("routingManager"))
config.NotificationResponseBuffer = viper.GetInt("notificationResponseBuffer")
config.BigRedButtonTimeoutSec = viper.GetInt("bigRedButtonTimeoutSec")
config.MaxConnectionAttempts = viper.GetInt("maxConnectionAttempts")
config.RnibRetryIntervalMs = viper.GetInt("rnibRetryIntervalMs")
config.KeepAliveResponseTimeoutMs = viper.GetInt("keepAliveResponseTimeoutMs")
config.KeepAliveDelayMs = viper.GetInt("KeepAliveDelayMs")
- config.RoutingManagerBaseUrl = viper.GetString("routingManagerBaseUrl")
return &config
}
-func (c *Configuration) fillLoggingConfig(logConfig *viper.Viper) {
+func (c *Configuration) populateLoggingConfig(logConfig *viper.Viper) {
if logConfig == nil {
- panic(fmt.Sprintf("#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n"))
+ panic(fmt.Sprintf("#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n"))
}
c.Logging.LogLevel = logConfig.GetString("logLevel")
}
-func (c *Configuration) fillHttpConfig(httpConfig *viper.Viper) {
+func (c *Configuration) populateHttpConfig(httpConfig *viper.Viper) {
if httpConfig == nil {
- panic(fmt.Sprintf("#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n"))
+ panic(fmt.Sprintf("#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n"))
}
c.Http.Port = httpConfig.GetInt("port")
}
-func (c *Configuration) fillRmrConfig(rmrConfig *viper.Viper) {
+func (c *Configuration) populateRmrConfig(rmrConfig *viper.Viper) {
if rmrConfig == nil {
- panic(fmt.Sprintf("#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n"))
+ panic(fmt.Sprintf("#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n"))
}
c.Rmr.Port = rmrConfig.GetInt("port")
c.Rmr.MaxMsgSize = rmrConfig.GetInt("maxMsgSize")
}
+
+func (c *Configuration) populateRoutingManagerConfig(rmConfig *viper.Viper) {
+ if rmConfig == nil {
+ panic(fmt.Sprintf("#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n"))
+ }
+ c.RoutingManager.BaseUrl = rmConfig.GetString("baseUrl")
+}
yamlMap := map[string]interface{}{
"logging": map[string]interface{}{"logLevel": "info"},
"http": map[string]interface{}{"port": 3800},
+ "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
}
buf, err := yaml.Marshal(yamlMap)
if err != nil {
if err != nil {
t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
}
- assert.PanicsWithValue(t, "#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
+ assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
}
func TestLoggingConfigNotFoundFailure(t *testing.T) {
yamlMap := map[string]interface{}{
"rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
"http": map[string]interface{}{"port": 3800},
+ "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
}
buf, err := yaml.Marshal(yamlMap)
if err != nil {
if err != nil {
t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
}
- assert.PanicsWithValue(t, "#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n",
+ assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
func() { ParseConfiguration() })
}
yamlMap := map[string]interface{}{
"rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
"logging": map[string]interface{}{"logLevel": "info"},
+ "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
}
buf, err := yaml.Marshal(yamlMap)
if err != nil {
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
}
- assert.PanicsWithValue(t, "#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
+ assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
+ func() { ParseConfiguration() })
+}
+
+func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
+ configPath := "../resources/configuration.yaml"
+ configPathTmp := "../resources/configuration.yaml_tmp"
+ err := os.Rename(configPath, configPathTmp)
+ if err != nil {
+ t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
+ }
+ defer func() {
+ err = os.Rename(configPathTmp, configPath)
+ if err != nil {
+ t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
+ }
+ }()
+ yamlMap := map[string]interface{}{
+ "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
+ "logging": map[string]interface{}{"logLevel": "info"},
+ "http": map[string]interface{}{"port": 3800},
+ }
+ buf, err := yaml.Marshal(yamlMap)
+ if err != nil {
+ t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
+ }
+ err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
+ if err != nil {
+ t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
+ }
+ assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
func() { ParseConfiguration() })
}
}
func (h E2TermInitNotificationHandler) Handle(request *models.NotificationRequest) {
-
- h.logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT")
-
unmarshalledPayload := models.E2TermInitPayload{}
err := json.Unmarshal(request.Payload, &unmarshalledPayload)
if err != nil {
- h.logger.Errorf("#E2TermInitNotificationHandler - Error unmarshaling E2 Term Init payload: %s", err)
+ h.logger.Errorf("#E2TermInitNotificationHandler.Handle - Error unmarshaling E2 Term Init payload: %s", err)
return
}
e2tAddress := unmarshalledPayload.Address
if len(e2tAddress) == 0 {
- h.logger.Errorf("#E2TermInitNotificationHandler - Empty E2T address received")
+ h.logger.Errorf("#E2TermInitNotificationHandler.Handle - Empty E2T address received")
return
}
+ h.logger.Infof("#E2TermInitNotificationHandler.Handle - E2T address: %s - handling E2_TERM_INIT", e2tAddress)
+
e2tInstance, err := h.e2tInstancesManager.GetE2TInstance(e2tAddress)
if err != nil {
_, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock := initRanLostConnectionTest(t)
var rnibErr error
- var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST}
+ var initialNodeb = &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST}
readerMock.On("GetNodeb", RanName).Return(initialNodeb, rnibErr)
- var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1}
+ var argNodeb = &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1}
writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr)
payload := e2pdus.PackedX2setupRequest
_, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock := initRanLostConnectionTest(t)
var rnibErr error
- var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST}
+ var initialNodeb = &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST}
readerMock.On("GetNodeb", RanName).Return(initialNodeb, rnibErr)
- var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0}
+ var argNodeb = &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0}
writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr)
payload := e2pdus.PackedX2setupRequest
rmr:
port: 3801
maxMsgSize: 65536
+routingManager:
+ baseUrl: http://iltlv740.intl.att.com:8080/ric/v1/handles/
notificationResponseBuffer: 100
bigRedButtonTimeoutSec: 5
maxConnectionAttempts: 3
rnibRetryIntervalMs: 10
keepAliveResponseTimeoutMs: 1500
keepAliveDelayMs: 500
-routingManagerBaseUrl: http://iltlv740.intl.att.com:8080/ric/v1/handles/v1/