Support for handling unordered IEs in RIC Subscription Response messgae

Inorder to support interoperability with other RAN simulators, adding
config parameter using which strict order checking of IEs can be
enabled or disabled.

Resolves RIC-963 partially.

Change-Id: Ie9c60f9dcbb8159ae21ee29451da24901dad1d6f

Change-Id: Icd660d38efb0331ad4f03b309dd7a3082a74e8e8
Signed-off-by: himanshup <himanshu.purohit@gslab.com>
diff --git a/pkg/control/control.go b/pkg/control/control.go
index 227eb0c..b4667e0 100755
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -72,6 +72,7 @@
 var readSubsFromDb string
 var dbRetryForever string
 var dbTryCount int
+var e2IEOrderCheckValue uint8
 
 type Control struct {
 	*xapp.RMRClient
@@ -348,6 +349,11 @@
 		xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms")
 	}
 	xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms)
+
+	viper.SetDefault("controls.checkE2IEOrder", 1)
+	e2IEOrderCheckValue = uint8(viper.GetUint("controls.checkE2IEOrder"))
+	c.e2ap.SetE2IEOrderCheck(e2IEOrderCheckValue)
+	xapp.Logger.Debug("e2IEOrderCheck= %v", e2IEOrderCheckValue)
 }
 
 //-------------------------------------------------------------------
diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go
index ae8c999..f233bc4 100644
--- a/pkg/control/e2ap.go
+++ b/pkg/control/e2ap.go
@@ -55,6 +55,10 @@
 	e2ap_wrapper.SetASN1DebugPrintStatus(logLevel)
 }
 
+func (e *E2ap) SetE2IEOrderCheck(ieOrderCheck uint8) {
+	e2ap_wrapper.SetE2IEOrderCheck(ieOrderCheck)
+}
+
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go
index c61a495..3d0b448 100644
--- a/pkg/control/ut_messaging_test.go
+++ b/pkg/control/ut_messaging_test.go
@@ -881,6 +881,100 @@
 }
 
 //-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// TestSubReqAndSubDelOkOutofOrderIEs
+//
+//   stub                          stub
+// +-------+     +---------+    +---------+
+// | xapp  |     | submgr  |    | e2term  |
+// +-------+     +---------+    +---------+
+//     |              |              |
+//     | SubReq       |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubResp | (Out of Order IEs)
+//     |              |<-------------|
+//     |              |              |
+//     |      SubResp |              |
+//     |<-------------|              |
+//     |              |              |
+//     |              |              |
+//     | SubDelReq    |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
+//     |   SubDelResp |              |
+//     |<-------------|              |
+//
+//-----------------------------------------------------------------------------
+
+func TestSubReqAndSubDelOkOutofOrderIEs(t *testing.T) {
+	CaseBegin("TestSubReqAndSubDelOkOutofOrderIEs")
+
+	mainCtrl.c.e2ap.SetE2IEOrderCheck(0)
+	// Init counter check
+	mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+		Counter{cSubReqFromXapp, 1},
+		Counter{cSubReqToE2, 1},
+		Counter{cSubRespFromE2, 1},
+		Counter{cSubRespToXapp, 1},
+		Counter{cSubDelReqFromXapp, 1},
+		Counter{cSubDelReqToE2, 1},
+		Counter{cSubDelRespFromE2, 1},
+		Counter{cSubDelRespToXapp, 1},
+	})
+
+	cretrans := xappConn1.SendSubsReq(t, nil, nil)
+	if cretrans == nil {
+		t.Logf("Could not send SubsReq")
+		t.FailNow()
+	}
+	crereq, cremsg := e2termConn1.RecvSubsReq(t)
+	if crereq == nil || cremsg == nil {
+		t.Logf("Could not recieve SubsReq")
+		t.FailNow()
+	}
+
+	e2termConn1.SendSubsResp(t, crereq, cremsg)
+
+	mainCtrl.c.e2ap.SetE2IEOrderCheck(0)
+
+	e2SubsId := xappConn1.RecvSubsResp(t, cretrans)
+	resp, _ := xapp.Subscription.QuerySubscriptions()
+	assert.Equal(t, resp[0].SubscriptionID, int64(e2SubsId))
+	assert.Equal(t, resp[0].Meid, "RAN_NAME_1")
+	assert.Equal(t, resp[0].ClientEndpoint, []string{"localhost:13560"})
+
+	deltrans := xappConn1.SendSubsDelReq(t, nil, e2SubsId)
+	delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+	e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+	xappConn1.RecvSubsDelResp(t, deltrans)
+
+	//Wait that subs is cleaned
+	mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+	xappConn1.TestMsgChanEmpty(t)
+	xappConn2.TestMsgChanEmpty(t)
+	e2termConn1.TestMsgChanEmpty(t)
+	mainCtrl.wait_registry_empty(t, 10)
+
+	mainCtrl.VerifyCounterValues(t)
+	mainCtrl.c.e2ap.SetE2IEOrderCheck(1)
+}
+
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
 // TestSubReqRetransmission
 //
 //   stub                          stub