[RICPLT-1852] Supports E2T Initialize + ExecuteSetup + prepare setup request on init
[ric-plt/e2mgr.git] / E2Manager / providers / rmrmsghandlerprovider / notification_handler_provider.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 package rmrmsghandlerprovider
19
20 import (
21         "e2mgr/handlers"
22         "e2mgr/managers"
23         "e2mgr/rNibWriter"
24         "e2mgr/rmrCgo"
25         "fmt"
26         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
27 )
28
29 type NotificationHandlerProvider struct {
30         notificationHandlers map[int]handlers.NotificationHandler
31 }
32
33 func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranReconnectionManager *managers.RanReconnectionManager) *NotificationHandlerProvider {
34         return &NotificationHandlerProvider{
35                 notificationHandlers: initNotificationHandlersMap(rnibReaderProvider, rnibWriterProvider, ranReconnectionManager),
36         }
37 }
38
39 func initNotificationHandlersMap(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranReconnectionManager *managers.RanReconnectionManager) map[int]handlers.NotificationHandler {
40         return map[int]handlers.NotificationHandler{
41                 //TODO change handlers.NotificationHandler to *handlers.NotificationHandler
42                 rmrCgo.RIC_X2_SETUP_RESP:           handlers.X2SetupResponseNotificationHandler{},
43                 rmrCgo.RIC_X2_SETUP_FAILURE:        handlers.X2SetupFailureResponseNotificationHandler{},
44                 rmrCgo.RIC_ENDC_X2_SETUP_RESP:      handlers.EndcX2SetupResponseNotificationHandler{},
45                 rmrCgo.RIC_ENDC_X2_SETUP_FAILURE:   handlers.EndcX2SetupFailureResponseNotificationHandler{},
46                 rmrCgo.RIC_SCTP_CONNECTION_FAILURE: handlers.NewRanLostConnectionHandler(ranReconnectionManager),
47                 rmrCgo.RIC_ENB_LOAD_INFORMATION:    handlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider),
48                 rmrCgo.RIC_ENB_CONF_UPDATE:         handlers.X2EnbConfigurationUpdateHandler{},
49                 rmrCgo.RIC_ENDC_CONF_UPDATE:        handlers.EndcConfigurationUpdateHandler{},
50                 rmrCgo.RIC_X2_RESET_RESP:           handlers.NewX2ResetResponseHandler(rnibReaderProvider),
51                 rmrCgo.RIC_X2_RESET:                handlers.NewX2ResetRequestNotificationHandler(rnibReaderProvider),
52                 rmrCgo.RIC_E2_TERM_INIT:            handlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider ),
53         }
54 }
55
56 func (provider NotificationHandlerProvider) GetNotificationHandler(messageType int) (handlers.NotificationHandler, error) {
57         handler, ok := provider.notificationHandlers[messageType]
58
59         if !ok {
60                 return nil, fmt.Errorf("notification handler not found for message %d", messageType)
61         }
62
63         return handler, nil
64
65 }