kalnagy | 4511475 | 2019-06-18 14:40:39 +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 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 22 | import "C" |
| 23 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 24 | import ( |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 25 | "errors" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 26 | rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client" |
| 27 | rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 28 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 29 | httptransport "github.com/go-openapi/runtime/client" |
| 30 | "github.com/go-openapi/strfmt" |
| 31 | "github.com/spf13/viper" |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 32 | "math/rand" |
| 33 | "strconv" |
| 34 | "time" |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 35 | "sync" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 36 | ) |
| 37 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 38 | var rmrSendMutex = &sync.Mutex{} |
| 39 | |
| 40 | var subReqTime time.Duration = 2 * time.Second |
| 41 | var SubDelReqTime time.Duration = 2 * time.Second |
| 42 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 43 | type Control struct { |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 44 | e2ap *E2ap |
| 45 | registry *Registry |
| 46 | rtmgrClient *RtmgrClient |
| 47 | tracker *Tracker |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 48 | rcChan chan *xapp.RMRParams |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 49 | timerMap *TimerMap |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | type RMRMeid struct { |
| 53 | PlmnID string |
| 54 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 55 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 56 | } |
| 57 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 58 | var seedSN uint16 |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 59 | |
| 60 | const ( |
| 61 | CREATE Action = 0 |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 62 | MERGE Action = 1 |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 63 | DELETE Action = 3 |
| 64 | ) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 65 | |
| 66 | func init() { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 67 | xapp.Logger.Info("SUBMGR /ric-plt-submgr:r3-test-v2") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 68 | viper.AutomaticEnv() |
| 69 | viper.SetEnvPrefix("submgr") |
| 70 | viper.AllowEmptyEnv(true) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 71 | seedSN = uint16(viper.GetInt("seed_sn")) |
| 72 | if seedSN == 0 { |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 73 | rand.Seed(time.Now().UnixNano()) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 74 | seedSN = uint16(rand.Intn(65535)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 75 | } |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 76 | if seedSN > 65535 { |
| 77 | seedSN = 0 |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 78 | } |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 79 | xapp.Logger.Info("SUBMGR: Initial Sequence Number: %v", seedSN) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func NewControl() Control { |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 83 | registry := new(Registry) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 84 | registry.Initialize(seedSN) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 85 | |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame] | 86 | tracker := new(Tracker) |
| 87 | tracker.Init() |
| 88 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 89 | timerMap := new(TimerMap) |
| 90 | timerMap.Init() |
| 91 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 92 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 93 | client := rtmgrclient.New(transport, strfmt.Default) |
| 94 | handle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 95 | deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 96 | rtmgrClient := RtmgrClient{client, handle, deleteHandle} |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 97 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 98 | return Control{new(E2ap), registry, &rtmgrClient, tracker, make(chan *xapp.RMRParams),timerMap} |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | func (c *Control) Run() { |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 102 | go c.controlLoop() |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 103 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 104 | } |
| 105 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 106 | func (c *Control) Consume(rp *xapp.RMRParams) (err error) { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 107 | c.rcChan <- rp |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 108 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 109 | } |
| 110 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 111 | func (c *Control) rmrSend(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 112 | status := false |
| 113 | i := 1 |
| 114 | rmrSendMutex.Lock() |
| 115 | for ; i <= 10 && status == false; i++ { |
| 116 | status = xapp.Rmr.Send(params, false) |
| 117 | if status == false { |
| 118 | xapp.Logger.Info("rmr.Send() failed. Retry count %v, Mtype: %v, SubId: %v, Xid %s",i, params.Mtype, params.SubId, params.Xid) |
| 119 | time.Sleep(500 * time.Millisecond) |
| 120 | } |
| 121 | } |
| 122 | if status == false { |
| 123 | err = errors.New("rmr.Send() failed") |
| 124 | xapp.Rmr.Free(params.Mbuf) |
| 125 | } |
| 126 | rmrSendMutex.Unlock() |
| 127 | |
| 128 | /* |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 129 | if !xapp.Rmr.Send(params, false) { |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 130 | err = errors.New("rmr.Send() failed") |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 131 | xapp.Rmr.Free(params.Mbuf) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 132 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 133 | */ |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 134 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 135 | } |
| 136 | |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 137 | func (c *Control) rmrReplyToSender(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 138 | c.rmrSend(params) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 139 | return |
| 140 | } |
| 141 | |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 142 | func (c *Control) controlLoop() { |
| 143 | for { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 144 | msg := <-c.rcChan |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 145 | switch msg.Mtype { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 146 | case xapp.RICMessageTypes["RIC_SUB_REQ"]: |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 147 | go c.handleSubscriptionRequest(msg) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 148 | case xapp.RICMessageTypes["RIC_SUB_RESP"]: |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 149 | go c.handleSubscriptionResponse(msg) |
| 150 | case xapp.RICMessageTypes["RIC_SUB_FAILURE"]: |
| 151 | go c.handleSubscriptionFailure(msg) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 152 | case xapp.RICMessageTypes["RIC_SUB_DEL_REQ"]: |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 153 | go c.handleSubscriptionDeleteRequest(msg) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 154 | case xapp.RICMessageTypes["RIC_SUB_DEL_RESP"]: |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 155 | go c.handleSubscriptionDeleteResponse(msg) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 156 | default: |
| 157 | err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded") |
| 158 | xapp.Logger.Error("Unknown message type: %v", err) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 163 | func (c *Control) handleSubscriptionRequest(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 164 | xapp.Logger.Info("Subscription Request Received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid) |
| 165 | xapp.Rmr.Free(params.Mbuf) |
| 166 | params.Mbuf = nil |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 167 | |
| 168 | /* Reserve a sequence number and set it in the payload */ |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 169 | newSubId, isIdValid := c.registry.ReserveSequenceNumber() |
| 170 | if isIdValid != true { |
| 171 | xapp.Logger.Info("Further processing of this SubscriptionRequest stopped. SubId: %v, Xid: %s",params.SubId, params.Xid) |
| 172 | return |
| 173 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 174 | |
Anssi Mannila | 0a9f260 | 2019-12-09 15:26:44 +0200 | [diff] [blame^] | 175 | err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 176 | if err != nil { |
| 177 | err = errors.New("Unable to set Subscription Sequence Number in Payload due to: " + err.Error()) |
| 178 | return |
| 179 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 180 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 181 | srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 182 | if err != nil { |
| 183 | xapp.Logger.Error("Failed to update routing-manager about the subscription request with reason: %s", err) |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | /* Create transatcion records for every subscription request */ |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 188 | xactKey := TransactionKey{newSubId, CREATE} |
| 189 | xactValue := Transaction{*srcAddr, *srcPort, params} |
| 190 | err = c.tracker.TrackTransaction(xactKey, xactValue) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 191 | if err != nil { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 192 | xapp.Logger.Error("Failed to create a Subscription Request transaction record due to %v", err) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 193 | return |
| 194 | } |
| 195 | |
| 196 | /* Update routing manager about the new subscription*/ |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 197 | subRouteAction := SubRouteInfo{CREATE, *srcAddr, *srcPort, newSubId} |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 198 | xapp.Logger.Info("Starting routing manager update") |
| 199 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 200 | |
| 201 | //time.Sleep(3 * time.Second) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 202 | |
| 203 | // Setting new subscription ID in the RMR header |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 204 | params.SubId = int(newSubId) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 205 | xapp.Logger.Info("Forwarding Subscription Request to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 206 | err = c.rmrSend(params) |
| 207 | if err != nil { |
| 208 | xapp.Logger.Error("Failed to send request to E2T %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 209 | } /*else { |
| 210 | c.timerMap.StartTimer(newSubId, subReqTime, c.handleSubscriptionRequestTimer) |
| 211 | }*/ |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 212 | xapp.Logger.Debug("--- Debugging transaction table = %v", c.tracker.transactionTable) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 213 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 214 | } |
| 215 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 216 | func (c *Control) handleSubscriptionResponse(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 0a9f260 | 2019-12-09 15:26:44 +0200 | [diff] [blame^] | 217 | xapp.Logger.Info("Subscription Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 218 | xapp.Rmr.Free(params.Mbuf) |
| 219 | params.Mbuf = nil |
| 220 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 221 | payloadSeqNum, err := c.e2ap.GetSubscriptionResponseSequenceNumber(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 222 | if err != nil { |
| 223 | err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error()) |
| 224 | return |
| 225 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 226 | |
| 227 | xapp.Logger.Info("Received payloadSeqNum: %v",payloadSeqNum) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 228 | if !c.registry.IsValidSequenceNumber(payloadSeqNum) { |
| 229 | err = errors.New("Unknown Subscription ID: " + strconv.Itoa(int(payloadSeqNum)) + " in Subscritpion Response. Message discarded.") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 230 | return |
| 231 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 232 | |
| 233 | // c.timerMap.StopTimer(payloadSeqNum) |
| 234 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 235 | c.registry.setSubscriptionToConfirmed(payloadSeqNum) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 236 | var transaction Transaction |
| 237 | transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, CREATE) |
| 238 | if err != nil { |
| 239 | xapp.Logger.Error("Failed to retrive transaction record. Err: %v", err) |
| 240 | xapp.Logger.Info("Further processing of this Subscription Response stopped. SubId: %v, Xid: %s",params.SubId, params.Xid) |
| 241 | return |
| 242 | } |
| 243 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Retrieved old subId...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort) |
| 244 | |
| 245 | params.SubId = int(payloadSeqNum) |
| 246 | params.Xid = transaction.OrigParams.Xid |
| 247 | |
| 248 | xapp.Logger.Info("Forwarding Subscription Response to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 249 | err = c.rmrReplyToSender(params) |
| 250 | if err != nil { |
| 251 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 252 | } |
| 253 | |
| 254 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort) |
| 255 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 256 | if err != nil { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 257 | xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 258 | return |
| 259 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 260 | return |
| 261 | } |
| 262 | |
| 263 | func (c *Control) handleSubscriptionFailure(params *xapp.RMRParams) (err error) { |
| 264 | xapp.Logger.Info("Subscription Failure Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid) |
| 265 | xapp.Rmr.Free(params.Mbuf) |
| 266 | params.Mbuf = nil |
| 267 | |
| 268 | payloadSeqNum, err := c.e2ap.GetSubscriptionFailureSequenceNumber(params.Payload) |
| 269 | if err != nil { |
| 270 | err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error()) |
| 271 | return |
| 272 | } |
| 273 | xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum) |
| 274 | |
| 275 | // should here be IsValidSequenceNumber check? |
| 276 | |
| 277 | // c.timerMap.StopTimer(payloadSeqNum) |
| 278 | |
| 279 | var transaction Transaction |
| 280 | transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, CREATE) |
| 281 | if err != nil { |
| 282 | xapp.Logger.Error("Failed to retrive transaction record. Err %v", err) |
| 283 | xapp.Logger.Info("Further processing of this Subscription Failure stopped. SubId: %v, Xid: %s",params.SubId, params.Xid) |
| 284 | return |
| 285 | } |
| 286 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort) |
| 287 | |
| 288 | params.SubId = int(payloadSeqNum) |
| 289 | params.Xid = transaction.OrigParams.Xid |
| 290 | |
| 291 | xapp.Logger.Info("Forwarding Subscription Failure to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 292 | err = c.rmrReplyToSender(params) |
| 293 | if err != nil { |
| 294 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 295 | } |
| 296 | |
| 297 | time.Sleep(3 * time.Second) |
| 298 | |
| 299 | xapp.Logger.Info("Starting routing manager update") |
Anssi Mannila | 0a9f260 | 2019-12-09 15:26:44 +0200 | [diff] [blame^] | 300 | subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum} |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 301 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 302 | |
| 303 | xapp.Logger.Info("Deleting trancaction record") |
| 304 | if c.registry.releaseSequenceNumber(payloadSeqNum) { |
| 305 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE) |
| 306 | if err != nil { |
| 307 | xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err) |
| 308 | return |
| 309 | } |
| 310 | } |
| 311 | return |
| 312 | } |
| 313 | |
| 314 | func (c *Control) handleSubscriptionRequestTimer(subId uint16) { |
| 315 | xapp.Logger.Info("Subscription Request timer expired. SubId: %v",subId) |
| 316 | /* |
| 317 | transaction, err := c.tracker.completeTransaction(subId, CREATE) |
| 318 | if err != nil { |
| 319 | xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err) |
| 320 | return |
| 321 | } |
| 322 | xapp.Logger.Info("SubId: %v, Xid %v, Meid: %v",subId, transaction.OrigParams.Xid, transaction.OrigParams.Meid) |
| 323 | |
| 324 | var params xapp.RMRParams |
| 325 | params.Mtype = 12012 //xapp.RICMessageTypes["RIC_SUB_FAILURE"] |
| 326 | params.SubId = int(subId) |
| 327 | params.Meid = transaction.OrigParams.Meid |
| 328 | params.Xid = transaction.OrigParams.Xid |
| 329 | payload := []byte("40C9408098000003EA7E00050000010016EA6300020021EA6E00808180EA6F000400000000EA6F000400010040EA6F000400020080EA6F0004000300C0EA6F000400040100EA6F000400050140EA6F000400060180EA6F0004000701C0EA6F000400080200EA6F000400090240EA6F0004000A0280EA6F0004000B02C0EA6F0004000C0300EA6F0004000D0340EA6F0004000E0380EA6F0004000F03C0") |
| 330 | params.PayloadLen = len(payload) |
| 331 | params.Payload = payload |
| 332 | |
| 333 | xapp.Logger.Info("Forwarding Subscription Failure to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 334 | err = c.rmrReplyToSender(¶ms) |
| 335 | if err != nil { |
| 336 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 337 | } |
| 338 | */ |
| 339 | /* |
| 340 | time.Sleep(3 * time.Second) |
| 341 | |
| 342 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(subId), transaction.XappInstanceAddress, transaction.XappPort) |
| 343 | |
| 344 | xapp.Logger.Info("Starting routing manager update") |
| 345 | subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum} |
| 346 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 347 | |
| 348 | xapp.Logger.Info("Deleting trancaction record") |
| 349 | if c.registry.releaseSequenceNumber(payloadSeqNum) { |
| 350 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE) |
| 351 | if err != nil { |
| 352 | xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err) |
| 353 | return |
| 354 | } |
| 355 | } |
| 356 | */ |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 357 | return |
| 358 | } |
| 359 | |
| 360 | func (act Action) String() string { |
| 361 | actions := [...]string{ |
| 362 | "CREATE", |
| 363 | "MERGE", |
| 364 | "DELETE", |
| 365 | } |
| 366 | |
| 367 | if act < CREATE || act > DELETE { |
| 368 | return "Unknown" |
| 369 | } |
| 370 | return actions[act] |
| 371 | } |
| 372 | |
| 373 | func (act Action) valid() bool { |
| 374 | switch act { |
| 375 | case CREATE, MERGE, DELETE: |
| 376 | return true |
| 377 | default: |
| 378 | return false |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | func (c *Control) handleSubscriptionDeleteRequest(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 383 | xapp.Logger.Info("Subscription Delete Request Received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid) |
| 384 | xapp.Rmr.Free(params.Mbuf) |
| 385 | params.Mbuf = nil |
| 386 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 387 | payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteRequestSequenceNumber(params.Payload) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 388 | if err != nil { |
| 389 | err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error()) |
| 390 | return |
| 391 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 392 | xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum) |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 393 | if c.registry.IsValidSequenceNumber(payloadSeqNum) { |
| 394 | c.registry.deleteSubscription(payloadSeqNum) |
| 395 | trackErr := c.trackDeleteTransaction(params, payloadSeqNum) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 396 | if trackErr != nil { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 397 | xapp.Logger.Error("Failed to create a Subscription Delete Request transaction record due to %v", trackErr) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 398 | return trackErr |
| 399 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 400 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 401 | |
| 402 | xapp.Logger.Info("Forwarding Delete Subscription Request to E2T: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 403 | c.rmrSend(params) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 404 | if err != nil { |
| 405 | xapp.Logger.Error("Failed to send request to E2T %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 406 | } /*else { |
| 407 | c.timerMap.StartTimer(payloadSeqNum, SubDelReqTime, c.handleSubscriptionDeleteRequestTimer) |
| 408 | }*/ |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 409 | return |
| 410 | } |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 411 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 412 | func (c *Control) trackDeleteTransaction(params *xapp.RMRParams, payloadSeqNum uint16) (err error) { |
| 413 | srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src) |
| 414 | if err != nil { |
| 415 | xapp.Logger.Error("Failed to update routing-manager about the subscription delete request with reason: %s", err) |
| 416 | } |
| 417 | xactKey := TransactionKey{payloadSeqNum, DELETE} |
| 418 | xactValue := Transaction{*srcAddr, *srcPort, params} |
| 419 | err = c.tracker.TrackTransaction(xactKey, xactValue) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 420 | return |
| 421 | } |
| 422 | |
| 423 | func (c *Control) handleSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 424 | xapp.Logger.Info("Subscription Delete Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid) |
| 425 | xapp.Rmr.Free(params.Mbuf) |
| 426 | params.Mbuf = nil |
| 427 | |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 428 | payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteResponseSequenceNumber(params.Payload) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 429 | if err != nil { |
| 430 | err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error()) |
| 431 | return |
| 432 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 433 | xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 434 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 435 | // should here be IsValidSequenceNumber check? |
| 436 | // c.timerMap.StopTimer(payloadSeqNum) |
| 437 | |
| 438 | var transaction Transaction |
| 439 | transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, DELETE) |
| 440 | if err != nil { |
| 441 | xapp.Logger.Error("Failed to retrive transaction record. Err %v", err) |
| 442 | xapp.Logger.Info("Further processing of this Subscription Delete Response stopped. SubId: %v, Xid: %s",params.SubId, params.Xid) |
| 443 | return |
| 444 | } |
| 445 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort) |
| 446 | |
| 447 | params.SubId = int(payloadSeqNum) |
| 448 | params.Xid = transaction.OrigParams.Xid |
| 449 | xapp.Logger.Info("Forwarding Subscription Delete Response to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 450 | err = c.rmrReplyToSender(params) |
| 451 | if err != nil { |
| 452 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 453 | // return |
| 454 | } |
| 455 | |
| 456 | time.Sleep(3 * time.Second) |
| 457 | |
| 458 | xapp.Logger.Info("Starting routing manager update") |
| 459 | subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum} |
| 460 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 461 | |
| 462 | xapp.Logger.Info("Deleting trancaction record") |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 463 | if c.registry.releaseSequenceNumber(payloadSeqNum) { |
| 464 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 465 | if err != nil { |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 466 | xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 467 | return |
| 468 | } |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 469 | } |
| 470 | return |
| 471 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 472 | |
| 473 | func (c *Control) handleSubscriptionDeleteFailure(params *xapp.RMRParams) (err error) { |
| 474 | xapp.Logger.Info("Subscription Delete Failure Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid) |
| 475 | xapp.Rmr.Free(params.Mbuf) |
| 476 | params.Mbuf = nil |
| 477 | |
| 478 | payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteFailureSequenceNumber(params.Payload) |
| 479 | if err != nil { |
| 480 | err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error()) |
| 481 | return |
| 482 | } |
| 483 | xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum) |
| 484 | |
| 485 | // should here be IsValidSequenceNumber check? |
| 486 | // c.timerMap.StopTimer(payloadSeqNum) |
| 487 | |
| 488 | var transaction Transaction |
| 489 | transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, DELETE) |
| 490 | if err != nil { |
| 491 | xapp.Logger.Error("Failed to retrive transaction record. Err %v", err) |
| 492 | xapp.Logger.Info("Further processing of this Subscription Delete Failure stopped. SubId: %v, Xid: %s",params.SubId, params.Xid) |
| 493 | return |
| 494 | } |
| 495 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort) |
| 496 | |
| 497 | params.SubId = int(payloadSeqNum) |
| 498 | params.Xid = transaction.OrigParams.Xid |
| 499 | xapp.Logger.Info("Forwarding Subscription Delete Failure to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 500 | err = c.rmrReplyToSender(params) |
| 501 | if err != nil { |
| 502 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 503 | // return |
| 504 | } |
| 505 | |
| 506 | time.Sleep(3 * time.Second) |
| 507 | |
| 508 | xapp.Logger.Info("Starting routing manager update") |
| 509 | subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum} |
| 510 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 511 | |
| 512 | xapp.Logger.Info("Deleting trancaction record") |
| 513 | if c.registry.releaseSequenceNumber(payloadSeqNum) { |
| 514 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE) |
| 515 | if err != nil { |
| 516 | xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err) |
| 517 | return |
| 518 | } |
| 519 | } |
| 520 | return |
| 521 | } |
| 522 | |
| 523 | func (c *Control) handleSubscriptionDeleteRequestTimer(subId uint16) { |
| 524 | xapp.Logger.Info("Subscription Delete Request timer expired. SubId: %v",subId) |
| 525 | /* |
| 526 | transaction, err := c.tracker.completeTransaction(subId, DELETE) |
| 527 | if err != nil { |
| 528 | xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err) |
| 529 | return |
| 530 | } |
| 531 | xapp.Logger.Info("SubId: %v, Xid %v, Meid: %v",subId, transaction.OrigParams.Xid, transaction.OrigParams.Meid) |
| 532 | |
| 533 | var params xapp.RMRParams |
| 534 | params.Mtype = 12022 //xapp.RICMessageTypes["RIC_SUB_DEL_FAILURE"] |
| 535 | params.SubId = int(subId) |
| 536 | params.Meid = transaction.OrigParams.Meid |
| 537 | params.Xid = transaction.OrigParams.Xid |
| 538 | payload := []byte("40CA4018000003EA7E00050000010016EA6300020021EA74000200C0") |
| 539 | params.PayloadLen = len(payload) |
| 540 | params.Payload = payload |
| 541 | |
| 542 | xapp.Logger.Info("Forwarding Subscription Delete Failure to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid) |
| 543 | err = c.rmrReplyToSender(¶ms) |
| 544 | if err != nil { |
| 545 | xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid) |
| 546 | } |
| 547 | */ |
| 548 | /* |
| 549 | time.Sleep(3 * time.Second) |
| 550 | xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(subId), transaction.XappInstanceAddress, transaction.XappPort) |
| 551 | |
| 552 | xapp.Logger.Info("Starting routing manager update") |
| 553 | subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum} |
| 554 | c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 555 | |
| 556 | xapp.Logger.Info("Deleting trancaction record") |
| 557 | if c.registry.releaseSequenceNumber(payloadSeqNum) { |
| 558 | transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE) |
| 559 | if err != nil { |
| 560 | xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err) |
| 561 | return |
| 562 | } |
| 563 | } |
| 564 | */ |
| 565 | return |
| 566 | } |