x2_reset_response.go was added
Change-Id: Iab4806ab29e6edf902e7bdfe98af3a2fdc8d7e10
Signed-off-by: irina <ib565x@intl.att.com>
diff --git a/E2Manager/e2pdus/x2_reset_response.go b/E2Manager/e2pdus/x2_reset_response.go
new file mode 100644
index 0000000..19c6a67
--- /dev/null
+++ b/E2Manager/e2pdus/x2_reset_response.go
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *******************************************************************************/
+ package e2pdus
+
+// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/
+// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
+// #include <x2reset_response_wrapper.h>
+import "C"
+import (
+ "fmt"
+ "unsafe"
+)
+
+var PackedX2ResetResponse []byte
+
+func prepareX2ResetResponsePDU(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int) error {
+
+ packedBuffer := make([]C.uchar, maxAsn1PackedBufferSize)
+ errorBuffer := make([]C.char, maxAsn1CodecMessageBufferSize)
+ var payloadSize = C.ulong(maxAsn1PackedBufferSize)
+
+ if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(maxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
+ return fmt.Errorf("#reset_response.prepareX2ResetResponsePDU - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0]))
+
+ }
+ PackedX2ResetResponse = C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
+
+ return nil
+}
+
+func init() {
+ if err := prepareX2ResetResponsePDU(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize); err != nil {
+ panic(err)
+ }
+}
diff --git a/E2Manager/e2pdus/x2_reset_response_test.go b/E2Manager/e2pdus/x2_reset_response_test.go
new file mode 100644
index 0000000..2463502
--- /dev/null
+++ b/E2Manager/e2pdus/x2_reset_response_test.go
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *******************************************************************************/
+package e2pdus
+
+import (
+ "e2mgr/logger"
+ "fmt"
+ "strings"
+ "testing"
+)
+
+func TestPrepareX2ResetResponsePDU(t *testing.T) {
+ _,err := logger.InitLogger(logger.InfoLevel)
+ if err!=nil{
+ t.Errorf("failed to initialize logger, error: %s", err)
+ }
+ packedPdu := "200700080000010011400100"
+ packedX2ResetResponse := PackedX2ResetResponse
+
+ tmp := fmt.Sprintf("%x", packedX2ResetResponse)
+ if len(tmp) != len(packedPdu) {
+ t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2ResetResponse)/2)
+ }
+
+ if strings.Compare(tmp, packedPdu) != 0 {
+ t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
+ }
+}
+
+func TestPrepareX2ResetResponsePDUFailure(t *testing.T) {
+ _, err := logger.InitLogger(logger.InfoLevel)
+ if err != nil {
+ t.Errorf("failed to initialize logger, error: %s", err)
+ }
+
+ err = prepareX2ResetResponsePDU(1, 4096)
+ if err == nil {
+ t.Errorf("want: error, got: success.\n")
+ }
+
+ expected:= "#reset_response.prepareX2ResetResponsePDU - failed to build and pack the reset response message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
+ if !strings.Contains(err.Error(), expected) {
+ t.Errorf("want :[%s], got: [%s]\n", expected, err)
+ }
+}
\ No newline at end of file
diff --git a/E2Manager/handlers/x2_reset_request_notification_handler.go b/E2Manager/handlers/x2_reset_request_notification_handler.go
index 3a68755..28a50e5 100644
--- a/E2Manager/handlers/x2_reset_request_notification_handler.go
+++ b/E2Manager/handlers/x2_reset_request_notification_handler.go
@@ -17,19 +17,14 @@
package handlers
-// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/
-// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
-// #include <asn1codec_utils.h>
-// #include <x2reset_response_wrapper.h>
-import "C"
import (
+ "e2mgr/e2pdus"
"e2mgr/logger"
"e2mgr/models"
"e2mgr/rmrCgo"
"e2mgr/sessions"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
- "unsafe"
)
type X2ResetRequestNotificationHandler struct {
@@ -69,24 +64,9 @@
return
}
- src.createAndAddToChannel(logger, request, messageChannel)
+ response := models.NotificationResponse{RanName: request.RanName, Payload: e2pdus.PackedX2ResetResponse, MgsType: rmrCgo.RIC_X2_RESET_RESP}
+ messageChannel <- &response
//TODO change name of printHandlingSetupResponseElapsedTimeInMs (remove setup response) and move to utils?
printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime)
-}
-
-func (src X2ResetRequestNotificationHandler) createAndAddToChannel(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
-
- packedBuffer := make([]C.uchar, MaxAsn1PackedBufferSize)
- errorBuffer := make([]C.char, MaxAsn1CodecMessageBufferSize)
- var payloadSize = C.ulong(MaxAsn1PackedBufferSize)
-
- if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(MaxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status {
- logger.Errorf("#X2ResetRequestNotificationHandler.createAndAddToChannel - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0]))
- return
- }
- payload := C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize))
- response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_X2_RESET_RESP}
-
- messageChannel <- &response
-}
+}
\ No newline at end of file