Skip to content
rnis_test.go 71.8 KiB
Newer Older
Simon Pastor's avatar
Simon Pastor committed
/*
Simon Pastor's avatar
Simon Pastor committed
 *
 * 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.
 */

Simon Pastor's avatar
Simon Pastor committed

import (
	"encoding/json"
	"fmt"
	"strconv"
	"testing"

	"context"
	"time"

	log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
	rnisClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-rnis-client"
)

var rnisAppClient *rnisClient.APIClient
var rnisServerUrl string

func init() {

	err := startSystemTest()
	if err != nil {
		log.Error("Cannot start system test: ", err)
	}
	//create client
	rnisAppClientCfg := rnisClient.NewConfiguration()
	if hostUrlStr == "" {
		hostUrlStr = "http://localhost"
	}

	rnisAppClientCfg.BasePath = hostUrlStr + "/" + sandboxName + "/rni/v2"

	rnisAppClient = rnisClient.NewAPIClient(rnisAppClientCfg)
	if rnisAppClient == nil {
		log.Error("Failed to create RNIS App REST API client: ", rnisAppClientCfg.BasePath)
	}
	//NOTE: if localhost is set as the hostUrl, might not be reachable from the service, export MEEP_HOST_TEST_URL ="http://[yourhost]"
	rnisServerUrl = hostUrlStr + ":" + httpListenerPort
}

func initialiseRnisTest() {
	log.Info("activating Scenario")
	err := activateScenario("rnis-system-test")
	if err != nil {
		log.Fatal("Scenario cannot be activated: ", err)
	}
	time.Sleep(1000 * time.Millisecond)
	if isAutomationReady(true, 10, 0) {
		geAutomationUpdate(true, false, true, true)
Simon Pastor's avatar
Simon Pastor committed
	}
}

func clearUpRnisTest() {
	log.Info("terminating Scenario")
	terminateScenario()
	time.Sleep(1000 * time.Millisecond)
}

//no really a test, but loading the scenarios needed that will be used in the following tests
//deletion of those scenarios at the end
func Test_RNIS_load_scenarios(t *testing.T) {

	// no override if the name is already in the DB.. security not to override something important
	err := createScenario("rnis-system-test", "rnis-system-test.yaml")
	if err != nil {
		t.Fatal("Cannot create scenario, keeping the one already there and continuing testing with it :", err)
	}
}

func Test_RNIS_periodic_4g_5gNei(t *testing.T) {
Simon Pastor's avatar
Simon Pastor committed
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())
Simon Pastor's avatar
Simon Pastor committed
	initialiseRnisTest()
	defer clearUpRnisTest()
Simon Pastor's avatar
Simon Pastor committed
	testAddress := "ue2"
	testAssociateId := rnisClient.AssociateId{Type_: 1, Value: testAddress}
	testSrcServing4GEcgi := rnisClient.Ecgi{CellId: "4000001", Plmn: &rnisClient.Plmn{"001", "001"}}
Simon Pastor's avatar
Simon Pastor committed
	testSrcServing4GRsrp := int32(70)
	testSrcServing4GRsrq := int32(28)
Simon Pastor's avatar
Simon Pastor committed
	testTrgServing4GEcgi := testSrcServing4GEcgi
Simon Pastor's avatar
Simon Pastor committed
	testTrgServing4GRsrp := int32(45)
	testTrgServing4GRsrq := int32(3)
Simon Pastor's avatar
Simon Pastor committed
	test5GPlmn := rnisClient.Plmn{"001", "001"}
	test5GPlmnArray := []rnisClient.Plmn{test5GPlmn}
Simon Pastor's avatar
Simon Pastor committed
	testTrgNrNCellInfo := rnisClient.MeasRepUeNotificationNrNCellInfo{NrNCellGId: "500000001", NrNCellPlmn: test5GPlmnArray}
	testTrgNrNCellInfoArray := []rnisClient.MeasRepUeNotificationNrNCellInfo{testTrgNrNCellInfo}
	testTrgNewRadioMeasNeiInfo := rnisClient.MeasRepUeNotificationNewRadioMeasNeiInfo{NrNCellInfo: testTrgNrNCellInfoArray, NrNCellRsrp: 51, NrNCellRsrq: 52}
Simon Pastor's avatar
Simon Pastor committed
	//moving to initial position
	geMoveAssetCoordinates(testAddress, 7.413917, 43.733505)
	time.Sleep(2000 * time.Millisecond)
Simon Pastor's avatar
Simon Pastor committed
	//subscriptions to test
	err := rnisSubscriptionMeasRepUe(testAssociateId, rnisServerUrl)
	if err != nil {
		t.Fatal("Subscription failed: ", err)
	}
Simon Pastor's avatar
Simon Pastor committed
	//wait to make sure the periodic timer got triggered
	time.Sleep(1000 * time.Millisecond)
Simon Pastor's avatar
Simon Pastor committed
	log.Info("moving asset")
	//still connected to 4G but seeing 5G as part of neighbor notification
Simon Pastor's avatar
Simon Pastor committed
	geMoveAssetCoordinates(testAddress, 7.412917, 43.733505)
	time.Sleep(2000 * time.Millisecond)

	if len(httpReqBody) > 1 {
		var body rnisClient.MeasRepUeNotification
		err = json.Unmarshal([]byte(httpReqBody[0]), &body)
		if err != nil {
			t.Fatalf("cannot unmarshall response")
		}
		errStr := validateMeasRepUeNotification(&body, &testAssociateId, &testSrcServing4GEcgi, testSrcServing4GRsrp, testSrcServing4GRsrq, nil, nil)
		if errStr != "" {
			printHttpReqBody()
			t.Fatalf(errStr)
		}
		err = json.Unmarshal([]byte(httpReqBody[len(httpReqBody)-1]), &body)
		if err != nil {
			t.Fatalf("cannot unmarshall response")
		}
		errStr = validateMeasRepUeNotification(&body, &testAssociateId, &testTrgServing4GEcgi, testTrgServing4GRsrp, testTrgServing4GRsrq, nil, &testTrgNewRadioMeasNeiInfo)
		if errStr != "" {
			printHttpReqBody()
			t.Fatalf(errStr)
		}

	} else {
		printHttpReqBody()
		t.Fatalf("Number of expected notifications not received")
	}
}

func Test_RNIS_periodic_4g_4gNei(t *testing.T) {
Simon Pastor's avatar
Simon Pastor committed
	fmt.Println("--- ", t.Name())
	log.MeepTextLogInit(t.Name())
Simon Pastor's avatar
Simon Pastor committed
	initialiseRnisTest()
	defer clearUpRnisTest()
Simon Pastor's avatar
Simon Pastor committed
	testAddress := "ue2"
	testAssociateId := rnisClient.AssociateId{Type_: 1, Value: testAddress}
	testSrcServing4GEcgi := rnisClient.Ecgi{CellId: "4000001", Plmn: &rnisClient.Plmn{"001", "001"}}
Simon Pastor's avatar
Simon Pastor committed
	testSrcServing4GRsrp := int32(70)
	testSrcServing4GRsrq := int32(28)
Simon Pastor's avatar
Simon Pastor committed
	testTrgServing4GEcgi := testSrcServing4GEcgi
Simon Pastor's avatar
Simon Pastor committed
	testTrgServing4GRsrp := int32(45)
	testTrgServing4GRsrq := int32(3)
Simon Pastor's avatar
Simon Pastor committed
	testTrgEutranNeighbourCellMeasInfo := rnisClient.MeasRepUeNotificationEutranNeighbourCellMeasInfo{Ecgi: &rnisClient.Ecgi{CellId: "4000002", Plmn: &rnisClient.Plmn{"001", "001"}}, Rsrp: testTrgServing4GRsrp, Rsrq: testTrgServing4GRsrq}
Simon Pastor's avatar
Simon Pastor committed
	//moving to initial position
	geMoveAssetCoordinates(testAddress, 7.413917, 43.733505)
	time.Sleep(2000 * time.Millisecond)
Simon Pastor's avatar
Simon Pastor committed
	//subscriptions to test
	err := rnisSubscriptionMeasRepUe(testAssociateId, rnisServerUrl)
	if err != nil {
		t.Fatal("Subscription failed: ", err)
	}

	//wait to make sure the periodic timer got triggered
Simon Pastor's avatar
Simon Pastor committed
	time.Sleep(1000 * time.Millisecond)
Simon Pastor's avatar
Simon Pastor committed
	log.Info("moving asset")
	//still connected to 4G but seeing 4G as part of neighbor notification
Simon Pastor's avatar
Simon Pastor committed
	geMoveAssetCoordinates(testAddress, 7.414917, 43.733505)
	time.Sleep(2000 * time.Millisecond)

	if len(httpReqBody) > 1 {
		var body rnisClient.MeasRepUeNotification
		err = json.Unmarshal([]byte(httpReqBody[0]), &body)
		if err != nil {
			t.Fatalf("cannot unmarshall response")
		}
		errStr := validateMeasRepUeNotification(&body, &testAssociateId, &testSrcServing4GEcgi, testSrcServing4GRsrp, testSrcServing4GRsrq, nil, nil)
		if errStr != "" {
			printHttpReqBody()
			t.Fatalf(errStr)
		}
		err = json.Unmarshal([]byte(httpReqBody[len(httpReqBody)-1]), &body)
Loading
Loading full blame…