Commit 3492cc90 authored by Yann Garcia's avatar Yann Garcia
Browse files

Validate meep-ams microservice with MEC021 v2.2.1

parent b772f601
Loading
Loading
Loading
Loading
+24 −34
Original line number Diff line number Diff line
@@ -93,27 +93,8 @@ const (
	FieldCtxOwner         string = "contextOwner"
)

const (
	AppMobilityServiceLevel_APP_MOBILITY_NOT_ALLOWED          = 1
	AppMobilityServiceLevel_APP_MOBILITY_WITH_CONFIRMATION    = 2
	AppMobilityServiceLevel_APP_MOBILITY_WITHOUT_CONFIRMATION = 3
)

const (
	MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED = 1
	MobilityStatus_INTERHOST_MOVEOUT_COMPLETED = 2
	MobilityStatus_INTERHOST_MOVEOUT_FAILED    = 3
)

const (
	ContextTransferState_NOT_TRANSFERRED                 = 0
	ContextTransferState_USER_CONTEXT_TRANSFER_COMPLETED = 1
)

const MOBILITY_PROCEDURE_SUBSCRIPTION_INT = int32(1)
const MOBILITY_PROCEDURE_SUBSCRIPTION = "MobilityProcedureSubscription"
const MOBILITY_PROCEDURE_NOTIFICATION = "MobilityProcedureNotification"
const ADJACENT_APP_INFO_SUBSCRIPTION_INT = int32(2)
const ADJACENT_APP_INFO_SUBSCRIPTION = "AdjacentAppInfoSubscription"
const ADJACENT_APP_INFO_NOTIFICATION = "AdjacentAppInfoNotification"
const APP_STATE_READY = "READY"
@@ -816,12 +797,13 @@ func sendMpNotifications(currentAppId string, targetAppId string, assocId *Assoc
		// Ignore mobility status filter

		// Prepare notification
		var mobilityStatus MobilityStatus = TRIGGERED // only supporting 1 = INTERHOST_MOVEOUT_TRIGGERED
		notif := MobilityProcedureNotification{
			NotificationType: MOBILITY_PROCEDURE_NOTIFICATION,
			TimeStamp: &TimeStamp{
				Seconds: int32(time.Now().Unix()),
			},
			MobilityStatus: 1, // only supporting 1 = INTERHOST_MOVEOUT_TRIGGERED
			MobilityStatus: &mobilityStatus,
			TargetAppInfo: &MobilityProcedureNotificationTargetAppInfo{
				AppInstanceId: targetAppId,
			},
@@ -859,7 +841,7 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	// Use discriminator to obtain subscription type
	var discriminator OneOfInlineSubscription
	var discriminator OneOfbody
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	err := json.Unmarshal(bodyBytes, &discriminator)
	if err != nil {
@@ -914,7 +896,7 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {
		subId := subMgr.GenerateSubscriptionId()

		// Set resource link
		mobProcSub.Links = &AdjacentAppInfoSubscriptionLinks{
		mobProcSub.Links = &MobilityProcedureSubscriptionLinks{
			Self: &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/" + subId,
			},
@@ -922,7 +904,7 @@ func subscriptionsPost(w http.ResponseWriter, r *http.Request) {

		// Set default mobility status filter criteria if none provided
		if len(mobProcSub.FilterCriteria.MobilityStatus) == 0 {
			mobProcSub.FilterCriteria.MobilityStatus = append(mobProcSub.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED)
			mobProcSub.FilterCriteria.MobilityStatus = append(mobProcSub.FilterCriteria.MobilityStatus, TRIGGERED)
		}

		// Create & store subscription
@@ -1015,7 +997,7 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) {
	subId := vars["subscriptionId"]

	// Use discriminator to obtain subscription type
	var discriminator OneOfInlineSubscription
	var discriminator OneOfbody
	bodyBytes, _ := ioutil.ReadAll(r.Body)
	err := json.Unmarshal(bodyBytes, &discriminator)
	if err != nil {
@@ -1098,7 +1080,7 @@ func subscriptionsPut(w http.ResponseWriter, r *http.Request) {

		// Set default mobility status filter criteria if none provided
		if len(mobProcSub.FilterCriteria.MobilityStatus) == 0 {
			mobProcSub.FilterCriteria.MobilityStatus = append(mobProcSub.FilterCriteria.MobilityStatus, MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED)
			mobProcSub.FilterCriteria.MobilityStatus = append(mobProcSub.FilterCriteria.MobilityStatus, TRIGGERED)
		}

		// Update subscription JSON
@@ -1243,6 +1225,8 @@ func subscriptionLinkListSubscriptionsGet(w http.ResponseWriter, r *http.Request
		},
	}

	var subscriptionLinkListLinks SubscriptionLinkListLinks

	// Find subscriptions by type
	subscriptionType := ""
	if subType != "" {
@@ -1265,19 +1249,22 @@ func subscriptionLinkListSubscriptionsGet(w http.ResponseWriter, r *http.Request
		var linkListSub SubscriptionLinkListSubscription

		// Add type-specific link
		var subscriptionType SubscriptionType
		if sub.Cfg.Type == MOBILITY_PROCEDURE_SUBSCRIPTION {
			linkListSub.SubscriptionType = MOBILITY_PROCEDURE_SUBSCRIPTION_INT
			subscriptionType = SubscriptionType_MOBILITY_PROCEDURE_
			subOrig := convertJsonToMobilityProcedureSubscription(sub.JsonSubOrig)
			linkListSub.Href = subOrig.Links.Self.Href
		} else if sub.Cfg.Type == ADJACENT_APP_INFO_SUBSCRIPTION {
			linkListSub.SubscriptionType = ADJACENT_APP_INFO_SUBSCRIPTION_INT
			subscriptionType = SubscriptionType_ADJACENT_APPINFO
			subOrig := convertJsonToAdjacentAppInfoSubscription(sub.JsonSubOrig)
			linkListSub.Href = subOrig.Links.Self.Href
		}
		linkListSub.SubscriptionType = &subscriptionType

		// Add to link list
		subscriptionLinkList.Subscription = append(subscriptionLinkList.Subscription, linkListSub)
		subscriptionLinkListLinks.Subscription = append(subscriptionLinkListLinks.Subscription, linkListSub)
	}
	subscriptionLinkList.Links = &subscriptionLinkListLinks

	// Send response
	w.WriteHeader(http.StatusOK)
@@ -1585,8 +1572,8 @@ func createService(appId string, regInfo *RegistrationInfo) error {
	for _, devInfo := range regInfo.DeviceInformation {
		dev := make(map[string]string)
		dev[FieldAssociateId] = devInfo.AssociateId.Value
		dev[FieldServiceLevel] = strconv.Itoa(int(devInfo.AppMobilityServiceLevel))
		dev[FieldCtxTransferState] = strconv.Itoa(int(devInfo.ContextTransferState))
		dev[FieldServiceLevel] = string(*devInfo.AppMobilityServiceLevel)
		dev[FieldCtxTransferState] = string(*devInfo.ContextTransferState)
		dev[FieldMobilitySvcId] = regInfo.AppMobilityServiceId
		dev[FieldAppInstanceId] = appId
		dev[FieldCtxOwner] = ""
@@ -1728,7 +1715,7 @@ func refreshTrackedDevCtxOwner(appName string) {
	deviceTargetMap := make(map[string][]string)
	for _, trackedDev := range matchingTrackedDevList {
		// Make sure device mobility is allowed
		if trackedDev[FieldServiceLevel] == strconv.Itoa(int(AppMobilityServiceLevel_APP_MOBILITY_NOT_ALLOWED)) {
		if trackedDev[FieldServiceLevel] == string(NOT_ALLOWED) {
			continue
		}

@@ -1790,9 +1777,10 @@ func refreshTrackedDevCtxOwner(appName string) {

				// Send MP Notification for subscriptions to current MEC App
				// NOTE: Only send for notifications for the source AM service dtracked devices
				modelType := UE_I_PV4_ADDRESS
				if trackedDev[FieldAppInstanceId] == currentAppId {
					assocId := AssociateId{
						Type_: 1, //ipv4 address
						Type_: &modelType,
						Value: address,
					}
					sendMpNotifications(currentAppId, targetAppId, &assocId)
@@ -1844,8 +1832,10 @@ func getTargetApps(appName string, address string) ([]string, error) {
func ExpiredSubscriptionCb(sub *subs.Subscription) {
	// Build expiry notification
	notif := ExpiryNotification{
		Links: &ExpiryNotificationLinks{
			Self: hostUrl.String() + basePath + "subscriptions/" + sub.Cfg.Id,
		Links: &MobilityProcedureNotificationLinks{
			Subscription: &LinkType{
				Href: hostUrl.String() + basePath + "subscriptions/" + sub.Cfg.Id,
			},
		},
		ExpiryDeadline: &TimeStamp{
			Seconds:     int32(sub.Cfg.ExpiryTime.Unix()),
+25 −17
Original line number Diff line number Diff line
@@ -850,7 +850,7 @@ func testSubscriptionListGet(t *testing.T) {
		t.Fatalf("Failed to get expected response")
	}
	nb := 0
	for range respBody.Subscription {
	for range respBody.Links.Subscription {
		nb++
	}
	if nb != expectedSubscriptionNb {
@@ -863,8 +863,11 @@ func testServicesPost(t *testing.T) (string, string) {
	/******************************
	 * expected response section
	 ******************************/
	expectedAssocId1 := AssociateId{1, "1.1.1.1"}
	expectedDeviceInfo1 := RegistrationInfoDeviceInformation{&expectedAssocId1, AppMobilityServiceLevel_APP_MOBILITY_WITH_CONFIRMATION, ContextTransferState_NOT_TRANSFERRED}
	var t_ ModelType = UE_I_PV4_ADDRESS
	expectedAssocId1 := AssociateId{&t_, "1.1.1.1"}
	var appMobilityServiceLevel AppMobilityServiceLevel = WITH_CONFIRMATION
	var contextTransferState ContextTransferState = NOT_TRANSFERRED
	expectedDeviceInfo1 := RegistrationInfoDeviceInformation{&expectedAssocId1, &appMobilityServiceLevel, &contextTransferState}
	expectedDeviceInfo := []RegistrationInfoDeviceInformation{expectedDeviceInfo1}
	expectedRegistrationInfo := RegistrationInfo{
		DeviceInformation: expectedDeviceInfo,
@@ -928,8 +931,11 @@ func testServicesPut(t *testing.T, serviceId string, expectSuccess bool) string
	/******************************
	 * expected response section
	 ******************************/
	expectedAssocId1 := AssociateId{1, "1.1.1.1"}
	expectedDeviceInfo1 := RegistrationInfoDeviceInformation{&expectedAssocId1, AppMobilityServiceLevel_APP_MOBILITY_WITH_CONFIRMATION, ContextTransferState_NOT_TRANSFERRED}
	var t_ ModelType = UE_I_PV4_ADDRESS
	expectedAssocId1 := AssociateId{&t_, "1.1.1.1"}
	var appMobilityServiceLevel AppMobilityServiceLevel = WITH_CONFIRMATION
	var contextTransferState ContextTransferState = NOT_TRANSFERRED
	expectedDeviceInfo1 := RegistrationInfoDeviceInformation{&expectedAssocId1, &appMobilityServiceLevel, &contextTransferState}
	expectedDeviceInfo := []RegistrationInfoDeviceInformation{expectedDeviceInfo1}
	expectedRegistrationInfo := RegistrationInfo{serviceId, expectedDeviceInfo, 0, &RegistrationInfoServiceConsumerId{"myApp", ""}}
	//expectedExpiry := TimeStamp{0, 1998599770}
@@ -1110,9 +1116,10 @@ func testSubscriptionMobilityProcedurePost(t *testing.T) (string, string) {
	/******************************
	 * expected response section
	 ******************************/
	expectedAssocId1 := AssociateId{1, "1.1.1.1"}
	var t_ ModelType = UE_I_PV4_ADDRESS
	expectedAssocId1 := AssociateId{&t_, "1.1.1.1"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := MobilityProcedureSubscriptionFilterCriteria{"myApp", expectedAssocId, []int32{MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED}}
	expectedFilter := MobilityProcedureSubscriptionFilterCriteria{"myApp", expectedAssocId, []MobilityStatus{TRIGGERED}}
	expectedCallBackRef := "myCallbakRef"

	/******************************
@@ -1126,7 +1133,7 @@ func testSubscriptionMobilityProcedurePost(t *testing.T) (string, string) {
	//filter is not exactly the same in response and request
	filterCriteria := expectedFilter
	filterCriteria.MobilityStatus = nil
	mobilityProcedureSubscriptionPost1 := MobilityProcedureSubscription{nil, expectedCallBackRef, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}
	mobilityProcedureSubscriptionPost1 := MobilityProcedureSubscription{nil, expectedCallBackRef, true, nil, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}

	body, err := json.Marshal(mobilityProcedureSubscriptionPost1)
	if err != nil {
@@ -1162,7 +1169,7 @@ func testSubscriptionMobilityProcedurePost(t *testing.T) (string, string) {
	subId := self[strings.LastIndex(self, "/")+1:]
	expectedLinkType := LinkType{"/" + testScenarioName + "/amsi/v1/subscriptions/" + subId}
	//expectedExpiry := TimeStamp{0, 1998599770}
	expectedResponse := MobilityProcedureSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}
	expectedResponse := MobilityProcedureSubscription{&MobilityProcedureSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}
	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
@@ -1179,13 +1186,14 @@ func testSubscriptionMobilityProcedurePut(t *testing.T, subscriptionId string, e
	/******************************
	 * expected response section
	 ******************************/
	expectedAssocId1 := AssociateId{1, "2.2.2.2"}
	var t_ ModelType = UE_I_PV4_ADDRESS
	expectedAssocId1 := AssociateId{&t_, "2.2.2.2"}
	expectedAssocId := []AssociateId{expectedAssocId1}
	expectedFilter := MobilityProcedureSubscriptionFilterCriteria{"myApp", expectedAssocId, []int32{MobilityStatus_INTERHOST_MOVEOUT_TRIGGERED}}
	expectedFilter := MobilityProcedureSubscriptionFilterCriteria{"myApp", expectedAssocId, []MobilityStatus{TRIGGERED}}
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/amsi/v1/subscriptions/" + subscriptionId}
	//expectedExpiry := TimeStamp{0, 1998599770}
	expectedResponse := MobilityProcedureSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}
	expectedResponse := MobilityProcedureSubscription{&MobilityProcedureSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
@@ -1201,7 +1209,7 @@ func testSubscriptionMobilityProcedurePut(t *testing.T, subscriptionId string, e
	/******************************
	 * request body section
	 ******************************/
	mobilityProcedureSubscription1 := MobilityProcedureSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}
	mobilityProcedureSubscription1 := MobilityProcedureSubscription{&MobilityProcedureSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, MOBILITY_PROCEDURE_SUBSCRIPTION}

	body, err := json.Marshal(mobilityProcedureSubscription1)
	if err != nil {
@@ -1335,7 +1343,7 @@ func testSubscriptionAdjPost(t *testing.T) (string, string) {
	 * request body section
	 ******************************/

	adjSubscriptionPost1 := AdjacentAppInfoSubscription{nil, expectedCallBackRef, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}
	adjSubscriptionPost1 := AdjacentAppInfoSubscription{nil, expectedCallBackRef, true, nil, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}

	body, err := json.Marshal(adjSubscriptionPost1)
	if err != nil {
@@ -1370,7 +1378,7 @@ func testSubscriptionAdjPost(t *testing.T) (string, string) {
	fmt.Println("subId: " + subId)
	expectedLinkType := LinkType{"/" + testScenarioName + "/amsi/v1/subscriptions/" + subId}
	//expectedExpiry := TimeStamp{0, 1998599770}
	expectedResponse := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}
	expectedResponse := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}
	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
		t.Fatalf(err.Error())
@@ -1390,7 +1398,7 @@ func testSubscriptionAdjPut(t *testing.T, subscriptionId string, expectSuccess b
	expectedCallBackRef := "myCallbakRef"
	expectedLinkType := LinkType{"/" + testScenarioName + "/amsi/v1/subscriptions/" + subscriptionId}
	//expectedExpiry := TimeStamp{0, 1998599770}
	expectedResponse := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}
	expectedResponse := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}

	expectedResponseStr, err := json.Marshal(expectedResponse)
	if err != nil {
@@ -1407,7 +1415,7 @@ func testSubscriptionAdjPut(t *testing.T, subscriptionId string, expectSuccess b
	 * request body section
	 ******************************/

	adjSubscriptionPost1 := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}
	adjSubscriptionPost1 := AdjacentAppInfoSubscription{&AdjacentAppInfoSubscriptionLinks{&expectedLinkType}, expectedCallBackRef, true, nil, nil, &expectedFilter, ADJACENT_APP_INFO_SUBSCRIPTION}

	body, err := json.Marshal(adjSubscriptionPost1)
	if err != nil {
+0 −1
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@
package server

type AdjacentAppInfoSubscription struct {

	Links *AdjacentAppInfoSubscriptionLinks `json:"_links,omitempty"`
	// URI selected by the service consumer to receive notifications on the subscribed Application Mobility Service. This shall be included both in the request and in response.
	CallbackReference string `json:"callbackReference"`
+0 −1
Original line number Diff line number Diff line
@@ -11,6 +11,5 @@ package server

// List of filtering criteria for the subscription. Any filtering criteria from below, which is included in the request, shall also be included in the response.
type AdjacentAppInfoSubscriptionFilterCriteria struct {

	AppInstanceId string `json:"appInstanceId,omitempty"`
}
+0 −1
Original line number Diff line number Diff line
@@ -11,6 +11,5 @@ package server

// Hyperlink related to the resource. This shall be only included in the HTTP responses and in HTTP PUT requests.
type AdjacentAppInfoSubscriptionLinks struct {

	Self *LinkType `json:"self"`
}
Loading