blob: 74bf8b6958ca96c8b0d709fce3844f5f71c95313 [file] [log] [blame]
Phaneendra Mandabc7c6942015-12-03 16:33:24 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Phaneendra Mandabc7c6942015-12-03 16:33:24 +05303 *
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.onosproject.vtnrsc.classifier.impl;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import com.google.common.collect.ImmutableList;
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053019import org.onosproject.net.DeviceId;
20import org.onosproject.store.serializers.KryoNamespaces;
21import org.onosproject.store.service.DistributedSet;
22import org.onosproject.store.service.Serializer;
23import org.onosproject.store.service.StorageService;
24import org.onosproject.vtnrsc.classifier.ClassifierService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070025import org.osgi.service.component.annotations.Activate;
26import org.osgi.service.component.annotations.Component;
27import org.osgi.service.component.annotations.Deactivate;
28import org.osgi.service.component.annotations.Reference;
29import org.osgi.service.component.annotations.ReferenceCardinality;
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053030import org.slf4j.Logger;
31
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032import static org.slf4j.LoggerFactory.getLogger;
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053033
34/**
35 * Provides implementation of the Classifier Service.
36 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Component(immediate = true, service = ClassifierService.class)
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053038public class ClassifierManager implements ClassifierService {
39
40 private final Logger log = getLogger(ClassifierManager.class);
41
Ray Milkeyd84f89b2018-08-17 14:54:17 -070042 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053043 protected StorageService storageService;
44
45 private DistributedSet<DeviceId> classifierList;
46
47 @Activate
48 protected void activate() {
49 classifierList = storageService.<DeviceId>setBuilder()
50 .withName("classifier")
51 .withSerializer(Serializer.using(KryoNamespaces.API))
Madan Jampani538be742016-02-10 14:55:38 -080052 .build()
53 .asDistributedSet();
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053054 log.info("Started");
55 }
56
57 @Deactivate
58 protected void deactivate() {
59 log.info("Stopped");
60 }
61
62 @Override
63 public void addClassifier(DeviceId deviceId) {
64 classifierList.add(deviceId);
65 }
66
67 @Override
68 public Iterable<DeviceId> getClassifiers() {
69 return ImmutableList.copyOf(classifierList);
70 }
71
72 @Override
73 public void removeClassifier(DeviceId deviceId) {
74 classifierList.remove(deviceId);
75 }
76}