Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 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 HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | import static org.onosproject.net.DeviceId.deviceId; |
| 20 | |
| 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; |
| 33 | |
| 34 | import com.google.common.collect.ImmutableMap; |
| 35 | import com.google.common.collect.ImmutableSet; |
| 36 | |
| 37 | public 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 Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 54 | rules = new SuppressionRules(ImmutableSet.of(Device.Type.ROADM, Device.Type.OTN), |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 55 | ImmutableMap.of("no-lldp", SuppressionRules.ANY_VALUE, |
| 56 | "sendLLDP", "false")); |
| 57 | } |
| 58 | |
| 59 | @Test |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 60 | 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 HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 104 | 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 | } |