blob: 01f948fc0c742882dac5fc89404430d205b7352c [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.opencord.sadis.impl;
17
18import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
19
20import java.util.Set;
21import java.util.concurrent.TimeUnit;
22
23import com.fasterxml.jackson.databind.ObjectMapper;
24import com.fasterxml.jackson.databind.module.SimpleModule;
25import com.google.common.cache.CacheBuilder;
26import org.onlab.packet.Ip4Address;
27import org.onlab.packet.VlanId;
28import org.onosproject.codec.JsonCodec;
29import org.onosproject.core.ApplicationId;
30import org.onosproject.net.config.ConfigFactory;
31import org.opencord.sadis.SubscriberAndDeviceInformation;
yasin sapli2c93ddb2021-06-11 17:46:26 +030032import org.opencord.sadis.UniTagInformation;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000033import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
36import com.google.common.collect.ImmutableSet;
37
38/**
39 * Subscriber And Device Information Service application component. Component
40 * that manages the integration of ONOS into a deployment providing a bridge
41 * between ONOS and deployment specific information about subscribers and access
42 * devices.
43 */
44
45public class SubscriberManager extends InformationAdapter<SubscriberAndDeviceInformation,
46 SubscriberAndDeviceInformationConfig> {
47 private final Logger log = LoggerFactory.getLogger(this.getClass());
48
49 private ApplicationId appId;
50
51 @SuppressWarnings("rawtypes")
52 private final Set<ConfigFactory> factories = ImmutableSet
53 .of(new ConfigFactory<ApplicationId, SubscriberAndDeviceInformationConfig>(APP_SUBJECT_FACTORY,
54 SubscriberAndDeviceInformationConfig.class, "sadis") {
55 @Override
56 public SubscriberAndDeviceInformationConfig createConfig() {
57 return new SubscriberAndDeviceInformationConfig();
58 }
59 });
60
61
62 public SubscriberManager(ApplicationId appId) {
63 this.appId = appId;
64 this.registerModule();
65 this.log.info("Started");
66 }
67
68 @Override
69 public void registerModule() {
70 cache = CacheBuilder.newBuilder().maximumSize(maxiumCacheSize)
71 .expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build();
72 log.info("Cache is {} and this {}", cache, this);
73 mapper = new ObjectMapper();
74 SimpleModule module = new SimpleModule();
75 SubscriberAndDeviceInformationConfig config = new SubscriberAndDeviceInformationConfig();
76 SubscriberAndDeviceInformationConfig.VlanIdDeserializer vlanID = config.new VlanIdDeserializer();
77 SubscriberAndDeviceInformationConfig.Ip4AddressDeserializer ip4Address = config.new Ip4AddressDeserializer();
yasin sapli2c93ddb2021-06-11 17:46:26 +030078 SubscriberAndDeviceInformationConfig.UniTagDeserializer uniTagSerializer = config.new UniTagDeserializer();
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000079 module.addDeserializer(VlanId.class, vlanID);
80 module.addDeserializer(Ip4Address.class, ip4Address);
yasin sapli2c93ddb2021-06-11 17:46:26 +030081 module.addDeserializer(UniTagInformation.class, uniTagSerializer);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000082 mapper.registerModule(module);
83 }
84
85 @Override
86 public ApplicationId getAppId() {
87 return this.appId;
88 }
89
90 @Override
91 public Set<ConfigFactory> getConfigFactories() {
92 return factories;
93 }
94
95 @Override
96 public JsonCodec<SubscriberAndDeviceInformation> getCodec() {
97 return new SubscriberAndDeviceInformationCodec();
98 }
99
100 @Override
101 public Class<SubscriberAndDeviceInformation> getInformationClass() {
102 return SubscriberAndDeviceInformation.class;
103 }
104
105 @Override
106 public Class<SubscriberAndDeviceInformationConfig> getConfigClass() {
107 return SubscriberAndDeviceInformationConfig.class;
108 }
109
110
111}