Commit 366c2b43 authored by Mudassar Khan's avatar Mudassar Khan
Browse files

add meep-ipe

parent b4ebcbe1
Loading
Loading
Loading
Loading
+46 −0
Changes for go-apps/meep-ipe/Dockerfile: 46 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright (c) 2022  The AdvantEDGE Authors
# 
# 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.

FROM debian:12-slim

# Real inputs read by entrypoint.sh. In the MEC Sandbox/Helm deployment,
# these are injected automatically by Helm and override the empty
# defaults below. For local `docker run` testing, pass them via -e or
# --env-file (see docker_run.sh).
ENV MEEP_HOST_URL=""
ENV MEEP_SANDBOX_NAME=""
ENV MEEP_LOCATION_NAME=""
ENV MEEP_INSTANCE_ID=""
ENV MEEP_IPE_URL=""
ENV MEEP_IPE_PORT=""
ENV MEEP_HTTPS=""
ENV MEEP_CSE_URL=""
ENV MEEP_CSE_PORT=""
ENV MEEP_CSE_ID=""
ENV MEEP_CSE_NAME=""
ENV MEEP_STANDALONE=""

COPY ./bin/meep-ipe/meep-ipe /meep-ipe
COPY entrypoint.sh /
COPY config.yaml.in /

RUN apt-get update && apt-get install -y --no-install-recommends \
    gettext \
    && apt-get autoremove --purge -y \
    && apt-get autoclean \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
RUN chmod +x /entrypoint.sh /meep-ipe

ENTRYPOINT ["/entrypoint.sh"]
 No newline at end of file
+46 −0
Changes for go-apps/meep-ipe/MEC/Get_App_Instances.go: 46 added lines, 0 removed lines.
Original line number Diff line number Diff line
package mec

import (
	"encoding/json"
	"fmt"
	"io"
	utils "meep-ipe/utils"
	"net/http"
)

// GetAppInstances retrieves all MEC Application Instances from the platform
//
// This function queries the MEC platform's application management API to obtain
// a list of all available application instances, including their IDs, names, and node names.
//
// Reference: ETSI GS MEC 011 - MEC Application Lifecycle Management API
//
// @param url The URL endpoint for querying application instances
//
//	(e.g., /sandbox-ctrl/v1/applications)
//
// @return []mec.AppInstanceID Array of application instance information
// @return error Returns nil on success, or an error if the request fails
func GetAppInstances(url string) ([]AppInstanceID, error) {
	resp, err := utils.SendMECRequest("GET", url, nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get MEC app instances: %v", err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("failed to get MEC App Instance ID: received status code %d", resp.StatusCode)
	}

	// From the response body, extract all App Instance IDs
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("failed to read response body: %v", err)
	}
	//log.Println("Response body:", string(body))

	var allAppInstances []AppInstanceID
	if err := json.Unmarshal(body, &allAppInstances); err != nil {
		return nil, fmt.Errorf("failed to unmarshal response body: %v", err)
	}
	return allAppInstances, nil
}
+15 −0
Changes for go-apps/meep-ipe/MEC/app_instance_id.go: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
package mec

// AppInstanceID represents a MEC Application Instance identifier
//
// This structure contains the identification information for a MEC Application Instance,
// including its unique ID, name, and the node name where it is deployed.
//
// Reference: ETSI GS MEC 011 - MEC Application Lifecycle Management API
//
// @struct AppInstanceID
type AppInstanceID struct {
	ID       string `json:"id"`       // Unique identifier for the application instance
	Name     string `json:"name"`     // Name of the application instance
	NodeName string `json:"nodeName"` // Name of the MEC host node where the instance is deployed
}
+170 −0
Changes for go-apps/meep-ipe/MEC/device_info.go: 170 added lines, 0 removed lines.
Original line number Diff line number Diff line
package mec

// This file models the request/response body for the ETSI GS MEC 033 IoT API
// POST /registered_devices endpoint (operationId: registereddevicesPOST),
// as defined in iot.yaml.

// RegisteredDevicesBody is the top-level request body wrapper for
// POST /registered_devices (schema: registered_devices_body).
type RegisteredDevicesBody struct {
	DeviceInfo *DeviceInfo `json:"DeviceInfo"`
}

// DeviceInfo describes an IoT device to be registered (schema: DeviceInfo).
//
// NOTE 1: At least one attribute among Gpsi, Pei, Supi, Msisdn, Imei, Imsi,
// and Iccid should be provided.
// NOTE 2: Until a valid traffic rule is provided, the device will not be
// able to use the IoTS.
type DeviceInfo struct {
	// Required fields
	DeviceAuthenticationInfo string `json:"deviceAuthenticationInfo"`
	DeviceId                 string `json:"deviceId"`
	Enabled                  bool   `json:"enabled"`

	// Optional fields
	DeviceMetadata               []KeyValuePair                `json:"deviceMetadata,omitempty"`
	Gpsi                         string                        `json:"gpsi,omitempty"`
	Pei                          string                        `json:"pei,omitempty"`
	Supi                         string                        `json:"supi,omitempty"`
	Msisdn                       string                        `json:"msisdn,omitempty"`
	Imei                         string                        `json:"imei,omitempty"`
	Imsi                         string                        `json:"imsi,omitempty"`
	Iccid                        string                        `json:"iccid,omitempty"`
	RequestedMecTrafficRule      []TrafficRuleDescriptor        `json:"requestedMecTrafficRule,omitempty"`
	RequestedIotPlatformId       string                        `json:"requestedIotPlatformId,omitempty"`
	RequestedUserTransportId     string                        `json:"requestedUserTransportId,omitempty"`
	DeviceSpecificMessageFormats *DeviceSpecificMessageFormats `json:"deviceSpecificMessageFormats,omitempty"`
	DownlinkInfo                 *DownlinkInfo                 `json:"downlinkInfo,omitempty"`
	ClientCertificate             string                        `json:"clientCertificate,omitempty"`
}

// KeyValuePair holds device metadata as a key-value pair (schema: KeyValuePair).
type KeyValuePair struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

// DeviceSpecificMessageFormats describes the format of messages published by
// the MEC IoTS on behalf of the IoT device (schema: DeviceSpecificMessageFormats).
type DeviceSpecificMessageFormats struct {
	EventMsgFormat  *EventMsg  `json:"eventMsgFormat,omitempty"`
	UplinkMsgFormat *UplinkMsg `json:"uplinkMsgFormat,omitempty"`
}

const (
	SerializerTypeJSON     SerializerType = "JSON"
	SerializerTypeXML      SerializerType = "XML"
	SerializerTypeProtobuf SerializerType = "PROTOBUF3"
)

// EventMsg describes the event message format (schema: EventMsg).
type EventMsg struct {
	// Required
	EventTopic         string         `json:"eventTopic"`
	SelectedSerializer SerializerType `json:"selectedSerializer"`

	// Optional
	IncludeDeviceAddr     bool `json:"includeDeviceAddr,omitempty"`
	IncludeDeviceMetadata bool `json:"includeDeviceMetadata,omitempty"`
	IncludePei            bool `json:"includePei,omitempty"`
	IncludeSupi           bool `json:"includeSupi,omitempty"`
	IncludeImei           bool `json:"includeImei,omitempty"`
	IncludeImsi           bool `json:"includeImsi,omitempty"`
	IncludeIccid          bool `json:"includeIccid,omitempty"`
	IncludeDeviceId       bool `json:"includeDeviceId,omitempty"`
}

// UplinkMsg describes the uplink message format (schema: UplinkMsg).
type UplinkMsg struct {
	// Required
	UplinkTopic        string         `json:"uplinkTopic"`
	SelectedSerializer SerializerType `json:"selectedSerializer"`

	// Optional
	IncludeDevicePort     bool `json:"includeDevicePort,omitempty"`
	IncludeDeviceAddr     bool `json:"includeDeviceAddr,omitempty"`
	IncludeDeviceMetadata bool `json:"includeDeviceMetadata,omitempty"`
	IncludePei            bool `json:"includePei,omitempty"`
	IncludeSupi           bool `json:"includeSupi,omitempty"`
	IncludeImei           bool `json:"includeImei,omitempty"`
	IncludeImsi           bool `json:"includeImsi,omitempty"`
	IncludeIccid          bool `json:"includeIccid,omitempty"`
	IncludeDeviceId       bool `json:"includeDeviceId,omitempty"`
}

// DownlinkInfo describes the downlink communication configuration of the
// user transport (schema: DownlinkInfo).
type DownlinkInfo struct {
	DownlinkTopic string `json:"downlinkTopic,omitempty"`
	DevicePort    int    `json:"devicePort,omitempty"`
}

// TrafficRuleDescriptor describes a MEC traffic rule the IoT device is
// requested to be associated to (schema: TrafficRuleDescriptor, from
// ETSI GS MEC 010-2).
type TrafficRuleDescriptor struct {
	// Required
	TrafficRuleId string           `json:"trafficRuleId"`
	FilterType    string           `json:"filterType"` // "per FLOW" | "per PACKET"
	Priority      int              `json:"priority"`
	TrafficFilter []TrafficFilter  `json:"trafficFilter"`
	Action        string           `json:"action"` // "SEE_DESCRIPTION"

	// Optional
	DstInterface *InterfaceDescriptor `json:"dstInterface,omitempty"`
}

// TrafficFilter identifies specific flows/packets to be handled by the
// MEC host (schema: TrafficFilter).
type TrafficFilter struct {
	SrcAddress       []string `json:"srcAddress,omitempty"`
	DstAddress       []string `json:"dstAddress,omitempty"`
	SrcPort          []string `json:"srcPort,omitempty"`
	DstPort          []string `json:"dstPort,omitempty"`
	Protocol         []string `json:"protocol,omitempty"`
	Tag              []string `json:"tag,omitempty"`
	Uri              []string `json:"uri,omitempty"`
	PacketLabel      []string `json:"packetLabel,omitempty"`
	SrcTunnelAddress []string `json:"srcTunnelAddress,omitempty"`
	TgtTunnelAddress []string `json:"tgtTunnelAddress,omitempty"`
	SrcTunnelPort    []string `json:"srcTunnelPort,omitempty"`
	DstTunnelPort    []string `json:"dstTunnelPort,omitempty"`
	QCI              int      `json:"qCI,omitempty"`
	DSCP             int      `json:"dSCP,omitempty"`
	TC               int      `json:"tC,omitempty"`
}

// InterfaceDescriptor describes the destination interface for a traffic
// rule (schema: InterfaceDescriptor).
type InterfaceDescriptor struct {
	// Required
	InterfaceType string `json:"interfaceType"` // "TUNNEL" | "MAC" | "IP"

	// Optional
	TunnelInfo    *TunnelInfo `json:"tunnelInfo,omitempty"`
	SrcMACAddress string      `json:"srcMACAddress,omitempty"`
	DstMACAddress string      `json:"dstMACAddress,omitempty"`
	DstIPAddress  string      `json:"dstIPAddress,omitempty"`
}

// TunnelInfo describes GTP/GRE tunnel parameters (schema: TunnelInfo).
type TunnelInfo struct {
	// Required
	TunnelType        string `json:"tunnelType"` // "GTP-U" | "GRE"
	TunnelDstAddress  string `json:"tunnelDstAddress"`
	TunnelSrcAddress  string `json:"tunnelSrcAddress"`

	// Optional
	TunnelSpecificData string `json:"tunnelSpecificData,omitempty"`
}

// ProblemDetails is the standard error response body used for 400/403/404
// responses (schema: ProblemDetails).
type ProblemDetails struct {
	Type     string `json:"type,omitempty"`
	Title    string `json:"title,omitempty"`
	Status   int    `json:"status,omitempty"`
	Detail   string `json:"detail,omitempty"`
	Instance string `json:"instance,omitempty"`
}
 No newline at end of file
+55 −0
Changes for go-apps/meep-ipe/MEC/device_registration.go: 55 added lines, 0 removed lines.
Original line number Diff line number Diff line
package mec

import (
	"fmt"
	// "io"
	"log"
	"net/http"

	utils "meep-ipe/utils"
	// onem2m "meep-ipe/oneM2M"
)

// PostRegisteredDevice sends a minimal POST /registered_devices request,
// populating only the required DeviceInfo fields:
//   - deviceAuthenticationInfo
//   - deviceId
//   - enabled

func PostRegisteredDevice(deviceInfo *DeviceInfo) (*http.Response, error) {
	// body := RegisteredDevicesBody{DeviceInfo: deviceInfo}

	url := fmt.Sprintf("%s/%s/%s/iots/v1/registered_devices", config["sandboxUrl"].(string), config["sandboxName"].(string),
		config["mecplatform"].(string))

	log.Println("Register Device URL : ", url)

	res, err := utils.SendMECRequest("POST", url, deviceInfo)
	if err != nil {
		return nil, fmt.Errorf("failed to send request: %w", err)
	}
	return res, nil
}

// func PostRegisterDeviceOnIoTPlatform(w http.ResponseWriter, r *http.Request) (*http.Response, error) {
// 	log.Println("PostRegisterDeviceOnIoTPlatform called")

// 	body, err := io.ReadAll(r.Body)
// 	if err != nil {
// 		log.Printf("Error reading request body: %v", err)
// 		http.Error(w, "Failed to read request body", http.StatusBadRequest)
// 		return nil, err
// 	}
// 	defer r.Body.Close()

// 	resp, err := onem2m.CreateAE(body)
// 	if err != nil {
// 		log.Printf("Error creating AE on IoT Platform: %v", err)
// 		http.Error(w, "Failed to create AE on IoT Platform", http.StatusInternalServerError)
// 		return nil, err
// 	}

// 	log.Printf("Response from IoT Platform: status %d, body: %s", resp.StatusCode, string(resp.Body))
// 	return resp, nil

// }
 No newline at end of file
Loading