blob: 03d431af55db0405bb4bf50eddf9808cecb87843 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
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 */
Yuta HIGUCHI41289382014-12-19 17:47:12 -080016package org.onosproject.provider.lldp.impl;
17
18import static org.junit.Assert.*;
19import static org.onosproject.net.DeviceId.deviceId;
20
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.ChassisId;
24import org.onosproject.net.Annotations;
25import org.onosproject.net.DefaultAnnotations;
26import org.onosproject.net.DefaultDevice;
27import org.onosproject.net.DefaultPort;
28import org.onosproject.net.Device;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.Port;
31import org.onosproject.net.PortNumber;
32import org.onosproject.net.provider.ProviderId;
33
34import com.google.common.collect.ImmutableMap;
35import com.google.common.collect.ImmutableSet;
36
37public class SuppressionRulesTest {
38
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();
47
48 private static final PortNumber P1 = PortNumber.portNumber(1);
49
50 private SuppressionRules rules;
51
52 @Before
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"));
58 }
59
60 @Test
61 public void testSuppressedDeviceId() {
62 Device device = new DefaultDevice(PID,
63 SUPPRESSED_DID,
64 Device.Type.SWITCH,
65 MFR, HW, SW1, SN, CID);
66 assertTrue(rules.isSuppressed(device));
67 }
68
69 @Test
70 public void testSuppressedDeviceType() {
71 Device device = new DefaultDevice(PID,
72 NON_SUPPRESSED_DID,
73 Device.Type.ROADM,
74 MFR, HW, SW1, SN, CID);
75 assertTrue(rules.isSuppressed(device));
76 }
77
78 @Test
79 public void testSuppressedDeviceAnnotation() {
80 Annotations annotation = DefaultAnnotations.builder()
81 .set("no-lldp", "random")
82 .build();
83
84 Device device = new DefaultDevice(PID,
85 NON_SUPPRESSED_DID,
86 Device.Type.SWITCH,
87 MFR, HW, SW1, SN, CID, annotation);
88 assertTrue(rules.isSuppressed(device));
89 }
90
91 @Test
92 public void testSuppressedDeviceAnnotationExact() {
93 Annotations annotation = DefaultAnnotations.builder()
94 .set("sendLLDP", "false")
95 .build();
96
97 Device device = new DefaultDevice(PID,
98 NON_SUPPRESSED_DID,
99 Device.Type.SWITCH,
100 MFR, HW, SW1, SN, CID, annotation);
101 assertTrue(rules.isSuppressed(device));
102 }
103
104 @Test
105 public void testNotSuppressedDevice() {
106 Device device = new DefaultDevice(PID,
107 NON_SUPPRESSED_DID,
108 Device.Type.SWITCH,
109 MFR, HW, SW1, SN, CID);
110 assertFalse(rules.isSuppressed(device));
111 }
112
113 @Test
114 public void testSuppressedPortOnSuppressedDevice() {
115 Device device = new DefaultDevice(PID,
116 SUPPRESSED_DID,
117 Device.Type.SWITCH,
118 MFR, HW, SW1, SN, CID);
119 Port port = new DefaultPort(device, P1, true);
120
121 assertTrue(rules.isSuppressed(port));
122 }
123
124 @Test
125 public void testSuppressedPortAnnotation() {
126 Annotations annotation = DefaultAnnotations.builder()
127 .set("no-lldp", "random")
128 .build();
129 Device device = new DefaultDevice(PID,
130 NON_SUPPRESSED_DID,
131 Device.Type.SWITCH,
132 MFR, HW, SW1, SN, CID);
133 Port port = new DefaultPort(device, P1, true, annotation);
134
135 assertTrue(rules.isSuppressed(port));
136 }
137
138 @Test
139 public void testSuppressedPortAnnotationExact() {
140 Annotations annotation = DefaultAnnotations.builder()
141 .set("sendLLDP", "false")
142 .build();
143 Device device = new DefaultDevice(PID,
144 NON_SUPPRESSED_DID,
145 Device.Type.SWITCH,
146 MFR, HW, SW1, SN, CID);
147 Port port = new DefaultPort(device, P1, true, annotation);
148
149 assertTrue(rules.isSuppressed(port));
150 }
151
152 @Test
153 public void testNotSuppressedPort() {
154 Device device = new DefaultDevice(PID,
155 NON_SUPPRESSED_DID,
156 Device.Type.SWITCH,
157 MFR, HW, SW1, SN, CID);
158 Port port = new DefaultPort(device, P1, true);
159
160 assertFalse(rules.isSuppressed(port));
161 }
162}