David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 180c109 | 2017-08-03 22:46:14 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 3 | * |
| 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 Ghosh | c29c7a9 | 2017-08-01 09:59:13 +0100 | [diff] [blame] | 16 | package org.opencord.sadis.impl; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 17 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 19 | import org.onosproject.codec.CodecService; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.core.CoreService; |
| 22 | import org.onosproject.net.config.ConfigFactory; |
| 23 | import org.onosproject.net.config.NetworkConfigEvent; |
| 24 | import org.onosproject.net.config.NetworkConfigListener; |
| 25 | import org.onosproject.net.config.NetworkConfigRegistry; |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 26 | import org.opencord.sadis.BandwidthProfileInformation; |
Carmelo Cascone | 3405985 | 2019-09-30 19:33:00 -0700 | [diff] [blame^] | 27 | import org.opencord.sadis.BaseInformationService; |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 28 | import org.opencord.sadis.SadisService; |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 29 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Carmelo Cascone | 3405985 | 2019-09-30 19:33:00 -0700 | [diff] [blame^] | 30 | import org.osgi.service.component.annotations.Activate; |
| 31 | import org.osgi.service.component.annotations.Component; |
| 32 | import org.osgi.service.component.annotations.Deactivate; |
| 33 | import org.osgi.service.component.annotations.Reference; |
| 34 | import org.osgi.service.component.annotations.ReferenceCardinality; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
| 37 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 38 | import java.util.List; |
| 39 | import java.util.Set; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 40 | |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 41 | @Component(immediate = true) |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 42 | public class SadisManager implements SadisService { |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 43 | private final Logger log = LoggerFactory.getLogger(this.getClass()); |
| 44 | |
| 45 | private static final String SADIS_APP = "org.opencord.sadis"; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 46 | |
Carmelo Cascone | 3405985 | 2019-09-30 19:33:00 -0700 | [diff] [blame^] | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 48 | protected CoreService coreService; |
| 49 | |
Carmelo Cascone | 3405985 | 2019-09-30 19:33:00 -0700 | [diff] [blame^] | 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 51 | protected NetworkConfigRegistry cfgService; |
| 52 | |
Carmelo Cascone | 3405985 | 2019-09-30 19:33:00 -0700 | [diff] [blame^] | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Deepa vaddireddy | 386f38b | 2017-08-02 06:24:01 +0000 | [diff] [blame] | 54 | protected CodecService codecService; |
| 55 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 56 | private final InternalConfigListener cfgListener = new InternalConfigListener(); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 57 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 58 | private SubscriberManager subscriberManager; |
| 59 | private BandwidthProfileManager bandwidthProfileManager; |
| 60 | |
| 61 | private List<InformationAdapter> internalServices = Lists.newArrayList(); |
| 62 | |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 63 | @Activate |
| 64 | protected void activate() { |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 65 | ApplicationId appId = this.coreService.registerApplication(SADIS_APP); |
| 66 | cfgService.addListener(this.cfgListener); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 67 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 68 | subscriberManager = new SubscriberManager(appId); |
| 69 | bandwidthProfileManager = new BandwidthProfileManager(appId); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 70 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 71 | internalServices.add(subscriberManager); |
| 72 | internalServices.add(bandwidthProfileManager); |
| 73 | |
| 74 | registerAdapters(); |
| 75 | |
| 76 | log.info("Started"); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 79 | private void registerAdapters() { |
| 80 | internalServices.forEach(service -> { |
| 81 | registerConfigFactory(service.getConfigFactories()); |
| 82 | registerCodec(service); |
| 83 | service.updateConfig(cfgService); |
| 84 | }); |
| 85 | } |
| 86 | |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 87 | @Deactivate |
| 88 | protected void deactivate() { |
Deepa Vaddireddy | fc67bdf | 2017-09-21 12:50:56 +0530 | [diff] [blame] | 89 | cfgService.removeListener(cfgListener); |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 90 | log.info("Stopped"); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 93 | private void registerConfigFactory(Set<ConfigFactory> factories) { |
| 94 | factories.forEach(cfgService::registerConfigFactory); |
| 95 | } |
Amit Ghosh | 38b232a | 2017-07-23 15:11:56 +0100 | [diff] [blame] | 96 | |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 97 | private void registerCodec(InformationAdapter service) { |
| 98 | codecService.registerCodec(service.getInformationClass(), service.getCodec()); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | @Override |
| 103 | public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() { |
| 104 | return subscriberManager; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() { |
| 109 | return bandwidthProfileManager; |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Listener for SADIS configuration events. |
| 114 | */ |
| 115 | private class InternalConfigListener implements NetworkConfigListener { |
| 116 | |
| 117 | @Override |
| 118 | public void event(final NetworkConfigEvent event) { |
| 119 | |
| 120 | if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 121 | || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) { |
| 122 | |
| 123 | internalServices.forEach(adapter -> { |
| 124 | if (event.configClass().equals(adapter.getConfigClass())) { |
| 125 | adapter.updateConfig(cfgService); |
| 126 | log.info("Reconfigured"); |
| 127 | } |
| 128 | }); |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 129 | } |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 130 | |
| 131 | |
David K. Bainbridge | eda2b05 | 2017-07-12 09:41:04 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | } |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 135 | |