4 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
5 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
6 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
7 "github.com/stretchr/testify/assert"
12 func initMock() *Control {
14 var payload = []byte{0, 8, 0, 50, 0, 0, 3, 0, 29, 0, 5, 0, 0, 3, 0, 159, 0, 5, 0, 2, 0, 2, 0, 30, 0, 28, 0, 7, 8, 0, 0, 5, 0, 0, 0, 0, 0, 19, 64, 14, 64, 122, 32, 10, 0, 1, 4, 64, 0, 0, 0, 0, 0, 23}
15 var payload1 = []byte{0, 8, 0, 50, 0, 0, 3, 0, 29, 0, 5, 0, 0, 3, 0, 160, 0, 5, 0, 2, 0, 2, 0, 30, 0, 28, 0, 7, 8, 0, 0, 5, 0, 0, 0, 0, 0, 19, 64, 14, 64, 122, 32, 10, 0, 2, 4, 64, 0, 0, 0, 0, 0, 23}
16 meid := &xapp.RMRMeid{}
17 meid.RanName = "RAN_NAME_20"
18 var params = &xapp.RMRParams{
21 PayloadLen: len(payload),
25 Src: "service-ricplt-e2term-rmr-alpha.ricplt:38000",
32 RMRClient: mainCtrl.c.RMRClient,
33 e2ap: mainCtrl.c.e2ap,
34 registry: mainCtrl.c.registry,
35 tracker: mainCtrl.c.tracker,
36 restDuplicateCtrl: mainCtrl.c.restDuplicateCtrl,
37 e2IfState: mainCtrl.c.e2IfState,
38 e2IfStateDb: mainCtrl.c.e2IfStateDb,
39 e2SubsDb: mainCtrl.c.e2SubsDb,
40 restSubsDb: mainCtrl.c.restSubsDb,
41 CntRecvMsg: mainCtrl.c.CntRecvMsg,
42 ResetTestFlag: mainCtrl.c.ResetTestFlag,
43 Counters: mainCtrl.c.Counters,
44 LoggerLevel: mainCtrl.c.LoggerLevel,
45 UTTesting: mainCtrl.c.UTTesting,
48 subReqMsg, _ := C1.e2ap.UnpackSubscriptionRequest(params.Payload)
49 subReqMsg1, _ := C1.e2ap.UnpackSubscriptionRequest(payload1)
51 trans := C1.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid)
52 trans1 := C1.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg1.RequestId, params.Meid)
54 for _, acts := range subReqMsg.ActionSetups {
55 acts.ActionType = e2ap.E2AP_ActionTypeInsert
57 for _, acts := range subReqMsg1.ActionSetups {
58 acts.ActionType = e2ap.E2AP_ActionTypeInsert
60 _, _, _ = C1.registry.AssignToSubscription(trans, subReqMsg, C1.ResetTestFlag, C1, true)
61 _, _, _ = C1.registry.AssignToSubscription(trans1, subReqMsg1, C1.ResetTestFlag, C1, true)
63 controlObj := testingSubmgrControl{
64 RmrControl: teststub.RmrControl{},
67 handler := controlObj.c
71 func TestControl_handleE2TSubscriptionDeleteRequired(t *testing.T) {
73 var payload = []byte{0, 12, 64, 20, 0, 0, 1, 0, 50, 64, 13, 1, 0, 51, 64, 8, 0, 0, 123, 0, 1, 0, 2, 86}
74 meid := &xapp.RMRMeid{}
75 meid.RanName = "RAN_NAME_20"
76 var params = &xapp.RMRParams{
79 PayloadLen: len(payload),
83 Src: "service-ricplt-e2term-rmr-alpha.ricplt:38000",
90 RMRClient *xapp.RMRClient
94 restDuplicateCtrl *DuplicateCtrl
96 e2IfStateDb XappRnibInterface
98 restSubsDb Sdlnterface
101 Counters map[string]xapp.Counter
106 params *xapp.RMRParams
116 RMRClient: handler.RMRClient,
118 registry: handler.registry,
119 tracker: handler.tracker,
120 restDuplicateCtrl: handler.restDuplicateCtrl,
121 e2IfState: handler.e2IfState,
122 e2IfStateDb: handler.e2IfStateDb,
123 e2SubsDb: handler.e2SubsDb,
124 restSubsDb: handler.restSubsDb,
125 CntRecvMsg: handler.CntRecvMsg,
126 ResetTestFlag: handler.ResetTestFlag,
127 Counters: handler.Counters,
128 LoggerLevel: handler.LoggerLevel,
129 UTTesting: handler.UTTesting,
132 args: args{params: params},
135 for _, tt := range tests {
136 t.Run(tt.name, func(t *testing.T) {
138 RMRClient: tt.fields.RMRClient,
139 e2ap: tt.fields.e2ap,
140 registry: tt.fields.registry,
141 tracker: tt.fields.tracker,
142 restDuplicateCtrl: tt.fields.restDuplicateCtrl,
143 e2IfState: tt.fields.e2IfState,
144 e2IfStateDb: tt.fields.e2IfStateDb,
145 e2SubsDb: tt.fields.e2SubsDb,
146 restSubsDb: tt.fields.restSubsDb,
147 CntRecvMsg: tt.fields.CntRecvMsg,
148 ResetTestFlag: tt.fields.ResetTestFlag,
149 Counters: tt.fields.Counters,
150 LoggerLevel: tt.fields.LoggerLevel,
151 UTTesting: tt.fields.UTTesting,
153 c.e2IfState.NbIdMap[params.Meid.RanName] = "_CONNECTED"
154 c.handleE2TSubscriptionDeleteRequired(tt.args.params)
155 subs, _ := c.registry.GetSubscriptionFirstMatch([]uint32{uint32(1)})
156 subs1, _ := c.registry.GetSubscriptionFirstMatch([]uint32{uint32(2)})
158 assert.NotNil(t, subs1)
159 time.Sleep(1 * time.Second)
164 func TestE2ap_UnpackSubscriptionDeleteRequired(t *testing.T) {
165 var payload = []byte{0, 12, 64, 20, 0, 0, 1, 0, 50, 64, 13, 1, 0, 51, 64, 8, 0, 0, 123, 0, 1, 0, 2, 86}
167 list, _ := e2ap1.UnpackSubscriptionDeleteRequired(payload)
168 expectedList := &e2ap.SubscriptionDeleteRequiredList{E2APSubscriptionDeleteRequiredRequests: []e2ap.E2APSubscriptionDeleteRequired{{
169 RequestId: e2ap.RequestId{
179 assert.Equal(t, expectedList, list)
181 func TestE2ap_UnpackSubscriptionDeleteRequiredForWrongPayload(t *testing.T) {
182 var payload = []byte{12, 64, 20, 0, 0, 1, 0, 50, 64, 13, 1, 0, 51, 64, 8, 0, 0, 123, 0, 1, 0, 2, 86}
184 _, err := e2ap1.UnpackSubscriptionDeleteRequired(payload)
185 assert.NotNil(t, err)
189 func TestE2ap_PackSubscriptionDeleteRequired(t *testing.T) {
190 list := &e2ap.SubscriptionDeleteRequiredList{E2APSubscriptionDeleteRequiredRequests: []e2ap.E2APSubscriptionDeleteRequired{{
191 RequestId: e2ap.RequestId{
202 payload1 := []byte{0, 12, 64, 20, 0, 0, 1, 0, 50, 64, 13, 1, 0, 51, 64, 8, 0, 0, 123, 0, 1, 0, 2, 86}
203 payload := &e2ap.PackedData{Buf: payload1}
204 _, packedata, _ := e2ap1.PackSubscriptionDeleteRequired(list)
205 assert.Equal(t, payload, packedata)