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