blob: 09b503762cefaa2f815c7720ce957f53b75f9ccf [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 {
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020054 rules = new SuppressionRules(ImmutableSet.of(Device.Type.ROADM, Device.Type.OTN),
Yuta HIGUCHI41289382014-12-19 17:47:12 -080055 ImmutableMap.of("no-lldp", SuppressionRules.ANY_VALUE,
56 "sendLLDP", "false"));
57 }
58
59 @Test
Yuta HIGUCHI41289382014-12-19 17:47:12 -080060 public void testSuppressedDeviceType() {
61 Device device = new DefaultDevice(PID,
62 NON_SUPPRESSED_DID,
63 Device.Type.ROADM,
64 MFR, HW, SW1, SN, CID);
65 assertTrue(rules.isSuppressed(device));
66 }
67
68 @Test
69 public void testSuppressedDeviceAnnotation() {
70 Annotations annotation = DefaultAnnotations.builder()
71 .set("no-lldp", "random")
72 .build();
73
74 Device device = new DefaultDevice(PID,
75 NON_SUPPRESSED_DID,
76 Device.Type.SWITCH,
77 MFR, HW, SW1, SN, CID, annotation);
78 assertTrue(rules.isSuppressed(device));
79 }
80
81 @Test
82 public void testSuppressedDeviceAnnotationExact() {
83 Annotations annotation = DefaultAnnotations.builder()
84 .set("sendLLDP", "false")
85 .build();
86
87 Device device = new DefaultDevice(PID,
88 NON_SUPPRESSED_DID,
89 Device.Type.SWITCH,
90 MFR, HW, SW1, SN, CID, annotation);
91 assertTrue(rules.isSuppressed(device));
92 }
93
94 @Test
95 public void testNotSuppressedDevice() {
96 Device device = new DefaultDevice(PID,
97 NON_SUPPRESSED_DID,
98 Device.Type.SWITCH,
99 MFR, HW, SW1, SN, CID);
100 assertFalse(rules.isSuppressed(device));
101 }
102
103 @Test
Yuta HIGUCHI41289382014-12-19 17:47:12 -0800104 public void testSuppressedPortAnnotation() {
105 Annotations annotation = DefaultAnnotations.builder()
106 .set("no-lldp", "random")
107 .build();
108 Device device = new DefaultDevice(PID,
109 NON_SUPPRESSED_DID,
110 Device.Type.SWITCH,
111 MFR, HW, SW1, SN, CID);
112 Port port = new DefaultPort(device, P1, true, annotation);
113
114 assertTrue(rules.isSuppressed(port));
115 }
116
117 @Test
118 public void testSuppressedPortAnnotationExact() {
119 Annotations annotation = DefaultAnnotations.builder()
120 .set("sendLLDP", "false")
121 .build();
122 Device device = new DefaultDevice(PID,
123 NON_SUPPRESSED_DID,
124 Device.Type.SWITCH,
125 MFR, HW, SW1, SN, CID);
126 Port port = new DefaultPort(device, P1, true, annotation);
127
128 assertTrue(rules.isSuppressed(port));
129 }
130
131 @Test
132 public void testNotSuppressedPort() {
133 Device device = new DefaultDevice(PID,
134 NON_SUPPRESSED_DID,
135 Device.Type.SWITCH,
136 MFR, HW, SW1, SN, CID);
137 Port port = new DefaultPort(device, P1, true);
138
139 assertFalse(rules.isSuppressed(port));
140 }
141}