2 * Copyright 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.
16 package org.onosproject.provider.lldp.impl;
18 import static org.junit.Assert.*;
19 import static org.onosproject.net.DeviceId.deviceId;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.onlab.packet.ChassisId;
24 import org.onosproject.net.Annotations;
25 import org.onosproject.net.DefaultAnnotations;
26 import org.onosproject.net.DefaultDevice;
27 import org.onosproject.net.DefaultPort;
28 import org.onosproject.net.Device;
29 import org.onosproject.net.DeviceId;
30 import org.onosproject.net.Port;
31 import org.onosproject.net.PortNumber;
32 import org.onosproject.net.provider.ProviderId;
34 import com.google.common.collect.ImmutableMap;
35 import com.google.common.collect.ImmutableSet;
37 public class SuppressionRulesTest {
39 private static final DeviceId NON_SUPPRESSED_DID = deviceId("of:1111000000000000");
40 private static final DeviceId SUPPRESSED_DID = deviceId("of:2222000000000000");
41 private static final ProviderId PID = new ProviderId("of", "foo");
42 private static final String MFR = "whitebox";
43 private static final String HW = "1.1.x";
44 private static final String SW1 = "3.8.1";
45 private static final String SN = "43311-12345";
46 private static final ChassisId CID = new ChassisId();
48 private static final PortNumber P1 = PortNumber.portNumber(1);
50 private SuppressionRules rules;
53 public void setUp() throws Exception {
54 rules = new SuppressionRules(ImmutableSet.of(SUPPRESSED_DID),
55 ImmutableSet.of(Device.Type.ROADM),
56 ImmutableMap.of("no-lldp", SuppressionRules.ANY_VALUE,
57 "sendLLDP", "false"));
61 public void testSuppressedDeviceId() {
62 Device device = new DefaultDevice(PID,
65 MFR, HW, SW1, SN, CID);
66 assertTrue(rules.isSuppressed(device));
70 public void testSuppressedDeviceType() {
71 Device device = new DefaultDevice(PID,
74 MFR, HW, SW1, SN, CID);
75 assertTrue(rules.isSuppressed(device));
79 public void testSuppressedDeviceAnnotation() {
80 Annotations annotation = DefaultAnnotations.builder()
81 .set("no-lldp", "random")
84 Device device = new DefaultDevice(PID,
87 MFR, HW, SW1, SN, CID, annotation);
88 assertTrue(rules.isSuppressed(device));
92 public void testSuppressedDeviceAnnotationExact() {
93 Annotations annotation = DefaultAnnotations.builder()
94 .set("sendLLDP", "false")
97 Device device = new DefaultDevice(PID,
100 MFR, HW, SW1, SN, CID, annotation);
101 assertTrue(rules.isSuppressed(device));
105 public void testNotSuppressedDevice() {
106 Device device = new DefaultDevice(PID,
109 MFR, HW, SW1, SN, CID);
110 assertFalse(rules.isSuppressed(device));
114 public void testSuppressedPortOnSuppressedDevice() {
115 Device device = new DefaultDevice(PID,
118 MFR, HW, SW1, SN, CID);
119 Port port = new DefaultPort(device, P1, true);
121 assertTrue(rules.isSuppressed(port));
125 public void testSuppressedPortAnnotation() {
126 Annotations annotation = DefaultAnnotations.builder()
127 .set("no-lldp", "random")
129 Device device = new DefaultDevice(PID,
132 MFR, HW, SW1, SN, CID);
133 Port port = new DefaultPort(device, P1, true, annotation);
135 assertTrue(rules.isSuppressed(port));
139 public void testSuppressedPortAnnotationExact() {
140 Annotations annotation = DefaultAnnotations.builder()
141 .set("sendLLDP", "false")
143 Device device = new DefaultDevice(PID,
146 MFR, HW, SW1, SN, CID);
147 Port port = new DefaultPort(device, P1, true, annotation);
149 assertTrue(rules.isSuppressed(port));
153 public void testNotSuppressedPort() {
154 Device device = new DefaultDevice(PID,
157 MFR, HW, SW1, SN, CID);
158 Port port = new DefaultPort(device, P1, true);
160 assertFalse(rules.isSuppressed(port));