Merge newe2 into master
[ric-plt/submgr.git] / pkg / control / subscription.go
index 5bfe2e1..b2516bd 100644 (file)
@@ -21,8 +21,9 @@ package control
 
 import (
        "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
+       "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
-       "strconv"
+       "reflect"
        "sync"
 )
 
@@ -30,62 +31,65 @@ import (
 //
 //-----------------------------------------------------------------------------
 type Subscription struct {
-       mutex      sync.Mutex                     // Lock
-       valid      bool                           // valid
-       registry   *Registry                      // Registry
-       Seq        uint16                         // SubsId
-       Meid       *xapp.RMRMeid                  // Meid/ RanName
-       EpList     RmrEndpointList                // Endpoints
-       TransLock  sync.Mutex                     // Lock transactions, only one executed per time for subs
-       TheTrans   *Transaction                   // Ongoing transaction from xapp
-       SubReqMsg  *e2ap.E2APSubscriptionRequest  // Subscription information
-       SubRespMsg *e2ap.E2APSubscriptionResponse // Subscription information
-       SubFailMsg *e2ap.E2APSubscriptionFailure  // Subscription information
+       mutex     sync.Mutex                    // Lock
+       valid     bool                          // valid
+       registry  *Registry                     // Registry
+       ReqId     RequestId                     // ReqId (Requestor Id + Seq Nro a.k.a subsid)
+       Meid      *xapp.RMRMeid                 // Meid/ RanName
+       EpList    xapptweaks.RmrEndpointList    // Endpoints
+       TransLock sync.Mutex                    // Lock transactions, only one executed per time for subs
+       TheTrans  TransactionIf                 // Ongoing transaction
+       SubReqMsg *e2ap.E2APSubscriptionRequest // Subscription information
+       SubRFMsg  interface{}                   // Subscription information
 }
 
 func (s *Subscription) String() string {
-       return "subs(" + strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.Meid.RanName + "/" + s.EpList.String() + ")"
+       return "subs(" + s.ReqId.String() + "/" + (&xapptweaks.RMRMeid{s.Meid}).String() + "/" + s.EpList.String() + ")"
 }
 
-func (s *Subscription) GetSubId() uint16 {
+func (s *Subscription) GetCachedResponse() (interface{}, bool) {
        s.mutex.Lock()
        defer s.mutex.Unlock()
-       return s.Seq
+       return s.SubRFMsg, s.valid
 }
 
-func (s *Subscription) GetMeid() *xapp.RMRMeid {
+func (s *Subscription) SetCachedResponse(subRFMsg interface{}, valid bool) (interface{}, bool) {
        s.mutex.Lock()
        defer s.mutex.Unlock()
-       if s.Meid != nil {
-               return s.Meid
-       }
-       return nil
+       s.SubRFMsg = subRFMsg
+       s.valid = valid
+       return s.SubRFMsg, s.valid
 }
 
-func (s *Subscription) IsTransactionReserved() bool {
+func (s *Subscription) GetReqId() *RequestId {
        s.mutex.Lock()
        defer s.mutex.Unlock()
-       if s.TheTrans != nil {
-               return true
-       }
-       return false
+       return &s.ReqId
+}
 
+func (s *Subscription) GetMeid() *xapp.RMRMeid {
+       s.mutex.Lock()
+       defer s.mutex.Unlock()
+       if s.Meid != nil {
+               return s.Meid
+       }
+       return nil
 }
 
-func (s *Subscription) GetTransaction() *Transaction {
+func (s *Subscription) GetTransaction() TransactionIf {
        s.mutex.Lock()
        defer s.mutex.Unlock()
        return s.TheTrans
 }
 
-func (s *Subscription) WaitTransactionTurn(trans *Transaction) {
+func (s *Subscription) WaitTransactionTurn(trans TransactionIf) {
        s.TransLock.Lock()
        s.mutex.Lock()
        s.TheTrans = trans
        s.mutex.Unlock()
 }
 
-func (s *Subscription) ReleaseTransactionTurn(trans *Transaction) {
+func (s *Subscription) ReleaseTransactionTurn(trans TransactionIf) {
        s.mutex.Lock()
        if trans != nil && trans == s.TheTrans {
                s.TheTrans = nil
@@ -94,7 +98,7 @@ func (s *Subscription) ReleaseTransactionTurn(trans *Transaction) {
        s.TransLock.Unlock()
 }
 
-func (s *Subscription) IsSame(trans *Transaction, subReqMsg *e2ap.E2APSubscriptionRequest) bool {
+func (s *Subscription) IsMergeable(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) bool {
        s.mutex.Lock()
        defer s.mutex.Unlock()
 
@@ -110,15 +114,6 @@ func (s *Subscription) IsSame(trans *Transaction, subReqMsg *e2ap.E2APSubscripti
                return false
        }
 
-       if s.EpList.Size() == 0 {
-               return false
-       }
-
-       //Somehow special case ... ?
-       if s.EpList.HasEndpoint(trans.GetEndpoint()) == true {
-               return false
-       }
-
        // EventTrigger check
        if s.SubReqMsg.EventTriggerDefinition.InterfaceDirection != subReqMsg.EventTriggerDefinition.InterfaceDirection ||
                s.SubReqMsg.EventTriggerDefinition.ProcedureCode != subReqMsg.EventTriggerDefinition.ProcedureCode ||
@@ -128,17 +123,13 @@ func (s *Subscription) IsSame(trans *Transaction, subReqMsg *e2ap.E2APSubscripti
 
        if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present ||
                s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[0] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[0] ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[1] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[1] ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[2] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.Val[2] {
+               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() {
                return false
        }
 
        if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present ||
                s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[0] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[0] ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[1] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[1] ||
-               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[2] != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.Val[2] {
+               s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() {
                return false
        }
 
@@ -156,11 +147,15 @@ func (s *Subscription) IsSame(trans *Transaction, subReqMsg *e2ap.E2APSubscripti
                                return false
                        }
 
-                       if acts.ActionDefinition.Present != actt.ActionDefinition.Present ||
-                               acts.ActionDefinition.StyleId != actt.ActionDefinition.StyleId ||
-                               acts.ActionDefinition.ParamId != actt.ActionDefinition.ParamId {
+                       if acts.ActionType != e2ap.E2AP_ActionTypeReport {
+                               return false
+                       }
+
+                       if acts.RicActionDefinitionPresent != actt.RicActionDefinitionPresent ||
+                               reflect.DeepEqual(acts.ActionDefinitionChoice, actt.ActionDefinitionChoice) == false {
                                return false
                        }
+
                        if acts.SubsequentAction.Present != actt.SubsequentAction.Present ||
                                acts.SubsequentAction.Type != actt.SubsequentAction.Type ||
                                acts.SubsequentAction.TimetoWait != actt.SubsequentAction.TimetoWait {