2 * Copyright 2014-2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.provider.lldp.impl;
20 import java.util.Map.Entry;
23 import org.onosproject.net.Annotations;
24 import org.onosproject.net.Device;
25 import org.onosproject.net.DeviceId;
26 import org.onosproject.net.Element;
27 import org.onosproject.net.Port;
29 import com.google.common.collect.ImmutableMap;
30 import com.google.common.collect.ImmutableSet;
32 public class SuppressionRules {
34 public static final String ANY_VALUE = "(any)";
36 private final Set<DeviceId> suppressedDevice;
37 private final Set<Device.Type> suppressedDeviceType;
38 private final Map<String, String> suppressedAnnotation;
40 public SuppressionRules(Set<DeviceId> suppressedDevice,
41 Set<Device.Type> suppressedType,
42 Map<String, String> suppressedAnnotation) {
44 this.suppressedDevice = ImmutableSet.copyOf(suppressedDevice);
45 this.suppressedDeviceType = ImmutableSet.copyOf(suppressedType);
46 this.suppressedAnnotation = ImmutableMap.copyOf(suppressedAnnotation);
49 public boolean isSuppressed(Device device) {
50 if (suppressedDevice.contains(device.id())) {
53 if (suppressedDeviceType.contains(device.type())) {
56 final Annotations annotations = device.annotations();
57 if (containsSuppressionAnnotation(annotations)) {
63 public boolean isSuppressed(Port port) {
64 Element parent = port.element();
65 if (parent instanceof Device) {
66 if (isSuppressed((Device) parent)) {
71 final Annotations annotations = port.annotations();
72 if (containsSuppressionAnnotation(annotations)) {
78 private boolean containsSuppressionAnnotation(final Annotations annotations) {
79 for (Entry<String, String> entry : suppressedAnnotation.entrySet()) {
80 final String suppValue = entry.getValue();
81 final String suppKey = entry.getKey();
82 if (suppValue == ANY_VALUE) {
83 if (annotations.keys().contains(suppKey)) {
87 if (suppValue.equals(annotations.value(suppKey))) {
95 Set<DeviceId> getSuppressedDevice() {
96 return suppressedDevice;
99 Set<Device.Type> getSuppressedDeviceType() {
100 return suppressedDeviceType;
103 Map<String, String> getSuppressedAnnotation() {
104 return suppressedAnnotation;