diff --git a/charts/meep-dai/templates/service.yaml b/charts/meep-dai/templates/service.yaml index d4a7e020e976959b06de61e43bb2b0cb695e4d49..6548b7d6b8700ed8cc25c874e897047eb54eaee0 100644 --- a/charts/meep-dai/templates/service.yaml +++ b/charts/meep-dai/templates/service.yaml @@ -24,7 +24,7 @@ spec: port: 31120 targetPort: 31120 - name: onboarded-demo1 - port: 31121 + port: 31122 targetPort: 31122 - name: onboarded-demo2 port: 31123 diff --git a/docs/meep-sss/SensorDataSubscriptionApi.md b/docs/meep-sss/SensorDataSubscriptionApi.md index 2f3fca78f1d996be2ce856783eb87ca2227c6f13..ce4d3bc14e56a307959bd9469cfc8e6cd5f7ad74 100644 --- a/docs/meep-sss/SensorDataSubscriptionApi.md +++ b/docs/meep-sss/SensorDataSubscriptionApi.md @@ -133,7 +133,7 @@ This method shall support the URI query parameters, request and response data st Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. - **body** | [**StatusDataSubscriptionIdBody**](StatusDataSubscriptionIdBody.md)| New SensorDataSubscription is included as entity body of the request | + **body** | [**SensorDataSubscriptionIdBody**](SensorDataSubscriptionIdBody.md)| New SensorDataSubscription is included as entity body of the request | **subscriptionId** | **string**| Unique identifiers of a subscription | ### Return type diff --git a/docs/meep-sss/StatusDataSubscriptionIdBody.md b/docs/meep-sss/StatusDataSubscriptionIdBody.md index 70a2b2e720cbd4db57155dfac153e1731ec911dc..ed1b52db2368fc0315aa62fac5da6d680ebb7556 100644 --- a/docs/meep-sss/StatusDataSubscriptionIdBody.md +++ b/docs/meep-sss/StatusDataSubscriptionIdBody.md @@ -1,4 +1,4 @@ -# StatusDataSubscriptionIdBody +# SensorDataSubscriptionIdBody ## Properties Name | Type | Description | Notes diff --git a/go-apps/meep-iot/sbi/iot-sbi.go b/go-apps/meep-iot/sbi/iot-sbi.go index 253f899a014901c9bd1e0491163325cf1731594f..57ae4f92494c9a7c55c8456e7b1b67df55ea7026 100644 --- a/go-apps/meep-iot/sbi/iot-sbi.go +++ b/go-apps/meep-iot/sbi/iot-sbi.go @@ -154,6 +154,7 @@ type TrafficFilter struct { SrcTunnelPort []string DstTunnelPort []string QCI int32 + DSCP int32 TC int32 } @@ -545,7 +546,52 @@ func convertDeviceInfoFromIotMgr(dev tm.DeviceInfo) (device DeviceInfo) { device.DeviceMetadata[i] = KeyValuePair{Key: k.Key, Value: k.Value} } // End of 'for' statement } + if len(dev.RequestedMecTrafficRule) != 0 { + device.RequestedMecTrafficRule = make([]TrafficRuleDescriptor, len(dev.RequestedMecTrafficRule)) + for i, v := range dev.RequestedMecTrafficRule { + device.RequestedMecTrafficRule[i] = TrafficRuleDescriptor{ + TrafficRuleId: v.TrafficRuleId, + FilterType: v.FilterType, + Priority: v.Priority, + Action: v.Action, + } + if len(dev.RequestedMecTrafficRule[i].TrafficFilter) != 0 { + device.RequestedMecTrafficRule[i].TrafficFilter = make([]TrafficFilter, len(dev.RequestedMecTrafficRule[i].TrafficFilter)) + for j, u := range dev.RequestedMecTrafficRule[i].TrafficFilter { + device.RequestedMecTrafficRule[i].TrafficFilter[j] = TrafficFilter{ + SrcAddress: u.SrcAddress, + DstAddress: u.DstAddress, + SrcPort: u.SrcPort, + DstPort: u.DstPort, + Protocol: u.Protocol, + Tag: u.Tag, + Uri: u.Uri, + PacketLabel: u.PacketLabel, + SrcTunnelAddress: u.SrcTunnelAddress, + TgtTunnelAddress: u.TgtTunnelAddress, + SrcTunnelPort: u.SrcTunnelPort, + DstTunnelPort: u.DstTunnelPort, + QCI: u.QCI, + DSCP: u.DSCP, + TC: u.TC, + } + } // End of 'for' statement + } + if v.DstInterface != nil { + device.RequestedMecTrafficRule[i].DstInterface = &InterfaceDescriptor{ + InterfaceType: device.RequestedMecTrafficRule[i].DstInterface.InterfaceType, + // FIXME FSCOM To be filled: TunnelInfo: nil, + SrcMACAddress: device.RequestedMecTrafficRule[i].DstInterface.SrcMACAddress, + DstMACAddress: device.RequestedMecTrafficRule[i].DstInterface.DstMACAddress, + DstIPAddress: device.RequestedMecTrafficRule[i].DstInterface.DstIPAddress, + } + } + } // End of 'for' statement + } // FIXME FSCOM Add missing fileds (pointers & arrays) + //DeviceSpecificMessageFormats *DeviceSpecificMessageFormats `json:"deviceSpecificMessageFormats,omitempty"` + //DownlinkInfo *DownlinkInfo `json:"downlinkInfo,omitempty"` + //log.Debug("convertDeviceInfoFromIotMgr: device: ", device) return device @@ -587,7 +633,52 @@ func convertDeviceInfoToIotMgr(dev DeviceInfo) (device tm.DeviceInfo) { device.DeviceMetadata[i] = tm.KeyValuePair{Key: k.Key, Value: k.Value} } // End of 'for' statement } + if len(dev.RequestedMecTrafficRule) != 0 { + device.RequestedMecTrafficRule = make([]tm.TrafficRuleDescriptor, len(dev.RequestedMecTrafficRule)) + for i, v := range dev.RequestedMecTrafficRule { + device.RequestedMecTrafficRule[i] = tm.TrafficRuleDescriptor{ + TrafficRuleId: v.TrafficRuleId, + FilterType: v.FilterType, + Priority: v.Priority, + Action: v.Action, + } + if len(dev.RequestedMecTrafficRule[i].TrafficFilter) != 0 { + device.RequestedMecTrafficRule[i].TrafficFilter = make([]tm.TrafficFilter, len(dev.RequestedMecTrafficRule[i].TrafficFilter)) + for j, u := range dev.RequestedMecTrafficRule[i].TrafficFilter { + device.RequestedMecTrafficRule[i].TrafficFilter[j] = tm.TrafficFilter{ + SrcAddress: u.SrcAddress, + DstAddress: u.DstAddress, + SrcPort: u.SrcPort, + DstPort: u.DstPort, + Protocol: u.Protocol, + Tag: u.Tag, + Uri: u.Uri, + PacketLabel: u.PacketLabel, + SrcTunnelAddress: u.SrcTunnelAddress, + TgtTunnelAddress: u.TgtTunnelAddress, + SrcTunnelPort: u.SrcTunnelPort, + DstTunnelPort: u.DstTunnelPort, + QCI: u.QCI, + DSCP: u.DSCP, + TC: u.TC, + } + } // End of 'for' statement + } + if v.DstInterface != nil { + device.RequestedMecTrafficRule[i].DstInterface = &tm.InterfaceDescriptor{ + InterfaceType: device.RequestedMecTrafficRule[i].DstInterface.InterfaceType, + // FIXME FSCOM To be filled: TunnelInfo: nil, + SrcMACAddress: device.RequestedMecTrafficRule[i].DstInterface.SrcMACAddress, + DstMACAddress: device.RequestedMecTrafficRule[i].DstInterface.DstMACAddress, + DstIPAddress: device.RequestedMecTrafficRule[i].DstInterface.DstIPAddress, + } + } + } // End of 'for' statement + } // FIXME FSCOM Add missing fileds (pointers & arrays) + //DeviceSpecificMessageFormats *DeviceSpecificMessageFormats `json:"deviceSpecificMessageFormats,omitempty"` + //DownlinkInfo *DownlinkInfo `json:"downlinkInfo,omitempty"` + //log.Debug("convertDeviceInfoToIotMgr: device: ", device) return device diff --git a/go-apps/meep-iot/server/meep-iot.go b/go-apps/meep-iot/server/meep-iot.go index aee94cfe55def0901b910fed01ab262d8de7ddac..ee77a0d3d8f41dfc5f540a0df93806061825cb67 100644 --- a/go-apps/meep-iot/server/meep-iot.go +++ b/go-apps/meep-iot/server/meep-iot.go @@ -711,6 +711,7 @@ func registerediotplatformsPOST(w http.ResponseWriter, r *http.Request) { log.Debug(">>> registerediotplatformsPOST: ", r) w.Header().Set("Content-Type", "application/json; charset=UTF-8") + var requestData IotPlatformInfo decoder := json.NewDecoder(r.Body) err := decoder.Decode(&requestData) @@ -744,7 +745,12 @@ func registerediotplatformsPOST(w http.ResponseWriter, r *http.Request) { errHandlerProblemDetails(w, "Mandatory attribute Name shall be absent in the request body.", http.StatusBadRequest) return } - if v.Type_ == nil || *v.Type_ != "MB_TOPIC_BASED" { + if v.Type_ == nil { + log.Error("Mandatory Type_ parameter shall be present") + errHandlerProblemDetails(w, "Mandatory attribute Type_ shall be present.", http.StatusBadRequest) + return + } + if *v.Type_ != "MB_TOPIC_BASED" { log.Error("Mandatory Type_ parameter shall be set to MB_TOPIC_BASED") errHandlerProblemDetails(w, "Mandatory attribute Type_ shall be set to MB_TOPIC_BASED in the request body.", http.StatusBadRequest) return @@ -777,14 +783,8 @@ func registerediotplatformsPOST(w http.ResponseWriter, r *http.Request) { } } - if requestData.CustomServicesTransportInfo == nil || len(requestData.CustomServicesTransportInfo) == 0 { - log.Error("No information to register IoT platform") - errHandlerProblemDetails(w, "No information to register IoT platform.", http.StatusInternalServerError) - return - } - - _, ok := registeredIotPlatformsMap[requestData.IotPlatformId] - if ok { + log.Debug("registerediotplatformsPOST: registeredIotPlatformsMap (before): ", registeredIotPlatformsMap) + if _, ok := registeredIotPlatformsMap[requestData.IotPlatformId]; ok { log.Error("IoT platform already created") errHandlerProblemDetails(w, "IoT platform already created.", http.StatusBadRequest) return @@ -799,9 +799,10 @@ func registerediotplatformsPOST(w http.ResponseWriter, r *http.Request) { return } registeredIotPlatformsMap[responseData.IotPlatformId] = responseData - log.Debug("registerediotplatformsPOST: new registeredIotPlatformsMap: ", registeredIotPlatformsMap) + log.Debug("registerediotplatformsPOST: registeredIotPlatformsMap (after): ", registeredIotPlatformsMap) // Prepare & send response + w.Header().Set("Location", hostUrl.String()+basePath+"registered_iot_platforms/"+responseData.IotPlatformId) c := convertIotPlatformInfoFromSbi(responseData) jsonResponse := convertIoTPlatformInfotoJson(&c) w.WriteHeader(http.StatusCreated) @@ -861,6 +862,8 @@ func registereddevicesByIdGET(w http.ResponseWriter, r *http.Request) { func registereddevicesByIdPUT(w http.ResponseWriter, r *http.Request) { log.Debug(">>> registereddevicesByIdPUT: ", r) + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + errHandlerProblemDetails(w, "Not implemented yet", http.StatusBadRequest) } @@ -921,6 +924,7 @@ func registereddevicesGET(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, string(jsonResponse)) w.WriteHeader(http.StatusOK) } + func applyFiltering(devicesList []sbi.DeviceInfo, filter []string) (devices []DeviceInfo, err error) { log.Debug(">>> applyFiltering") devices, err = convertDeviceInfosFromSbi_with_filter(devicesList, filter) @@ -931,6 +935,8 @@ func applyFiltering(devicesList []sbi.DeviceInfo, filter []string) (devices []De func registereddevicesPOST(w http.ResponseWriter, r *http.Request) { log.Debug(">>> registereddevicesPOST: ", r) + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + // Read JSON input stream provided in the Request, and stores it in the bodyBytes as bytes var deviceInfo DeviceInfo bodyBytes, _ := ioutil.ReadAll(r.Body) @@ -966,16 +972,18 @@ func registereddevicesPOST(w http.ResponseWriter, r *http.Request) { errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } - log.Info("registereddevicesPOST: deviceInfoResp: ", deviceInfoResp) + devInfoResp := convertDeviceInfoFromSbi(deviceInfoResp) + log.Info("registereddevicesPOST: devInfoResp: ", devInfoResp) - jsonResponse, err := json.Marshal(deviceInfoResp) + // Prepare & send the reponse + w.Header().Set("Location", hostUrl.String()+basePath+"registered_devices/"+devInfoResp.DeviceId) + jsonResponse, err := json.Marshal(devInfoResp) if err != nil { log.Error(err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) return } log.Info("registereddevicesPOST: jsonResponse: ", string(jsonResponse)) - w.WriteHeader(http.StatusCreated) fmt.Fprint(w, string(jsonResponse)) } @@ -1057,6 +1065,7 @@ func convertIotPlatformInfoFromSbi(val sbi.IotPlatformInfo) (item IotPlatformInf } } e.Extensions = userTransportInfo.Security.Extensions + v.Security = &e } if userTransportInfo.ImplSpecificInfo != nil { v.ImplSpecificInfo = &ImplSpecificInfo{ @@ -1138,6 +1147,7 @@ func convertIotPlatformInfoToSbi(val IotPlatformInfo) (item sbi.IotPlatformInfo) } } e.Extensions = userTransportInfo.Security.Extensions + v.Security = &e } if userTransportInfo.ImplSpecificInfo != nil { v.ImplSpecificInfo = &sbi.ImplSpecificInfo{ @@ -1147,7 +1157,7 @@ func convertIotPlatformInfoToSbi(val IotPlatformInfo) (item sbi.IotPlatformInfo) } } item.UserTransportInfo = append(item.UserTransportInfo, v) - } + } // End of 'for' statement if val.CustomServicesTransportInfo != nil && len(val.CustomServicesTransportInfo) != 0 { item.CustomServicesTransportInfo = make([]sbi.TransportInfo, 0) for _, customServicesTransportInfo := range val.CustomServicesTransportInfo { @@ -1176,7 +1186,7 @@ func convertIotPlatformInfoToSbi(val IotPlatformInfo) (item sbi.IotPlatformInfo) v.Endpoint = &e } item.CustomServicesTransportInfo = append(item.CustomServicesTransportInfo, v) - } + } // End of 'for' statement } return item @@ -1204,9 +1214,53 @@ func convertDeviceInfoFromSbi(dev sbi.DeviceInfo) (device DeviceInfo) { device.DeviceMetadata[i] = KeyValuePair{Key: k.Key, Value: k.Value} } // End of 'for' statement } + if len(dev.RequestedMecTrafficRule) != 0 { + device.RequestedMecTrafficRule = make([]TrafficRuleDescriptor, len(dev.RequestedMecTrafficRule)) + for i, v := range dev.RequestedMecTrafficRule { + device.RequestedMecTrafficRule[i] = TrafficRuleDescriptor{ + TrafficRuleId: v.TrafficRuleId, + FilterType: v.FilterType, + Priority: v.Priority, + Action: v.Action, + } + if len(dev.RequestedMecTrafficRule[i].TrafficFilter) != 0 { + device.RequestedMecTrafficRule[i].TrafficFilter = make([]TrafficFilter, len(dev.RequestedMecTrafficRule[i].TrafficFilter)) + for j, u := range dev.RequestedMecTrafficRule[i].TrafficFilter { + device.RequestedMecTrafficRule[i].TrafficFilter[j] = TrafficFilter{ + SrcAddress: u.SrcAddress, + DstAddress: u.DstAddress, + SrcPort: u.SrcPort, + DstPort: u.DstPort, + Protocol: u.Protocol, + Tag: u.Tag, + Uri: u.Uri, + PacketLabel: u.PacketLabel, + SrcTunnelAddress: u.SrcTunnelAddress, + TgtTunnelAddress: u.TgtTunnelAddress, + SrcTunnelPort: u.SrcTunnelPort, + DstTunnelPort: u.DstTunnelPort, + QCI: u.QCI, + DSCP: u.DSCP, + TC: u.TC, + } + } // End of 'for' statement + } + if v.DstInterface != nil { + device.RequestedMecTrafficRule[i].DstInterface = &InterfaceDescriptor{ + InterfaceType: device.RequestedMecTrafficRule[i].DstInterface.InterfaceType, + TunnelInfo: nil, // FIXME FSCOM To be filled + SrcMACAddress: device.RequestedMecTrafficRule[i].DstInterface.SrcMACAddress, + DstMACAddress: device.RequestedMecTrafficRule[i].DstInterface.DstMACAddress, + DstIPAddress: device.RequestedMecTrafficRule[i].DstInterface.DstIPAddress, + } + } + } // End of 'for' statement + } // FIXME FSCOM Add missing fileds (pointers & arrays) - //log.Debug("convertDeviceInfosFromSbi: devices: ", devices) + //DeviceSpecificMessageFormats *DeviceSpecificMessageFormats `json:"deviceSpecificMessageFormats,omitempty"` + //DownlinkInfo *DownlinkInfo `json:"downlinkInfo,omitempty"` + //log.Debug("convertDeviceInfosFromSbi: devices: ", devices) return device } @@ -1284,8 +1338,52 @@ func convertDeviceInfoToSbi(dev DeviceInfo) (device sbi.DeviceInfo) { device.DeviceMetadata[i] = sbi.KeyValuePair{Key: k.Key, Value: k.Value} } // End of 'for' statement } + if len(dev.RequestedMecTrafficRule) != 0 { + device.RequestedMecTrafficRule = make([]sbi.TrafficRuleDescriptor, len(dev.RequestedMecTrafficRule)) + for i, v := range dev.RequestedMecTrafficRule { + device.RequestedMecTrafficRule[i] = sbi.TrafficRuleDescriptor{ + TrafficRuleId: v.TrafficRuleId, + FilterType: v.FilterType, + Priority: v.Priority, + Action: v.Action, + } + if len(dev.RequestedMecTrafficRule[i].TrafficFilter) != 0 { + device.RequestedMecTrafficRule[i].TrafficFilter = make([]sbi.TrafficFilter, len(dev.RequestedMecTrafficRule[i].TrafficFilter)) + for j, u := range dev.RequestedMecTrafficRule[i].TrafficFilter { + device.RequestedMecTrafficRule[i].TrafficFilter[j] = sbi.TrafficFilter{ + SrcAddress: u.SrcAddress, + DstAddress: u.DstAddress, + SrcPort: u.SrcPort, + DstPort: u.DstPort, + Protocol: u.Protocol, + Tag: u.Tag, + Uri: u.Uri, + PacketLabel: u.PacketLabel, + SrcTunnelAddress: u.SrcTunnelAddress, + TgtTunnelAddress: u.TgtTunnelAddress, + SrcTunnelPort: u.SrcTunnelPort, + DstTunnelPort: u.DstTunnelPort, + QCI: u.QCI, + DSCP: u.DSCP, + TC: u.TC, + } + } // End of 'for' statement + } + if v.DstInterface != nil { + device.RequestedMecTrafficRule[i].DstInterface = &sbi.InterfaceDescriptor{ + InterfaceType: device.RequestedMecTrafficRule[i].DstInterface.InterfaceType, + // FIXME FSCOM To be filled: TunnelInfo: nil, + SrcMACAddress: device.RequestedMecTrafficRule[i].DstInterface.SrcMACAddress, + DstMACAddress: device.RequestedMecTrafficRule[i].DstInterface.DstMACAddress, + DstIPAddress: device.RequestedMecTrafficRule[i].DstInterface.DstIPAddress, + } + } + } // End of 'for' statement + } // FIXME FSCOM Add missing fileds (pointers & arrays) - //log.Debug("convertDeviceInfoToSbi: devices: ", devices) + //DeviceSpecificMessageFormats *DeviceSpecificMessageFormats `json:"deviceSpecificMessageFormats,omitempty"` + //DownlinkInfo *DownlinkInfo `json:"downlinkInfo,omitempty"` + //log.Debug("convertDeviceInfoToSbi: devices: ", devices) return device } diff --git a/go-apps/meep-sss/server/api_sensor_data_lookup.go b/go-apps/meep-sss/server/api_sensor_data_lookup.go index 191b7a8a65f79479b8fdc54e489f558711f37d1c..194094776f7dee6bd0dd9948340e687b810f1c46 100644 --- a/go-apps/meep-sss/server/api_sensor_data_lookup.go +++ b/go-apps/meep-sss/server/api_sensor_data_lookup.go @@ -14,6 +14,5 @@ import ( ) func SensorDataLookupGET(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) + sensorDataLookupGET(w, r) } diff --git a/go-apps/meep-sss/server/meep-sss.go b/go-apps/meep-sss/server/meep-sss.go index d07e22f94a1efdee4ce4562fd1ea6c6d15cb002d..db7e595d8d7cbd104d422bf320e802849689d7ff 100644 --- a/go-apps/meep-sss/server/meep-sss.go +++ b/go-apps/meep-sss/server/meep-sss.go @@ -606,10 +606,20 @@ func sensorDiscoveryLookupGET(w http.ResponseWriter, r *http.Request) { log.Debug("sensorDiscoveryLookupGET: q: ", q) if len(q) == 0 { err := errors.New("Invalid query parameters") + log.Error("sensorDiscoveryLookupGET: ", err.Error()) + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } else if _, ok := q["type"]; !ok { + err := errors.New("Invalid query parameters: type parameter is mandatory") + log.Error("sensorDiscoveryLookupGET: ", err.Error()) + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } else if len(q["type"][0]) == 0 { + err := errors.New("Invalid query parameters: Wrong type parameter value") + log.Error("sensorDiscoveryLookupGET: ", err.Error()) errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) return } - log.Debug("sensorDiscoveryLookupGET: q[type][0]: ", q["type"][0]) //log.Debug("sensorDiscoveryLookupGET: q[sensorCharacteristicList][0]: ", q["sensorCharacteristicList"][0]) //log.Debug("sensorDiscoveryLookupGET: type(q[sensorCharacteristicList][0]): ", reflect.TypeOf(q["sensorCharacteristicList"][0])) //q: map[geographicalArea:[[object Object]] sensorCharacteristicList:[[object Object]] sensorPropertyList:[string1,string2] type:[string]]","time":"2025-02-04T08:35:35Z"} @@ -634,7 +644,7 @@ func sensorDiscoveryLookupGET(w http.ResponseWriter, r *http.Request) { // Prepare response and send jsonResponse := convertSensorDiscoveryInfoListToJson(sensors) if jsonResponse == "" { - log.Error("Marshalling failure") + log.Error("sensorDiscoveryLookupGET: Marshalling failure") errHandlerProblemDetails(w, "Marshalling failure", http.StatusInternalServerError) return } @@ -656,6 +666,10 @@ func sensorStatusLookupGET(w http.ResponseWriter, r *http.Request) { err := errors.New("Invalid query parameters") errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) return + } else if len(q["sensorIdentifier"][0]) == 0 { + err := errors.New("Invalid query parameters") + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return } log.Debug("sensorStatusLookupGET: q[sensorIdentifier][0]: ", q["sensorIdentifier"][0]) @@ -669,7 +683,7 @@ func sensorStatusLookupGET(w http.ResponseWriter, r *http.Request) { // Prepare response and send jsonResponse := convertSensorStatusToJson(convertSensorStatusInfoFromSbi(s)) if jsonResponse == "" { - log.Error("Marshalling failure") + log.Error("sensorDiscoveryLookupGET: Marshalling failure") errHandlerProblemDetails(w, "Marshalling failure", http.StatusInternalServerError) return } @@ -678,6 +692,45 @@ func sensorStatusLookupGET(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } +func sensorDataLookupGET(w http.ResponseWriter, r *http.Request) { + log.Debug(">>> sensorDataLookupGET: ", r) + + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + + // Validate query parameters + u, _ := url.Parse(r.URL.String()) + q := u.Query() + log.Debug("sensorDataLookupGET: q: ", q) + if _, ok := q["sensorIdentifier"]; !ok { + err := errors.New("Invalid query parameters") + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } else if len(q["sensorIdentifier"][0]) == 0 { + err := errors.New("Invalid query parameters") + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } + log.Debug("sensorDataLookupGET: q[sensorIdentifier][0]: ", q["sensorIdentifier"][0]) + + s, err := sbi.GetSensorStatus(q["sensorIdentifier"][0]) + if err != nil { + errHandlerProblemDetails(w, err.Error(), http.StatusInternalServerError) + return + } + log.Debug("sensorDataLookupGET: s: ", s) + + // Prepare response and send + jsonResponse := convertSensorStatusToJson(convertSensorStatusInfoFromSbi(s)) + if jsonResponse == "" { + log.Error("sensorDataLookupGET: Marshalling failure") + errHandlerProblemDetails(w, "Marshalling failure", http.StatusInternalServerError) + return + } + log.Info("sensorDataLookupGET: jsonResponse: ", jsonResponse) + fmt.Fprint(w, jsonResponse) + w.WriteHeader(http.StatusOK) +} + func sensorDiscoverySubscriptionGET(w http.ResponseWriter, r *http.Request) { log.Debug(">>> sensorDiscoverySubscriptionGET: ", r) @@ -695,6 +748,7 @@ func sensorDataSubscriptionGET(w http.ResponseWriter, r *http.Request) { subscriptionsGET(SENS_DATA, w, r) } + func sensorDiscoverySubscriptionPOST(w http.ResponseWriter, r *http.Request) { log.Debug(">>> sensorDiscoverySubscriptionPOST: ", r) @@ -785,13 +839,13 @@ func subscriptionsPOST(subType string, w http.ResponseWriter, r *http.Request) { // create a unique link for every subscription and concatenate subscription to it link := new(SubscriptionLinks) self := new(LinkType) - self.Href = hostUrl.String() + basePath + "subscriptions/" + subsIdStr - link.Self = self // switch statement is based on provided subscriptionType in the request body var jsonResponse string switch subscriptionType { case SENS_DISCOVERY: + self.Href = hostUrl.String() + basePath + "subscriptions/sensor_discovery/" + subsIdStr + link.Self = self var sensorDiscoveryEventSubscription SensorDiscoveryEventSubscription jsonResponse, err = processSensorDiscoveryEventSubscription(bodyBytes, link, subsIdStr, &sensorDiscoveryEventSubscription) if err != nil { @@ -802,6 +856,8 @@ func subscriptionsPOST(subType string, w http.ResponseWriter, r *http.Request) { w.Header().Set("Location", sensorDiscoveryEventSubscription.Links.Self.Href) case SENS_STATUS: + self.Href = hostUrl.String() + basePath + "subscriptions/sensor_status/" + subsIdStr + link.Self = self var sensorStatusSubscription SensorStatusSubscription jsonResponse, err = processSensorStatusSubscription(bodyBytes, link, subsIdStr, &sensorStatusSubscription) if err != nil { @@ -812,6 +868,8 @@ func subscriptionsPOST(subType string, w http.ResponseWriter, r *http.Request) { w.Header().Set("Location", sensorStatusSubscription.Links.Self.Href) case SENS_DATA: + self.Href = hostUrl.String() + basePath + "subscriptions/sensor_data/" + subsIdStr + link.Self = self var sensorDataSubscription SensorDataSubscription jsonResponse, err = processSensorDataSubscription(bodyBytes, link, subsIdStr, &sensorDataSubscription) if err != nil { @@ -858,13 +916,27 @@ func subscriptionsGET(subType string, w http.ResponseWriter, r *http.Request) { u, _ := url.Parse(r.URL.String()) log.Info("url: ", u.RequestURI()) q := u.Query() - sensorIdentifier := q.Get("sensorIdentifier") - log.Debug("subscriptionsGET: sensorIdentifier: ", sensorIdentifier) - sensorIdentifiers := strings.Split(sensorIdentifier, ",") + sensorIdentifiers := []string{} + if len(q) != 0 { + sensorIdentifier := q.Get("sensorIdentifier") + if len(sensorIdentifier) == 0 { + err := errors.New("Wrong query parameters") + log.Error(err.Error()) + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } + log.Debug("subscriptionsGET: sensorIdentifier: ", sensorIdentifier) + sensorIdentifiers = strings.Split(sensorIdentifier, ",") + } log.Debug("subscriptionsGET: sensorIdentifiers: ", sensorIdentifiers) // get the response against particular subscription type - response := createSubscriptionLinkList(subType, sensorIdentifiers) + response, err := createSubscriptionLinkList(subType, sensorIdentifiers) + if err != nil { + log.Error(err.Error()) + errHandlerProblemDetails(w, err.Error(), http.StatusBadRequest) + return + } // prepare & send response jsonResponse, err := json.Marshal(response) @@ -1476,7 +1548,7 @@ func isSubscriptionIdRegisteredSensorData(subsIdStr string) bool { return returnVal } -func createSubscriptionLinkList(subType string, sensorIdentifiers []string) *SubscriptionLinkList { +func createSubscriptionLinkList(subType string, sensorIdentifiers []string) (*SubscriptionLinkList, error) { log.Debug(">>> createSubscriptionLinkList: subType: ", subType) log.Debug(">>> createSubscriptionLinkList: sensorIdentifiers: ", sensorIdentifiers) @@ -1553,7 +1625,7 @@ func createSubscriptionLinkList(subType string, sensorIdentifiers []string) *Sub subscriptionLinkList.Links = links - return subscriptionLinkList + return subscriptionLinkList, nil } /* @@ -1845,8 +1917,9 @@ func convertSensorDiscoveryInfoListFromSbi_with_filter(s []sbi.SensorDiscoveryIn func convertSensorDiscoveryInfoFromSbi(s sbi.SensorDiscoveryInfo) (sensor SensorDiscoveryInfo) { sensor = SensorDiscoveryInfo{ - SensorIdentifier: s.SensorIdentifier, - SensorType: s.SensorType, + SensorIdentifier: s.SensorIdentifier, + SensorType: s.SensorType, + SensorPropertyList: []string{"SAREF"}, } if len(s.SensorPropertyList) != 0 { copy(sensor.SensorPropertyList, s.SensorPropertyList) @@ -1866,6 +1939,11 @@ func convertSensorDiscoveryInfoFromSbi(s sbi.SensorDiscoveryInfo) (sensor Sensor Latitude: s.SensorPosition.Latitude, Longitude: s.SensorPosition.Longitude, } + } else { // SensorPosition is mandatory + sensor.SensorPosition = &Point{ + Latitude: 0, + Longitude: 0, + } } return sensor diff --git a/go-apps/meep-sss/server/model_status_data_subscription_id_body.go b/go-apps/meep-sss/server/model_status_data_subscription_id_body.go index f6b6594b6a0a485869e7d20725293c33ad90228c..c6fa315bc2f698883c2d76919ef01793acf91cc6 100644 --- a/go-apps/meep-sss/server/model_status_data_subscription_id_body.go +++ b/go-apps/meep-sss/server/model_status_data_subscription_id_body.go @@ -9,6 +9,6 @@ */ package server -type StatusDataSubscriptionIdBody struct { +type SensorDataSubscriptionIdBody struct { SensorStatusSubscription *SensorDataSubscription `json:"SensorStatusSubscription,omitempty"` } diff --git a/go-apps/meep-sss/server/routers.go b/go-apps/meep-sss/server/routers.go index 35b06a0dbc8d6ef324419a306f9265eb16458575..a8d164cf5fb93afd80cd01a532b78ebd3b1134f7 100644 --- a/go-apps/meep-sss/server/routers.go +++ b/go-apps/meep-sss/server/routers.go @@ -83,21 +83,21 @@ var routes = Routes{ Route{ "SensorDataLookupGET", strings.ToUpper("Get"), - "/sens/v1/queries/status_data", + "/sens/v1/queries/sensor_data", SensorDataLookupGET, }, Route{ "SensorDataIndividualSubscriptionGET", strings.ToUpper("Get"), - "/sens/v1/queries/status_data/{subscriptionId}", + "/sens/v1/queries/sensor_data/{subscriptionId}", SensorDataIndividualSubscriptionGET, }, Route{ "SensorDataSubscriptionDELETE", strings.ToUpper("Delete"), - "/sens/v1/queries/status_data/{subscriptionId}", + "/sens/v1/queries/sensor_data/{subscriptionId}", SensorDataSubscriptionDELETE, }, @@ -118,7 +118,7 @@ var routes = Routes{ Route{ "SensorDataSubscriptionPUT", strings.ToUpper("Put"), - "/sens/v1/queries/status_data/{subscriptionId}", + "/sens/v1/queries/sensor_data/{subscriptionId}", SensorDataSubscriptionPUT, }, diff --git a/go-packages/meep-iot-mgr/go.mod b/go-packages/meep-iot-mgr/go.mod index d9b09212a86a776b391f2f2ab8bc2a2bbe6f034f..c082d159a3aaa746ec7de005658eb881edd0cbe0 100644 --- a/go-packages/meep-iot-mgr/go.mod +++ b/go-packages/meep-iot-mgr/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/BurntSushi/toml v1.2.0 // indirect + github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sss-mgr v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0 github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/google/uuid v1.6.0 @@ -16,4 +17,5 @@ require ( replace ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger + github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sss-mgr => ../../go-packages/meep-sss-mgr ) diff --git a/go-packages/meep-iot-mgr/iot-mgr.go b/go-packages/meep-iot-mgr/iot-mgr.go index a517df845209a71ebd8e6be5a984b07d60aa7318..f4b7d34f60153c9e5d5692fd15181fef15385fcd 100644 --- a/go-packages/meep-iot-mgr/iot-mgr.go +++ b/go-packages/meep-iot-mgr/iot-mgr.go @@ -125,6 +125,7 @@ type TrafficFilter struct { SrcTunnelPort []string DstTunnelPort []string QCI int32 + DSCP int32 TC int32 } @@ -153,10 +154,11 @@ type DeviceInfo struct { Enabled bool } -var registeredIotPlatformsMap = map[string]IotPlatformInfo{} // List of discovered IOT Plateform -var devicesMap = map[string]DeviceInfo{} // Map device by deviceId -var devicesPerPlatformMap = map[string][]string{} // Map deviceIds per platform -var platformPerUserTransportIdMap = map[string][]string{} // Map userTransportId per platform +var registeredIotPlatformsMap = map[string]IotPlatformInfo{} // List of discovered IOT Plateform +var devicesMap = map[string]DeviceInfo{} // Map device by deviceId +var devicesPerPlatformMap = map[string][]string{} // Map deviceIds per platform +var platformPerUserTransportIdMap = map[string][]string{} // Map userTransportId per platform +var registeredIotPlatformsAEMap = map[string]sssmgr.SensorDiscoveryInfo{} // Map AE created per IOT Plateform // Timer to refresh devices list for all IoT platform const refreshTickerExpeary = 30 // In seconds @@ -202,11 +204,18 @@ func (tm *IotMgr) init() { devicesMap = make(map[string]DeviceInfo, 0) devicesPerPlatformMap = make(map[string][]string, 0) platformPerUserTransportIdMap = make(map[string][]string, 0) + registeredIotPlatformsAEMap = make(map[string]sssmgr.SensorDiscoveryInfo, 0) tm.refreshTicker = nil } // DeleteIotMgr - func (tm *IotMgr) DeleteIotMgr() (err error) { + registeredIotPlatformsMap = nil + devicesMap = nil + devicesPerPlatformMap = nil + platformPerUserTransportIdMap = nil + registeredIotPlatformsAEMap = nil + tm.refreshTicker = nil return nil } @@ -219,7 +228,7 @@ func (tm *IotMgr) startRefreshTicker() { for range tm.refreshTicker.C { // Refresh the list of devices tm.wg.Add(1) - log.Debug("startRefreshTicker: registeredIotPlatformsMap: ", registeredIotPlatformsMap) + log.Debug("iotmgr.startRefreshTicker: registeredIotPlatformsMap: ", registeredIotPlatformsMap) for _, v := range registeredIotPlatformsMap { if v.oneM2M != nil { err := tm.populateDevicesPerIotPlatforms(v) @@ -227,14 +236,14 @@ func (tm *IotMgr) startRefreshTicker() { log.Error(err) } } else { - log.Debug("startRefreshTicker: Nothing to do") + log.Debug("iotmgr.startRefreshTicker: Nothing to do") } } // End of 'for' statement - log.Debug("startRefreshTicker: Before Done()") + log.Debug("iotmgr.startRefreshTicker: Before Done()") tm.wg.Done() - log.Debug("startRefreshTicker: After Done()") + log.Debug("iotmgr.startRefreshTicker: After Done()") } // End of 'for' statement - log.Debug("startRefreshTicker: Leaving time loop") + log.Debug("iotmgr.startRefreshTicker: Leaving time loop") } }() } @@ -257,20 +266,33 @@ func (tm *IotMgr) RegisterIotPlatformInfo(iotPlatformInfo IotPlatformInfo) (err log.Info(">>> RegisterIotPlatformInfo: iotPlatformId: ", iotPlatformInfo) if iotPlatformInfo.Enabled { - //{{\"iotPlatformId\": \"1a584db5-6a3e-4f56-b126-29180069ecf1\", \"userTransportInfo\": [{\"id\": \"ca22ca5e-e0ce-4da8-a2ce-2966f4759032\", \"name\": \"MQTT\", \"description\": \"MQTT\", \"type\": \"MB_TOPIC_BASED\", \"protocol\": \"MQTT\", \"version\": \"2\", \"endpoint\": {\"addresses\": [{\"host\": \"172.29.10.56\", \"port\": 1883}]}, \"security\": {}, \"implSpecificInfo\": {}}], \"customServicesTransportInfo\": [{\"id\": \"85fe5e7f-c371-4f71-b7f6-61a1f808fbb3\", \"name\": \"/laboai-acme-ic-cse\", \"description\": \"ACME oneM2M CSE\", \"type\": \"REST_HTTP\", \"protocol\": \"REST_HTTP\", \"version\": \"4\", \"endpoint\": {\"addresses\": [{\"host\": \"172.29.10.20\", \"port\": 31110}]}, \"security\": {}}], \"enabled\": true}} iotPlatformInfo.oneM2M = nil - if len(iotPlatformInfo.CustomServicesTransportInfo) == 0 || iotPlatformInfo.CustomServicesTransportInfo[0].Endpoint == nil || len(iotPlatformInfo.CustomServicesTransportInfo[0].Endpoint.Addresses) == 0 { + if len(iotPlatformInfo.UserTransportInfo) == 0 || iotPlatformInfo.UserTransportInfo[0].Endpoint == nil || len(iotPlatformInfo.UserTransportInfo[0].Endpoint.Addresses) == 0 { log.Warn("RegisterIotPlatformInfo: Cannot use provided CustomServicesTransportInfo") } else { - // FIXME FSCOM How to get the CSE_ID + // FIXME FSCOM How to get the CSE_ID. For the time being, iotPlatformInfo.UserTransportInfo[0].Name is the CSE-resourceID // TODO FSCOM Add notification support? - pltf, err := sssmgr.NewSssMgr(tm.name, tm.namespace, iotPlatformInfo.CustomServicesTransportInfo[0].Protocol /*"MQTT"*/, iotPlatformInfo.CustomServicesTransportInfo[0].Endpoint.Addresses[0].Host /*"172.29.10.56"*/, int(iotPlatformInfo.CustomServicesTransportInfo[0].Endpoint.Addresses[0].Port) /*1883*/, iotPlatformInfo.IotPlatformId /*"7feaadbb0400"*/, iotPlatformInfo.CustomServicesTransportInfo[0].Name /*"laboai-acme-ic-cse"*/, nil, nil, nil) + pltf, err := sssmgr.NewSssMgr(tm.name, tm.namespace, iotPlatformInfo.UserTransportInfo[0].Protocol, iotPlatformInfo.UserTransportInfo[0].Endpoint.Addresses[0].Host, int(iotPlatformInfo.UserTransportInfo[0].Endpoint.Addresses[0].Port), iotPlatformInfo.IotPlatformId, iotPlatformInfo.UserTransportInfo[0].Name, nil, nil, nil) if err != nil { log.Error("RegisterIotPlatformInfo: ", err) iotPlatformInfo.oneM2M = nil } else { log.Info("RegisterIotPlatformInfo: IoT pltf created") iotPlatformInfo.oneM2M = pltf + // Create the an AE for this ETSI MEC platform + var ae = sssmgr.SensorDiscoveryInfo{ + SensorIdentifier: iotPlatformInfo.IotPlatformId, + SensorType: "AE", + SensorPosition: nil, + IotPlatformId: iotPlatformInfo.IotPlatformId, + } + ae, err = pltf.OneM2M_create(ae, "") + if err != nil { + log.Warn("RegisterIotPlatformInfo: Failed to create new AE sensor") + } else { + registeredIotPlatformsAEMap[iotPlatformInfo.IotPlatformId] = ae + } + registeredIotPlatformsAEMap[iotPlatformInfo.IotPlatformId] = ae if tm.refreshTicker == nil { log.Info("RegisterIotPlatformInfo: Start RefreshTicker") tm.startRefreshTicker() @@ -278,6 +300,7 @@ func (tm *IotMgr) RegisterIotPlatformInfo(iotPlatformInfo IotPlatformInfo) (err } } registeredIotPlatformsMap[iotPlatformInfo.IotPlatformId] = iotPlatformInfo + log.Info("RegisterIotPlatformInfo: iotPlatformId: ", registeredIotPlatformsMap[iotPlatformInfo.IotPlatformId]) } // else, Skip disabled platform @@ -314,6 +337,10 @@ func (tm *IotMgr) DeregisterIotPlatformInfo(iotPlatformId string) (err error) { } if pltf, ok := registeredIotPlatformsMap[iotPlatformId]; ok { if pltf.oneM2M != nil { + if val, ok := registeredIotPlatformsAEMap[iotPlatformId]; ok { + _ = pltf.oneM2M.OneM2M_delete(val) + delete(registeredIotPlatformsAEMap, iotPlatformId) + } _ = pltf.oneM2M.DeleteSssMgr() pltf.oneM2M = nil log.Info("RegisterIotPlatformInfo: IoT pltf removed") @@ -395,7 +422,7 @@ func (tm *IotMgr) CreateDevice(device DeviceInfo) (deviceResp DeviceInfo, err er log.Info(">>> CreateDevice: ", device) tm.wg.Wait() - log.Info("GetDevices: After Wait()") + log.Info("CreateDevice: After Wait()") // RequestedMecTrafficRule is not supported yet if len(device.RequestedMecTrafficRule) != 0 { @@ -471,6 +498,10 @@ func (tm *IotMgr) createDeviceWithIotPlatformId(device DeviceInfo, requestedIotP err = errors.New("Device already exist") return deviceResp, err } + if _, ok := registeredIotPlatformsAEMap[requestedIotPlatformId]; !ok { + err = errors.New("Devaice cannot be created witout oneM2M AE parent") + return deviceResp, err + } if registeredIotPlatformsMap[requestedIotPlatformId].oneM2M != nil && device.Enabled == true { log.Info("createDeviceWithIotPlatformId: Create device on IoT platform", device) @@ -500,7 +531,7 @@ func (tm *IotMgr) createDeviceWithIotPlatformId(device DeviceInfo, requestedIotP // //DownlinkInfo *DownlinkInfo // ClientCertificate string // } - sensor, err := registeredIotPlatformsMap[requestedIotPlatformId].oneM2M.OneM2M_create(sensor, "") + sensor, err := registeredIotPlatformsMap[requestedIotPlatformId].oneM2M.OneM2M_create(sensor, registeredIotPlatformsAEMap[requestedIotPlatformId].SensorIdentifier) if err != nil { return deviceResp, err } @@ -522,7 +553,7 @@ func (tm *IotMgr) createDeviceWithRequestedUserTransportId(device DeviceInfo, re if val, ok := platformPerUserTransportIdMap[requestedUserTransportId]; ok { deviceResp, err = tm.createDeviceWithIotPlatformId(device, val[0]) } else { - err = errors.New("Invalid UserTransportId") + err = errors.New("Invalid requestedUserTransportId") } if err != nil { log.Error("createDeviceWithIotPlatformId: ", err.Error()) diff --git a/go-packages/meep-iot-mgr/iot-mgr_test.go b/go-packages/meep-iot-mgr/iot-mgr_test.go index 84ca215aa4d2d3c1ae0bff247d0b87452313fda6..b9be619adec006a2b85763026e61112c49e5b4a0 100644 --- a/go-packages/meep-iot-mgr/iot-mgr_test.go +++ b/go-packages/meep-iot-mgr/iot-mgr_test.go @@ -74,10 +74,10 @@ func TestRegisterIotPlatformInfo(t *testing.T) { var userTransportInfo = []MbTransportInfo{} userTransportInfo = append(userTransportInfo, MbTransportInfo{ Id: "d5673793-c55c-4969-b5bc-2121f84b9f8d", - Name: "MQTT", + Name: "laboai-acme-ic-cse", Description: "MQTT", Protocol: "MQTT", - Version: "2", + Version: "3", Endpoint: &endpoint, }) var adresses_1 = []Addresses{} @@ -91,7 +91,7 @@ func TestRegisterIotPlatformInfo(t *testing.T) { } customServicesTransportInfo = append(customServicesTransportInfo, TransportInfo{ Id: "2ddb713c-2b41-4ded-a7ad-a5a047c5df13", - Name: "/laboai-acme-ic-cse", + Name: "laboai-acme-ic-cse", Description: "ACME oneM2M CSE", Protocol: "REST_HTTP", Version: "4", @@ -430,7 +430,7 @@ func registerIotPltf(tm *IotMgr) (iotPlatformInfo IotPlatformInfo, err error) { var userTransportInfo = []MbTransportInfo{} userTransportInfo = append(userTransportInfo, MbTransportInfo{ Id: "d5673793-c55c-4969-b5bc-2121f84b9f8d", - Name: "MQTT", + Name: "laboai-acme-ic-cse", Description: "MQTT", Protocol: "MQTT", Version: "2", @@ -447,7 +447,7 @@ func registerIotPltf(tm *IotMgr) (iotPlatformInfo IotPlatformInfo, err error) { } customServicesTransportInfo = append(customServicesTransportInfo, TransportInfo{ Id: "2ddb713c-2b41-4ded-a7ad-a5a047c5df13", - Name: "/laboai-acme-ic-cse", + Name: "laboai-acme-ic-cse", Description: "ACME oneM2M CSE", Protocol: "REST_HTTP", Version: "4", @@ -481,7 +481,7 @@ func registerIotPltfAndCreateDevice(tm *IotMgr) (iotPlatformInfo IotPlatformInfo var userTransportInfo = []MbTransportInfo{} userTransportInfo = append(userTransportInfo, MbTransportInfo{ Id: "d5673793-c55c-4969-b5bc-2121f84b9f8d", - Name: "MQTT", + Name: "laboai-acme-ic-cse", Description: "MQTT", Protocol: "MQTT", Version: "2", @@ -498,7 +498,7 @@ func registerIotPltfAndCreateDevice(tm *IotMgr) (iotPlatformInfo IotPlatformInfo } customServicesTransportInfo = append(customServicesTransportInfo, TransportInfo{ Id: "2ddb713c-2b41-4ded-a7ad-a5a047c5df13", - Name: "/laboai-acme-ic-cse", + Name: "laboai-acme-ic-cse", Description: "ACME oneM2M CSE", Protocol: "REST_HTTP", Version: "4", diff --git a/go-packages/meep-sss-client/README.md b/go-packages/meep-sss-client/README.md index 6bfa0a4cc2635c4fd08fda90227b5727b6360157..6fe84ed604d91c194d802e39cf24b3952c23bb10 100644 --- a/go-packages/meep-sss-client/README.md +++ b/go-packages/meep-sss-client/README.md @@ -60,7 +60,7 @@ Class | Method | HTTP request | Description - [SensorStatusSubscription](docs/SensorStatusSubscription.md) - [SensorStatusSubscriptionIdBody](docs/SensorStatusSubscriptionIdBody.md) - [ShapeType](docs/ShapeType.md) - - [StatusDataSubscriptionIdBody](docs/StatusDataSubscriptionIdBody.md) + - [SensorDataSubscriptionIdBody](docs/SensorDataSubscriptionIdBody.md) - [SubscriptionLinkList](docs/SubscriptionLinkList.md) - [SubscriptionLinkListLinks](docs/SubscriptionLinkListLinks.md) - [SubscriptionLinkListSubscription](docs/SubscriptionLinkListSubscription.md) diff --git a/go-packages/meep-sss-client/api_sensor_data_subscription.go b/go-packages/meep-sss-client/api_sensor_data_subscription.go index c541e06a78dbcf889004fb49099286754d8d13c1..f551617a6a93f92c7d1df122116a91ac73b4e7bd 100644 --- a/go-packages/meep-sss-client/api_sensor_data_subscription.go +++ b/go-packages/meep-sss-client/api_sensor_data_subscription.go @@ -498,7 +498,7 @@ This method shall support the URI query parameters, request and response data st * @param subscriptionId Unique identifiers of a subscription @return []SensorDataSubscription */ -func (a *SensorDataSubscriptionApiService) SensorDataSubscriptionPUT(ctx context.Context, body StatusDataSubscriptionIdBody, subscriptionId string) ([]SensorDataSubscription, *http.Response, error) { +func (a *SensorDataSubscriptionApiService) SensorDataSubscriptionPUT(ctx context.Context, body SensorDataSubscriptionIdBody, subscriptionId string) ([]SensorDataSubscription, *http.Response, error) { var ( localVarHttpMethod = strings.ToUpper("Put") localVarPostBody interface{} diff --git a/go-packages/meep-sss-client/model_status_data_subscription_id_body.go b/go-packages/meep-sss-client/model_status_data_subscription_id_body.go index 0b09d725c28b1300586e7ff603315696f0f8cfa3..02e2be891964fcb9a9d3be3d28b0a0ef9bf1b759 100644 --- a/go-packages/meep-sss-client/model_status_data_subscription_id_body.go +++ b/go-packages/meep-sss-client/model_status_data_subscription_id_body.go @@ -9,6 +9,6 @@ */ package client -type StatusDataSubscriptionIdBody struct { +type SensorDataSubscriptionIdBody struct { SensorStatusSubscription *SensorDataSubscription `json:"SensorStatusSubscription,omitempty"` } diff --git a/go-packages/meep-sss-mgr/mqtt.go b/go-packages/meep-sss-mgr/mqtt.go index 9eec0dde79d4c506852262f62f4d2adb553f0f3a..38784d1de798ebc2a11b5e750bb4448fa9ace6cd 100644 --- a/go-packages/meep-sss-mgr/mqtt.go +++ b/go-packages/meep-sss-mgr/mqtt.go @@ -6,6 +6,7 @@ import ( "fmt" "reflect" "strconv" + "strings" "sync" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" @@ -30,7 +31,7 @@ func onMessageReceived(client mqtt.Client, msg mqtt.Message) { // if _notify != nil { // ... // } else { - // log.Info("onMessageReceived: null pointer for the callbacl") + // log.Info("onMessageReceived: null pointer for the callback") // } }() } @@ -41,7 +42,7 @@ func onMessageReceivedReq(client mqtt.Client, msg mqtt.Message) { // if _notify != nil { // ... // } else { - // log.Info("onMessageReceivedReq: null pointer for the callbacl") + // log.Info("onMessageReceivedReq: null pointer for the callback") // } }() } @@ -54,12 +55,57 @@ func onMessageReceivedResp(client mqtt.Client, msg mqtt.Message) { }() } +func onMessageReceivedNot(client mqtt.Client, msg mqtt.Message) { + go func() { + log.Info("onMessageReceivedNot: Received message: ", string(msg.Payload()), " on topic ", msg.Topic()) + //{\"fr\": \"/laboai-acme-ic-cse\", \"to\": \"mqtt://172.29.10.56:1883\", \"ot\": \"20250327T134413,103223\", \"op\": 5, \"rqi\": \"6400213617020980613\", \"rvi\": \"4\", \"drt\": 1, \"pc\": {\"m2m:sgn\": {\"nev\": {\"net\": 3, \"rep\": {\"m2m:cin\": {\"cnf\": \"text/plain:0\", \"con\": \"toto\", \"rn\": \"1234\", \"ri\": \"cin3503344383965775257\", \"pi\": \"cnt1992620086833081496\", \"ct\": \"20250327T134413,093784\", \"lt\": \"20250327T134413,093784\", \"ty\": 4, \"cs\": 4, \"st\": 2, \"et\": \"20300326T134347,108295\"}}}, \"sur\": \"/laboai-acme-ic-cse/sub3169944238694067800\"}}} on topic /oneM2M/req/laboai-acme-ic-cse/mqtt:::172.29.10.56:1883/json" + // Prepare response + s := strings.Split(msg.Topic(), "/") // /oneM2M/req/laboai-acme-ic-cse/mqtt:::172.29.10.56:1883/json + resp_topic := "/oneM2M/resp/" + s[4] + "/" + s[3] + "/" + s[5] + log.Debug("onMessageReceivedNot: resp_topic: ", resp_topic) + if _notify != nil { + var d map[string]interface{} + err := json.Unmarshal(msg.Payload(), &d) + if err != nil { + log.Warn("onMessageReceivedNot: ", err.Error()) + return + } + if pc, ok := d["pc"]; ok { + log.Debug("onMessageReceivedNot: pc: ", pc) + log.Debug("onMessageReceivedNot: TypeOf(pc): ", reflect.TypeOf(pc)) + if _, ok := d["pc"].(map[string]interface{}); !ok { + log.Warn("onMessageReceivedNot: pc entry has an unexpected type") + return + } + body := d["pc"].(map[string]interface{}) + if _, ok := body["m2m:sgn"]; !ok { + log.Error("Only m2m:sgn is expected") + return + } + if _, ok := body["m2m:sgn"].(map[string]interface{}); !ok { + log.Warn("onMessageReceivedNot: m2m:sgn entry has an unexpected type") + return + } + m := body["m2m:sgn"].(map[string]interface{}) + log.Info("handleRoot: m: ", m) + _notify(m) + } else { + log.Warn("onMessageReceivedNot: pc entry not found") + return + } + } else { + log.Debug("onMessageReceivedNot: null pointer for the callback") + } + // FIXME FSCOM Send the response + }() +} + var connectHandler mqtt.OnConnectHandler = func(client mqtt.Client) { - log.Info("mqtt.OnConnectHandler: Connected") + //log.Info("mqtt.OnConnectHandler: Connected") } var connectLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client, err error) { - log.Info("Connect lost:", err) + //log.Info("Connect lost:", err) } func NewSssMgrMqtt() (broker_mqtt *SssMgrMqtt) { @@ -76,7 +122,7 @@ func (broker_mqtt *SssMgrMqtt) init(tm *SssMgr, notify func(map[string]interface broker_mqtt.opts = mqtt.NewClientOptions() broker_mqtt.opts.SetDefaultPublishHandler(onMessageReceived) - broker_mqtt.opts.SetClientID("AdvantEDGE.meep-vis-traffic-mgr") + broker_mqtt.opts.SetClientID("AdvantEDGE.meep-sss-mgr") broker_mqtt.opts.OnConnect = connectHandler broker_mqtt.opts.OnConnectionLost = connectLostHandler broker_mqtt.opts.CleanSession = true @@ -95,15 +141,25 @@ func (broker_mqtt *SssMgrMqtt) init(tm *SssMgr, notify func(map[string]interface token.Wait() // Subscribe - log.Info("init: Subscribe to: ", "oneM2M/req/+") - token = broker_mqtt.client.Subscribe("oneM2M/req/+", 0, onMessageReceivedReq) // qos:0 + // tp := "/oneM2M/req/+/" + tm.cse_name + "/#" + // log.Info("init: Subscribe to: ", tp) + // token = broker_mqtt.client.Subscribe(tp, 0, onMessageReceivedReq) // qos:0 + // if token.Error() != nil { + // log.Error(token.Error()) + // return token.Error() + // } + // token.Wait() + tp := "/oneM2M/resp/+/" + tm.cse_name + "/#" + log.Info("init: Subscribe to: ", tp) + token = broker_mqtt.client.Subscribe(tp, 0, onMessageReceivedResp) // qos:0 if token.Error() != nil { log.Error(token.Error()) return token.Error() } - // token.Wait() - log.Info("init: Subscribe to: ", "/oneM2M/resp/#") - token = broker_mqtt.client.Subscribe("/oneM2M/resp/#", 0, onMessageReceivedResp) // qos:0 + token.Wait() + tp = "/oneM2M/req/" + tm.cse_name + "/+/#" + log.Info("init: Subscribe to: ", tp) + token = broker_mqtt.client.Subscribe(tp, 1, onMessageReceivedNot) // qos:1 if token.Error() != nil { log.Error(token.Error()) return token.Error() @@ -222,19 +278,6 @@ func (broker_mqtt *SssMgrMqtt) send(p_ctx SssMgrBindingProtocolContext) (err err if r, ok := d["pc"]; ok { log.Debug("send: r: ", r) log.Debug("send: TypeOf(r): ", reflect.TypeOf(r)) - // var b []byte - // b, err = json.Marshal(r) - // if err != nil { - // log.Error("send: ", err.Error()) - // return err, nil - // } - // log.Info("send: b: ", b) - // log.Info("send: TypeOf(b): ", reflect.TypeOf(b)) - // err = json.Unmarshal(b, &resp) - // if err != nil { - // log.Error("send: ", err.Error()) - // return err, nil - // } return nil, r } return err, nil diff --git a/go-packages/meep-sss-mgr/onem2m-mgr.go b/go-packages/meep-sss-mgr/onem2m-mgr.go index ceebba77f64920186eb82b0434c1b7e6981f24b5..6b6d76b41054edcddf33c1b20ae77daab9344b07 100644 --- a/go-packages/meep-sss-mgr/onem2m-mgr.go +++ b/go-packages/meep-sss-mgr/onem2m-mgr.go @@ -72,6 +72,7 @@ type SensorDiscoveryInfo struct { SensorCharacteristicList []SensorCharacteristic SensorPosition *Point IotPlatformId string + Flex map[string]interface{} } var registeredIotPlatformsMap = map[string]IotPlatformInfo{} // List of discovered IOT Plateform @@ -193,7 +194,7 @@ func (tm *SssMgr) DeleteSssMgr() (err error) { } func (tm *SssMgr) startRefreshTicker() { - log.Debug("Starting refresh loop") + log.Debug(">>> sssmgr.startRefreshTicker") tm.refreshTicker = time.NewTicker(refreshTickerExpeary * time.Second) go func() { if tm.refreshTicker != nil { @@ -204,8 +205,11 @@ func (tm *SssMgr) startRefreshTicker() { if err != nil { log.Error(err) } + log.Debug("sssmgr.startRefreshTicker: Before Done()") tm.wg.Done() - } + log.Debug("sssmgr.startRefreshTicker: Before Done()") + } // End of 'for' statement + log.Debug("sssmgr.startRefreshTicker: Leaving time loop") } }() } @@ -304,7 +308,12 @@ func (tm *SssMgr) populateDevicesPerIotPlatforms() error { // Refresh the list of devices for all registered Iot platform for _, iotPlatform := range registeredIotPlatformsMap { log.Debug("populateDevicesPerIotPlatforms: processing: ", iotPlatform.Address) - err := tm.populateSensors(iotPlatform) + err := tm.populateSensors(iotPlatform, "3") + if err != nil { + log.Error("populateDevicesPerIotPlatforms: ", err) + continue + } + err = tm.populateSensors(iotPlatform, "28") if err != nil { log.Error("populateDevicesPerIotPlatforms: ", err) continue @@ -324,7 +333,7 @@ func (tm *SssMgr) populateDevicesPerIotPlatforms() error { * @param {string} iotPlatformId contains the IoT platform identifier * @return {struct} nil on success, error otherwise */ -func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo) error { +func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo, type_ string) error { if profiling { profilingTimers["populateSensors"] = time.Now() } @@ -348,7 +357,7 @@ func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo) error { // Build the queries queries := map[string]string{} queries["fu"] = "1" // Filter usage - queries["ty"] = "3" // FIXME FSCOM Filter on oneM2M CNT for sensors or on AE because AE if the platform and CNT is a sensor and CIN the values + queries["ty"] = type_ ctx.queries = queries err, resp := protocol.send(ctx) @@ -375,12 +384,12 @@ func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo) error { ctx.queries["fu"] = "2" err, resp := protocol.send(ctx) if err != nil { - log.Error("OneM2M_create: ", err.Error()) + log.Error("populateSensors: ", err.Error()) continue } log.Debug("populateSensors: resp: ", resp) log.Debug("populateSensors: type(resp): ", reflect.TypeOf(resp)) - if resp.(map[string]interface{}) == nil || resp.(map[string]interface{})["m2m:cnt"] == nil { + if resp.(map[string]interface{}) == nil { continue } // oneM2M_cin := resp.(map[string]interface{})["m2m:cnt"].(map[string]interface{}) @@ -390,6 +399,11 @@ func (tm *SssMgr) populateSensors(iotPlatformInfo IotPlatformInfo) error { var sensor = SensorDiscoveryInfo{ IotPlatformId: iotPlatformInfo.IotPlatformId, } + if type_ == "28" { + sensor.SensorType = "FLX" + sensor.Flex = map[string]interface{}{} // FIXME FSCOM How to create flex container map from list of attributes recieved? Q&D: extract all attributes != attributes[AE/CNT/CNI]??? + // ==> Use cnd which contains the link to download the onthology or the reference to the oneM2M standard + } sensor, err = tm.oneM2M_deserialize(sensor, resp.(map[string]interface{})) if err != nil { log.Warn("populateSensors: ", err.Error()) @@ -468,6 +482,38 @@ func (tm *SssMgr) OneM2M_create(sensor SensorDiscoveryInfo, path string) (sensor bodyMap["m2m:cin"][val.CharacteristicName] = val.CharacteristicValue } // End of 'for' statement } + } else if sensor.SensorType == "FLX" { + // Sanity checks + if sensor.Flex == nil { + err = errors.New("flex parameter shall be present") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } else if _, ok := sensor.Flex["type"]; !ok { + err = errors.New("'type' entry is required") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } else if _, ok := sensor.Flex["type"].(string); !ok { + err = errors.New("'type' entry is required") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } else if _, ok := sensor.Flex["cnd"]; !ok { + err = errors.New("'cnd' entry is required") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } else if _, ok := sensor.Flex["cnd"].(string); !ok { + err = errors.New("'cnd' entry is required") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } + k := sensor.Flex["type"].(string) + bodyMap[k] = make(map[string]interface{}, 0) + bodyMap[k]["rn"] = sensor.SensorIdentifier + for i, v := range sensor.Flex { + if i == "type" { + continue // skip it + } + bodyMap[k][i] = v + } // End of 'for' statement } else { err = errors.New("OneM2M_create: Invalid type") log.Error("OneM2M_create: ", err.Error()) @@ -496,6 +542,8 @@ func (tm *SssMgr) OneM2M_create(sensor SensorDiscoveryInfo, path string) (sensor ctx.ty = 3 } else if sensor.SensorType == "CIN" { ctx.ty = 4 + } else if sensor.SensorType == "FLX" { + ctx.ty = 28 } else { err = errors.New("OneM2M_create: Invalid type") log.Error("send: ", err.Error()) @@ -510,7 +558,13 @@ func (tm *SssMgr) OneM2M_create(sensor SensorDiscoveryInfo, path string) (sensor log.Debug("OneM2M_create: resp: ", resp) log.Debug("OneM2M_create: TypeOf(resp): ", reflect.TypeOf(resp)) if _, ok := resp.(map[string]interface{}); !ok { - log.Error("OneM2M_create: Interface not available") + err = errors.New("Interface not available") + log.Error("OneM2M_create: ", err.Error()) + return sensorResp, err + } + if val, ok := resp.(map[string]interface{})["m2m:dbg"]; ok { + err = errors.New(val.(string)) + log.Error("OneM2M_create: ", err.Error()) return sensorResp, err } @@ -519,6 +573,7 @@ func (tm *SssMgr) OneM2M_create(sensor SensorDiscoveryInfo, path string) (sensor sensorResp.SensorType = sensor.SensorType sensorResp.IotPlatformId = sensor.IotPlatformId sensorResp.SensorPosition = sensor.SensorPosition + sensorResp.Flex = sensor.Flex sensorResp, err = tm.oneM2M_deserialize(sensorResp, resp.(map[string]interface{})) if err != nil { log.Error("OneM2M_create: ", err.Error()) @@ -722,9 +777,13 @@ func (tm *SssMgr) OneM2M_subscribe(iotPlatformId string, path string) (subscript var bodyMap = map[string]map[string]interface{}{} bodyMap["m2m:sub"] = make(map[string]interface{}, 0) net := make(map[string][]int) - net["net"] = []int{2, 3, 4} + net["net"] = []int{1, 2, 3, 4} bodyMap["m2m:sub"]["enc"] = net - bodyMap["m2m:sub"]["nu"] = []string{"http://172.29.10.52:31122/"} // FIXME FSCOM The URI of the listener + if tm.bindingProtocol == "MQTT" { + bodyMap["m2m:sub"]["nu"] = []string{"mqtt://172.29.10.56:1883"} // FIXME FSCOM The URI of the listener + } else { + bodyMap["m2m:sub"]["nu"] = []string{"http://172.29.10.52:31122/"} // FIXME FSCOM The URI of the listener + } bodyMap["m2m:sub"]["rn"] = uuid.New().String() ctx.body = bodyMap @@ -759,7 +818,7 @@ func (tm *SssMgr) OneM2M_subscribe(iotPlatformId string, path string) (subscript log.Error("OneM2M_subscribe: ", err.Error()) return "", err } - log.Debug("OneM2M_cOneM2M_subscribereate: sensvorResp: ", v) + log.Debug("OneM2M_subscribe: v: ", v) subscriptionListPerSubId[subId] = v @@ -773,28 +832,28 @@ func (tm *SssMgr) OneM2M_subscribe(iotPlatformId string, path string) (subscript return subId, nil } -func (tm *SssMgr) OneM2M_Delete(sensor SensorDiscoveryInfo) (err error) { +func (tm *SssMgr) OneM2M_delete(sensor SensorDiscoveryInfo) (err error) { if profiling { - profilingTimers["OneM2M_Delete"] = time.Now() + profilingTimers["OneM2M_delete"] = time.Now() } - log.Info(">>> OneM2M_Delete: sensor=", sensor) + log.Info(">>> OneM2M_delete: sensor=", sensor) if sensor.SensorIdentifier == "" { - err = errors.New("OneM2M_Delete: Cannot find \"ri\" value") - log.Error("OneM2M_Delete: ", err.Error()) + err = errors.New("OneM2M_delete: Cannot find \"ri\" value") + log.Error("OneM2M_delete: ", err.Error()) return err } if sensor.IotPlatformId == "" { err = errors.New("IotPlatformId fiels shall be set") - log.Error("OneM2M_Delete: ", err.Error()) + log.Error("OneM2M_delete: ", err.Error()) return err } tm.wg.Wait() - log.Info("OneM2M_Delete: After Synchro") + log.Info("OneM2M_delete: After Synchro") // Send it and get the result var ctx = SssMgrBindingProtocolContext{ @@ -811,40 +870,40 @@ func (tm *SssMgr) OneM2M_Delete(sensor SensorDiscoveryInfo) (err error) { } err, _ = protocol.send(ctx) if err != nil { - log.Error("OneM2M_Delete: ", err.Error()) + log.Error("OneM2M_delete: ", err.Error()) return err } if profiling { now := time.Now() - log.Debug("OneM2M_Delete: ", now.Sub(profilingTimers["OneM2M_Delete"])) + log.Debug("OneM2M_delete: ", now.Sub(profilingTimers["OneM2M_delete"])) } return nil } -func (tm *SssMgr) OneM2M_DeleteSub(subId string) (err error) { +func (tm *SssMgr) OneM2M_delete_subscription(subId string) (err error) { if profiling { - profilingTimers["OneM2M_DeleteSub"] = time.Now() + profilingTimers["OneM2M_delete_subscription"] = time.Now() } - log.Info(">>> OneM2M_DeleteSub: sensor=", subId) + log.Info(">>> OneM2M_delete_subscription: sensor=", subId) if subId == "" { err = errors.New("subId fiels shall be set") - log.Error("OneM2M_DeleteSub: ", err.Error()) + log.Error("OneM2M_delete_subscription: ", err.Error()) return err } if _, ok := subscriptionListPerSubId[subId]; !ok { err = errors.New("Unkmown subscription identifier") - log.Error("OneM2M_DeleteSub: ", err.Error()) + log.Error("OneM2M_delete_subscription: ", err.Error()) return err } tm.wg.Wait() - log.Info("OneM2M_DeleteSub: After Synchro") + log.Info("OneM2M_delete_subscription: After Synchro") // Send it and get the result var ctx = SssMgrBindingProtocolContext{ @@ -861,16 +920,16 @@ func (tm *SssMgr) OneM2M_DeleteSub(subId string) (err error) { } err, _ = protocol.send(ctx) if err != nil { - log.Error("OneM2M_DeleteSub: ", err.Error()) + log.Error("OneM2M_delete_subscription: ", err.Error()) return err } delete(subscriptionListPerSubId, subId) - log.Info("OneM2M_DeleteSub: New subscriptionListPerSubId: ", subscriptionListPerSubId) + log.Info("OneM2M_delete_subscription: New subscriptionListPerSubId: ", subscriptionListPerSubId) if profiling { now := time.Now() - log.Debug("OneM2M_DeleteSub: ", now.Sub(profilingTimers["OneM2M_DeleteSub"])) + log.Debug("OneM2M_delete_subscription: ", now.Sub(profilingTimers["OneM2M_delete_subscription"])) } return nil @@ -889,7 +948,7 @@ func (tm *SssMgr) notify(sub map[string]interface{}) { return } if _, ok := sub["nev"].(map[string]interface{}); !ok { - log.Warn("notify: nev entry has unexpected type") + log.Warn("notify: nev entry has an unexpected type") return } if _, ok := sub["sur"]; !ok { @@ -947,10 +1006,35 @@ func (tm *SssMgr) notify(sub map[string]interface{}) { } func (tm *SssMgr) oneM2M_deserialize(sensor SensorDiscoveryInfo, response map[string]interface{}) (sensorResp SensorDiscoveryInfo, err error) { + log.Debug(">>> oneM2M_deserialize: sensor: ", sensor) log.Debug(">>> oneM2M_deserialize: response: ", response) sensorResp = sensor // Same data structure + if sensor.SensorType == "FLX" { // Extract flex specific attributes first + // Sanity checks + if sensor.Flex == nil { + err = errors.New("Wrong 'flex' parameter value") + log.Error("oneM2M_deserialize: ", err.Error()) + return sensorResp, err + } + log.Debug("oneM2M_deserialize: Extract flex specific attributes first") + sensorResp.Flex = make(map[string]interface{}) + s := sensor.Flex["type"].(string) + log.Debug("oneM2M_deserialize: s=", s) + log.Debug("oneM2M_deserialize: response[s]: ", response[s]) + for k, v := range sensor.Flex { + log.Debug("oneM2M_deserialize: Processing k= ", k, ", v= ", v) + if e, ok := response[s].(map[string]interface{})[k]; ok { + log.Debug("oneM2M_deserialize: ", k, " is a flex attribute: ", v) + sensorResp.Flex[k] = e + delete(response[s].(map[string]interface{}), k) + } + } // End of 'for' statement + sensorResp.Flex["type"] = s + log.Debug("oneM2M_deserialize: sensorResp.Flex: ", sensorResp.Flex) + } + for i, m := range response { log.Debug("==> ", i, " value is ", m) if _, ok := m.(map[string]interface{}); !ok { diff --git a/go-packages/meep-sss-mgr/onem2m-mgr_test.go b/go-packages/meep-sss-mgr/onem2m-mgr_test.go index e3b43d099c1ca495f0b170e9c7d95d53541f552e..254dfdcc278990be21060e04263b4b9ebeb2f65e 100644 --- a/go-packages/meep-sss-mgr/onem2m-mgr_test.go +++ b/go-packages/meep-sss-mgr/onem2m-mgr_test.go @@ -20,7 +20,7 @@ import ( "fmt" "reflect" "testing" - "time" + //"time" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" ) @@ -34,15 +34,15 @@ const tmNamespace = "sandboxtest" // // Invalid Connector // fmt.Println("Invalid SSS Asset Manager") -// tm, err := NewSssMgr("", tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr("", tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err == nil || tm != nil { // t.Fatalf("Service name not set") // } -// tm, err = NewSssMgr(tmName, tmNamespace, "", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err = NewSssMgr(tmName, tmNamespace, "", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err == nil || tm != nil { // t.Fatalf("Binding protocol not set") // } -// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err == nil || tm != nil { // t.Fatalf("Host not set") // } @@ -50,14 +50,14 @@ const tmNamespace = "sandboxtest" // if err == nil || tm != nil { // t.Fatalf("Host id not set") // } -// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "", nil, nil, nil) +// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "", nil, nil, nil) // if err == nil || tm != nil { // t.Fatalf("CSE name not set") // } // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err = NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -69,7 +69,7 @@ const tmNamespace = "sandboxtest" // tm = nil // fmt.Println("Create valid SSS Asset Manager") -// tm, err = NewSssMgr(tmName, tmNamespace, "REST_HTTP", "172.29.10.56", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err = NewSssMgr(tmName, tmNamespace, "REST_HTTP", "172.29.10.56", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -87,7 +87,7 @@ const tmNamespace = "sandboxtest" // log.MeepTextLogInit(t.Name()) // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -110,7 +110,7 @@ const tmNamespace = "sandboxtest" // log.MeepTextLogInit(t.Name()) // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "", 0, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "", 0, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -136,7 +136,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -170,7 +170,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -179,7 +179,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "12345", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor, err := tm.OneM2M_create(sensor, "") // if err != nil { @@ -191,7 +191,7 @@ const tmNamespace = "sandboxtest" // t.Fatalf("Failed to validate AE content") // } -// _ = tm.OneM2M_Delete(new_sensor) +// _ = tm.OneM2M_delete(new_sensor) // // Cleanup // err = tm.DeleteSssMgr() @@ -207,7 +207,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -216,7 +216,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "CMyAE", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor_ae, err := tm.OneM2M_create(sensor_ae, "") // if err != nil { @@ -232,7 +232,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "CMyCNT", // SensorType: "CNT", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // // sensor_cnt.SensorCharacteristicList = make([]SensorCharacteristic, 1) // // sensor_cnt.SensorCharacteristicList[0] = SensorCharacteristic{CharacteristicName: "con", CharacteristicValue: "OFF"} @@ -244,14 +244,14 @@ const tmNamespace = "sandboxtest" // // Verify content // if !validate_sensor_cnt(sensor_cnt, new_sensor_cnt) { -// t.Fatalf("Failed to validate AE content") +// t.Fatalf("Failed to validate CNT content") // } -// err = tm.OneM2M_Delete(new_sensor_cnt) +// err = tm.OneM2M_delete(new_sensor_cnt) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_ae) +// err = tm.OneM2M_delete(new_sensor_ae) // if err != nil { // t.Fatalf("Failed to create new sensor") // } @@ -264,13 +264,87 @@ const tmNamespace = "sandboxtest" // tm = nil // } +func TestOneM2M_createAE_FLEXHttp(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + // Valid Connector + fmt.Println("Create valid SSS Asset Manager") + tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) + if err != nil || tm == nil { + t.Fatalf("Failed to create SSS Asset Manager") + } + + var sensor_ae = SensorDiscoveryInfo{ + SensorIdentifier: "CMyAE", + SensorType: "AE", + SensorPosition: nil, + IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", + } + new_sensor_ae, err := tm.OneM2M_create(sensor_ae, "") + if err != nil { + t.Fatalf("Failed to create new AE sensor") + } + + // Verify content + if !validate_sensor_ae(sensor_ae, new_sensor_ae) { + t.Fatalf("Failed to validate AE content") + } + + var sensor_flex = SensorDiscoveryInfo{ + SensorIdentifier: "CMyFLX", + SensorType: "FLX", + SensorPosition: nil, + IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", + } + sensor_flex.Flex = make(map[string]interface{}, 0) + sensor_flex.Flex["type"] = "cod:color" + sensor_flex.Flex["cnd"] = "org.onem2m.common.moduleclass.colour" + sensor_flex.Flex["red"] = 20 + sensor_flex.Flex["green"] = 20 + sensor_flex.Flex["blue"] = 20 + sensorPath := new_sensor_ae.SensorIdentifier + new_sensor_flex, err := tm.OneM2M_create(sensor_flex, sensorPath) + if err != nil { + t.Fatalf("Failed to create new CNT sensor") + } + + // Verify content + if !validate_sensor_flex(sensor_flex, new_sensor_flex) { + t.Fatalf("Failed to validate FLEX content") + } + + sensors, err := tm.SensorDiscoveryInfoAll() + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("len=", len(sensors)) + fmt.Println("sensors", sensors) + + err = tm.OneM2M_delete(new_sensor_flex) + if err != nil { + t.Fatalf("Failed to create new sensor") + } + err = tm.OneM2M_delete(new_sensor_ae) + if err != nil { + t.Fatalf("Failed to create new sensor") + } + + // Cleanup + err = tm.DeleteSssMgr() + if err != nil { + t.Fatalf("Failed to cleanup SSS Asset Manager") + } + tm = nil +} + // func TestOneM2M_createAE_CNT_CNIHttp(t *testing.T) { // fmt.Println("--- ", t.Name()) // log.MeepTextLogInit(t.Name()) // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -279,7 +353,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "CMyAE", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor_ae, err := tm.OneM2M_create(sensor_ae, "") // if err != nil { @@ -295,7 +369,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "CMyCNT", // SensorType: "CNT", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensorPath := new_sensor_ae.SensorIdentifier // new_sensor_cnt, err := tm.OneM2M_create(sensor_cnt, sensorPath) @@ -312,7 +386,7 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "CMyCNI", // SensorType: "CIN", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensor_cin.SensorCharacteristicList = make([]SensorCharacteristic, 1) // sensor_cin.SensorCharacteristicList[0] = SensorCharacteristic{CharacteristicName: "con", CharacteristicValue: "OFF"} @@ -327,15 +401,15 @@ const tmNamespace = "sandboxtest" // t.Fatalf("Failed to validate CIN content") // } -// err = tm.OneM2M_Delete(new_sensor_cin) +// err = tm.OneM2M_delete(new_sensor_cin) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_cnt) +// err = tm.OneM2M_delete(new_sensor_cnt) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_ae) +// err = tm.OneM2M_delete(new_sensor_ae) // if err != nil { // t.Fatalf("Failed to create new sensor") // } @@ -354,7 +428,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -363,14 +437,14 @@ const tmNamespace = "sandboxtest" // SensorIdentifier: "12345", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensor, err := oneM2M_create(tm, new_sensor, "") // if err != nil { // t.Fatalf("Failed to create new sensor: " + err.Error()) // } -// err = tm.OneM2M_Delete(sensor) +// err = tm.OneM2M_delete(sensor) // if err != nil { // t.Fatalf("Failed to create new sensor: " + err.Error()) // } @@ -389,7 +463,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -423,9 +497,9 @@ const tmNamespace = "sandboxtest" // t.Fatalf("Failed to validate CIN content") // } -// _ = tm.OneM2M_Delete(received_sensors["CIN"]) -// _ = tm.OneM2M_Delete(received_sensors["CNT"]) -// _ = tm.OneM2M_Delete(received_sensors["AE"]) +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) // // Cleanup // err = tm.DeleteSssMgr() @@ -441,7 +515,7 @@ const tmNamespace = "sandboxtest" // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -482,9 +556,9 @@ const tmNamespace = "sandboxtest" // t.Fatalf("Failed to validate AE content") // } -// _ = tm.OneM2M_Delete(received_sensors["CIN"]) -// _ = tm.OneM2M_Delete(received_sensors["CNT"]) -// _ = tm.OneM2M_Delete(received_sensors["AE"]) +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) // // Cleanup // err = tm.DeleteSssMgr() @@ -494,67 +568,67 @@ const tmNamespace = "sandboxtest" // tm = nil // } -func TestOneM2M_subscribeHttp(t *testing.T) { - fmt.Println("--- ", t.Name()) - log.MeepTextLogInit(t.Name()) +// func TestOneM2M_subscribeHttp(t *testing.T) { +// fmt.Println("--- ", t.Name()) +// log.MeepTextLogInit(t.Name()) - // Valid Connector - fmt.Println("Create valid SSS Asset Manager") - tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "7feaadbb0400", "laboai-acme-ic-cse", discoveryNotify, statusNotify, dataNotify) - if err != nil || tm == nil { - t.Fatalf("Failed to create SSS Asset Manager") - } +// // Valid Connector +// fmt.Println("Create valid SSS Asset Manager") +// tm, err := NewSssMgr(tmName, tmNamespace, "REST_HTTP", "lab-oai.etsi.org", 31110, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", discoveryNotify, statusNotify, dataNotify) +// if err != nil || tm == nil { +// t.Fatalf("Failed to create SSS Asset Manager") +// } - _, received_sensors, err := oneM2M_createAE_CNT_CIN(tm) - if err != nil { - t.Fatalf("Failed to create sensors") - } +// _, received_sensors, err := oneM2M_createAE_CNT_CIN(tm) +// if err != nil { +// t.Fatalf("Failed to create sensors") +// } - subscriptionMap := make(map[string]interface{}) - subId, err := tm.OneM2M_subscribe(received_sensors["AE"].IotPlatformId, received_sensors["AE"].SensorIdentifier) - if err != nil { - t.Fatalf("Failed to subscribe") - } - fmt.Println("subId=" + subId) - subscriptionMap[subId] = received_sensors["AE"] +// subscriptionMap := make(map[string]interface{}) +// subId, err := tm.OneM2M_subscribe(received_sensors["AE"].IotPlatformId, received_sensors["AE"].SensorIdentifier) +// if err != nil { +// t.Fatalf("Failed to subscribe") +// } +// fmt.Println("subId=" + subId) +// subscriptionMap[subId] = received_sensors["AE"] - subId, err = tm.OneM2M_subscribe(received_sensors["CNT"].IotPlatformId, received_sensors["CNT"].SensorIdentifier) - if err != nil { - t.Fatalf("Failed to subscribe") - } - fmt.Println("subId=" + subId) - subscriptionMap[subId] = received_sensors["CNT"] +// subId, err = tm.OneM2M_subscribe(received_sensors["CNT"].IotPlatformId, received_sensors["CNT"].SensorIdentifier) +// if err != nil { +// t.Fatalf("Failed to subscribe") +// } +// fmt.Println("subId=" + subId) +// subscriptionMap[subId] = received_sensors["CNT"] - fmt.Println("len(subscriptionMap)=" + fmt.Sprint(len(subscriptionMap))) +// fmt.Println("len(subscriptionMap)=" + fmt.Sprint(len(subscriptionMap))) - fmt.Println("You have 120 seconds to trigger subscriptions") - time.Sleep(time.Duration(120) * time.Second) +// fmt.Println("You have 120 seconds to trigger subscriptions") +// time.Sleep(time.Duration(120) * time.Second) - for k := range subscriptionMap { - err = tm.OneM2M_DeleteSub(k) - if err != nil { - t.Fatalf("Failed to cancel subscription") - } - } // End of 'for' statement +// for k := range subscriptionMap { +// err = tm.OneM2M_delete_subscription(k) +// if err != nil { +// t.Fatalf("Failed to cancel subscription") +// } +// } // End of 'for' statement - _ = tm.OneM2M_Delete(received_sensors["CIN"]) - _ = tm.OneM2M_Delete(received_sensors["CNT"]) - _ = tm.OneM2M_Delete(received_sensors["AE"]) +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) - // Cleanup - err = tm.DeleteSssMgr() - if err != nil { - t.Fatalf("Failed to cleanup SSS Asset Manager") - } - tm = nil -} +// // Cleanup +// err = tm.DeleteSssMgr() +// if err != nil { +// t.Fatalf("Failed to cleanup SSS Asset Manager") +// } +// tm = nil +// } // func TestPopulateDevicesPerIotPlatformsMqtt(t *testing.T) { // fmt.Println("--- ", t.Name()) // log.MeepTextLogInit(t.Name()) // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -576,7 +650,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -605,7 +679,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -639,7 +713,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -648,7 +722,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "12345", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor, err := tm.OneM2M_create(sensor, "") // if err != nil { @@ -660,7 +734,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // t.Fatalf("Failed to validate AE content") // } -// _ = tm.OneM2M_Delete(new_sensor) +// _ = tm.OneM2M_delete(new_sensor) // // Cleanup // err = tm.DeleteSssMgr() @@ -676,7 +750,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -685,7 +759,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "CMyAE", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor_ae, err := tm.OneM2M_create(sensor_ae, "") // if err != nil { @@ -701,7 +775,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "CMyCNT", // SensorType: "CNT", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // // sensor_cnt.SensorCharacteristicList = make([]SensorCharacteristic, 1) // // sensor_cnt.SensorCharacteristicList[0] = SensorCharacteristic{CharacteristicName: "con", CharacteristicValue: "OFF"} @@ -716,11 +790,11 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // t.Fatalf("Failed to validate CNT content") // } -// err = tm.OneM2M_Delete(new_sensor_cnt) +// err = tm.OneM2M_delete(new_sensor_cnt) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_ae) +// err = tm.OneM2M_delete(new_sensor_ae) // if err != nil { // t.Fatalf("Failed to create new sensor") // } @@ -739,7 +813,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -748,7 +822,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "CMyAE", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // new_sensor_ae, err := tm.OneM2M_create(sensor_ae, "") // if err != nil { @@ -764,7 +838,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "CMyCNT", // SensorType: "CNT", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensorPath := new_sensor_ae.SensorIdentifier // new_sensor_cnt, err := tm.OneM2M_create(sensor_cnt, sensorPath) @@ -781,7 +855,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "CMyCNI", // SensorType: "CIN", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensor_cin.SensorCharacteristicList = make([]SensorCharacteristic, 1) // sensor_cin.SensorCharacteristicList[0] = SensorCharacteristic{CharacteristicName: "con", CharacteristicValue: "OFF"} @@ -800,15 +874,15 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // t.Fatalf("received_sensor.SensorCharacteristicList shall not be empty") // } -// err = tm.OneM2M_Delete(new_sensor_cin) +// err = tm.OneM2M_delete(new_sensor_cin) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_cnt) +// err = tm.OneM2M_delete(new_sensor_cnt) // if err != nil { // t.Fatalf("Failed to create new sensor") // } -// err = tm.OneM2M_Delete(new_sensor_ae) +// err = tm.OneM2M_delete(new_sensor_ae) // if err != nil { // t.Fatalf("Failed to create new sensor") // } @@ -827,7 +901,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -836,14 +910,14 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // SensorIdentifier: "12345", // SensorType: "AE", // SensorPosition: nil, -// IotPlatformId: "7feaadbb0400", +// IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", // } // sensor, err := oneM2M_create(tm, new_sensor, "") // if err != nil { // t.Fatalf("Failed to create new sensor: " + err.Error()) // } -// err = tm.OneM2M_Delete(sensor) +// err = tm.OneM2M_delete(sensor) // if err != nil { // t.Fatalf("Failed to create new sensor: " + err.Error()) // } @@ -862,7 +936,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -896,9 +970,9 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // t.Fatalf("Failed to validate CIN content") // } -// _ = tm.OneM2M_Delete(received_sensors["CIN"]) -// _ = tm.OneM2M_Delete(received_sensors["CNT"]) -// _ = tm.OneM2M_Delete(received_sensors["AE"]) +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) // // Cleanup // err = tm.DeleteSssMgr() @@ -914,7 +988,7 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", nil, nil, nil) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } @@ -955,9 +1029,9 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // t.Fatalf("Failed to validate AE content") // } -// _ = tm.OneM2M_Delete(received_sensors["CIN"]) -// _ = tm.OneM2M_Delete(received_sensors["CNT"]) -// _ = tm.OneM2M_Delete(received_sensors["AE"]) +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) // // Cleanup // err = tm.DeleteSssMgr() @@ -966,26 +1040,59 @@ func TestOneM2M_subscribeHttp(t *testing.T) { // } // tm = nil // } - -// func TestVaidateOneM2MNotificationServer(t *testing.T) { +// func TestOneM2M_subscribeMQTT(t *testing.T) { // fmt.Println("--- ", t.Name()) // log.MeepTextLogInit(t.Name()) // // Valid Connector // fmt.Println("Create valid SSS Asset Manager") -// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "MQTT", "172.29.10.56", 1883, "7feaadbb0400", "laboai-acme-ic-cse", nil, nil, nil) +// tm, err := NewSssMgr(tmName, tmNamespace, "MQTT", "172.29.10.56", 1883, "0a692154-0f93-11f0-b554-df2f6a756f6a", "laboai-acme-ic-cse", discoveryNotify, statusNotify, dataNotify) // if err != nil || tm == nil { // t.Fatalf("Failed to create SSS Asset Manager") // } -// tm.init() -// fmt.Println("Waiting for 2 minutes to do curl request: curl -v http://mec-platform.etsi.org:31122/sbxykqjr17/mep1/sens/v1 ") +// _, received_sensors, err := oneM2M_createAE_CNT_CIN(tm) +// if err != nil { +// t.Fatalf("Failed to create sensors") +// } + +// subscriptionMap := make(map[string]interface{}) +// subId, err := tm.OneM2M_subscribe(received_sensors["AE"].IotPlatformId, received_sensors["AE"].SensorIdentifier) +// if err != nil { +// t.Fatalf("Failed to subscribe") +// } +// fmt.Println("subId=" + subId) +// subscriptionMap[subId] = received_sensors["AE"] + +// subId, err = tm.OneM2M_subscribe(received_sensors["CNT"].IotPlatformId, received_sensors["CNT"].SensorIdentifier) +// if err != nil { +// t.Fatalf("Failed to subscribe") +// } +// fmt.Println("subId=" + subId) +// subscriptionMap[subId] = received_sensors["CNT"] + +// fmt.Println("len(subscriptionMap)=" + fmt.Sprint(len(subscriptionMap))) + +// fmt.Println("You have 120 seconds to trigger subscriptions") +// time.Sleep(time.Duration(120) * time.Second) + +// for k := range subscriptionMap { +// err = tm.OneM2M_delete_subscription(k) +// if err != nil { +// t.Fatalf("Failed to cancel subscription") +// } +// } // End of 'for' statement + +// _ = tm.OneM2M_delete(received_sensors["CIN"]) +// _ = tm.OneM2M_delete(received_sensors["CNT"]) +// _ = tm.OneM2M_delete(received_sensors["AE"]) // // Cleanup // err = tm.DeleteSssMgr() // if err != nil { // t.Fatalf("Failed to cleanup SSS Asset Manager") // } +// tm = nil // } func oneM2M_create(tm *SssMgr, sensor SensorDiscoveryInfo, path string) (sensorResp SensorDiscoveryInfo, err error) { @@ -1005,7 +1112,7 @@ func oneM2M_createAE_CNT_CIN(tm *SssMgr) (sensors map[string]SensorDiscoveryInfo SensorIdentifier: "CMyAE", SensorType: "AE", SensorPosition: nil, - IotPlatformId: "7feaadbb0400", + IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", } sensors[sensor_ae.SensorType] = sensor_ae new_sensor_ae, err := oneM2M_create(tm, sensor_ae, "") @@ -1018,7 +1125,7 @@ func oneM2M_createAE_CNT_CIN(tm *SssMgr) (sensors map[string]SensorDiscoveryInfo SensorIdentifier: "CMyCNT", SensorType: "CNT", SensorPosition: nil, - IotPlatformId: "7feaadbb0400", + IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", } sensorPath := new_sensor_ae.SensorIdentifier sensors[sensor_cnt.SensorType] = sensor_cnt @@ -1032,7 +1139,7 @@ func oneM2M_createAE_CNT_CIN(tm *SssMgr) (sensors map[string]SensorDiscoveryInfo SensorIdentifier: "CMyCNI", SensorType: "CIN", SensorPosition: nil, - IotPlatformId: "7feaadbb0400", + IotPlatformId: "0a692154-0f93-11f0-b554-df2f6a756f6a", } sensor_cin.SensorCharacteristicList = make([]SensorCharacteristic, 1) sensor_cin.SensorCharacteristicList[0] = SensorCharacteristic{CharacteristicName: "con", CharacteristicValue: "OFF"} @@ -1122,7 +1229,7 @@ func validate_sensor_cnt(expected_sensor SensorDiscoveryInfo, received_sensor Se fmt.Println(">>> validate_sensor_cnt: received_sensor: ", received_sensor) if received_sensor.SensorIdentifier == "" { - fmt.Println("validate_sensor_ae.SensorIdentifier shall be set") + fmt.Println("validate_sensor_cnt.SensorIdentifier shall be set") return false } if received_sensor.SensorType != received_sensor.SensorType { @@ -1207,6 +1314,39 @@ func validate_sensor_cin(expected_sensor SensorDiscoveryInfo, received_sensor Se return true } +func validate_sensor_flex(expected_sensor SensorDiscoveryInfo, received_sensor SensorDiscoveryInfo) bool { + fmt.Println(">>> validate_sensor_flex: expected_sensor: ", expected_sensor) + fmt.Println(">>> validate_sensor_flex: received_sensor: ", received_sensor) + + if received_sensor.SensorIdentifier == "" { + fmt.Println("validate_sensor_flex.SensorIdentifier shall be set") + return false + } + if received_sensor.SensorType != received_sensor.SensorType { + fmt.Println("validate_sensor_flex.SensorType != SensorType") + return false + } + if received_sensor.IotPlatformId != expected_sensor.IotPlatformId { + fmt.Println("validate_sensor_flex.IotPlatformId != IotPlatformId") + return false + } + if expected_sensor.Flex == nil || received_sensor.Flex == nil { + fmt.Println("validate_sensor_flex.Flex != Flex") + return false + } else if len(expected_sensor.Flex) != len(received_sensor.Flex) { + fmt.Println("len(validate_sensor_flex.Flex) != len(Flex)") + return false + } else if expected_sensor.Flex["type"] != received_sensor.Flex["type"] { + fmt.Println("validate_sensor_flex.Flex[type] != Flex[type]") + return false + } else if expected_sensor.Flex["cnd"] != received_sensor.Flex["cnd"] { + fmt.Println("validate_sensor_flex.Flex[cnd] != Flex[cnd]") + return false + } + + return true +} + func discoveryNotify(map[string]interface{}) { log.Debug(">>> discoveryNotify") diff --git a/go-packages/meep-vis-traffic-mgr/mqtt.go b/go-packages/meep-vis-traffic-mgr/mqtt.go index 07cec8eb26404ed432a676af8b86f6b6bb4269ee..43c6832ad960a7e29797b014563533b986c28711 100644 --- a/go-packages/meep-vis-traffic-mgr/mqtt.go +++ b/go-packages/meep-vis-traffic-mgr/mqtt.go @@ -43,7 +43,7 @@ func onMessageReceived(client mqtt.Client, msg mqtt.Message) { _v2x_notify(msg.Payload(), 16, 2, "ETSI", nil, nil) } } else { - log.Info("onMessageReceived: null pointer for the callbacl") + log.Info("onMessageReceived: null pointer for the callback") } }() }