+//-------------------------------------------------------------------
+//
+//------------------------------------------------------------------
+func (c *Control) SubscriptionProcessingStartDelay() {
+ if c.UTTesting == true {
+ // This is temporary fix for the UT problem that notification arrives before subscription response
+ // Correct fix would be to allow notification come before response and process it correctly
+ xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions")
+ <-time.After(time.Millisecond * 50)
+ xapp.Logger.Debug("Continuing after delay")
+ }
+}
+
+//-------------------------------------------------------------------
+//
+//------------------------------------------------------------------
+func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string,
+ restSubId string, e2SubscriptionDirectives *E2SubscriptionDirectives) (*e2ap.E2APSubscriptionResponse, *ErrorInfo, error) {
+
+ errorInfo := ErrorInfo{}
+
+ err := c.tracker.Track(trans)
+ if err != nil {
+ xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans))
+ errorInfo.ErrorCause = err.Error()
+ err = fmt.Errorf("Tracking failure")
+ return nil, &errorInfo, err
+ }
+
+ subs, errorInfo, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, e2SubscriptionDirectives.CreateRMRRoute)
+ if err != nil {
+ xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans))
+ return nil, &errorInfo, err
+ }
+
+ //
+ // Wake subs request
+ //
+ go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives)
+ event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
+
+ err = nil
+ if event != nil {
+ switch themsg := event.(type) {
+ case *e2ap.E2APSubscriptionResponse:
+ trans.Release()
+ return themsg, &errorInfo, nil
+ case *e2ap.E2APSubscriptionFailure:
+ err = fmt.Errorf("E2 SubscriptionFailure received")
+ errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
+ return nil, &errorInfo, err
+ case *PackSubscriptionRequestErrortEvent:
+ err = fmt.Errorf("E2 SubscriptionRequest pack failure")
+ return nil, &themsg.ErrorInfo, err
+ case *SDLWriteErrortEvent:
+ err = fmt.Errorf("SDL write failure")
+ return nil, &themsg.ErrorInfo, err
+ default:
+ err = fmt.Errorf("Unexpected E2 subscription response received")
+ errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
+ break