52f0bb1ed0f70f409ffa1069550f303062fe7c3c
[onosfw.git] /
1 package org.onosproject.provider.lldp.impl;
2
3 import static org.junit.Assert.*;
4 import static org.onosproject.net.DeviceId.deviceId;
5
6 import org.junit.Before;
7 import org.junit.Test;
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;
18
19 import com.google.common.collect.ImmutableMap;
20 import com.google.common.collect.ImmutableSet;
21
22 public class SuppressionRulesTest {
23
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();
32
33     private static final PortNumber P1 = PortNumber.portNumber(1);
34
35     private SuppressionRules rules;
36
37     @Before
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"));
43     }
44
45     @Test
46     public void testSuppressedDeviceId() {
47         Device device = new DefaultDevice(PID,
48                                           SUPPRESSED_DID,
49                                           Device.Type.SWITCH,
50                                           MFR, HW, SW1, SN, CID);
51         assertTrue(rules.isSuppressed(device));
52     }
53
54     @Test
55     public void testSuppressedDeviceType() {
56         Device device = new DefaultDevice(PID,
57                                           NON_SUPPRESSED_DID,
58                                           Device.Type.ROADM,
59                                           MFR, HW, SW1, SN, CID);
60         assertTrue(rules.isSuppressed(device));
61     }
62
63     @Test
64     public void testSuppressedDeviceAnnotation() {
65         Annotations annotation = DefaultAnnotations.builder()
66                 .set("no-lldp", "random")
67                 .build();
68
69         Device device = new DefaultDevice(PID,
70                                           NON_SUPPRESSED_DID,
71                                           Device.Type.SWITCH,
72                                           MFR, HW, SW1, SN, CID, annotation);
73         assertTrue(rules.isSuppressed(device));
74     }
75
76     @Test
77     public void testSuppressedDeviceAnnotationExact() {
78         Annotations annotation = DefaultAnnotations.builder()
79                 .set("sendLLDP", "false")
80                 .build();
81
82         Device device = new DefaultDevice(PID,
83                                           NON_SUPPRESSED_DID,
84                                           Device.Type.SWITCH,
85                                           MFR, HW, SW1, SN, CID, annotation);
86         assertTrue(rules.isSuppressed(device));
87     }
88
89     @Test
90     public void testNotSuppressedDevice() {
91         Device device = new DefaultDevice(PID,
92                                           NON_SUPPRESSED_DID,
93                                           Device.Type.SWITCH,
94                                           MFR, HW, SW1, SN, CID);
95         assertFalse(rules.isSuppressed(device));
96     }
97
98     @Test
99     public void testSuppressedPortOnSuppressedDevice() {
100         Device device = new DefaultDevice(PID,
101                                           SUPPRESSED_DID,
102                                           Device.Type.SWITCH,
103                                           MFR, HW, SW1, SN, CID);
104         Port port = new DefaultPort(device, P1, true);
105
106         assertTrue(rules.isSuppressed(port));
107     }
108
109     @Test
110     public void testSuppressedPortAnnotation() {
111         Annotations annotation = DefaultAnnotations.builder()
112                 .set("no-lldp", "random")
113                 .build();
114         Device device = new DefaultDevice(PID,
115                                           NON_SUPPRESSED_DID,
116                                           Device.Type.SWITCH,
117                                           MFR, HW, SW1, SN, CID);
118         Port port = new DefaultPort(device, P1, true, annotation);
119
120         assertTrue(rules.isSuppressed(port));
121     }
122
123     @Test
124     public void testSuppressedPortAnnotationExact() {
125         Annotations annotation = DefaultAnnotations.builder()
126                 .set("sendLLDP", "false")
127                 .build();
128         Device device = new DefaultDevice(PID,
129                                           NON_SUPPRESSED_DID,
130                                           Device.Type.SWITCH,
131                                           MFR, HW, SW1, SN, CID);
132         Port port = new DefaultPort(device, P1, true, annotation);
133
134         assertTrue(rules.isSuppressed(port));
135     }
136
137     @Test
138     public void testNotSuppressedPort() {
139         Device device = new DefaultDevice(PID,
140                                           NON_SUPPRESSED_DID,
141                                           Device.Type.SWITCH,
142                                           MFR, HW, SW1, SN, CID);
143         Port port = new DefaultPort(device, P1, true);
144
145         assertFalse(rules.isSuppressed(port));
146     }
147 }