Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 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.ElementType; |
| 21 | import org.onosproject.tetopology.management.api.link.Label; |
| 22 | import org.onosproject.tetopology.management.api.link.PathElement; |
| 23 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 24 | import org.onosproject.tetopology.management.api.link.UnderlayBackupPath; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | |
| 29 | import static org.junit.Assert.assertFalse; |
| 30 | import static org.junit.Assert.assertTrue; |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for TE link APIs. |
| 35 | */ |
| 36 | public class TeLinkApiTest { |
| 37 | private static final long DEFAULT_PROVIDER_ID = 123; |
| 38 | private static final long DEFAULT_CLIENT_ID = 456; |
| 39 | private static final long DEFAULT_TOPOLOGY_ID = 789; |
| 40 | private static final long DEFAULT_TE_NODE_ID = 1234; |
| 41 | private static final long DEFAULT_TE_LINK_TP_ID = 5678; |
| 42 | private static final String DEFAULT_TOPOLOGY_ID_STRING = |
| 43 | "default-topology-123"; |
| 44 | private static final long DEFAULT_PATH_ELEMENT_ID = 234; |
| 45 | private static final long DEFAULT_UNDERLAY_BACKUP_PATH_IDX = 10; |
| 46 | |
| 47 | private long providerId; |
| 48 | private long clientId; |
| 49 | private long topologyId; |
| 50 | private long teNodeId; |
| 51 | private long teLinkTpId; |
| 52 | private long pathElementId; |
| 53 | private long underlayBackupPathIndex; |
| 54 | |
| 55 | private String topologyIdString; |
| 56 | |
| 57 | @Before |
| 58 | public void setUp() { |
| 59 | providerId = DEFAULT_PROVIDER_ID; |
| 60 | clientId = DEFAULT_CLIENT_ID; |
| 61 | topologyId = DEFAULT_TOPOLOGY_ID; |
| 62 | teNodeId = DEFAULT_TE_NODE_ID; |
| 63 | teLinkTpId = DEFAULT_TE_LINK_TP_ID; |
| 64 | topologyIdString = DEFAULT_TOPOLOGY_ID_STRING; |
| 65 | pathElementId = DEFAULT_PATH_ELEMENT_ID; |
| 66 | underlayBackupPathIndex = DEFAULT_UNDERLAY_BACKUP_PATH_IDX; |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void teLinkTpGlobalKeyEqualOperatorTest() { |
| 71 | TeLinkTpGlobalKey key1 = new TeLinkTpGlobalKey(providerId, clientId, |
| 72 | topologyId, teNodeId, |
| 73 | teLinkTpId); |
| 74 | TeLinkTpGlobalKey key2 = new TeLinkTpGlobalKey(providerId, clientId, |
| 75 | topologyId, teNodeId, |
| 76 | teLinkTpId); |
| 77 | TeLinkTpGlobalKey key3 = new TeLinkTpGlobalKey(providerId + 1, clientId, |
| 78 | topologyId, teNodeId, |
| 79 | teLinkTpId); |
| 80 | TeLinkTpGlobalKey key4 = new TeLinkTpGlobalKey(providerId, clientId + 1, |
| 81 | topologyId, teNodeId, |
| 82 | teLinkTpId); |
| 83 | TeLinkTpGlobalKey key5 = new TeLinkTpGlobalKey(providerId, clientId, |
| 84 | topologyId + 1, |
| 85 | teNodeId, teLinkTpId); |
| 86 | TeLinkTpGlobalKey key6 = new TeLinkTpGlobalKey(providerId, clientId, |
| 87 | topologyId, |
| 88 | teNodeId + 1, teLinkTpId); |
| 89 | TeLinkTpGlobalKey key7 = new TeLinkTpGlobalKey(providerId, clientId, |
| 90 | topologyId, |
| 91 | teNodeId, teLinkTpId + 1); |
| 92 | |
| 93 | assertTrue("Two topology Ids must be equal", key1.equals(key2)); |
| 94 | |
| 95 | assertFalse("Two topology Ids must be unequal", key1.equals(key3)); |
| 96 | assertFalse("Two topology Ids must be unequal", key3.equals(key1)); |
| 97 | |
| 98 | assertFalse("Two topology Ids must be unequal", key1.equals(key4)); |
| 99 | assertFalse("Two topology Ids must be unequal", key4.equals(key1)); |
| 100 | |
| 101 | assertFalse("Two topology Ids must be unequal", key1.equals(key5)); |
| 102 | assertFalse("Two topology Ids must be unequal", key5.equals(key1)); |
| 103 | |
| 104 | assertFalse("Two topology Ids must be unequal", key1.equals(key6)); |
| 105 | assertFalse("Two topology Ids must be unequal", key6.equals(key1)); |
| 106 | |
| 107 | assertFalse("Two topology Ids must be unequal", key1.equals(key7)); |
| 108 | assertFalse("Two topology Ids must be unequal", key7.equals(key1)); |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void underLayBackupPathEqualOperatorTest() { |
| 113 | ElementType pathElementType1 = new Label(pathElementId + 1); |
| 114 | ElementType pathElementType2 = new Label(pathElementId + 2); |
| 115 | ElementType pathElementType3 = new Label(pathElementId + 3); |
| 116 | ElementType pathElementType4 = new Label(pathElementId + 4); |
| 117 | |
| 118 | PathElement pathElement1 = new PathElement(pathElementId, teNodeId, |
| 119 | pathElementType1, true); |
| 120 | PathElement pathElement2 = new PathElement(pathElementId + 1, |
| 121 | teNodeId + 1, |
| 122 | pathElementType2, true); |
| 123 | PathElement pathElement3 = new PathElement(pathElementId + 2, |
| 124 | teNodeId + 2, |
| 125 | pathElementType3, true); |
| 126 | PathElement pathElement4 = new PathElement(pathElementId + 3, |
| 127 | teNodeId + 3, |
| 128 | pathElementType4, true); |
| 129 | |
| 130 | List<PathElement> pathElementList1 = new ArrayList<>(); |
| 131 | pathElementList1.add(pathElement1); |
| 132 | pathElementList1.add(pathElement2); |
| 133 | pathElementList1.add(pathElement3); |
| 134 | |
| 135 | List<PathElement> pathElementList2 = new ArrayList<>(); |
| 136 | pathElementList1.add(pathElement1); |
| 137 | pathElementList1.add(pathElement2); |
| 138 | pathElementList1.add(pathElement4); |
| 139 | |
| 140 | // bp1 and bp2 are the same. bp3, bp4, and bp5 differ by one |
| 141 | // attribute comparing to bp1. |
| 142 | UnderlayBackupPath bp1 = new UnderlayBackupPath( |
| 143 | underlayBackupPathIndex, pathElementList1, true); |
| 144 | UnderlayBackupPath bp2 = new UnderlayBackupPath( |
| 145 | underlayBackupPathIndex, pathElementList1, true); |
| 146 | |
| 147 | UnderlayBackupPath bp3 = new UnderlayBackupPath( |
| 148 | underlayBackupPathIndex + 1, pathElementList1, true); |
| 149 | UnderlayBackupPath bp4 = new UnderlayBackupPath( |
| 150 | underlayBackupPathIndex, pathElementList2, true); |
| 151 | UnderlayBackupPath bp5 = new UnderlayBackupPath( |
| 152 | underlayBackupPathIndex, pathElementList1, false); |
| 153 | |
| 154 | |
| 155 | assertTrue("Two backup paths must be equal", bp1.equals(bp2)); |
| 156 | |
| 157 | assertFalse("Two backup paths must be unequal", bp1.equals(bp3)); |
| 158 | assertFalse("Two backup paths must be unequal", bp3.equals(bp1)); |
| 159 | |
| 160 | assertFalse("Two backup paths must be unequal", bp1.equals(bp4)); |
| 161 | assertFalse("Two backup paths must be unequal", bp4.equals(bp1)); |
| 162 | |
| 163 | assertFalse("Two backup paths must be unequal", bp1.equals(bp5)); |
| 164 | assertFalse("Two backup paths must be unequal", bp5.equals(bp1)); |
| 165 | } |
| 166 | } |