X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fsubscription.go;h=6ea2c1fadcadcf2385942cf9b89afea24752dab4;hb=de457a14f98c546fdb009e9915745ef398388ddd;hp=45c13ec107f88fc3c67e86049e709d20efd3d2e7;hpb=12d31af1cdfcbf5f634d9cf666e8e174c74ecb27;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/subscription.go b/pkg/control/subscription.go index 45c13ec..6ea2c1f 100644 --- a/pkg/control/subscription.go +++ b/pkg/control/subscription.go @@ -22,7 +22,8 @@ package control import ( "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - "strconv" + + //"reflect" "sync" ) @@ -30,60 +31,71 @@ import ( // //----------------------------------------------------------------------------- type Subscription struct { - mutex sync.Mutex // Lock - 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 + 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 xapp.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 + RetryFromXapp bool // Retry form xApp for subscription that already exist + SubRespRcvd bool // Subscription response received + DeleteFromDb bool // Delete subscription form db + NoRespToXapp bool // Send no response for subscription delete to xApp after restart + DoNotWaitSubResp bool // Test flag. Response is not waited for Subscription Request } func (s *Subscription) String() string { - return "subs(" + strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.Meid.RanName + "/" + s.EpList.String() + ")" + meidstr := "N/A" + if s.Meid != nil { + meidstr = s.Meid.String() + } + return "subs(" + s.ReqId.String() + "/" + meidstr + "/" + 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() + return s.Meid } -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 @@ -91,3 +103,72 @@ func (s *Subscription) ReleaseTransactionTurn(trans *Transaction) { s.mutex.Unlock() s.TransLock.Unlock() } + +func (s *Subscription) IsMergeable(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) bool { + s.mutex.Lock() + defer s.mutex.Unlock() + + if s.valid == false { + return false + } + + if s.SubReqMsg == nil { + return false + } + + if s.Meid.RanName != trans.Meid.RanName { + return false + } + + // EventTrigger check + if s.SubReqMsg.EventTriggerDefinition.Data.Length != subReqMsg.EventTriggerDefinition.Data.Length { + return false + } + for i := uint64(0); i < s.SubReqMsg.EventTriggerDefinition.Data.Length; i++ { + if s.SubReqMsg.EventTriggerDefinition.Data.Data[i] != subReqMsg.EventTriggerDefinition.Data.Data[i] { + return false + } + } + + // Actions check + if len(s.SubReqMsg.ActionSetups) != len(subReqMsg.ActionSetups) { + return false + } + + for _, acts := range s.SubReqMsg.ActionSetups { + for _, actt := range subReqMsg.ActionSetups { + if acts.ActionId != actt.ActionId { + return false + } + if acts.ActionType != actt.ActionType { + return false + } + + if acts.ActionType != e2ap.E2AP_ActionTypeReport { + return false + } + + if acts.RicActionDefinitionPresent != actt.RicActionDefinitionPresent { + return false + } + + if acts.ActionDefinitionChoice.Data.Length != actt.ActionDefinitionChoice.Data.Length { + return false + } + for i := uint64(0); i < acts.ActionDefinitionChoice.Data.Length; i++ { + if acts.ActionDefinitionChoice.Data.Data[i] != actt.ActionDefinitionChoice.Data.Data[i] { + return false + } + } + //reflect.DeepEqual(acts.ActionDefinitionChoice, actt.ActionDefinitionChoice) + + if acts.SubsequentAction.Present != actt.SubsequentAction.Present || + acts.SubsequentAction.Type != actt.SubsequentAction.Type || + acts.SubsequentAction.TimetoWait != actt.SubsequentAction.TimetoWait { + return false + } + } + } + + return true +}