Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | |
| 17 | package org.onosproject.sdxl2; |
| 18 | |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 19 | import com.google.common.collect.Sets; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.TestApplicationId; |
| 24 | |
| 25 | import java.util.HashSet; |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 26 | import java.util.Optional; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 27 | import java.util.Set; |
| 28 | |
| 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertNotEquals; |
| 31 | |
| 32 | |
| 33 | /** |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 34 | * Tests SdxL2Manager functionality. |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 35 | */ |
| 36 | public class SdxL2ManagerTest { |
| 37 | |
| 38 | protected SdxL2Manager manager; |
| 39 | |
| 40 | @Before |
| 41 | public void setUp() { |
| 42 | manager = new SdxL2Manager(); |
| 43 | manager.appId = new TestApplicationId("sdxl2-test"); |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 44 | SdxL2DistributedStore store = new SdxL2DistributedStore(); |
| 45 | store.initForTest(); |
| 46 | manager.sdxL2Store = store; |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @After |
| 50 | public void tearDown() { |
| 51 | } |
| 52 | |
| 53 | public static final String SDXL2 = "test"; |
| 54 | public static final String SDXL2_2 = "test2"; |
| 55 | |
| 56 | |
| 57 | @Test |
| 58 | public void testCreateSdxL2s() { |
| 59 | |
| 60 | manager.createSdxL2(SDXL2); |
| 61 | manager.createSdxL2(SDXL2_2); |
| 62 | manager.createSdxL2(SDXL2); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testRemoveSdxL2s() { |
| 67 | manager.createSdxL2(SDXL2); |
| 68 | manager.createSdxL2(SDXL2_2); |
| 69 | manager.deleteSdxL2(SDXL2); |
| 70 | manager.deleteSdxL2(SDXL2_2); |
| 71 | manager.deleteSdxL2(SDXL2); |
| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testGetSdxL2s() { |
| 76 | Set<String> old = new HashSet<String>(); |
| 77 | old.add(SDXL2_2); |
| 78 | old.add(SDXL2); |
| 79 | manager.createSdxL2(SDXL2); |
| 80 | manager.createSdxL2(SDXL2_2); |
| 81 | Set<String> sdxl2 = manager.getSdxL2s(); |
| 82 | assertEquals(sdxl2, old); |
| 83 | manager.deleteSdxL2(SDXL2); |
| 84 | sdxl2 = manager.getSdxL2s(); |
| 85 | assertNotEquals(sdxl2, old); |
| 86 | } |
| 87 | |
pierventre | 3849e56 | 2016-05-11 11:47:32 +0200 | [diff] [blame^] | 88 | public static final String CP1 = "of:00000000000001/1"; |
| 89 | public static final String CP2 = "of:00000000000002/1"; |
| 90 | public static final String CP3 = "of:00000000000003/1"; |
| 91 | public static final String CP4 = "of:00000000000003/2"; |
| 92 | public static final String CP5 = "of:00000000000004/2"; |
| 93 | |
| 94 | public static final String VLANS1 = "1,2,3,4"; |
| 95 | public static final String VLANS2 = "-1"; |
| 96 | public static final String VLANS3 = "1,2,3"; |
| 97 | public static final String VLANS4 = "2,2,2"; |
| 98 | public static final String VLANS7 = "5"; |
| 99 | public static final String VLANS8 = "3,2,1"; |
| 100 | |
| 101 | public static final String CEMAC1 = "52:40:00:12:44:01"; |
| 102 | |
| 103 | @Test |
| 104 | public void testaddSdxL2ConnectionPoint() { |
| 105 | |
| 106 | manager.createSdxL2(SDXL2); |
| 107 | manager.createSdxL2(SDXL2_2); |
| 108 | manager.createSdxL2("test1"); |
| 109 | |
| 110 | SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1); |
| 111 | manager.addSdxL2ConnectionPoint(SDXL2, one); |
| 112 | |
| 113 | SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1); |
| 114 | manager.addSdxL2ConnectionPoint(SDXL2, three); |
| 115 | |
| 116 | SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1); |
| 117 | manager.addSdxL2ConnectionPoint(SDXL2_2, six); |
| 118 | |
| 119 | SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1); |
| 120 | manager.addSdxL2ConnectionPoint(SDXL2, seven); |
| 121 | |
| 122 | SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1); |
| 123 | manager.addSdxL2ConnectionPoint(SDXL2_2, nine); |
| 124 | |
| 125 | SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1); |
| 126 | manager.addSdxL2ConnectionPoint(SDXL2, ten); |
| 127 | |
| 128 | SdxL2ConnectionPoint fourteen = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO1", |
| 129 | "of:0000000000000003/3", "1", "52:54:00:04:E5:9E"); |
| 130 | manager.addSdxL2ConnectionPoint("test1", fourteen); |
| 131 | |
| 132 | SdxL2ConnectionPoint fifteen = SdxL2ConnectionPoint.sdxl2ConnectionPoint("RO2", |
| 133 | "of:0000000000000009/3", "1", "52:54:00:68:F7:D9"); |
| 134 | manager.addSdxL2ConnectionPoint("test1", fifteen); |
| 135 | |
| 136 | SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP2, VLANS1, CEMAC1); |
| 137 | manager.addSdxL2ConnectionPoint(SDXL2, two); |
| 138 | |
| 139 | SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1); |
| 140 | manager.addSdxL2ConnectionPoint(SDXL2_2, four); |
| 141 | |
| 142 | SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS2, CEMAC1); |
| 143 | manager.addSdxL2ConnectionPoint(SDXL2_2, five); |
| 144 | |
| 145 | SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM4", CP3, VLANS4, CEMAC1); |
| 146 | manager.addSdxL2ConnectionPoint(SDXL2, eight); |
| 147 | |
| 148 | SdxL2ConnectionPoint eleven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI3", CP5, VLANS1, CEMAC1); |
| 149 | manager.addSdxL2ConnectionPoint(SDXL2_2, eleven); |
| 150 | |
| 151 | SdxL2ConnectionPoint twelve = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS1, CEMAC1); |
| 152 | manager.addSdxL2ConnectionPoint(SDXL2_2, twelve); |
| 153 | |
| 154 | SdxL2ConnectionPoint thirteen = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS8, CEMAC1); |
| 155 | manager.addSdxL2ConnectionPoint(SDXL2_2, thirteen); |
| 156 | |
| 157 | } |
| 158 | |
| 159 | @Test |
| 160 | public void testgetSdxL2ConnectionPoints() { |
| 161 | |
| 162 | manager.createSdxL2(SDXL2); |
| 163 | manager.createSdxL2(SDXL2_2); |
| 164 | |
| 165 | Set<String> allExt = Sets.newHashSet(); |
| 166 | Set<String> allExtBySdxl2 = Sets.newHashSet(); |
| 167 | Set<String> allExtBySdxl22 = Sets.newHashSet(); |
| 168 | |
| 169 | SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1); |
| 170 | manager.addSdxL2ConnectionPoint(SDXL2, one); |
| 171 | allExt.add(one.name()); |
| 172 | allExtBySdxl2.add(one.name()); |
| 173 | SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1); |
| 174 | manager.addSdxL2ConnectionPoint(SDXL2, three); |
| 175 | allExt.add(three.name()); |
| 176 | allExtBySdxl2.add(three.name()); |
| 177 | SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1); |
| 178 | manager.addSdxL2ConnectionPoint(SDXL2_2, six); |
| 179 | allExt.add(six.name()); |
| 180 | allExtBySdxl22.add(six.name()); |
| 181 | SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1); |
| 182 | manager.addSdxL2ConnectionPoint(SDXL2, seven); |
| 183 | allExt.add(seven.name()); |
| 184 | allExtBySdxl2.add(seven.name()); |
| 185 | SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1); |
| 186 | manager.addSdxL2ConnectionPoint(SDXL2_2, nine); |
| 187 | allExt.add(nine.name()); |
| 188 | allExtBySdxl22.add(nine.name()); |
| 189 | SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1); |
| 190 | manager.addSdxL2ConnectionPoint(SDXL2, ten); |
| 191 | allExt.add(ten.name()); |
| 192 | allExtBySdxl2.add(ten.name()); |
| 193 | |
| 194 | Set<String> all = manager.getSdxL2ConnectionPoints(Optional.ofNullable(null)); |
| 195 | Set<String> allBySdxl2 = manager.getSdxL2ConnectionPoints(Optional.of(SDXL2)); |
| 196 | Set<String> allBySdxl22 = manager.getSdxL2ConnectionPoints(Optional.of(SDXL2_2)); |
| 197 | |
| 198 | assertEquals(allExt, all); |
| 199 | assertNotEquals(allExtBySdxl2, all); |
| 200 | assertNotEquals(allExtBySdxl22, all); |
| 201 | |
| 202 | assertNotEquals(allExt, allBySdxl2); |
| 203 | assertEquals(allExtBySdxl2, allBySdxl2); |
| 204 | assertNotEquals(allExtBySdxl22, allBySdxl2); |
| 205 | |
| 206 | assertNotEquals(allExt, allBySdxl22); |
| 207 | assertNotEquals(allExtBySdxl2, allBySdxl22); |
| 208 | assertEquals(allExtBySdxl22, allBySdxl22); |
| 209 | |
| 210 | } |
| 211 | |
| 212 | @Test |
| 213 | public void testremoveSdxL2ConnectionPoint() { |
| 214 | |
| 215 | manager.createSdxL2(SDXL2); |
| 216 | manager.createSdxL2(SDXL2_2); |
| 217 | |
| 218 | SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1); |
| 219 | manager.addSdxL2ConnectionPoint(SDXL2, one); |
| 220 | |
| 221 | SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1); |
| 222 | manager.addSdxL2ConnectionPoint(SDXL2, three); |
| 223 | |
| 224 | SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1); |
| 225 | manager.addSdxL2ConnectionPoint(SDXL2_2, six); |
| 226 | |
| 227 | SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1); |
| 228 | manager.addSdxL2ConnectionPoint(SDXL2, seven); |
| 229 | |
| 230 | SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1); |
| 231 | manager.addSdxL2ConnectionPoint(SDXL2_2, nine); |
| 232 | |
| 233 | SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1); |
| 234 | manager.addSdxL2ConnectionPoint(SDXL2, ten); |
| 235 | |
| 236 | manager.removeSdxL2ConnectionPoint(one.name()); |
| 237 | manager.removeSdxL2ConnectionPoint(six.name()); |
| 238 | manager.removeSdxL2ConnectionPoint(one.name()); |
| 239 | manager.removeSdxL2ConnectionPoint("ROM"); |
| 240 | |
| 241 | } |
| 242 | |
Pier Luigi Ventre | 0a023f4 | 2016-04-30 11:03:15 +0200 | [diff] [blame] | 243 | } |