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