Commit 6ae2e1df authored by Yann Garcia's avatar Yann Garcia
Browse files

Enhance demo6 with MEC 040 subscription features

parent 32e90f5e
Loading
Loading
Loading
Loading
+129 −13
Changes for examples/demo6/golang/main.go: 129 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -147,7 +147,13 @@ type V2xMsgSubscriptionFilterCriteria struct {
}

// MEC 040
// TODO
type SystemUpdateNotificationSubscription struct {
	SubscriptionType  string     `json:"subscriptionType"`
	CallbackReference string     `json:"callbackReference"`
	Links             *Links     `json:"links,omitempty"`
	SystemId          []string   `json:"systemId,omitempty"`
	ExpiryDeadline    *TimeStamp `json:"expiryDeadline,omitempty"`
}

// MEC Common types
type LinkType struct {
@@ -160,6 +166,10 @@ type Links struct {
type Self struct {
	Self *LinkType `json:"self"`
}
type TimeStamp struct {
	Seconds     int32 `json:"seconds"`
	NanoSeconds int32 `json:"nanoSeconds"`
}

type UeContext struct {
	id string
@@ -180,7 +190,7 @@ var (
	userCode                  string                = ""
	mecUrl                    string                = ""
	mecPlateform              string                = ""
	callbackUrl               string                = "http://mec-platform.etsi.org/callbacks"
	callbackUrl               string                = "http://yanngarcia.ddns.net"
	terminationSubscriptionID string                = ""
	scenarios                 []client.SandboxNetworkScenario
	scenario                  []client.Scenario
@@ -219,6 +229,9 @@ const (
	MEC030_V2X_DEL_SUB    = "Z"
	MEC040_FED_SYS_GET    = "0"
	MEC040_FED_SRV_GET    = "1"
	MEC040_FED_SUB_POST   = "2"
	MEC040_FED_SUB_GET    = "3"
	MEC040_FED_SUB_DEL    = "4"
	STATUS                = "Q"
	QUIT                  = "q"
)
@@ -245,10 +258,10 @@ func menu(message string) []string {
			"MEC 030:\n"+
			"\t%s: Get V2X UU unicast setting', %s: V2X Msg subscription, %s <subID>: Delete V2X subscription\n"+
			"MEC 040:\n"+
			"\t%s: Get Federation Systems list', %s <systemId>: Get Federation Services list\n"+
			"\t%s: Get Federation Systems list', %s <systemId>: Get Federation Services list, %s: Subscribe, %s [<subId>]: Get subscription, %s <subId>: Delete subscription\n"+
			"\t%s: Current status:\n"+
			"%s: Quit\n",
		LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, LIST_UES, INC_UE, DEC_UE, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, MEC040_FED_SYS_GET, MEC040_FED_SRV_GET, STATUS, QUIT)
		LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, LIST_UES, INC_UE, DEC_UE, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC011_GET_SVC, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, MEC040_FED_SYS_GET, MEC040_FED_SRV_GET, MEC040_FED_SUB_POST, MEC040_FED_SUB_GET, MEC040_FED_SUB_DEL, STATUS, QUIT)
	if message != "" {
		fmt.Println("Last message: ", message)
	}
@@ -1060,6 +1073,90 @@ func mec40_get_services_list(choice string) (body []byte, response *http.Respons
	return body, response, nil
}

func mec40_create_subscription() (body []byte, response *http.Response, err error) {
	fmt.Println(">>> mec40_create_subscription")

	// Sanity checks
	if sandboxName == "" {
		return nil, nil, errors.New("No sandbox available")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/fed_enablement/v1/subscriptions"
	fmt.Println("mec40_create_subscription: url: " + url)
	// Build message body
	var systemUpdateNotificationSubscription = SystemUpdateNotificationSubscription{
		SubscriptionType:  "SystemUpdateNotificationSubscription",
		CallbackReference: callbackUrl + "/fed/v1/notification",
	}
	json_body, err := json.Marshal(systemUpdateNotificationSubscription)
	if err != nil {
		return nil, nil, err
	}
	io_body := bytes.NewReader(json_body)
	// Send request and await response
	body, response, err = send_mec_service_request(http.MethodPost, url, io_body, nil, nil, nil)
	if err != nil {
		return nil, nil, err
	}
	defer response.Body.Close()

	return body, response, nil
}

func mec40_get_subscriptions(choice []string) (body []byte, response *http.Response, err error) {
	fmt.Println(">>> mec40_get_subscriptions: ", choice)

	// Sanity checks
	if sandboxName == "" {
		return nil, nil, errors.New("No sandbox available")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/fed_enablement/v1/subscriptions"
	if len(choice) == 2 { // Individual GET
		url = url + "/" + choice[1]
	}
	fmt.Println("mec40_get_subscriptions: url: " + url)
	// Send request and await response
	body, response, err = send_mec_service_request(http.MethodGet, url, nil, nil, nil, nil)
	if err != nil {
		return nil, nil, err
	}
	defer response.Body.Close()

	return body, response, nil
	return nil, nil, errors.New("not implemented")
}

func mec40_delete_subscriptions(choice string) (response *http.Response, err error) {
	fmt.Println(">>> mec40_delete_subscriptions: ", choice)

	// Sanity checks
	if sandboxName == "" {
		return nil, errors.New("No sandbox available")
	}
	if choice == "" {
		return nil, errors.New("Wrong parameter")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/fed_enablement/v1/subscriptions/" + choice
	fmt.Println("mec40_delete_subscriptions: url: " + url)
	// Send request and await response
	_, response, err = send_mec_service_request(http.MethodDelete, url, nil, nil, nil, nil)
	if err != nil {
		return nil, err
	}

	return response, nil
}

func fed_notification(w http.ResponseWriter, r *http.Request) {
	fmt.Println(">>> fed_notification: ", r)
	w.WriteHeader(http.StatusOK)
}

func app_status() (resp string) {
	resp = ""
	if sandboxName != "" {
@@ -1201,8 +1298,6 @@ func main() {
		}
		time.Sleep(time.Second)
	}

	return
}

func LoadConfig(path string, name string) (config Config, err error) {
@@ -1247,7 +1342,7 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("scenarios: %s", fmt.Sprint(scenarios))
	} else if strings.Compare(choice[0], SC) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("Index is not set")
			return "Index is not set"
		}
		idx, err := verify_idx_len(choice[1], len(scenarios))
		if err != nil {
@@ -1257,7 +1352,7 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("Scenario %s:", fmt.Sprint(scenario))
	} else if strings.Compare(choice[0], ACTIVATE) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("Index is not set")
			return "Index is not set"
		}
		var err error
		scenarioId, err = verify_idx_len(choice[1], len(scenarios))
@@ -1322,7 +1417,7 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("List of UEs %v", ues)
	} else if strings.Compare(choice[0], INC_UE) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("Index is not set")
			return "Index is not set"
		}
		ueId, err := verify_idx_len(choice[1], len(ues))
		if err != nil {
@@ -1335,7 +1430,7 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("Increase %s, new value: %d", ues[ueId].id, ues[ueId].v)
	} else if strings.Compare(choice[0], DEC_UE) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("Index is not set")
			return "Index is not set"
		}
		ueId, err := verify_idx_len(choice[1], len(ues))
		if err != nil {
@@ -1379,7 +1474,7 @@ func process_choice(choice []string) string {
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("MEC Service deleted.")
		message = "MEC Service deleted."
	} else if strings.Compare(choice[0], MEC011_GET_SVC) == 0 {
		body, _, err := mec011_get_mec_services()
		if err != nil {
@@ -1402,7 +1497,7 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC030_V2X_DEL_SUB) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("Subscription ID is not set")
			return "Subscription ID is not set"
		}
		_, err := mec030_delete_v2x_messages_subscription(choice[1])
		if err != nil {
@@ -1417,13 +1512,34 @@ func process_choice(choice []string) string {
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC040_FED_SRV_GET) == 0 {
		if len(choice) == 1 {
			return fmt.Sprintf("System ID is not set")
			return "System ID is not set"
		}
		body, _, err := mec40_get_services_list(choice[1])
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC040_FED_SUB_POST) == 0 {
		body, _, err := mec40_create_subscription()
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC040_FED_SUB_GET) == 0 {
		body, _, err := mec40_get_subscriptions(choice)
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC040_FED_SUB_DEL) == 0 {
		if len(choice) == 1 {
			return "Subscription ID is not set"
		}
		response, err := mec40_delete_subscriptions(choice[1])
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response: %s", response.Status)
	} else if strings.Compare(choice[0], STATUS) == 0 {
		resp := app_status()
		message = fmt.Sprintf("Current status: %s", resp)
+6 −0
Changes for examples/demo6/golang/routers.go: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -71,4 +71,10 @@ var routes = Routes{
		"/vis/v2/v2x_msg_notification",
		v2x_msg_notification,
	},
	Route{
		"Index",
		"POST",
		"/fed/v1/notification",
		fed_notification,
	},
}