Commit be762086 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add support of UE control GET; Bug fixed in login (static URL)

parent e25a42da
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
#!/bin/bash
set -e

echo "mode: advantedge" >app_instance.yaml
echo "mode: sandbox" >app_instance.yaml
echo "sandbox:" >>app_instance.yaml
echo "mecplatform: ${MEEP_MEP_NAME}" >>app_instance.yaml
echo "appid:" ${MEEP_APP_ID} >>app_instance.yaml
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ type Configuration struct {

func NewConfiguration() *Configuration {
	cfg := &Configuration{
		BasePath:      "http://192.168.10.42/sandbox-api/v1",
		BasePath:      "http://localhost/sandbox-api/v1",
		DefaultHeader: make(map[string]string),
		UserAgent:     "Swagger-Codegen/1.0.0/go",
	}
+4 −0
Original line number Diff line number Diff line
@@ -17,7 +17,11 @@ require (
	github.com/magiconair/properties v1.8.0 // indirect
	github.com/mitchellh/mapstructure v1.1.2 // indirect
	github.com/pelletier/go-toml v1.2.0 // indirect
	github.com/spf13/afero v1.1.2 // indirect
	github.com/spf13/cast v1.3.0 // indirect
	github.com/spf13/jwalterweatherman v1.0.0 // indirect
	github.com/spf13/pflag v1.0.3 // indirect
	golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a // indirect
	golang.org/x/text v0.3.0 // indirect
	gopkg.in/yaml.v2 v2.2.2 // indirect
)
+0 −1549

File changed.

Preview size limit exceeded, changes collapsed.

+122 −78
Original line number Diff line number Diff line
@@ -38,13 +38,10 @@ import (
	"os/signal"
	"path/filepath"

	//"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"
	"github.com/gorilla/mux"
	// "crypto/tls"

	client "github.com/InterDigitalInc/AdvantEDGE/example/demo6/client"

@@ -94,6 +91,11 @@ type Links struct {
	self *LinkType `json:"self"`
}

type UeContext struct {
	id string
	v  int
}

var (
	dir             string
	fileName        string
@@ -114,6 +116,7 @@ var (
	mecUrl          string = ""
	mecPlateform    string = ""
	appServiceInfo  ServiceInfo
	ues             []UeContext
)

// Display menu and read selection
@@ -134,53 +137,13 @@ const (
	MEC011_DEREGISTRATION = "R"
	MEC011_CREATE_SVC     = "v"
	MEC011_DELETE_SVC     = "V"
	MEC030_UU_SETTINGS    = "u"
	LIST_UES              = "u"
	INC_UE                = "x"
	DEC_UE                = "X"
	MEC030_UU_SETTINGS    = "z"
	QUIT                  = "q"
)

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

type Routes []Route

func NewRouter() *mux.Router {
	var handler http.Handler
	router := mux.NewRouter().StrictSlash(true)
	for _, route := range routes {
		handler = route.HandlerFunc
		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}

	return router
}

func Index(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World!")
}

var routes = Routes{
	Route{
		"Index",
		"GET",
		"/",
		Index,
	},
	Route{
		"Index",
		"GET",
		"/demo6/v1/",
		Index,
	},
}

func clearScreen() {
	fmt.Println("\033[2J")
}
@@ -195,6 +158,7 @@ func menu(message string) []string {
			"\t%s <index>: Get scenario description\n"+
			"\t%s: Get MEC 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"+
@@ -202,7 +166,7 @@ func menu(message string) []string {
			"MEC 030:\n"+
			"\t%s: Get V2X UU unicast setting\n"+
			"%s: Quit\n",
		LOGIN, NAMESPACE, LOGOUT, LIST_SC, ACTIVATE, DEACTIVATE, SC, LIST_SERVICES, LIST_APP, CREATE_APP, DELETE_APP, MEC011_CONFIRM_READY, MEC011_REGISTRATION, MEC011_DEREGISTRATION, MEC011_CREATE_SVC, MEC011_DELETE_SVC, MEC030_UU_SETTINGS, 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, MEC030_UU_SETTINGS, QUIT)
	if message != "" {
		fmt.Println("Last message: ", message)
	}
@@ -432,6 +396,60 @@ func verify_idx_len(choice string, len int) (int, error) {
	return idx, nil
}

func getListOfUes() (ues []UeContext, err error) {
	fmt.Println(">>> getListOfUes")

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

	u, _, err := cl.SandboxUEControllerApi.SandboxUeControllerGET(context.TODO(), sandboxName)
	if err != nil {
		return ues, err
	}

	for _, k := range u {
		ues = append(ues, UeContext{id: k.Id, v: 1})
	}

	return ues, nil
}

func increaseUE(idx int) error {
	fmt.Println(">>> increaseUE")

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

	_, err := cl.SandboxUEControllerApi.SandboxUeControllerPATCH(context.TODO(), sandboxName, ues[idx].id, int32((ues[idx].v+1)%4))
	if err != nil {
		return err
	}
	ues[idx].v = (ues[idx].v + 1) % 4

	return nil
}

func decreaseUE(idx int) error {
	fmt.Println(">>> decreaseUE")

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

	_, err := cl.SandboxUEControllerApi.SandboxUeControllerPATCH(context.TODO(), sandboxName, ues[idx].id, int32((ues[idx].v-1)%4))
	if err != nil {
		return err
	}
	ues[idx].v = (ues[idx].v - 1) % 4

	return nil
}

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

@@ -761,8 +779,6 @@ func main() {

	// Start REST API Server
	go func() {
		fmt.Println(">>> Start REST API Server")

		router := NewRouter()
		methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"})
		header := handlers.AllowedHeaders([]string{"content-type"})
@@ -894,6 +910,34 @@ func process_choice(choice []string) string {
		}
		message = fmt.Sprintf("appsInfo:  %s deleted", fmt.Sprint(appsInfo.Id))
		appsInfo.Id = ""
	} else if strings.Compare(choice[0], LIST_UES) == 0 {
		ues = make([]UeContext, 0)
		var err error
		ues, err = getListOfUes()
		if err != nil {
			return fmt.Sprintf("Failed to get the list of UEs: %s", err.Error())
		}
		message = fmt.Sprintf("List of UEs %v", ues)
	} else if strings.Compare(choice[0], INC_UE) == 0 {
		ueId, err := verify_idx_len(choice[1], len(ues))
		if err != nil {
			return fmt.Sprintf("Invalid index: %s", err.Error())
		}
		err = increaseUE(ueId)
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("Increase %s, new value: %d", ues[ueId].id, ues[ueId].v)
	} else if strings.Compare(choice[0], DEC_UE) == 0 {
		ueId, err := verify_idx_len(choice[1], len(ues))
		if err != nil {
			return fmt.Sprintf("Invalid index: %s", err.Error())
		}
		err = decreaseUE(ueId)
		if err != nil {
			return err.Error()
		}
		message = fmt.Sprintf("Decrease %s, new value: %d", ues[ueId].id, ues[ueId].v)
	} else if strings.Compare(choice[0], MEC011_CONFIRM_READY) == 0 {
		var err error
		body, _, err := mec011_send_confirm_ready()
Loading