1 package org.onosproject.provider.lldp.impl;
3 import static org.junit.Assert.*;
4 import static org.onosproject.net.DeviceId.deviceId;
6 import org.junit.Before;
8 import org.onlab.packet.ChassisId;
9 import org.onosproject.net.Annotations;
10 import org.onosproject.net.DefaultAnnotations;
11 import org.onosproject.net.DefaultDevice;
12 import org.onosproject.net.DefaultPort;
13 import org.onosproject.net.Device;
14 import org.onosproject.net.DeviceId;
15 import org.onosproject.net.Port;
16 import org.onosproject.net.PortNumber;
17 import org.onosproject.net.provider.ProviderId;
19 import com.google.common.collect.ImmutableMap;
20 import com.google.common.collect.ImmutableSet;
22 public class SuppressionRulesTest {
24 private static final DeviceId NON_SUPPRESSED_DID = deviceId("of:1111000000000000");
25 private static final DeviceId SUPPRESSED_DID = deviceId("of:2222000000000000");
26 private static final ProviderId PID = new ProviderId("of", "foo");
27 private static final String MFR = "whitebox";
28 private static final String HW = "1.1.x";
29 private static final String SW1 = "3.8.1";
30 private static final String SN = "43311-12345";
31 private static final ChassisId CID = new ChassisId();
33 private static final PortNumber P1 = PortNumber.portNumber(1);
35 private SuppressionRules rules;
38 public void setUp() throws Exception {
39 rules = new SuppressionRules(ImmutableSet.of(SUPPRESSED_DID),
40 ImmutableSet.of(Device.Type.ROADM),
41 ImmutableMap.of("no-lldp", SuppressionRules.ANY_VALUE,
42 "sendLLDP", "false"));
46 public void testSuppressedDeviceId() {
47 Device device = new DefaultDevice(PID,
50 MFR, HW, SW1, SN, CID);
51 assertTrue(rules.isSuppressed(device));
55 public void testSuppressedDeviceType() {
56 Device device = new DefaultDevice(PID,
59 MFR, HW, SW1, SN, CID);
60 assertTrue(rules.isSuppressed(device));
64 public void testSuppressedDeviceAnnotation() {
65 Annotations annotation = DefaultAnnotations.builder()
66 .set("no-lldp", "random")
69 Device device = new DefaultDevice(PID,
72 MFR, HW, SW1, SN, CID, annotation);
73 assertTrue(rules.isSuppressed(device));
77 public void testSuppressedDeviceAnnotationExact() {
78 Annotations annotation = DefaultAnnotations.builder()
79 .set("sendLLDP", "false")
82 Device device = new DefaultDevice(PID,
85 MFR, HW, SW1, SN, CID, annotation);
86 assertTrue(rules.isSuppressed(device));
90 public void testNotSuppressedDevice() {
91 Device device = new DefaultDevice(PID,
94 MFR, HW, SW1, SN, CID);
95 assertFalse(rules.isSuppressed(device));
99 public void testSuppressedPortOnSuppressedDevice() {
100 Device device = new DefaultDevice(PID,
103 MFR, HW, SW1, SN, CID);
104 Port port = new DefaultPort(device, P1, true);
106 assertTrue(rules.isSuppressed(port));
110 public void testSuppressedPortAnnotation() {
111 Annotations annotation = DefaultAnnotations.builder()
112 .set("no-lldp", "random")
114 Device device = new DefaultDevice(PID,
117 MFR, HW, SW1, SN, CID);
118 Port port = new DefaultPort(device, P1, true, annotation);
120 assertTrue(rules.isSuppressed(port));
124 public void testSuppressedPortAnnotationExact() {
125 Annotations annotation = DefaultAnnotations.builder()
126 .set("sendLLDP", "false")
128 Device device = new DefaultDevice(PID,
131 MFR, HW, SW1, SN, CID);
132 Port port = new DefaultPort(device, P1, true, annotation);
134 assertTrue(rules.isSuppressed(port));
138 public void testNotSuppressedPort() {
139 Device device = new DefaultDevice(PID,
142 MFR, HW, SW1, SN, CID);
143 Port port = new DefaultPort(device, P1, true);
145 assertFalse(rules.isSuppressed(port));