Bharat saraswal
Committed by Ray Milkey

[ONOS-3116] FlowClassifier Manager.

Change-Id: I9122f3add8aff2ce780a9da23d279bae345cdf1c
1 +/*
2 + * Copyright 2015 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 + */
16 +package org.onosproject.vtnrsc.flowClassifier.impl;
17 +
18 +import java.util.concurrent.ConcurrentHashMap;
19 +import java.util.concurrent.ConcurrentMap;
20 +
21 +import org.apache.felix.scr.annotations.Activate;
22 +import org.apache.felix.scr.annotations.Component;
23 +import org.apache.felix.scr.annotations.Deactivate;
24 +import org.apache.felix.scr.annotations.Service;
25 +import org.onosproject.vtnrsc.FlowClassifierId;
26 +import org.onosproject.vtnrsc.FlowClassifier;
27 +import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService;
28 +
29 +import org.slf4j.Logger;
30 +import static org.slf4j.LoggerFactory.getLogger;
31 +
32 +import static com.google.common.base.Preconditions.checkNotNull;
33 +import com.google.common.collect.ImmutableList;
34 +
35 +/**
36 + * Provides implementation of the Flow Classifier Service.
37 + */
38 +@Component(immediate = true)
39 +@Service
40 +public class FlowClassifierManager implements FlowClassifierService {
41 +
42 + private final Logger log = getLogger(FlowClassifierManager.class);
43 +
44 + private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null";
45 + private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null";
46 +
47 + private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore
48 + = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>();
49 +
50 + @Activate
51 + private void activate() {
52 + log.info("Flow Classifier service activated");
53 + }
54 +
55 + @Deactivate
56 + private void deactivate() {
57 + log.info("Flow Classifier service deactivated");
58 + }
59 +
60 + @Override
61 + public boolean createFlowClassifier(FlowClassifier flowClassifier) {
62 + log.debug("createFlowClassifier");
63 + checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
64 + FlowClassifierId id = flowClassifier.flowClassifierId();
65 +
66 + flowClassifierStore.put(id, flowClassifier);
67 + if (!flowClassifierStore.containsKey(id)) {
68 + log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString());
69 + return false;
70 + }
71 + return true;
72 + }
73 +
74 + @Override
75 + public Iterable<FlowClassifier> getFlowClassifiers() {
76 + return ImmutableList.copyOf(flowClassifierStore.values());
77 + }
78 +
79 + @Override
80 + public boolean hasFlowClassifier(FlowClassifierId id) {
81 + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
82 + return flowClassifierStore.containsKey(id);
83 + }
84 +
85 + @Override
86 + public FlowClassifier getFlowClassifier(FlowClassifierId id) {
87 + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
88 + return flowClassifierStore.get(id);
89 + }
90 +
91 + @Override
92 + public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
93 + checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
94 + FlowClassifierId id = flowClassifier.flowClassifierId();
95 + return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier);
96 + }
97 +
98 + @Override
99 + public boolean removeFlowClassifier(FlowClassifierId id) {
100 + checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
101 + flowClassifierStore.remove(id);
102 + if (flowClassifierStore.containsKey(id)) {
103 + log.debug("The Flow Classifier removal is failed whose identifier is {}", id.toString());
104 + return false;
105 + }
106 + return true;
107 + }
108 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 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 + */
16 +
17 +/**
18 + * Provides implementation of the flow Classifier service.
19 + */
20 +package org.onosproject.vtnrsc.flowClassifier.impl;