blob: f66a1f14a1863f40dddcc3805beeb0a8d68d537c [file] [log] [blame]
Juha Hyttinen0388dd92020-01-09 14:14:16 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17==================================================================================
18*/
19
20package control
21
22import (
Juha Hyttinen422d0182020-01-17 13:37:05 +020023 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
Juha Hyttinen0388dd92020-01-09 14:14:16 +020024 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
Juha Hyttinen0388dd92020-01-09 14:14:16 +020025 "sync"
26)
27
28//-----------------------------------------------------------------------------
29//
30//-----------------------------------------------------------------------------
31type Subscription struct {
Juha Hyttinen83ada002020-01-30 10:36:33 +020032 mutex sync.Mutex // Lock
33 valid bool // valid
34 registry *Registry // Registry
35 ReqId RequestId // ReqId (Requestor Id + Seq Nro a.k.a subsid)
36 Meid *xapp.RMRMeid // Meid/ RanName
37 EpList RmrEndpointList // Endpoints
38 TransLock sync.Mutex // Lock transactions, only one executed per time for subs
39 TheTrans TransactionIf // Ongoing transaction
40 SubReqMsg *e2ap.E2APSubscriptionRequest // Subscription information
41 SubRFMsg interface{} // Subscription information
Juha Hyttinen31797b42020-01-16 14:05:01 +020042}
43
Juha Hyttinen0388dd92020-01-09 14:14:16 +020044func (s *Subscription) String() string {
Juha Hyttinen83ada002020-01-30 10:36:33 +020045 return "subs(" + s.ReqId.String() + "/" + s.Meid.RanName + "/" + s.EpList.String() + ")"
Juha Hyttinen0388dd92020-01-09 14:14:16 +020046}
47
Juha Hyttinen83ada002020-01-30 10:36:33 +020048func (s *Subscription) GetCachedResponse() (interface{}, bool) {
Juha Hyttinene406a342020-01-13 13:02:26 +020049 s.mutex.Lock()
50 defer s.mutex.Unlock()
Juha Hyttinen83ada002020-01-30 10:36:33 +020051 return s.SubRFMsg, s.valid
52}
53
54func (s *Subscription) SetCachedResponse(subRFMsg interface{}, valid bool) (interface{}, bool) {
55 s.mutex.Lock()
56 defer s.mutex.Unlock()
57 s.SubRFMsg = subRFMsg
58 s.valid = valid
59 return s.SubRFMsg, s.valid
60}
61
62func (s *Subscription) GetReqId() *RequestId {
63 s.mutex.Lock()
64 defer s.mutex.Unlock()
65 return &s.ReqId
Juha Hyttinene406a342020-01-13 13:02:26 +020066}
67
68func (s *Subscription) GetMeid() *xapp.RMRMeid {
69 s.mutex.Lock()
70 defer s.mutex.Unlock()
71 if s.Meid != nil {
72 return s.Meid
73 }
74 return nil
75}
76
Juha Hyttinen83ada002020-01-30 10:36:33 +020077func (s *Subscription) GetTransaction() TransactionIf {
Juha Hyttinen0388dd92020-01-09 14:14:16 +020078 s.mutex.Lock()
79 defer s.mutex.Unlock()
Juha Hyttinen422d0182020-01-17 13:37:05 +020080 return s.TheTrans
81}
82
Juha Hyttinen83ada002020-01-30 10:36:33 +020083func (s *Subscription) WaitTransactionTurn(trans TransactionIf) {
Juha Hyttinen422d0182020-01-17 13:37:05 +020084 s.TransLock.Lock()
85 s.mutex.Lock()
86 s.TheTrans = trans
87 s.mutex.Unlock()
88}
89
Juha Hyttinen83ada002020-01-30 10:36:33 +020090func (s *Subscription) ReleaseTransactionTurn(trans TransactionIf) {
Juha Hyttinen422d0182020-01-17 13:37:05 +020091 s.mutex.Lock()
92 if trans != nil && trans == s.TheTrans {
93 s.TheTrans = nil
94 }
95 s.mutex.Unlock()
96 s.TransLock.Unlock()
Juha Hyttinen0388dd92020-01-09 14:14:16 +020097}
Juha Hyttinen3944a222020-01-24 11:51:46 +020098
Juha Hyttinen83ada002020-01-30 10:36:33 +020099func (s *Subscription) IsMergeable(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) bool {
Juha Hyttinen3944a222020-01-24 11:51:46 +0200100 s.mutex.Lock()
101 defer s.mutex.Unlock()
102
103 if s.valid == false {
104 return false
105 }
106
107 if s.SubReqMsg == nil {
108 return false
109 }
110
111 if s.Meid.RanName != trans.Meid.RanName {
112 return false
113 }
114
Juha Hyttinen3944a222020-01-24 11:51:46 +0200115 // EventTrigger check
116 if s.SubReqMsg.EventTriggerDefinition.InterfaceDirection != subReqMsg.EventTriggerDefinition.InterfaceDirection ||
117 s.SubReqMsg.EventTriggerDefinition.ProcedureCode != subReqMsg.EventTriggerDefinition.ProcedureCode ||
118 s.SubReqMsg.EventTriggerDefinition.TypeOfMessage != subReqMsg.EventTriggerDefinition.TypeOfMessage {
119 return false
120 }
121
122 if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present ||
123 s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId ||
Juha Hyttinen14f82732020-02-27 13:49:06 +0200124 s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() {
Juha Hyttinen3944a222020-01-24 11:51:46 +0200125 return false
126 }
127
128 if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present ||
129 s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId ||
Juha Hyttinen14f82732020-02-27 13:49:06 +0200130 s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() {
Juha Hyttinen3944a222020-01-24 11:51:46 +0200131 return false
132 }
133
134 // Actions check
135 if len(s.SubReqMsg.ActionSetups) != len(subReqMsg.ActionSetups) {
136 return false
137 }
138
139 for _, acts := range s.SubReqMsg.ActionSetups {
140 for _, actt := range subReqMsg.ActionSetups {
141 if acts.ActionId != actt.ActionId {
142 return false
143 }
144 if acts.ActionType != actt.ActionType {
145 return false
146 }
147
Juha Hyttinen83ada002020-01-30 10:36:33 +0200148 if acts.ActionType != e2ap.E2AP_ActionTypeReport {
149 return false
150 }
151
Juha Hyttinen3944a222020-01-24 11:51:46 +0200152 if acts.ActionDefinition.Present != actt.ActionDefinition.Present ||
153 acts.ActionDefinition.StyleId != actt.ActionDefinition.StyleId ||
154 acts.ActionDefinition.ParamId != actt.ActionDefinition.ParamId {
155 return false
156 }
157 if acts.SubsequentAction.Present != actt.SubsequentAction.Present ||
158 acts.SubsequentAction.Type != actt.SubsequentAction.Type ||
159 acts.SubsequentAction.TimetoWait != actt.SubsequentAction.TimetoWait {
160 return false
161 }
162 }
163 }
164
165 return true
166}