ASN.1 debug printouts hided by default 31/7031/1
authorAnssi Mannila <anssi.mannila@nokia.com>
Wed, 10 Nov 2021 11:10:54 +0000 (13:10 +0200)
committerAnssi Mannila <anssi.mannila@nokia.com>
Wed, 10 Nov 2021 11:13:36 +0000 (13:13 +0200)
 - ASN.1 debug printouts are made now on logger level >= 4

Change-Id: I2b3072825c16742c1cea9a8b1612d65c53b1bd3a
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
e2ap/libe2ap_wrapper/E2AP_if.c
e2ap/libe2ap_wrapper/E2AP_if.h
e2ap/pkg/e2ap_wrapper/packer_e2ap.go
pkg/control/control.go
pkg/control/e2ap.go
pkg/control/ut_ctrl_submgr_test.go

index 8686908..fe0d5d5 100644 (file)
 #include "asn_constant.h"
 #include "E2AP_if.h"
 
-
-#ifdef DEBUG
-    static const bool debug = true;
-#else
-    static const bool debug = true; //false;
-#endif
+static bool debugPrints = false;
 
 const int64_t cMaxNrOfErrors = 256;
 const uint64_t cMaxSizeOfOctetString = 1024;
@@ -74,6 +69,11 @@ typedef union {
     uint8_t   octets[4];
 } IdOctects_t;
 
+//////////////////////////////////////////////////////////////////////
+void allowASN1DebugPrints(bool allowASN1DebugPrints) {
+    debugPrints = allowASN1DebugPrints;
+}
+
 //////////////////////////////////////////////////////////////////////
 const char* getE2ErrorString(uint64_t errorCode) {
 
@@ -83,8 +83,7 @@ const char* getE2ErrorString(uint64_t errorCode) {
 /////////////////////////////////////////////////////////////////////
 bool E2encode(E2AP_PDU_t* pE2AP_PDU, size_t* dataBufferSize, byte* dataBuffer, char* pLogBuffer) {
 
-    // Debug print
-    if (debug)
+    if (debugPrints)
         asn_fprint(stdout, &asn_DEF_E2AP_PDU, pE2AP_PDU);
 
     asn_enc_rval_t rval;
@@ -100,7 +99,7 @@ bool E2encode(E2AP_PDU_t* pE2AP_PDU, size_t* dataBufferSize, byte* dataBuffer, c
         return false;
     }
     else {
-        if (debug)
+        if (debugPrints)
             sprintf(pLogBuffer,"Successfully encoded %s. Buffer size %zu, encoded size %zu",asn_DEF_E2AP_PDU.name, *dataBufferSize, rval.encoded);
 
         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
@@ -653,8 +652,7 @@ e2ap_pdu_ptr_t* unpackE2AP_pdu(const size_t dataBufferSize, const byte* dataBuff
     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **)&pE2AP_PDU, dataBuffer, dataBufferSize);
     switch (rval.code) {
     case RC_OK:
-        // Debug print
-        if (debug) {
+        if (debugPrints) {
             sprintf(pLogBuffer,"Successfully decoded E2AP-PDU");
             asn_fprint(stdout, &asn_DEF_E2AP_PDU, pE2AP_PDU);
         }
index aab8aaa..c52db2b 100644 (file)
@@ -429,6 +429,8 @@ typedef struct  {
 //////////////////////////////////////////////////////////////////////
 // Function declarations
 
+void allowASN1DebugPrints(bool);
+
 const char* getE2ErrorString(uint64_t);
 
 typedef void* e2ap_pdu_ptr_t;
index dafac42..dcf84ab 100644 (file)
@@ -1115,6 +1115,19 @@ func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) String() string {
        return b.String()
 }
 
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+func SetASN1DebugPrintStatus(logLevel int) {
+       if logLevel >= 4 {
+               fmt.Println("Setting ASN1 debug prints ON")
+               C.allowASN1DebugPrints(true)
+       } else {
+               fmt.Println("Setting ASN1 debug prints OFF")
+               C.allowASN1DebugPrints(false)
+       }
+}
+
 //-----------------------------------------------------------------------------
 // Public E2AP packer creators
 //-----------------------------------------------------------------------------
index a3d9cdb..08000b0 100755 (executable)
@@ -150,7 +150,7 @@ func NewControl() *Control {
                e2SubsDb:          CreateSdl(),
                restSubsDb:        CreateRESTSdl(),
                Counters:          xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"),
-               LoggerLevel:       4,
+               LoggerLevel:       1,
        }
 
        e2IfState.Init(c)
@@ -161,16 +161,13 @@ func NewControl() *Control {
        xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET")
        xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET")
 
-       if readSubsFromDb == "false" {
-               return c
+       if readSubsFromDb == "true" {
+               // Read subscriptions from db
+               c.ReadE2Subscriptions()
+               c.ReadRESTSubscriptions()
        }
 
-       // Read subscriptions from db
-       c.ReadE2Subscriptions()
-       c.ReadRESTSubscriptions()
-
        go xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler)
-
        return c
 }
 
@@ -242,6 +239,7 @@ func (c *Control) ReadConfigParameters(f string) {
 
        c.LoggerLevel = int(xapp.Logger.GetLevel())
        xapp.Logger.Debug("LoggerLevel= %v", c.LoggerLevel)
+       c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel)
 
        // viper.GetDuration returns nanoseconds
        e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
index 0aa5ebe..0d763e6 100644 (file)
@@ -47,6 +47,13 @@ func SetPackerIf(iface e2ap.E2APPackerIf) {
 type E2ap struct {
 }
 
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+func (c *E2ap) SetASN1DebugPrintStatus(logLevel int) {
+       e2ap_wrapper.SetASN1DebugPrintStatus(logLevel)
+}
+
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
index 8d559bd..3a11983 100644 (file)
@@ -56,7 +56,8 @@ func createSubmgrControl(srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc) *te
        mainCtrl.RmrControl.Init("SUBMGRCTL", srcId, rtgSvc)
        mainCtrl.c = NewControl()
        mainCtrl.c.UTTesting = true
-       mainCtrl.c.LoggerLevel = int(xapp.Logger.GetLevel())
+       mainCtrl.c.LoggerLevel = 4
+       mainCtrl.c.e2ap.SetASN1DebugPrintStatus(mainCtrl.c.LoggerLevel)
        xapp.Logger.Debug("Test: LoggerLevel %v", mainCtrl.c.LoggerLevel)
        xapp.Logger.Debug("Replacing real db with test db")
        mainCtrl.c.e2SubsDb = CreateMock()              // This overrides real E2 Subscription database for testing