Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package control |
| 21 | |
| 22 | import ( |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 23 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
Juha Hyttinen | d708a43 | 2020-03-09 09:37:06 +0200 | [diff] [blame^] | 24 | "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 25 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 26 | "sync" |
| 27 | ) |
| 28 | |
| 29 | //----------------------------------------------------------------------------- |
| 30 | // |
| 31 | //----------------------------------------------------------------------------- |
| 32 | type Subscription struct { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 33 | mutex sync.Mutex // Lock |
| 34 | valid bool // valid |
| 35 | registry *Registry // Registry |
| 36 | ReqId RequestId // ReqId (Requestor Id + Seq Nro a.k.a subsid) |
| 37 | Meid *xapp.RMRMeid // Meid/ RanName |
| 38 | EpList RmrEndpointList // Endpoints |
| 39 | TransLock sync.Mutex // Lock transactions, only one executed per time for subs |
| 40 | TheTrans TransactionIf // Ongoing transaction |
| 41 | SubReqMsg *e2ap.E2APSubscriptionRequest // Subscription information |
| 42 | SubRFMsg interface{} // Subscription information |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 45 | func (s *Subscription) String() string { |
Juha Hyttinen | d708a43 | 2020-03-09 09:37:06 +0200 | [diff] [blame^] | 46 | return "subs(" + s.ReqId.String() + "/" + (&xapptweaks.RMRMeid{s.Meid}).String() + "/" + s.EpList.String() + ")" |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 49 | func (s *Subscription) GetCachedResponse() (interface{}, bool) { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 50 | s.mutex.Lock() |
| 51 | defer s.mutex.Unlock() |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 52 | return s.SubRFMsg, s.valid |
| 53 | } |
| 54 | |
| 55 | func (s *Subscription) SetCachedResponse(subRFMsg interface{}, valid bool) (interface{}, bool) { |
| 56 | s.mutex.Lock() |
| 57 | defer s.mutex.Unlock() |
| 58 | s.SubRFMsg = subRFMsg |
| 59 | s.valid = valid |
| 60 | return s.SubRFMsg, s.valid |
| 61 | } |
| 62 | |
| 63 | func (s *Subscription) GetReqId() *RequestId { |
| 64 | s.mutex.Lock() |
| 65 | defer s.mutex.Unlock() |
| 66 | return &s.ReqId |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | func (s *Subscription) GetMeid() *xapp.RMRMeid { |
| 70 | s.mutex.Lock() |
| 71 | defer s.mutex.Unlock() |
| 72 | if s.Meid != nil { |
| 73 | return s.Meid |
| 74 | } |
| 75 | return nil |
| 76 | } |
| 77 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 78 | func (s *Subscription) GetTransaction() TransactionIf { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 79 | s.mutex.Lock() |
| 80 | defer s.mutex.Unlock() |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 81 | return s.TheTrans |
| 82 | } |
| 83 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 84 | func (s *Subscription) WaitTransactionTurn(trans TransactionIf) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 85 | s.TransLock.Lock() |
| 86 | s.mutex.Lock() |
| 87 | s.TheTrans = trans |
| 88 | s.mutex.Unlock() |
| 89 | } |
| 90 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 91 | func (s *Subscription) ReleaseTransactionTurn(trans TransactionIf) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 92 | s.mutex.Lock() |
| 93 | if trans != nil && trans == s.TheTrans { |
| 94 | s.TheTrans = nil |
| 95 | } |
| 96 | s.mutex.Unlock() |
| 97 | s.TransLock.Unlock() |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 98 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 99 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 100 | func (s *Subscription) IsMergeable(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) bool { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 101 | s.mutex.Lock() |
| 102 | defer s.mutex.Unlock() |
| 103 | |
| 104 | if s.valid == false { |
| 105 | return false |
| 106 | } |
| 107 | |
| 108 | if s.SubReqMsg == nil { |
| 109 | return false |
| 110 | } |
| 111 | |
| 112 | if s.Meid.RanName != trans.Meid.RanName { |
| 113 | return false |
| 114 | } |
| 115 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 116 | // EventTrigger check |
| 117 | if s.SubReqMsg.EventTriggerDefinition.InterfaceDirection != subReqMsg.EventTriggerDefinition.InterfaceDirection || |
| 118 | s.SubReqMsg.EventTriggerDefinition.ProcedureCode != subReqMsg.EventTriggerDefinition.ProcedureCode || |
| 119 | s.SubReqMsg.EventTriggerDefinition.TypeOfMessage != subReqMsg.EventTriggerDefinition.TypeOfMessage { |
| 120 | return false |
| 121 | } |
| 122 | |
| 123 | if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present || |
| 124 | s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.NodeId || |
Juha Hyttinen | 14f8273 | 2020-02-27 13:49:06 +0200 | [diff] [blame] | 125 | s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalEnbId.PlmnIdentity.String() { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 126 | return false |
| 127 | } |
| 128 | |
| 129 | if s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.Present || |
| 130 | s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.NodeId || |
Juha Hyttinen | 14f8273 | 2020-02-27 13:49:06 +0200 | [diff] [blame] | 131 | s.SubReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() != subReqMsg.EventTriggerDefinition.InterfaceId.GlobalGnbId.PlmnIdentity.String() { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 132 | return false |
| 133 | } |
| 134 | |
| 135 | // Actions check |
| 136 | if len(s.SubReqMsg.ActionSetups) != len(subReqMsg.ActionSetups) { |
| 137 | return false |
| 138 | } |
| 139 | |
| 140 | for _, acts := range s.SubReqMsg.ActionSetups { |
| 141 | for _, actt := range subReqMsg.ActionSetups { |
| 142 | if acts.ActionId != actt.ActionId { |
| 143 | return false |
| 144 | } |
| 145 | if acts.ActionType != actt.ActionType { |
| 146 | return false |
| 147 | } |
| 148 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 149 | if acts.ActionType != e2ap.E2AP_ActionTypeReport { |
| 150 | return false |
| 151 | } |
| 152 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 153 | if acts.ActionDefinition.Present != actt.ActionDefinition.Present || |
| 154 | acts.ActionDefinition.StyleId != actt.ActionDefinition.StyleId || |
| 155 | acts.ActionDefinition.ParamId != actt.ActionDefinition.ParamId { |
| 156 | return false |
| 157 | } |
| 158 | if acts.SubsequentAction.Present != actt.SubsequentAction.Present || |
| 159 | acts.SubsequentAction.Type != actt.SubsequentAction.Type || |
| 160 | acts.SubsequentAction.TimetoWait != actt.SubsequentAction.TimetoWait { |
| 161 | return false |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return true |
| 167 | } |