Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.onosproject.segmentrouting.grouphandler; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import static org.junit.Assert.assertFalse; |
| 23 | import static org.junit.Assert.assertTrue; |
| 24 | |
| 25 | public class DestinationSetTest { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 26 | DestinationSet ds1, ds2, ds3, ds4, ds5, ds6; |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 27 | DeviceId d201, d202; |
| 28 | int el201, el202; |
| 29 | |
| 30 | @Before |
| 31 | public void setUp() { |
| 32 | d201 = DeviceId.deviceId("of:0000000000000201"); |
| 33 | d202 = DeviceId.deviceId("of:0000000000000202"); |
| 34 | el201 = 201; |
| 35 | el202 = 202; |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 36 | ds1 = new DestinationSet(false, false, d201); |
| 37 | ds2 = new DestinationSet(false, false, el201, d201); |
| 38 | ds3 = new DestinationSet(false, false, el201, d201, el202, d202); |
| 39 | ds4 = new DestinationSet(false, false, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 40 | DestinationSet.NO_EDGE_LABEL, d201, |
| 41 | DestinationSet.NO_EDGE_LABEL, d202); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 42 | ds5 = new DestinationSet(true, false, d201); // not-bos |
| 43 | ds6 = new DestinationSet(false, true, el201, d201); // swap group |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testIsValid() { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 48 | assertTrue(!ds1.notBos()); |
| 49 | assertTrue(!ds1.swap()); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 50 | assertTrue(ds1.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL); |
| 51 | assertTrue(ds1.getDestinationSwitches().size() == 1); |
| 52 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 53 | assertTrue(!ds2.notBos()); |
| 54 | assertTrue(!ds2.swap()); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 55 | assertTrue(ds2.getEdgeLabel(d201) == el201); |
| 56 | assertTrue(ds2.getDestinationSwitches().size() == 1); |
| 57 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 58 | assertTrue(!ds3.notBos()); |
| 59 | assertTrue(!ds3.swap()); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 60 | assertTrue(ds3.getEdgeLabel(d201) == el201); |
| 61 | assertTrue(ds3.getEdgeLabel(d202) == el202); |
| 62 | assertTrue(ds3.getDestinationSwitches().size() == 2); |
| 63 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 64 | assertTrue(!ds4.notBos()); |
| 65 | assertTrue(!ds4.swap()); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 66 | assertTrue(ds4.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL); |
| 67 | assertTrue(ds4.getEdgeLabel(d202) == DestinationSet.NO_EDGE_LABEL); |
| 68 | assertTrue(ds4.getDestinationSwitches().size() == 2); |
| 69 | |
| 70 | assertFalse(ds1.equals(ds2)); |
| 71 | assertFalse(ds1.equals(ds4)); |
| 72 | assertFalse(ds3.equals(ds4)); |
| 73 | assertFalse(ds2.equals(ds3)); |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 74 | assertFalse(ds1.equals(ds3)); |
| 75 | |
| 76 | assertFalse(ds1.equals(ds5)); |
| 77 | assertFalse(ds2.equals(ds6)); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | @Test |
| 82 | public void testOneDestinationWithoutLabel() { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 83 | DestinationSet testds = new DestinationSet(false, false, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 84 | assertTrue(testds.equals(ds1)); // match |
| 85 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 86 | testds = new DestinationSet(true, false, d201); |
| 87 | assertFalse(testds.equals(ds1)); // wrong notBos |
| 88 | assertTrue(testds.equals(ds5)); // correct notBos |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 89 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 90 | testds = new DestinationSet(false, false, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 91 | assertFalse(testds.equals(ds1)); //wrong device |
| 92 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 93 | testds = new DestinationSet(false, false, el201, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 94 | assertFalse(testds.equals(ds1)); // wrong label |
| 95 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 96 | testds = new DestinationSet(false, false, -1, d201, -1, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 97 | assertFalse(testds.equals(ds1)); // 2-devs should not match |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 98 | |
| 99 | testds = new DestinationSet(false, true, d201); |
| 100 | assertFalse(testds.equals(ds1)); // wrong swap |
| 101 | assertFalse(testds.equals(ds6)); // wrong label |
| 102 | |
| 103 | testds = new DestinationSet(false, true, el201, d201); |
| 104 | assertTrue(testds.equals(ds6)); // correct swap |
| 105 | |
| 106 | testds = new DestinationSet(false, true, DestinationSet.NO_EDGE_LABEL, d201); |
| 107 | assertFalse(testds.equals(ds6)); // wrong label |
| 108 | |
| 109 | testds = new DestinationSet(true, true, el201, d201); |
| 110 | assertFalse(testds.equals(ds6)); // wrong notbos |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
| 114 | |
| 115 | @Test |
| 116 | public void testOneDestinationWithLabel() { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 117 | DestinationSet testds = new DestinationSet(false, false, 203, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 118 | assertFalse(testds.equals(ds2)); //wrong label |
| 119 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 120 | testds = new DestinationSet(true, false, 201, d201); |
| 121 | assertFalse(testds.equals(ds2)); // wrong notBos |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 122 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 123 | testds = new DestinationSet(false, false, 201, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 124 | assertFalse(testds.equals(ds2)); //wrong device |
| 125 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 126 | testds = new DestinationSet(false, false, 201, |
| 127 | DeviceId.deviceId("of:0000000000000201")); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 128 | assertTrue(testds.equals(ds2)); // match |
| 129 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 130 | testds = new DestinationSet(false, false, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 131 | assertFalse(testds.equals(ds2)); // wrong label |
| 132 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 133 | testds = new DestinationSet(false, false, el201, d201, el202, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 134 | assertFalse(testds.equals(ds1)); // 2-devs should not match |
| 135 | } |
| 136 | |
| 137 | @Test |
| 138 | public void testDestPairWithLabel() { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 139 | DestinationSet testds = new DestinationSet(false, false, el201, d201, el202, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 140 | assertTrue(testds.equals(ds3)); // match same switches, same order |
| 141 | assertTrue(testds.hashCode() == ds3.hashCode()); |
| 142 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 143 | testds = new DestinationSet(false, false, el202, d202, el201, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 144 | assertTrue(testds.equals(ds3)); // match same switches, order reversed |
| 145 | assertTrue(testds.hashCode() == ds3.hashCode()); |
| 146 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 147 | testds = new DestinationSet(false, false, el202, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 148 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 149 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 150 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 151 | testds = new DestinationSet(false, false, el201, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 152 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 153 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 154 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 155 | testds = new DestinationSet(false, false, el201, d201, 0, DeviceId.NONE); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 156 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 157 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 158 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 159 | testds = new DestinationSet(false, false, el201, d202, el201, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 160 | assertFalse(testds.equals(ds3)); // wrong labels |
| 161 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 162 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 163 | testds = new DestinationSet(true, false, el202, d202, el201, d201); |
| 164 | assertFalse(testds.equals(ds3)); // wrong not bos |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 165 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 166 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 167 | testds = new DestinationSet(false, false, el202, d202, el201, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 168 | assertFalse(testds.equals(ds3)); // wrong device |
| 169 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 170 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 171 | testds = new DestinationSet(false, false, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 172 | el202, DeviceId.deviceId("of:0000000000000205"), |
| 173 | el201, d201); |
| 174 | assertFalse(testds.equals(ds3)); // wrong device |
| 175 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void testDestPairWithoutLabel() { |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 180 | DestinationSet testds = new DestinationSet(false, false, -1, d201, -1, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 181 | assertTrue(testds.equals(ds4)); // match same switches, same order |
| 182 | assertTrue(testds.hashCode() == ds4.hashCode()); |
| 183 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 184 | testds = new DestinationSet(false, false, -1, d202, -1, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 185 | assertTrue(testds.equals(ds4)); // match same switches, order reversed |
| 186 | assertTrue(testds.hashCode() == ds4.hashCode()); |
| 187 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 188 | testds = new DestinationSet(false, false, -1, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 189 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 190 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 191 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 192 | testds = new DestinationSet(false, false, -1, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 193 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 194 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 195 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 196 | testds = new DestinationSet(false, false, -1, d201, 0, DeviceId.NONE); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 197 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 198 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 199 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 200 | testds = new DestinationSet(false, false, el201, d201, -1, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 201 | assertFalse(testds.equals(ds4)); // wrong labels |
| 202 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 203 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 204 | testds = new DestinationSet(true, false, -1, d202, -1, d201); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 205 | assertFalse(testds.equals(ds4)); // wrong mpls set |
| 206 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 207 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 208 | testds = new DestinationSet(false, false, -1, d202, -1, d202); |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 209 | assertFalse(testds.equals(ds4)); // wrong device |
| 210 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 211 | |
Saurav Das | 9724186 | 2018-02-14 14:14:54 -0800 | [diff] [blame^] | 212 | testds = new DestinationSet(false, false, |
Saurav Das | 261c300 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 213 | -1, DeviceId.deviceId("of:0000000000000205"), |
| 214 | -1, d201); |
| 215 | assertFalse(testds.equals(ds4)); // wrong device |
| 216 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 217 | } |
| 218 | |
| 219 | } |