Commit 9c880f50 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add README file for examples

parent ab916217
Loading
Loading
Loading
Loading

examples/README.md

0 → 100644
+13 −0
Original line number Diff line number Diff line

# MEC application examples

The examples folder contains a set of MEC application examples relative to different MEC topics.

- [demo1](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/tree/master/examples/demo1?ref_type=heads#demo1) showcases platform capabilities using iperf application;
- [demo2](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/tree/master/examples/demo2?ref_type=heads#demo2) is similar than demo1, using user charts to deploy its components instead of using dynamic chart generation;
- [demo3](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/tree/master/examples/demo3?ref_type=heads#demo3) demonstrates the usage of mobility services and MEC application handover (MEC 021);
- [demo4](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/tree/master/examples/demo4-ue?ref_type=heads#demo4) demonstrates the usage of MEC 016
- [demo6]() demonstrates the MEC Sandbox API usage, MEC 013, MEC 030 and MEC Federation;
- [demo7](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/tree/master/examples/demo7?ref_type=heads#demo7) is about MEC 030 & ETSI ITS;
- [demo8](https://labs.etsi.org/rep/mec/etsi-mec-sandbox/-/blob/master/examples/demo8/README.md?ref_type=heads) demonstrates the usage of MEC profile for CAPIF;
- [demo9](under construction) demonstrates the usage of MEC 033 & MEC 046 and MEC interworking wuth oneM2M.
+109 −2
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ var (
	appServiceInfo            ServiceInfo
	subscriptions             []LinkType
	iotPlatformInfo           IotPlatformInfo
	iotDevices                []DeviceInfo
)

// Display menu and read selection
@@ -339,6 +340,8 @@ const (
	IOT_PLTF_DISCOVERY      = "d"
	IOT_DEV_DISCOVERY_BY_ID = "D"
	IOT_DEV_DISCOVERY       = "v"
	IOT_CREATE_DEVICE       = "c"
	IOT_DELETE_DEVICE       = "C"
	STATUS                  = "T"
	OM2M_DISCOVERY          = "0"
	OM2M_DISCOVERY_BY_ID    = "1"
@@ -363,12 +366,13 @@ func menu(message string) []string {
			"\t%s: Current status:\n"+
			"MEC 033:\n"+
			"\t%s: Full IoT platform discovery, %s <io_t_platform_id>: Get IoT platform by IoTPlatformId, %s: Full device discovery\n"+
			"\t%s: Create a device, %s: Delete a device\n"+
			"MEC 046:\n"+
			"\t%s: Full discovery, %s <resource_id>: Get data for a specific oneM2M resource\n"+
			"oneM2M commands:\n"+
			"\t%s: Create an AE, %s: Create a CNT, %s: Create a CIN, %s: Create a subscription, %s: Delete a subscription\n"+
			"%s: Quit\n",
		LOGIN, LOGOUT, STATUS, IOT_PLTF_DISCOVERY, IOT_DEV_DISCOVERY_BY_ID, IOT_DEV_DISCOVERY, OM2M_DISCOVERY, OM2M_DISCOVERY_BY_ID, OM2M_CREATE_AE, OM2M_CREATE_CNT, OM2M_CREATE_CIN, OM2M_CREATE_SUB, OM2M_DELETE_SUB, QUIT)
		LOGIN, LOGOUT, STATUS, IOT_PLTF_DISCOVERY, IOT_DEV_DISCOVERY_BY_ID, IOT_DEV_DISCOVERY, IOT_CREATE_DEVICE, IOT_DELETE_DEVICE, OM2M_DISCOVERY, OM2M_DISCOVERY_BY_ID, OM2M_CREATE_AE, OM2M_CREATE_CNT, OM2M_CREATE_CIN, OM2M_CREATE_SUB, OM2M_DELETE_SUB, QUIT)
	if message != "" {
		fmt.Println("Last message: ", message)
	}
@@ -426,6 +430,12 @@ func logout() error {
		return err
	}

	if len(iotDevices) != 0 {
		for _, d := range iotDevices {
			mec033_om2m_delete_device(d.DeviceId)
		} // End of 'for' statement
	}

	// Delete subscriptions done
	if len(subscriptions) != 0 {
		for _, l := range subscriptions {
@@ -1187,6 +1197,83 @@ func mec033_om2m_dev_discovery() (body []byte, response *http.Response, err erro
	return body, nil, nil
}

func mec033_om2m_create_device() (deviceInfo DeviceInfo, response *http.Response, err error) {
	fmt.Println(">>> mec033_om2m_create_device")

	// Sanity checks
	if sandboxName == "" {
		return deviceInfo, nil, errors.New("No sandbox available")
	} else if scenarioId == -1 {
		return deviceInfo, nil, errors.New("No network scenario available")
	} else if appsInfo.Id == "" {
		return deviceInfo, nil, errors.New("No App instance available")
	} else if iotPlatformInfo.IotPlatformId == "" {
		return deviceInfo, nil, errors.New("No IoT platform available")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/iots/v1/registered_devices"
	fmt.Println("mec033_om2m_create_device: url: " + url)

	// Build message body
	new_device := DeviceInfo{
		DeviceAuthenticationInfo: "deviceAuthenticationInfo",
		DeviceMetadata:           []KeyValuePair{},
		Supi:                     "001011234567890",
		DeviceId:                 uuid.New().String(),
		RequestedIotPlatformId:   iotPlatformInfo.IotPlatformId,
	}
	// Add oneM2M device metadata
	new_device.DeviceMetadata = []KeyValuePair{
		{Key: "ri", Value: new_device.DeviceId},
		{Key: "rn", Value: new_device.Supi + "_" + new_device.DeviceId},
	}
	fmt.Println("mec033_om2m_create_device: device: " + fmt.Sprint(new_device))

	// Send request and await response
	body, err := json.Marshal(new_device)
	if err != nil {
		return deviceInfo, nil, err
	}
	body, response, err = send_mec_service_request(http.MethodPost, url, bytes.NewBuffer(body), nil, nil, nil)
	fmt.Println("mec033_om2m_create_device: " + response.Status)
	if err == nil && response.StatusCode == 201 {
		fmt.Println("mec033_om2m_create_device: body: " + string(body))
		err = json.Unmarshal([]byte(body), &deviceInfo)
		if err != nil {
			return deviceInfo, response, err
		}
		fmt.Println("mec033_om2m_create_device: deviceInfo: " + fmt.Sprint(deviceInfo))
		return deviceInfo, response, nil
	}

	return deviceInfo, response, err
}

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

	// Sanity checks
	if sandboxName == "" {
		return response, errors.New("No sandbox available")
	} else if scenarioId == -1 {
		return response, errors.New("No network scenario available")
	} else if appsInfo.Id == "" {
		return response, errors.New("No App instance available")
	} else if deviceId == "" {
		return response, errors.New("No device available")
	}

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/iots/v1/registered_devices/" + deviceId
	fmt.Println("mec033_om2m_delete_device: url: " + url)

	// Send request and await response
	_, response, err = send_mec_service_request(http.MethodDelete, url, nil, nil, nil, nil)
	fmt.Println("mec033_om2m_delete_device: " + response.Status)
	return response, err
}

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

@@ -1437,7 +1524,7 @@ func process_choice(choice []string) string {
		fmt.Println("message: " + message)

		// // Send mecApp registration
		// body, _, err := mec011_send_registration()
		// body, response, err := mec011_send_registration()
		// if err != nil {
		// 	scenarioId = -1
		// 	scenarios = nil
@@ -1486,6 +1573,26 @@ func process_choice(choice []string) string {
		} else {
			message = fmt.Sprintf("response body:  %s", string(body))
		}
	} else if strings.Compare(choice[0], IOT_CREATE_DEVICE) == 0 {
		deviceInfo, response, err := mec033_om2m_create_device()
		if err != nil {
			return err.Error()
		}
		if response.StatusCode != 200 {
			message = fmt.Sprintf("response status:  %d", response.StatusCode)
		} else {
			message = fmt.Sprintf("response body:  %s", fmt.Sprint(deviceInfo))
			iotDevices = append(iotDevices, deviceInfo)
		}
	} else if strings.Compare(choice[0], IOT_DELETE_DEVICE) == 0 {
		if len(choice) == 1 {
			return "IoT device ID was not set"
		}
		response, err := mec033_om2m_delete_device(choice[1])
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response status:  %d", response.StatusCode)
	} else if strings.Compare(choice[0], STATUS) == 0 {
		resp := app_status()
		message = fmt.Sprintf("Current status: %s", resp)