blob: bcd4ae62dff99e5690eef2cf3f18af925a5c0f37 [file] [log] [blame]
David K. Bainbridgeeda2b052017-07-12 09:41:04 -07001/*
Brian O'Connor180c1092017-08-03 22:46:14 -07002 * Copyright 2017-present Open Networking Foundation
David K. Bainbridgeeda2b052017-07-12 09:41:04 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Amit Ghoshc29c7a92017-08-01 09:59:13 +010016package org.opencord.sadis.impl;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070017
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000018import com.google.common.collect.Lists;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070019import org.apache.felix.scr.annotations.Component;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070020import org.apache.felix.scr.annotations.Reference;
21import org.apache.felix.scr.annotations.ReferenceCardinality;
22import org.apache.felix.scr.annotations.Service;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000023import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.onosproject.codec.CodecService;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070026import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
28import org.onosproject.net.config.ConfigFactory;
29import org.onosproject.net.config.NetworkConfigEvent;
30import org.onosproject.net.config.NetworkConfigListener;
31import org.onosproject.net.config.NetworkConfigRegistry;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000032import org.opencord.sadis.BaseInformationService;
33import org.opencord.sadis.BandwidthProfileInformation;
34import org.opencord.sadis.SadisService;
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000035import org.opencord.sadis.SubscriberAndDeviceInformation;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070036import org.slf4j.Logger;
37import org.slf4j.LoggerFactory;
38
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000039import java.util.List;
40import java.util.Set;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070041
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070042@Service
43@Component(immediate = true)
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000044public class SadisManager implements SadisService {
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070045 private final Logger log = LoggerFactory.getLogger(this.getClass());
46
47 private static final String SADIS_APP = "org.opencord.sadis";
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070048
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected CoreService coreService;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 protected NetworkConfigRegistry cfgService;
54
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000055 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected CodecService codecService;
57
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000058 private final InternalConfigListener cfgListener = new InternalConfigListener();
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070059
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000060 private SubscriberManager subscriberManager;
61 private BandwidthProfileManager bandwidthProfileManager;
62
63 private List<InformationAdapter> internalServices = Lists.newArrayList();
64
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070065 @Activate
66 protected void activate() {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000067 ApplicationId appId = this.coreService.registerApplication(SADIS_APP);
68 cfgService.addListener(this.cfgListener);
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070069
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000070 subscriberManager = new SubscriberManager(appId);
71 bandwidthProfileManager = new BandwidthProfileManager(appId);
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070072
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000073 internalServices.add(subscriberManager);
74 internalServices.add(bandwidthProfileManager);
75
76 registerAdapters();
77
78 log.info("Started");
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070079 }
80
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000081 private void registerAdapters() {
82 internalServices.forEach(service -> {
83 registerConfigFactory(service.getConfigFactories());
84 registerCodec(service);
85 service.updateConfig(cfgService);
86 });
87 }
88
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070089 @Deactivate
90 protected void deactivate() {
Deepa Vaddireddyfc67bdf2017-09-21 12:50:56 +053091 cfgService.removeListener(cfgListener);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000092 log.info("Stopped");
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070093 }
94
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000095 private void registerConfigFactory(Set<ConfigFactory> factories) {
96 factories.forEach(cfgService::registerConfigFactory);
97 }
Amit Ghosh38b232a2017-07-23 15:11:56 +010098
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000099 private void registerCodec(InformationAdapter service) {
100 codecService.registerCodec(service.getInformationClass(), service.getCodec());
101 }
102
103
104 @Override
105 public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() {
106 return subscriberManager;
107 }
108
109 @Override
110 public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() {
111 return bandwidthProfileManager;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -0700112 }
113
114 /**
115 * Listener for SADIS configuration events.
116 */
117 private class InternalConfigListener implements NetworkConfigListener {
118
119 @Override
120 public void event(final NetworkConfigEvent event) {
121
122 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000123 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) {
124
125 internalServices.forEach(adapter -> {
126 if (event.configClass().equals(adapter.getConfigClass())) {
127 adapter.updateConfig(cfgService);
128 log.info("Reconfigured");
129 }
130 });
David K. Bainbridgeeda2b052017-07-12 09:41:04 -0700131 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000132
133
David K. Bainbridgeeda2b052017-07-12 09:41:04 -0700134 }
135 }
136}
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000137