Loading go-apps/meep-vis/server/api_v2xi.go +2 −2 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ func IndividualSubscriptionGET(w http.ResponseWriter, r *http.Request) { } func IndividualSubscriptionPUT(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) individualSubscriptionPut(w, r) } func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { Loading @@ -56,7 +56,7 @@ func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { } func SubGET(w http.ResponseWriter, r *http.Request) { subGET(w, r) subscriptionsGET(w, r) } func V2xMessagePOST(w http.ResponseWriter, r *http.Request) { Loading go-apps/meep-vis/server/subscriptionCommon.go +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ package server type SubscriptionCommon struct { Links *Links `json:"_links,omitempty"` // URI selected by the service consumer, to receive notifications on the subscribed RNIS information. This shall be included in the request and response. SubscriptionType string `json:"subscriptionType"` CallbackReference string `json:"callbackReference,omitempty"` Loading go-apps/meep-vis/server/vis.go +121 −1 Original line number Diff line number Diff line Loading @@ -220,6 +220,35 @@ func sendTerminationConfirmation(appInstanceId string) error { return nil } func isSubscriptionIdRegisteredV2x(subsIdStr string) bool { var returnVal bool subsId, _ := strconv.Atoi(subsIdStr) mutex.Lock() defer mutex.Unlock() if v2xMsgSubscriptionMap[subsId] != nil { returnVal = true } else { returnVal = false } return returnVal } func registerV2x(v2xMsgSubscription *V2xMsgSubscription, subsIdStr string) { subsId, _ := strconv.Atoi(subsIdStr) mutex.Lock() defer mutex.Unlock() v2xMsgSubscriptionMap[subsId] = v2xMsgSubscription if v2xMsgSubscription.ExpiryDeadline != nil { //get current list of subscription meant to expire at this time intList := subscriptionExpiryMap[int(v2xMsgSubscription.ExpiryDeadline.Seconds)] intList = append(intList, subsId) subscriptionExpiryMap[int(v2xMsgSubscription.ExpiryDeadline.Seconds)] = intList } log.Info("New registration: ", subsId, " type: ", v2xSubscriptionType) } func subscribeAppTermination(appInstanceId string) error { var sub asc.AppTerminationNotificationSubscription sub.SubscriptionType = "AppTerminationNotificationSubscription" Loading Loading @@ -1029,7 +1058,7 @@ func createSubscriptionLinkList(subType string) *SubscriptionLinkList { return subscriptionLinkList } func subGET(w http.ResponseWriter, r *http.Request) { func subscriptionsGET(w http.ResponseWriter, r *http.Request) { log.Info("subGet") w.Header().Set("Content-Type", "application/json; charset=UTF-8") Loading Loading @@ -1244,3 +1273,94 @@ func repopulateV2xMsgSubscriptionMap(key string, jsonInfo string, userData inter return nil } func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) { log.Info("individualSubPut") w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) subIdParamStr := vars["subscriptionId"] var subscriptionCommon SubscriptionCommon bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscriptionCommon.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") errHandlerProblemDetails(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") errHandlerProblemDetails(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case V2X_MSG: var subscription V2xMsgSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") errHandlerProblemDetails(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) return } if subscription.FilterCriteria.StdOrganization != "ETSI" { log.Error("StdOrganizaztion should not be other than ETSI for this subscription type") errHandlerProblemDetails(w, "StdOrganizaztion should not be other than ETSI for this subscription type", http.StatusBadRequest) return } //registration if isSubscriptionIdRegisteredV2x(subsIdStr) { registerV2x(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertV2xMsgSubscriptionToJson(&subscription)) alreadyRegistered = true jsonResponse, err = json.Marshal(subscription) } default: w.WriteHeader(http.StatusBadRequest) return } if alreadyRegistered { if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } else { w.WriteHeader(http.StatusNotFound) } } Loading
go-apps/meep-vis/server/api_v2xi.go +2 −2 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ func IndividualSubscriptionGET(w http.ResponseWriter, r *http.Request) { } func IndividualSubscriptionPUT(w http.ResponseWriter, r *http.Request) { notImplemented(w, r) individualSubscriptionPut(w, r) } func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { Loading @@ -56,7 +56,7 @@ func ProvInfoUuUnicastGET(w http.ResponseWriter, r *http.Request) { } func SubGET(w http.ResponseWriter, r *http.Request) { subGET(w, r) subscriptionsGET(w, r) } func V2xMessagePOST(w http.ResponseWriter, r *http.Request) { Loading
go-apps/meep-vis/server/subscriptionCommon.go +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ package server type SubscriptionCommon struct { Links *Links `json:"_links,omitempty"` // URI selected by the service consumer, to receive notifications on the subscribed RNIS information. This shall be included in the request and response. SubscriptionType string `json:"subscriptionType"` CallbackReference string `json:"callbackReference,omitempty"` Loading
go-apps/meep-vis/server/vis.go +121 −1 Original line number Diff line number Diff line Loading @@ -220,6 +220,35 @@ func sendTerminationConfirmation(appInstanceId string) error { return nil } func isSubscriptionIdRegisteredV2x(subsIdStr string) bool { var returnVal bool subsId, _ := strconv.Atoi(subsIdStr) mutex.Lock() defer mutex.Unlock() if v2xMsgSubscriptionMap[subsId] != nil { returnVal = true } else { returnVal = false } return returnVal } func registerV2x(v2xMsgSubscription *V2xMsgSubscription, subsIdStr string) { subsId, _ := strconv.Atoi(subsIdStr) mutex.Lock() defer mutex.Unlock() v2xMsgSubscriptionMap[subsId] = v2xMsgSubscription if v2xMsgSubscription.ExpiryDeadline != nil { //get current list of subscription meant to expire at this time intList := subscriptionExpiryMap[int(v2xMsgSubscription.ExpiryDeadline.Seconds)] intList = append(intList, subsId) subscriptionExpiryMap[int(v2xMsgSubscription.ExpiryDeadline.Seconds)] = intList } log.Info("New registration: ", subsId, " type: ", v2xSubscriptionType) } func subscribeAppTermination(appInstanceId string) error { var sub asc.AppTerminationNotificationSubscription sub.SubscriptionType = "AppTerminationNotificationSubscription" Loading Loading @@ -1029,7 +1058,7 @@ func createSubscriptionLinkList(subType string) *SubscriptionLinkList { return subscriptionLinkList } func subGET(w http.ResponseWriter, r *http.Request) { func subscriptionsGET(w http.ResponseWriter, r *http.Request) { log.Info("subGet") w.Header().Set("Content-Type", "application/json; charset=UTF-8") Loading Loading @@ -1244,3 +1273,94 @@ func repopulateV2xMsgSubscriptionMap(key string, jsonInfo string, userData inter return nil } func individualSubscriptionPut(w http.ResponseWriter, r *http.Request) { log.Info("individualSubPut") w.Header().Set("Content-Type", "application/json; charset=UTF-8") vars := mux.Vars(r) subIdParamStr := vars["subscriptionId"] var subscriptionCommon SubscriptionCommon bodyBytes, _ := ioutil.ReadAll(r.Body) err := json.Unmarshal(bodyBytes, &subscriptionCommon) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } //extract common body part subscriptionType := subscriptionCommon.SubscriptionType //mandatory parameter if subscriptionCommon.CallbackReference == "" { log.Error("Mandatory CallbackReference parameter not present") errHandlerProblemDetails(w, "Mandatory CallbackReference parameter not present", http.StatusBadRequest) return } link := subscriptionCommon.Links if link == nil || link.Self == nil { log.Error("Mandatory Link parameter not present") errHandlerProblemDetails(w, "Mandatory Link parameter not present", http.StatusBadRequest) return } selfUrl := strings.Split(link.Self.Href, "/") subsIdStr := selfUrl[len(selfUrl)-1] if subsIdStr != subIdParamStr { log.Error("SubscriptionId in endpoint and in body not matching") errHandlerProblemDetails(w, "SubscriptionId in endpoint and in body not matching", http.StatusBadRequest) return } alreadyRegistered := false var jsonResponse []byte switch subscriptionType { case V2X_MSG: var subscription V2xMsgSubscription err = json.Unmarshal(bodyBytes, &subscription) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } if subscription.FilterCriteria == nil { log.Error("FilterCriteria should not be null for this subscription type") errHandlerProblemDetails(w, "FilterCriteria should not be null for this subscription type", http.StatusBadRequest) return } if subscription.FilterCriteria.StdOrganization != "ETSI" { log.Error("StdOrganizaztion should not be other than ETSI for this subscription type") errHandlerProblemDetails(w, "StdOrganizaztion should not be other than ETSI for this subscription type", http.StatusBadRequest) return } //registration if isSubscriptionIdRegisteredV2x(subsIdStr) { registerV2x(&subscription, subsIdStr) _ = rc.JSONSetEntry(baseKey+"subscriptions:"+subsIdStr, ".", convertV2xMsgSubscriptionToJson(&subscription)) alreadyRegistered = true jsonResponse, err = json.Marshal(subscription) } default: w.WriteHeader(http.StatusBadRequest) return } if alreadyRegistered { if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) fmt.Fprint(w, string(jsonResponse)) } else { w.WriteHeader(http.StatusNotFound) } }