blob: 37114bd3968de8ebc7e6d055bbdbfbee160488ab [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
18import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
19
20import java.util.Set;
21
22import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Reference;
26import org.apache.felix.scr.annotations.ReferenceCardinality;
27import org.apache.felix.scr.annotations.Service;
28import org.onosproject.core.ApplicationId;
29import org.onosproject.core.CoreService;
30import org.onosproject.net.config.ConfigFactory;
31import org.onosproject.net.config.NetworkConfigEvent;
32import org.onosproject.net.config.NetworkConfigListener;
33import org.onosproject.net.config.NetworkConfigRegistry;
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000034import org.onosproject.codec.CodecService;
35import org.opencord.sadis.SubscriberAndDeviceInformation;
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070036import org.slf4j.Logger;
37import org.slf4j.LoggerFactory;
38
39import com.google.common.collect.ImmutableSet;
40
41/**
42 * Subscriber And Device Information Service application component. Component
43 * that manages the integration of ONOS into a deployment providing a bridge
44 * between ONOS and deployment specific information about subscribers and access
45 * devices.
46 */
47@Service
48@Component(immediate = true)
49public class SadisManager extends SubscriberAndDeviceInformationAdapter {
50 private final Logger log = LoggerFactory.getLogger(this.getClass());
51
52 private static final String SADIS_APP = "org.opencord.sadis";
53 private ApplicationId appId;
54 private final InternalConfigListener cfgListener = new InternalConfigListener();
55
56 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected CoreService coreService;
58
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected NetworkConfigRegistry cfgService;
61
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000062 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected CodecService codecService;
64
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070065 @SuppressWarnings("rawtypes")
66 private final Set<ConfigFactory> factories = ImmutableSet
67 .of(new ConfigFactory<ApplicationId, SadisConfig>(APP_SUBJECT_FACTORY, SadisConfig.class, "sadis") {
68 @Override
69 public SadisConfig createConfig() {
70 return new SadisConfig();
71 }
72 });
73
74 /**
75 * Initialize the SADIS ONOS application.
76 */
77 @Activate
78 protected void activate() {
79
80 this.appId = this.coreService.registerApplication(SADIS_APP);
Deepa vaddireddy386f38b2017-08-02 06:24:01 +000081 codecService.registerCodec(SubscriberAndDeviceInformation.class, new SubscriberAndDeviceInformationCodec());
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070082 this.cfgService.addListener(this.cfgListener);
83 this.factories.forEach(this.cfgService::registerConfigFactory);
84 this.updateConfig();
85
86 this.log.info("Started");
87 }
88
89 /**
90 * Cleans up resources utilized by the SADIS ONOS application.
91 */
92 @Deactivate
93 protected void deactivate() {
Deepa Vaddireddyfc67bdf2017-09-21 12:50:56 +053094 cfgService.removeListener(cfgListener);
David K. Bainbridgeeda2b052017-07-12 09:41:04 -070095 this.log.info("Stopped");
96 }
97
98 /**
99 * Validates the configuration and updates any operational settings that are
100 * affected by configuration changes.
101 */
102 private void updateConfig() {
103 final SadisConfig cfg = this.cfgService.getConfig(this.appId, SadisConfig.class);
104 if (cfg == null) {
105 this.log.warn("Subscriber And Device Information Service (SADIS) configuration not available");
106 return;
107 }
108 this.log.info("Cache Enabled: {}", cfg.getCacheEnabled());
109 this.log.info("Cache Mac Size: {}", cfg.getCacheMaxSize());
110 this.log.info("Cache TTL: {}", cfg.getCacheTtl().getSeconds());
111 this.log.info("Entries: {}", cfg.getEntries());
Amit Ghosh38b232a2017-07-23 15:11:56 +0100112
113 configure(cfg);
David K. Bainbridgeeda2b052017-07-12 09:41:04 -0700114 }
115
116 /**
117 * Listener for SADIS configuration events.
118 */
119 private class InternalConfigListener implements NetworkConfigListener {
120
121 @Override
122 public void event(final NetworkConfigEvent event) {
123
124 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
125 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
126 && event.configClass().equals(SadisConfig.class)) {
127 SadisManager.this.updateConfig();
128 SadisManager.this.log.info("Reconfigured");
129 }
130 }
131 }
132}