Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
| 16 | package org.onosproject.tetopology.manager.api; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.tetopology.management.api.link.ConnectivityMatrixId; |
| 21 | import org.onosproject.tetopology.management.api.link.ElementType; |
| 22 | import org.onosproject.tetopology.management.api.link.Label; |
| 23 | import org.onosproject.tetopology.management.api.link.PathElement; |
| 24 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 25 | import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath; |
| 26 | import org.onosproject.tetopology.management.api.link.UnderlayBackupPath; |
| 27 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
| 28 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrixKey; |
| 29 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 30 | import org.onosproject.tetopology.management.api.node.TtpKey; |
| 31 | |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.BitSet; |
| 34 | import java.util.List; |
| 35 | |
| 36 | import static org.junit.Assert.assertFalse; |
| 37 | import static org.junit.Assert.assertTrue; |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Unit tests for TE node APIs. |
| 42 | */ |
| 43 | public class TeNodeApiTest { |
| 44 | private static final long DEFAULT_PROVIDER_ID = 123; |
| 45 | private static final long DEFAULT_CLIENT_ID = 456; |
| 46 | private static final long DEFAULT_TOPOLOGY_ID = 789; |
| 47 | private static final long DEFAULT_TE_NODE_ID = 1234; |
| 48 | private static final long DEFAULT_CONNECTIVITY_ENTRY_ID = 5678; |
| 49 | private static final long DEFAULT_TTP_ID = 897; |
| 50 | private static final String DEFAULT_TOPOLOGY_ID_STRING = |
| 51 | "default-topology-123"; |
| 52 | private static final long DEFAULT_PATH_ELEMENT_ID = 234; |
| 53 | private static final long DEFAULT_UNDERLAY_BACKUP_PATH_IDX = 10; |
| 54 | |
| 55 | private long providerId; |
| 56 | private long clientId; |
| 57 | private long topologyId; |
| 58 | private long teNodeId; |
| 59 | private long connectivityMatrixEntryId; |
| 60 | private long pathElementId; |
| 61 | private long underlayBackupPathIndex; |
| 62 | private long ttpId; |
| 63 | |
| 64 | private String topologyIdString; |
| 65 | |
| 66 | @Before |
| 67 | public void setUp() { |
| 68 | providerId = DEFAULT_PROVIDER_ID; |
| 69 | clientId = DEFAULT_CLIENT_ID; |
| 70 | topologyId = DEFAULT_TOPOLOGY_ID; |
| 71 | teNodeId = DEFAULT_TE_NODE_ID; |
| 72 | connectivityMatrixEntryId = DEFAULT_CONNECTIVITY_ENTRY_ID; |
| 73 | topologyIdString = DEFAULT_TOPOLOGY_ID_STRING; |
| 74 | pathElementId = DEFAULT_PATH_ELEMENT_ID; |
| 75 | underlayBackupPathIndex = DEFAULT_UNDERLAY_BACKUP_PATH_IDX; |
| 76 | ttpId = DEFAULT_TTP_ID; |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void connectivityMatrixKeyEqualOperatorTest() { |
| 81 | ConnectivityMatrixKey key1 = new ConnectivityMatrixKey(providerId, |
| 82 | clientId, |
| 83 | topologyId, |
| 84 | teNodeId, |
| 85 | connectivityMatrixEntryId); |
| 86 | ConnectivityMatrixKey key2 = new ConnectivityMatrixKey(providerId, |
| 87 | clientId, |
| 88 | topologyId, |
| 89 | teNodeId, |
| 90 | connectivityMatrixEntryId); |
| 91 | ConnectivityMatrixKey key3 = new ConnectivityMatrixKey(providerId + 1, |
| 92 | clientId, |
| 93 | topologyId, |
| 94 | teNodeId, |
| 95 | connectivityMatrixEntryId); |
| 96 | ConnectivityMatrixKey key4 = new ConnectivityMatrixKey(providerId, |
| 97 | clientId + 1, |
| 98 | topologyId, |
| 99 | teNodeId, |
| 100 | connectivityMatrixEntryId); |
| 101 | ConnectivityMatrixKey key5 = new ConnectivityMatrixKey(providerId, |
| 102 | clientId, |
| 103 | topologyId + 1, |
| 104 | teNodeId, |
| 105 | connectivityMatrixEntryId); |
| 106 | ConnectivityMatrixKey key6 = new ConnectivityMatrixKey(providerId, |
| 107 | clientId, |
| 108 | topologyId, |
| 109 | teNodeId + 1, |
| 110 | connectivityMatrixEntryId); |
| 111 | ConnectivityMatrixKey key7 = new ConnectivityMatrixKey(providerId, |
| 112 | clientId, |
| 113 | topologyId, |
| 114 | teNodeId, |
| 115 | connectivityMatrixEntryId + 1); |
| 116 | |
| 117 | assertTrue("Two matrix keys must be equal", key1.equals(key2)); |
| 118 | |
| 119 | assertFalse("Two matrix keys must be unequal", key1.equals(key3)); |
| 120 | assertFalse("Two matrix keys must be unequal", key3.equals(key1)); |
| 121 | |
| 122 | assertFalse("Two matrix keys must be unequal", key1.equals(key4)); |
| 123 | assertFalse("Two matrix keys must be unequal", key4.equals(key1)); |
| 124 | |
| 125 | assertFalse("Two matrix keys must be unequal", key1.equals(key5)); |
| 126 | assertFalse("Two matrix keys must be unequal", key5.equals(key1)); |
| 127 | |
| 128 | assertFalse("Two matrix keys must be unequal", key1.equals(key6)); |
| 129 | assertFalse("Two matrix keys must be unequal", key6.equals(key1)); |
| 130 | |
| 131 | assertFalse("Two matrix keys must be unequal", key1.equals(key7)); |
| 132 | assertFalse("Two matrix keys must be unequal", key7.equals(key1)); |
| 133 | } |
| 134 | |
| 135 | @Test |
| 136 | public void underlayBackupPathEqualOperatorTest() { |
| 137 | ElementType pathElementType1 = new Label(pathElementId + 1); |
| 138 | ElementType pathElementType2 = new Label(pathElementId + 2); |
| 139 | ElementType pathElementType3 = new Label(pathElementId + 3); |
| 140 | ElementType pathElementType4 = new Label(pathElementId + 4); |
| 141 | |
| 142 | PathElement pathElement1 = new PathElement(pathElementId, teNodeId, |
| 143 | pathElementType1, true); |
| 144 | PathElement pathElement2 = new PathElement(pathElementId + 1, |
| 145 | teNodeId + 1, |
| 146 | pathElementType2, true); |
| 147 | PathElement pathElement3 = new PathElement(pathElementId + 2, |
| 148 | teNodeId + 2, |
| 149 | pathElementType3, true); |
| 150 | PathElement pathElement4 = new PathElement(pathElementId + 3, |
| 151 | teNodeId + 3, |
| 152 | pathElementType4, true); |
| 153 | |
| 154 | List<PathElement> pathElementList1 = new ArrayList<>(); |
| 155 | pathElementList1.add(pathElement1); |
| 156 | pathElementList1.add(pathElement2); |
| 157 | pathElementList1.add(pathElement3); |
| 158 | |
| 159 | List<PathElement> pathElementList2 = new ArrayList<>(); |
| 160 | pathElementList2.add(pathElement1); |
| 161 | pathElementList2.add(pathElement2); |
| 162 | pathElementList2.add(pathElement4); |
| 163 | |
| 164 | // bp1 and bp2 are the same. bp3, bp4, and bp5 differ by one |
| 165 | // attribute comparing to bp1. |
| 166 | UnderlayBackupPath bp1 = new UnderlayBackupPath( |
| 167 | underlayBackupPathIndex, pathElementList1, true); |
| 168 | UnderlayBackupPath bp2 = new UnderlayBackupPath( |
| 169 | underlayBackupPathIndex, pathElementList1, true); |
| 170 | |
| 171 | UnderlayBackupPath bp3 = new UnderlayBackupPath( |
| 172 | underlayBackupPathIndex + 1, pathElementList1, true); |
| 173 | UnderlayBackupPath bp4 = new UnderlayBackupPath( |
| 174 | underlayBackupPathIndex, pathElementList2, true); |
| 175 | UnderlayBackupPath bp5 = new UnderlayBackupPath( |
| 176 | underlayBackupPathIndex, pathElementList1, false); |
| 177 | |
| 178 | |
| 179 | assertTrue("Two backup paths must be equal", bp1.equals(bp2)); |
| 180 | |
| 181 | assertFalse("Two backup paths must be unequal", bp1.equals(bp3)); |
| 182 | assertFalse("Two backup paths must be unequal", bp3.equals(bp1)); |
| 183 | |
| 184 | assertFalse("Two backup paths must be unequal", bp1.equals(bp4)); |
| 185 | assertFalse("Two backup paths must be unequal", bp4.equals(bp1)); |
| 186 | |
| 187 | assertFalse("Two backup paths must be unequal", bp1.equals(bp5)); |
| 188 | assertFalse("Two backup paths must be unequal", bp5.equals(bp1)); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | @Test |
| 193 | public void connectivityMatrixEqualOperatorTest() { |
| 194 | long key1 = connectivityMatrixEntryId; |
| 195 | long key2 = connectivityMatrixEntryId + 1; |
| 196 | |
| 197 | ElementType pathElementType1 = new Label(pathElementId + 1); |
| 198 | ElementType pathElementType2 = new Label(pathElementId + 2); |
| 199 | ElementType pathElementType3 = new Label(pathElementId + 3); |
| 200 | ElementType pathElementType4 = new Label(pathElementId + 4); |
| 201 | |
| 202 | PathElement pathElement1 = new PathElement(pathElementId, teNodeId, |
| 203 | pathElementType1, true); |
| 204 | PathElement pathElement2 = new PathElement(pathElementId + 1, |
| 205 | teNodeId + 1, |
| 206 | pathElementType2, true); |
| 207 | PathElement pathElement3 = new PathElement(pathElementId + 2, |
| 208 | teNodeId + 2, |
| 209 | pathElementType3, true); |
| 210 | PathElement pathElement4 = new PathElement(pathElementId + 3, |
| 211 | teNodeId + 3, |
| 212 | pathElementType4, true); |
| 213 | |
| 214 | List<PathElement> pathElementList1 = new ArrayList<>(); |
| 215 | pathElementList1.add(pathElement1); |
| 216 | pathElementList1.add(pathElement2); |
| 217 | pathElementList1.add(pathElement3); |
| 218 | |
| 219 | List<PathElement> pathElementList2 = new ArrayList<>(); |
| 220 | pathElementList2.add(pathElement1); |
| 221 | pathElementList2.add(pathElement2); |
| 222 | pathElementList2.add(pathElement4); |
| 223 | |
| 224 | UnderlayAbstractPath abstractPath1 = new UnderlayAbstractPath( |
| 225 | pathElementList1, true); |
| 226 | UnderlayAbstractPath abstractPath2 = new UnderlayAbstractPath( |
| 227 | pathElementList2, true); |
| 228 | |
| 229 | ElementType from = new ConnectivityMatrixId(connectivityMatrixEntryId); |
| 230 | List<ElementType> mergingList = new ArrayList<>(); |
| 231 | mergingList.add(new ConnectivityMatrixId(connectivityMatrixEntryId + 1)); |
| 232 | mergingList.add(new ConnectivityMatrixId(connectivityMatrixEntryId + 2)); |
| 233 | |
| 234 | List<ElementType> constrainList = new ArrayList<>(); |
| 235 | constrainList.add(new ConnectivityMatrixId(connectivityMatrixEntryId + 3)); |
| 236 | constrainList.add(new ConnectivityMatrixId(connectivityMatrixEntryId + 4)); |
| 237 | |
| 238 | BitSet flags = new BitSet(1); |
| 239 | |
| 240 | List<Long> srlgs = new ArrayList<>(); |
| 241 | srlgs.add(new Long(10)); |
| 242 | TePathAttributes tePathAttributes = new TePathAttributes(new Long(10), |
| 243 | new Long(10), |
| 244 | srlgs); |
| 245 | |
| 246 | ConnectivityMatrix matrix1 = new ConnectivityMatrix(key1, |
| 247 | from, |
| 248 | mergingList, |
| 249 | constrainList, |
| 250 | flags, |
| 251 | tePathAttributes, |
| 252 | abstractPath1); |
| 253 | ConnectivityMatrix matrix2 = new ConnectivityMatrix(key1, |
| 254 | from, |
| 255 | mergingList, |
| 256 | constrainList, |
| 257 | flags, |
| 258 | tePathAttributes, |
| 259 | abstractPath1); |
| 260 | ConnectivityMatrix matrix3 = new ConnectivityMatrix(key1, |
| 261 | from, |
| 262 | mergingList, |
| 263 | constrainList, |
| 264 | flags, |
| 265 | tePathAttributes, |
| 266 | abstractPath2); |
| 267 | ConnectivityMatrix matrix4 = new ConnectivityMatrix(key2, |
| 268 | from, |
| 269 | mergingList, |
| 270 | constrainList, |
| 271 | flags, |
| 272 | tePathAttributes, |
| 273 | abstractPath1); |
| 274 | |
| 275 | assertTrue("Two conn matrices must be equal", matrix1.equals(matrix2)); |
| 276 | |
| 277 | assertFalse("Two conn matrices must be unequal", matrix1.equals(matrix3)); |
| 278 | assertFalse("Two conn matrices must be unequal", matrix3.equals(matrix1)); |
| 279 | |
| 280 | assertFalse("Two conn matrices must be unequal", matrix1.equals(matrix4)); |
| 281 | assertFalse("Two conn matrices must be unequal", matrix4.equals(matrix1)); |
| 282 | } |
| 283 | |
| 284 | @Test |
| 285 | public void teNodeKeyEqualOperatorTest() { |
| 286 | TeNodeKey key1 = new TeNodeKey(providerId, clientId, |
| 287 | topologyId, teNodeId); |
| 288 | TeNodeKey key2 = new TeNodeKey(providerId, clientId, |
| 289 | topologyId, teNodeId); |
| 290 | TeNodeKey key3 = new TeNodeKey(providerId + 1, clientId, |
| 291 | topologyId, teNodeId); |
| 292 | TeNodeKey key4 = new TeNodeKey(providerId, clientId + 1, |
| 293 | topologyId, teNodeId); |
| 294 | TeNodeKey key5 = new TeNodeKey(providerId, clientId, |
| 295 | topologyId + 1, teNodeId); |
| 296 | TeNodeKey key6 = new TeNodeKey(providerId, clientId, |
| 297 | topologyId, teNodeId + 1); |
| 298 | |
| 299 | assertTrue("Two matrix keys must be equal", key1.equals(key2)); |
| 300 | |
| 301 | assertFalse("Two matrix keys must be unequal", key1.equals(key3)); |
| 302 | assertFalse("Two matrix keys must be unequal", key3.equals(key1)); |
| 303 | |
| 304 | assertFalse("Two matrix keys must be unequal", key1.equals(key4)); |
| 305 | assertFalse("Two matrix keys must be unequal", key4.equals(key1)); |
| 306 | |
| 307 | assertFalse("Two matrix keys must be unequal", key1.equals(key5)); |
| 308 | assertFalse("Two matrix keys must be unequal", key5.equals(key1)); |
| 309 | |
| 310 | assertFalse("Two matrix keys must be unequal", key1.equals(key6)); |
| 311 | assertFalse("Two matrix keys must be unequal", key6.equals(key1)); |
| 312 | } |
| 313 | |
| 314 | @Test |
| 315 | public void ttpMatrixKeyEqualOperatorTest() { |
| 316 | TtpKey key1 = new TtpKey(providerId, clientId, topologyId, |
| 317 | teNodeId, ttpId); |
| 318 | TtpKey key2 = new TtpKey(providerId, clientId, topologyId, |
| 319 | teNodeId, ttpId); |
| 320 | TtpKey key3 = new TtpKey(providerId + 1, clientId, topologyId, |
| 321 | teNodeId, ttpId); |
| 322 | TtpKey key4 = new TtpKey(providerId, clientId + 1, topologyId, |
| 323 | teNodeId, ttpId); |
| 324 | TtpKey key5 = new TtpKey(providerId, clientId, topologyId + 1, |
| 325 | teNodeId, ttpId); |
| 326 | TtpKey key6 = new TtpKey(providerId, clientId, topologyId, |
| 327 | teNodeId + 1, ttpId); |
| 328 | TtpKey key7 = new TtpKey(providerId, clientId, topologyId, |
| 329 | teNodeId, ttpId + 1); |
| 330 | |
| 331 | assertTrue("Two TTP keys must be equal", key1.equals(key2)); |
| 332 | |
| 333 | assertFalse("Two TTP keys must be unequal", key1.equals(key3)); |
| 334 | assertFalse("Two TTP keys must be unequal", key3.equals(key1)); |
| 335 | |
| 336 | assertFalse("Two TTP keys must be unequal", key1.equals(key4)); |
| 337 | assertFalse("Two TTP keys must be unequal", key4.equals(key1)); |
| 338 | |
| 339 | assertFalse("Two TTP keys must be unequal", key1.equals(key5)); |
| 340 | assertFalse("Two TTP keys must be unequal", key5.equals(key1)); |
| 341 | |
| 342 | assertFalse("Two TTP keys must be unequal", key1.equals(key6)); |
| 343 | assertFalse("Two TTP keys must be unequal", key6.equals(key1)); |
| 344 | |
| 345 | assertFalse("Two TTP keys must be unequal", key1.equals(key7)); |
| 346 | assertFalse("Two TTP keys must be unequal", key7.equals(key1)); |
| 347 | } |
| 348 | |
| 349 | } |