Loading go-apps/meep-vis/main_test.go +0 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ package main import ( Loading go-apps/meep-vis/server/api_v2xi.go +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ func IndividualSubscriptionPUT(w http.ResponseWriter, r *http.Request) { } func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) provInfoUuUnicastGET(w, r) } func SubGET(w http.ResponseWriter, r *http.Request) { Loading go-apps/meep-vis/server/vis.go +99 −0 Original line number Diff line number Diff line Loading @@ -1417,3 +1417,102 @@ func individualSubscriptionDelete(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } func provInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { log.Info("infoUuUnicastGET") w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Retrieve query parameters u, _ := url.Parse(r.URL.String()) log.Info("url: ", u.RequestURI()) q := u.Query() log.Info("infoUuUnicastGET: q= ", q) validQueryParams := []string{"location_info"} if !validateQueryParams(q, validQueryParams) { w.WriteHeader(http.StatusBadRequest) return } // Get & validate query param values location_info := q.Get("location_info") log.Info("infoUuUnicastGET: location_info= ", location_info) // Extract parameters params := strings.Split(location_info, ",") log.Info("infoUuUnicastGET: args= ", params) if !validateQueryParamValue(params[0], []string{"ecgi", "latitude"}) { w.WriteHeader(http.StatusBadRequest) return } // Extract list of items i := 1 for i < len(params) { if validateQueryParamValue(params[i], []string{"longitude"}) { break } i += 1 } // End of 'for' statement i -= 1 log.Info("infoUuUnicastGET: i= ", i) if i <= 1 || ((params[0] == "latitude") && (i != (len(params)-2)/2)) { w.WriteHeader(http.StatusBadRequest) return } // Process the request log.Info("infoUuUnicastGET: Process the request") // FIXME Add logic ecgi := Ecgi{ CellId: &CellId{CellId: "cellid"}, Plmn: &Plmn{Mcc: "mcc", Mnc: "mnc"}, } plmn := Plmn{Mcc: "mcc", Mnc: "mnc"} uuUniNeighbourCellInfo := make([]UuUniNeighbourCellInfo, 1) uuUniNeighbourCellInfo[0] = UuUniNeighbourCellInfo{&ecgi, nil, 0, &plmn, nil} proInfoUuUnicast := make([]UuUnicastProvisioningInfoProInfoUuUnicast, 1) proInfoUuUnicast[0] = UuUnicastProvisioningInfoProInfoUuUnicast{nil, uuUniNeighbourCellInfo, nil} uuUnicastProvisioningInfo := UuUnicastProvisioningInfo{ ProInfoUuUnicast: proInfoUuUnicast, TimeStamp: &TimeStamp{ Seconds: int32(time.Now().Unix()), }, } // Send response jsonResponse, err := json.Marshal(uuUnicastProvisioningInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } log.Info("infoUuUnicastGET: Response: ", string(jsonResponse)) w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } func validateQueryParams(params url.Values, validParamList []string) bool { for param := range params { found := false for _, validParam := range validParamList { if param == validParam { found = true break } } if !found { log.Error("Invalid query param: ", param) return false } } return true } func validateQueryParamValue(val string, validValues []string) bool { for _, validVal := range validValues { if val == validVal { return true } } //log.Error("Invalid query param value: ", val) return false } go-apps/meep-vis/server/vis_test.go +124 −17 Original line number Diff line number Diff line Loading @@ -525,21 +525,6 @@ func TestNotImplemented(t *testing.T) { t.Fatalf("Failed to get expected response") } _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info", nil, nil, nil, http.StatusNotImplemented, ProvInfoUuUnicastGET) if err != nil { t.Fatalf("Failed to get expected response") } // _, err = sendRequest(http.MethodGet, "/subscriptions", nil, nil, nil, http.StatusNotImplemented, SubGET) // if err != nil { // t.Fatalf("Failed to get expected response") // } // _, err = sendRequest(http.MethodPost, "/publish_v2x_message", nil, nil, nil, http.StatusNotImplemented, V2xMessagePOST) // if err != nil { // t.Fatalf("Failed to get expected response") // } } func TestPredictedQosPost(t *testing.T) { Loading Loading @@ -644,7 +629,128 @@ func TestPredictedQosPost(t *testing.T) { terminateScenario() } func TestSubscriptionPost(t *testing.T) string { func TestProvInfoUuUnicastGET(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) initializeVars() err := Init() if err != nil { t.Fatalf("Error initializing test basic procedure") } err = Run() if err != nil { t.Fatalf("Error running test basic procedure") } fmt.Println("Set a scenario") initialiseScenario(testScenario) time.Sleep(1000 * time.Millisecond) updateScenario("mobility1") /****************************** * expected response section ******************************/ // Initialize the data structure for the GET request // MEC-030 Clause 6.2.2 // MEC-030 Clause 7.3.3 /****************************** * expected request section ******************************/ ecgi := Ecgi{ CellId: &CellId{CellId: "cellid"}, Plmn: &Plmn{Mcc: "mcc", Mnc: "mnc"}, } plmn := Plmn{Mcc: "mcc", Mnc: "mnc"} uuUniNeighbourCellInfo := make([]UuUniNeighbourCellInfo, 1) uuUniNeighbourCellInfo[0] = UuUniNeighbourCellInfo{&ecgi, nil, 0, &plmn, nil} proInfoUuUnicast := make([]UuUnicastProvisioningInfoProInfoUuUnicast, 1) proInfoUuUnicast[0] = UuUnicastProvisioningInfoProInfoUuUnicast{nil, uuUniNeighbourCellInfo, nil} uuUnicastProvisioningInfo := UuUnicastProvisioningInfo{ ProInfoUuUnicast: proInfoUuUnicast, TimeStamp: &TimeStamp{ Seconds: int32(time.Now().Unix()), }, } expected_json_response, err := json.Marshal(uuUnicastProvisioningInfo) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_json_response: ", string(expected_json_response)) /****************************** * request execution section ******************************/ rr, err := sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=ecgi,1357924680,1357924681", nil, nil, nil, http.StatusOK, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("Respone: rr: ", rr) var resp UuUnicastProvisioningInfo err = json.Unmarshal([]byte(rr), &resp) if err != nil { t.Fatalf("Failed to get expected response") } log.Info("Respone: resp: ", resp) if !validateUuUnicastProvisioningInfo(resp, uuUnicastProvisioningInfo) { t.Errorf("handler returned unexpected body: got %v want %v", rr, expected_json_response) } _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=ecgi", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") rr, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000,longitude,000.000,001.000", nil, nil, nil, http.StatusOK, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("Respone: rr: ", rr) err = json.Unmarshal([]byte(rr), &resp) if err != nil { t.Fatalf("Failed to get expected response") } log.Info("Respone: resp: ", resp) // TODO Validate with expected response _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000,longitude,000.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=longitude,000.000,001.000,latitude,000.000,001.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") } func validateUuUnicastProvisioningInfo(received UuUnicastProvisioningInfo, expected UuUnicastProvisioningInfo) bool { if len(received.ProInfoUuUnicast) != len(expected.ProInfoUuUnicast) { fmt.Println("len(received.ProInfoUuUnicast) mismatch") return false } // TODO return true } func testSubscriptionPost(t *testing.T) string { /****************************** * expected response section Loading Loading @@ -732,7 +838,7 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { updateScenario("mobility1") // POST expectedGetResponse := TestSubscriptionPost(t) expectedGetResponse := testSubscriptionPost(t) //GET Subscription //expectedListResourceURL := "/" + testScenarioName + "vis/v2/subscriptions" Loading Loading @@ -939,6 +1045,7 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { return string(expected_v2xMsgSubscriptionPut_str) } func TestV2xMsgPublicationPost(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading Loading
go-apps/meep-vis/main_test.go +0 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ package main import ( Loading
go-apps/meep-vis/server/api_v2xi.go +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ func IndividualSubscriptionPUT(w http.ResponseWriter, r *http.Request) { } func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) provInfoUuUnicastGET(w, r) } func SubGET(w http.ResponseWriter, r *http.Request) { Loading
go-apps/meep-vis/server/vis.go +99 −0 Original line number Diff line number Diff line Loading @@ -1417,3 +1417,102 @@ func individualSubscriptionDelete(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } func provInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { log.Info("infoUuUnicastGET") w.Header().Set("Content-Type", "application/json; charset=UTF-8") // Retrieve query parameters u, _ := url.Parse(r.URL.String()) log.Info("url: ", u.RequestURI()) q := u.Query() log.Info("infoUuUnicastGET: q= ", q) validQueryParams := []string{"location_info"} if !validateQueryParams(q, validQueryParams) { w.WriteHeader(http.StatusBadRequest) return } // Get & validate query param values location_info := q.Get("location_info") log.Info("infoUuUnicastGET: location_info= ", location_info) // Extract parameters params := strings.Split(location_info, ",") log.Info("infoUuUnicastGET: args= ", params) if !validateQueryParamValue(params[0], []string{"ecgi", "latitude"}) { w.WriteHeader(http.StatusBadRequest) return } // Extract list of items i := 1 for i < len(params) { if validateQueryParamValue(params[i], []string{"longitude"}) { break } i += 1 } // End of 'for' statement i -= 1 log.Info("infoUuUnicastGET: i= ", i) if i <= 1 || ((params[0] == "latitude") && (i != (len(params)-2)/2)) { w.WriteHeader(http.StatusBadRequest) return } // Process the request log.Info("infoUuUnicastGET: Process the request") // FIXME Add logic ecgi := Ecgi{ CellId: &CellId{CellId: "cellid"}, Plmn: &Plmn{Mcc: "mcc", Mnc: "mnc"}, } plmn := Plmn{Mcc: "mcc", Mnc: "mnc"} uuUniNeighbourCellInfo := make([]UuUniNeighbourCellInfo, 1) uuUniNeighbourCellInfo[0] = UuUniNeighbourCellInfo{&ecgi, nil, 0, &plmn, nil} proInfoUuUnicast := make([]UuUnicastProvisioningInfoProInfoUuUnicast, 1) proInfoUuUnicast[0] = UuUnicastProvisioningInfoProInfoUuUnicast{nil, uuUniNeighbourCellInfo, nil} uuUnicastProvisioningInfo := UuUnicastProvisioningInfo{ ProInfoUuUnicast: proInfoUuUnicast, TimeStamp: &TimeStamp{ Seconds: int32(time.Now().Unix()), }, } // Send response jsonResponse, err := json.Marshal(uuUnicastProvisioningInfo) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } log.Info("infoUuUnicastGET: Response: ", string(jsonResponse)) w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } func validateQueryParams(params url.Values, validParamList []string) bool { for param := range params { found := false for _, validParam := range validParamList { if param == validParam { found = true break } } if !found { log.Error("Invalid query param: ", param) return false } } return true } func validateQueryParamValue(val string, validValues []string) bool { for _, validVal := range validValues { if val == validVal { return true } } //log.Error("Invalid query param value: ", val) return false }
go-apps/meep-vis/server/vis_test.go +124 −17 Original line number Diff line number Diff line Loading @@ -525,21 +525,6 @@ func TestNotImplemented(t *testing.T) { t.Fatalf("Failed to get expected response") } _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info", nil, nil, nil, http.StatusNotImplemented, ProvInfoUuUnicastGET) if err != nil { t.Fatalf("Failed to get expected response") } // _, err = sendRequest(http.MethodGet, "/subscriptions", nil, nil, nil, http.StatusNotImplemented, SubGET) // if err != nil { // t.Fatalf("Failed to get expected response") // } // _, err = sendRequest(http.MethodPost, "/publish_v2x_message", nil, nil, nil, http.StatusNotImplemented, V2xMessagePOST) // if err != nil { // t.Fatalf("Failed to get expected response") // } } func TestPredictedQosPost(t *testing.T) { Loading Loading @@ -644,7 +629,128 @@ func TestPredictedQosPost(t *testing.T) { terminateScenario() } func TestSubscriptionPost(t *testing.T) string { func TestProvInfoUuUnicastGET(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) initializeVars() err := Init() if err != nil { t.Fatalf("Error initializing test basic procedure") } err = Run() if err != nil { t.Fatalf("Error running test basic procedure") } fmt.Println("Set a scenario") initialiseScenario(testScenario) time.Sleep(1000 * time.Millisecond) updateScenario("mobility1") /****************************** * expected response section ******************************/ // Initialize the data structure for the GET request // MEC-030 Clause 6.2.2 // MEC-030 Clause 7.3.3 /****************************** * expected request section ******************************/ ecgi := Ecgi{ CellId: &CellId{CellId: "cellid"}, Plmn: &Plmn{Mcc: "mcc", Mnc: "mnc"}, } plmn := Plmn{Mcc: "mcc", Mnc: "mnc"} uuUniNeighbourCellInfo := make([]UuUniNeighbourCellInfo, 1) uuUniNeighbourCellInfo[0] = UuUniNeighbourCellInfo{&ecgi, nil, 0, &plmn, nil} proInfoUuUnicast := make([]UuUnicastProvisioningInfoProInfoUuUnicast, 1) proInfoUuUnicast[0] = UuUnicastProvisioningInfoProInfoUuUnicast{nil, uuUniNeighbourCellInfo, nil} uuUnicastProvisioningInfo := UuUnicastProvisioningInfo{ ProInfoUuUnicast: proInfoUuUnicast, TimeStamp: &TimeStamp{ Seconds: int32(time.Now().Unix()), }, } expected_json_response, err := json.Marshal(uuUnicastProvisioningInfo) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_json_response: ", string(expected_json_response)) /****************************** * request execution section ******************************/ rr, err := sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=ecgi,1357924680,1357924681", nil, nil, nil, http.StatusOK, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("Respone: rr: ", rr) var resp UuUnicastProvisioningInfo err = json.Unmarshal([]byte(rr), &resp) if err != nil { t.Fatalf("Failed to get expected response") } log.Info("Respone: resp: ", resp) if !validateUuUnicastProvisioningInfo(resp, uuUnicastProvisioningInfo) { t.Errorf("handler returned unexpected body: got %v want %v", rr, expected_json_response) } _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=ecgi", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") rr, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000,longitude,000.000,001.000", nil, nil, nil, http.StatusOK, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("Respone: rr: ", rr) err = json.Unmarshal([]byte(rr), &resp) if err != nil { t.Fatalf("Failed to get expected response") } log.Info("Respone: resp: ", resp) // TODO Validate with expected response _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000,longitude,000.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=latitude,000.000,001.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") _, err = sendRequest(http.MethodGet, "/queries/uu_unicast_provisioning_info?location_info=longitude,000.000,001.000,latitude,000.000,001.000", nil, nil, nil, http.StatusBadRequest, ProvInfoUuUnicastGET) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") } func validateUuUnicastProvisioningInfo(received UuUnicastProvisioningInfo, expected UuUnicastProvisioningInfo) bool { if len(received.ProInfoUuUnicast) != len(expected.ProInfoUuUnicast) { fmt.Println("len(received.ProInfoUuUnicast) mismatch") return false } // TODO return true } func testSubscriptionPost(t *testing.T) string { /****************************** * expected response section Loading Loading @@ -732,7 +838,7 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { updateScenario("mobility1") // POST expectedGetResponse := TestSubscriptionPost(t) expectedGetResponse := testSubscriptionPost(t) //GET Subscription //expectedListResourceURL := "/" + testScenarioName + "vis/v2/subscriptions" Loading Loading @@ -939,6 +1045,7 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { return string(expected_v2xMsgSubscriptionPut_str) } func TestV2xMsgPublicationPost(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading