Saurav Das | 7bcbe70 | 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 | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 26 | DestinationSet ds1, ds2, ds3, ds4, ds5, ds6; |
Saurav Das | 7bcbe70 | 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; |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 36 | ds1 = DestinationSet.createTypePushNone(d201); |
| 37 | ds2 = DestinationSet.createTypePushBos(el201, d201); |
| 38 | ds3 = DestinationSet.createTypePushBos(el201, d201, el202, d202); |
| 39 | ds4 = DestinationSet.createTypePushBos(DestinationSet.NO_EDGE_LABEL, d201, |
| 40 | DestinationSet.NO_EDGE_LABEL, d202); |
| 41 | ds5 = DestinationSet.createTypePopNotBos(d201); |
| 42 | ds6 = DestinationSet.createTypeSwapBos(el201, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Test |
| 46 | public void testIsValid() { |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 47 | assertTrue(!ds1.notBos()); |
| 48 | assertTrue(!ds1.swap()); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 49 | assertTrue(ds1.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL); |
| 50 | assertTrue(ds1.getDestinationSwitches().size() == 1); |
| 51 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 52 | assertTrue(!ds2.notBos()); |
| 53 | assertTrue(!ds2.swap()); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 54 | assertTrue(ds2.getEdgeLabel(d201) == el201); |
| 55 | assertTrue(ds2.getDestinationSwitches().size() == 1); |
| 56 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 57 | assertTrue(!ds3.notBos()); |
| 58 | assertTrue(!ds3.swap()); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 59 | assertTrue(ds3.getEdgeLabel(d201) == el201); |
| 60 | assertTrue(ds3.getEdgeLabel(d202) == el202); |
| 61 | assertTrue(ds3.getDestinationSwitches().size() == 2); |
| 62 | |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 63 | assertTrue(!ds4.notBos()); |
| 64 | assertTrue(!ds4.swap()); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 65 | assertTrue(ds4.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL); |
| 66 | assertTrue(ds4.getEdgeLabel(d202) == DestinationSet.NO_EDGE_LABEL); |
| 67 | assertTrue(ds4.getDestinationSwitches().size() == 2); |
| 68 | |
| 69 | assertFalse(ds1.equals(ds2)); |
| 70 | assertFalse(ds1.equals(ds4)); |
| 71 | assertFalse(ds3.equals(ds4)); |
| 72 | assertFalse(ds2.equals(ds3)); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 73 | assertFalse(ds1.equals(ds3)); |
| 74 | |
| 75 | assertFalse(ds1.equals(ds5)); |
| 76 | assertFalse(ds2.equals(ds6)); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
| 80 | @Test |
| 81 | public void testOneDestinationWithoutLabel() { |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 82 | DestinationSet testds = DestinationSet.createTypePushNone(d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 83 | assertTrue(testds.equals(ds1)); // match |
| 84 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 85 | testds = DestinationSet.createTypePopNotBos(d201); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 86 | assertFalse(testds.equals(ds1)); // wrong notBos |
| 87 | assertTrue(testds.equals(ds5)); // correct notBos |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 88 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 89 | testds = DestinationSet.createTypePushNone(d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 90 | assertFalse(testds.equals(ds1)); //wrong device |
| 91 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 92 | testds = DestinationSet.createTypePushBos(el201, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 93 | assertFalse(testds.equals(ds1)); // wrong label |
| 94 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 95 | testds = DestinationSet.createTypePushBos(-1, d201, -1, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 96 | assertFalse(testds.equals(ds1)); // 2-devs should not match |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 97 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 98 | testds = DestinationSet.createTypeSwapBos(el201, d201); |
| 99 | assertFalse(testds.equals(ds1)); // wrong type and label |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 100 | assertTrue(testds.equals(ds6)); // correct swap |
| 101 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 102 | testds = DestinationSet.createTypeSwapNotBos(el201, d201); |
Saurav Das | a402038 | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 103 | assertFalse(testds.equals(ds6)); // wrong notbos |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | @Test |
| 109 | public void testOneDestinationWithLabel() { |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 110 | DestinationSet testds = DestinationSet.createTypePushBos(203, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 111 | assertFalse(testds.equals(ds2)); //wrong label |
| 112 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 113 | testds = DestinationSet.createTypePushBos(201, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 114 | assertFalse(testds.equals(ds2)); //wrong device |
| 115 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 116 | testds = DestinationSet.createTypePushBos(201, DeviceId.deviceId("of:0000000000000201")); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 117 | assertTrue(testds.equals(ds2)); // match |
| 118 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 119 | testds = DestinationSet.createTypePushNone(d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 120 | assertFalse(testds.equals(ds2)); // wrong label |
| 121 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 122 | testds = DestinationSet.createTypePushBos(el201, d201, el202, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 123 | assertFalse(testds.equals(ds1)); // 2-devs should not match |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void testDestPairWithLabel() { |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 128 | DestinationSet testds = DestinationSet.createTypePushBos(el201, d201, el202, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 129 | assertTrue(testds.equals(ds3)); // match same switches, same order |
| 130 | assertTrue(testds.hashCode() == ds3.hashCode()); |
| 131 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 132 | testds = DestinationSet.createTypePushBos(el202, d202, el201, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 133 | assertTrue(testds.equals(ds3)); // match same switches, order reversed |
| 134 | assertTrue(testds.hashCode() == ds3.hashCode()); |
| 135 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 136 | testds = DestinationSet.createTypePushBos(el202, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 137 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 138 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 139 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 140 | testds = DestinationSet.createTypePushBos(el201, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 141 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 142 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 143 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 144 | testds = DestinationSet.createTypePushBos(el201, d201, 0, DeviceId.NONE); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 145 | assertFalse(testds.equals(ds3)); // one less switch should not match |
| 146 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 147 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 148 | testds = DestinationSet.createTypePushBos(el201, d202, el201, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 149 | assertFalse(testds.equals(ds3)); // wrong labels |
| 150 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 151 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 152 | testds = DestinationSet.createTypePushBos(el202, d202, el201, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 153 | assertFalse(testds.equals(ds3)); // wrong device |
| 154 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 155 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 156 | testds = DestinationSet.createTypePushBos( |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 157 | el202, DeviceId.deviceId("of:0000000000000205"), |
| 158 | el201, d201); |
| 159 | assertFalse(testds.equals(ds3)); // wrong device |
| 160 | assertFalse(testds.hashCode() == ds3.hashCode()); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void testDestPairWithoutLabel() { |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 165 | DestinationSet testds = DestinationSet.createTypePushBos(-1, d201, -1, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 166 | assertTrue(testds.equals(ds4)); // match same switches, same order |
| 167 | assertTrue(testds.hashCode() == ds4.hashCode()); |
| 168 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 169 | testds = DestinationSet.createTypePushBos(-1, d202, -1, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 170 | assertTrue(testds.equals(ds4)); // match same switches, order reversed |
| 171 | assertTrue(testds.hashCode() == ds4.hashCode()); |
| 172 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 173 | testds = DestinationSet.createTypePushBos(-1, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 174 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 175 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 176 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 177 | testds = DestinationSet.createTypePushBos(-1, d201); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 178 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 179 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 180 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 181 | testds = DestinationSet.createTypePushBos(-1, d201, 0, DeviceId.NONE); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 182 | assertFalse(testds.equals(ds4)); // one less switch should not match |
| 183 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 184 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 185 | testds = DestinationSet.createTypePushBos(el201, d201, -1, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 186 | assertFalse(testds.equals(ds4)); // wrong labels |
| 187 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 188 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 189 | testds = DestinationSet.createTypePushBos(-1, d202, -1, d202); |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 190 | assertFalse(testds.equals(ds4)); // wrong device |
| 191 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 192 | |
Andreas Pantelopoulos | e8d5f41 | 2018-05-01 14:56:05 -0700 | [diff] [blame^] | 193 | testds = DestinationSet.createTypePushBos( |
Saurav Das | 7bcbe70 | 2017-06-13 15:35:54 -0700 | [diff] [blame] | 194 | -1, DeviceId.deviceId("of:0000000000000205"), |
| 195 | -1, d201); |
| 196 | assertFalse(testds.equals(ds4)); // wrong device |
| 197 | assertFalse(testds.hashCode() == ds4.hashCode()); |
| 198 | } |
| 199 | |
| 200 | } |