blob: 713b8b0c6560ce983389ebaf8adb9820a2c87eed [file] [log] [blame]
David K. Bainbridgeeda2b052017-07-12 09:41:04 -07001/*
2 * Copyright 2017-present Open Networking Laboratory
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 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;
34import org.slf4j.Logger;
35import org.slf4j.LoggerFactory;
36
37import com.google.common.collect.ImmutableSet;
38
39/**
40 * Subscriber And Device Information Service application component. Component
41 * that manages the integration of ONOS into a deployment providing a bridge
42 * between ONOS and deployment specific information about subscribers and access
43 * devices.
44 */
45@Service
46@Component(immediate = true)
47public class SadisManager extends SubscriberAndDeviceInformationAdapter {
48 private final Logger log = LoggerFactory.getLogger(this.getClass());
49
50 private static final String SADIS_APP = "org.opencord.sadis";
51 private ApplicationId appId;
52 private final InternalConfigListener cfgListener = new InternalConfigListener();
53
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 protected CoreService coreService;
56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected NetworkConfigRegistry cfgService;
59
60 @SuppressWarnings("rawtypes")
61 private final Set<ConfigFactory> factories = ImmutableSet
62 .of(new ConfigFactory<ApplicationId, SadisConfig>(APP_SUBJECT_FACTORY, SadisConfig.class, "sadis") {
63 @Override
64 public SadisConfig createConfig() {
65 return new SadisConfig();
66 }
67 });
68
69 /**
70 * Initialize the SADIS ONOS application.
71 */
72 @Activate
73 protected void activate() {
74
75 this.appId = this.coreService.registerApplication(SADIS_APP);
76 this.cfgService.addListener(this.cfgListener);
77 this.factories.forEach(this.cfgService::registerConfigFactory);
78 this.updateConfig();
79
80 this.log.info("Started");
81 }
82
83 /**
84 * Cleans up resources utilized by the SADIS ONOS application.
85 */
86 @Deactivate
87 protected void deactivate() {
88 this.log.info("Stopped");
89 }
90
91 /**
92 * Validates the configuration and updates any operational settings that are
93 * affected by configuration changes.
94 */
95 private void updateConfig() {
96 final SadisConfig cfg = this.cfgService.getConfig(this.appId, SadisConfig.class);
97 if (cfg == null) {
98 this.log.warn("Subscriber And Device Information Service (SADIS) configuration not available");
99 return;
100 }
101 this.log.info("Cache Enabled: {}", cfg.getCacheEnabled());
102 this.log.info("Cache Mac Size: {}", cfg.getCacheMaxSize());
103 this.log.info("Cache TTL: {}", cfg.getCacheTtl().getSeconds());
104 this.log.info("Entries: {}", cfg.getEntries());
Amit Ghosh38b232a2017-07-23 15:11:56 +0100105
106 configure(cfg);
David K. Bainbridgeeda2b052017-07-12 09:41:04 -0700107 }
108
109 /**
110 * Listener for SADIS configuration events.
111 */
112 private class InternalConfigListener implements NetworkConfigListener {
113
114 @Override
115 public void event(final NetworkConfigEvent event) {
116
117 if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
118 || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
119 && event.configClass().equals(SadisConfig.class)) {
120 SadisManager.this.updateConfig();
121 SadisManager.this.log.info("Reconfigured");
122 }
123 }
124 }
125}