2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
31 type RanLostConnectionHandler struct{
32 rnibReaderProvider func() reader.RNibReader
33 rnibWriterProvider func() rNibWriter.RNibWriter
36 func NewRanLostConnectionHandler(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) RanLostConnectionHandler {
37 return RanLostConnectionHandler{
38 rnibReaderProvider: rnibReaderProvider,
39 rnibWriterProvider: rnibWriterProvider,
42 func (src RanLostConnectionHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions,
43 request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
45 logger.Warnf("#ranLostConnectionHandler.Handle - Received lost connection (transaction id = %s): %s", request.TransactionId, request.Payload)
47 var nb *entities.NodebInfo
48 var rNibErr common.IRNibError
49 if nb, rNibErr = src.rnibReaderProvider().GetNodeb(request.RanName); rNibErr != nil {
50 logger.Errorf("#ranLostConnectionHandler.Handle - transactionId %s: rNib reader failed to retrieve nb entity with RanName: %s. Error: %s", request.TransactionId, request.RanName, rNibErr.Error())
52 logger.Debugf("#ranLostConnectionHandler.Handle - transactionId %s: nb entity has been retrieved. RanName %s, ConnectionStatus %s", request.TransactionId, nb.RanName, nb.ConnectionStatus)
53 changeNodebState(logger, nb)
54 nbIdentity := &entities.NbIdentity{InventoryName:nb.RanName, GlobalNbId:nb.GlobalNbId}
55 if rNibErr = src.rnibWriterProvider().SaveNodeb(nbIdentity, nb); rNibErr != nil {
56 logger.Errorf("#ranLostConnectionHandler.Handle - transactionId %s: rNibWriter failed to save nb entity %s. Error: %s", request.TransactionId, nb.RanName, rNibErr.Error())
58 logger.Infof("#ranLostConnectionHandler.Handle - transactionId %s: saved to rNib", request.TransactionId)
59 logger.Debugf("#ranLostConnectionHandler.Handle - transactionId %s: saved to rNib. RanName %s, ConnectionStatus %v", request.TransactionId, nb.RanName, nb.ConnectionStatus)
63 e2session, ok := e2Sessions[request.TransactionId]
64 printHandlingSetupResponseElapsedTimeInMs(logger, "#ranLostConnectionHandler.Handle - Summary: Elapsed time for receiving and handling sctp error response from E2 terminator", request.StartTime)
66 printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#ranLostConnectionHandler.Handle- Summary: Total roundtrip elapsed time for transactionId %s", request.TransactionId), e2session.SessionStart)
67 delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC)
72 func changeNodebState(logger *logger.Logger, nb *entities.NodebInfo) {
73 switch nb.ConnectionStatus{
74 case entities.ConnectionStatus_CONNECTED, entities.ConnectionStatus_CONNECTING, entities.ConnectionStatus_CONNECTED_SETUP_FAILED:
75 nb.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
76 case entities.ConnectionStatus_DISCONNECTED:
77 logger.Infof("#ranLostConnectionHandler.changeNodebState - nb entity with ConnectionStatus %v occurred. RanName: %s", nb.ConnectionStatus, nb.RanName)
79 nb.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN