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