Commit 982e2e16 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add Status menu emtry in demo6

parent 5ec345ec
Loading
Loading
Loading
Loading
+78 −9
Original line number Diff line number Diff line
@@ -76,12 +76,19 @@ type AppInfo struct {
type ServiceInfo struct {
	SerInstanceId string        `json:"serInstanceId,omitempty"`
	SerName       string        `json:"serName"`
	SerCategory   *CategoryRef  `json:"serCategory,omitempty"`
	Version       string        `json:"version"` // Service version
	State         string        `json:"state"`
	TransportInfo TransportInfo `json:"transportInfo"`
	Serializer    string        `json:"serializer"`
	Links         *Links        `json:"_links,omitempty"`
}
type CategoryRef struct {
	Href    string `json:"href"`
	Id      string `json:"id"`
	Name    string `json:"name"`
	Version string `json:"version"`
}
type TransportInfo struct {
	Id       string                      `json:"id"`
	Name     string                      `json:"name"`
@@ -159,7 +166,7 @@ type UeContext struct {
var (
	dir                       string
	fileName                  string
	provider                  string = "Jupyter2024" //"github"
	provider                  string = "github" //"Jupyter2024"
	run                       bool   = true
	done                      chan bool
	cfg                       *client.Configuration = nil
@@ -200,17 +207,19 @@ const (
	MEC011_DEREGISTRATION = "R"
	MEC011_CREATE_SVC     = "v"
	MEC011_DELETE_SVC     = "V"
	MEC011_GET_SVC        = "g"
	LIST_UES              = "u"
	INC_UE                = "x"
	DEC_UE                = "X"
	MEC030_UU_SETTINGS    = "Y"
	MEC030_V2X_SUB        = "z"
	MEC030_V2X_DEL_SUB    = "Z"
	STATUS                = "Q"
	QUIT                  = "q"
)

func clearScreen() {
	//fmt.Println("\033[2J")
	fmt.Println("\033[2J")
}

func menu(message string) []string {
@@ -221,17 +230,18 @@ func menu(message string) []string {
			"\t%s <index>: Activate a scenario, %s: Terminate a scenario\n"+
			"Optional commands:\n"+
			"\t%s <index>: Get scenario description\n"+
			"\t%s: Get MEC services list\n"+
			"\t%s: Get MEC application services list\n"+
			"\t%s: Get application instances list, %s: Create a new application instance, %s: Delete a new application instance\n"+
			"\t%s: Get UEs, %s <index>: Increase UE, %s <index>: Decrease UE\n"+
			"MEC 011 App Support:\n"+
			"\t%s: Send ConfirmReady, %s: Send Registration, %s: Send Deregistration\n"+
			"MEC 011 Service Management:\n"+
			"\t%s: Create new service, %s: Delete service\n"+
			"\t%s: Create new service, %s: Delete service, %s: Get list of MEC services\n"+
			"MEC 030:\n"+
			"\t%s: Get V2X UU unicast setting', %s: V2X Msg subscription, %s <subID>: Delete V2X 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, MEC030_UU_SETTINGS, MEC030_V2X_SUB, MEC030_V2X_DEL_SUB, 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, STATUS, QUIT)
	if message != "" {
		fmt.Println("Last message: ", message)
	}
@@ -722,6 +732,12 @@ func mec011_create_service() (resId string, response *http.Response, err error)
	transportType := "REST_HTTP"
	appServiceInfo = ServiceInfo{
		SerName: "demo6 MEC Service",
		SerCategory: &CategoryRef{
			Href:    callbackUrl + "/demo6svc/v1/Demo",
			Id:      uuid.New().String(),
			Name:    "Demo",
			Version: "1.0.0",
		},
		Version: "1.0.0",
		State:   "ACTIVE",
		TransportInfo: TransportInfo{
@@ -772,9 +788,9 @@ func mec011_delete_service() (err error) {

	// Sanity checks
	if sandboxName == "" {
		errors.New("No sandbox available")
		return errors.New("No sandbox available")
	} else if appsInfo.Id == "" {
		errors.New("No App instance available")
		return errors.New("No App instance available")
	} else if appServiceInfo.SerInstanceId == "" {
		return errors.New("No MEC service created")
	}
@@ -793,6 +809,28 @@ func mec011_delete_service() (err error) {
	return nil
}

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

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

	// Set URL
	url := mecUrl + "/" + sandboxName + "/" + mecPlateform + "/mec_service_mgmt/v1/services"
	fmt.Println("mec011_get_mec_services: 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
	}

	return body, nil, nil
}

func send_mec_service_request(method string, path string, body io.Reader, vars url.Values, queryParams url.Values, location *string) (resbody []byte, res *http.Response, err error) {
	fmt.Println(">>> send_mec_service_request: ", appsInfo.Name)

@@ -940,6 +978,29 @@ func v2x_msg_notification(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
}

func app_status() (resp string) {
	resp = ""
	if sandboxName != "" {
		resp += "Sandbox: " + sandboxName
	}
	if appsInfo.Id != "" {
		resp += ", appsInfo.Id: " + appsInfo.Id
	}
	if appServiceInfo.SerInstanceId != "" {
		resp += ", SerInstanceId: " + appServiceInfo.SerInstanceId
	}
	if terminationSubscriptionID != "" {
		resp += ", Subscription: " + terminationSubscriptionID
	}
	if isRegistered {
		resp += ", Demo6 app registered"
	} else {
		resp += ", Demo6 app not registered"
	}

	return resp
}

func main() {
	if len(os.Args) < 2 {
		// no config argument
@@ -1236,8 +1297,13 @@ func process_choice(choice []string) string {
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("MEC Service deleted:  %s", appServiceInfo.SerInstanceId)
		appServiceInfo.SerInstanceId = ""
		message = fmt.Sprintf("MEC Service deleted.")
	} else if strings.Compare(choice[0], MEC011_GET_SVC) == 0 {
		body, _, err := mec011_get_mec_services()
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  %s", string(body))
	} else if strings.Compare(choice[0], MEC030_UU_SETTINGS) == 0 {
		var err error
		body, _, err := mec030_get_v2x_uu_unicast_setting()
@@ -1261,6 +1327,9 @@ func process_choice(choice []string) string {
			return err.Error()
		}
		message = fmt.Sprintf("response body:  Subscription %s deleted", choice[1])
	} else if strings.Compare(choice[0], STATUS) == 0 {
		resp := app_status()
		message = fmt.Sprintf("Current status: %s", resp)
	} else {
		message = fmt.Sprintf("Invalid command: %s", choice)
	}
+1 −3
Original line number Diff line number Diff line
@@ -17,11 +17,9 @@ info:
    email: AdvantEDGE@InterDigital.com
externalDocs:
  description: 'ETSI GS MEC011 Application Enablement API, V3.1.1'
  url: >-
    https://www.etsi.org/deliver/etsi_gs/MEC/001_099/011/03.01.01_60/gs_MEC011v030101p.pdf
  url: https://www.etsi.org/deliver/etsi_gs/MEC/001_099/011/03.01.01_60/gs_MEC011v030101p.pdf
servers:
  - url: 'https://localhost/sandboxname/mec_app_support/v2'
    variables: {}
tags:
  - name: mec_app_support
  - name: unsupported
+1 −3
Original line number Diff line number Diff line
@@ -17,11 +17,9 @@ info:
    email: AdvantEDGE@InterDigital.com
externalDocs:
  description: 'ETSI GS MEC011 Application Enablement API, V3.1.1'
  url: >-
    https://www.etsi.org/deliver/etsi_gs/MEC/001_099/011/03.01.01_60/gs_MEC011v030101p.pdf
  url: https://www.etsi.org/deliver/etsi_gs/MEC/001_099/011/03.01.01_60/gs_MEC011v030101p.pdf
servers:
  - url: 'https://localhost/sandboxname/mec_app_support/v2'
    variables: {}
tags:
  - name: mec_app_support
  - name: unsupported
+26 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ info:
  license:
    name: BSD-3-Clause
    url: https://forge.etsi.org/legal-matters
  version: 3.1.1
  version: 3.2.2
externalDocs:
  description: "ETSI GS MEC 030 V2X Information Services API, v3.1.1"
  url: https://www.etsi.org/deliver/etsi_gs/MEC/001_099/030/03.02.01_60/
@@ -3001,6 +3001,31 @@ components:
        subscription:
          $ref: '#/components/schemas/LinkType'
      description: 'Hyperlink related to the resource. '
    ExpiryNotification:
      properties:
        _links:
          description: Hyperlink related to the resource.
          properties:
            subscription:
              $ref: '#/components/schemas/LinkType'
          required:
            - subscription
          type: object
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: Structure (inlined)
        expiryDeadline:
          $ref: '#/components/schemas/TimeStamp'
        notificationType:
          description: Shall be set to "ExpiryNotification".
          type: string
          x-etsi-mec-cardinality: '1'
          x-etsi-mec-origin-type: String
      required:
        - notificationType
        - _links
        - expiryDeadline
      type: object
      x-etsi-ref: 6.4.4
  responses:
    "204":
      description: No Content