Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [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.drivers.microsemi.yang; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertNotNull; |
| 20 | import static org.junit.Assert.fail; |
| 21 | |
| 22 | import java.io.UncheckedIOException; |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.HashMap; |
| 25 | import java.util.List; |
| 26 | import java.util.Map; |
| 27 | import java.util.TreeMap; |
| 28 | |
| 29 | import org.junit.After; |
| 30 | import org.junit.Before; |
| 31 | import org.junit.Test; |
| 32 | import org.onlab.packet.Ip4Address; |
| 33 | import org.onosproject.drivers.microsemi.yang.impl.MseaUniEvcServiceManager; |
| 34 | import org.onosproject.drivers.microsemi.yang.utils.CeVlanMapUtils; |
| 35 | import org.onosproject.netconf.DatastoreId; |
| 36 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 37 | import org.onosproject.netconf.NetconfException; |
| 38 | import org.onosproject.netconf.NetconfSession; |
| 39 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45; |
| 40 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.ServiceListType; |
| 41 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.VlanIdType; |
| 42 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.MseaUniEvcService; |
| 43 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.MseaUniEvcServiceOpParam; |
| 44 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.DefaultMefServices; |
| 45 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.MefServices; |
| 46 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.evcperuniextensionattributes.EvcPerUniServiceTypeEnum; |
| 47 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.evcperuniextensionattributes.tagmanipulation.TagPush; |
| 48 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.evcperuniextensionattributes.tagmanipulation.tagpush.tagpush.PushTagTypeEnum; |
| 49 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.evcperuniextensionattributes.tagmanipulation.DefaultTagPush; |
| 50 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.Profiles; |
| 51 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.DefaultProfiles; |
| 52 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.DefaultUni; |
| 53 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.Uni; |
| 54 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.BwpGroup; |
| 55 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.Cos; |
| 56 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.DefaultBwpGroup; |
| 57 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.DefaultCos; |
| 58 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.bwpgroup.Bwp; |
| 59 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.bwpgroup.DefaultBwp; |
| 60 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.profiles.bwpgroup.bwp.ColorModeEnum; |
| 61 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.DefaultEvc; |
| 62 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.Evc; |
| 63 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.UniSideInterfaceAssignmentEnum; |
| 64 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.evc.DefaultEvcPerUni; |
| 65 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.evc.EvcPerUni; |
| 66 | import org.onosproject.drivers.microsemi.yang.custom.CustomEvcPerUnic; |
| 67 | import org.onosproject.drivers.microsemi.yang.custom.CustomEvcPerUnin; |
| 68 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.evc.evcperuni.EvcPerUnic; |
| 69 | import org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice.mefservices.uni.evc.evcperuni.EvcPerUnin; |
| 70 | |
| 71 | public class MseaUniEvcServiceManagerTest { |
| 72 | |
| 73 | MseaUniEvcServiceManager mseaUniEvcServiceSvc; |
| 74 | NetconfSession session; |
| 75 | |
| 76 | @Before |
| 77 | public void setUp() throws Exception { |
| 78 | try { |
| 79 | mseaUniEvcServiceSvc = new MockMseaUniEvcServiceManager(); |
| 80 | mseaUniEvcServiceSvc.activate(); |
| 81 | } catch (UncheckedIOException e) { |
| 82 | fail(e.getMessage()); |
| 83 | } |
| 84 | NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo("netconf", "netconf", Ip4Address.valueOf("1.2.3.4"), 830); |
| 85 | session = new MockNetconfSessionEa1000(deviceInfo); |
| 86 | } |
| 87 | |
| 88 | @After |
| 89 | public void tearDown() throws Exception { |
| 90 | } |
| 91 | |
| 92 | @Test |
| 93 | public void testGetMseaUniEvcServiceMseaUniEvcServiceOpParamNetconfSession() { |
| 94 | MefServices mefServices = new DefaultMefServices(); |
| 95 | mefServices.uni(new DefaultUni()); |
| 96 | |
| 97 | MseaUniEvcServiceOpParam evcUni = new MseaUniEvcServiceOpParam(); |
| 98 | evcUni.mefServices(mefServices); |
| 99 | |
| 100 | MseaUniEvcService result = null; |
| 101 | try { |
| 102 | result = |
| 103 | mseaUniEvcServiceSvc.getConfigMseaUniEvcService( |
| 104 | evcUni, session, DatastoreId.RUNNING); |
| 105 | } catch (NetconfException e) { |
| 106 | // TODO Auto-generated catch block |
| 107 | e.printStackTrace(); |
| 108 | fail("Error: " + e.getMessage()); |
| 109 | } |
| 110 | |
| 111 | assertNotNull(result); |
| 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void testSetMseaUniEvcServiceMseaUniEvcServiceOpParamEvcs() { |
| 116 | TagPush tp1 = new DefaultTagPush(); |
| 117 | org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317.mseaunievcservice |
| 118 | .evcperuniextensionattributes.tagmanipulation |
| 119 | .tagpush.TagPush tpInner1 = |
| 120 | new org.onosproject.yang.gen.v1.mseaunievcservice.rev20160317 |
| 121 | .mseaunievcservice.evcperuniextensionattributes |
| 122 | .tagmanipulation.tagpush.DefaultTagPush(); |
| 123 | tpInner1.outerTagVlan(new VlanIdType(3)); |
| 124 | tpInner1.pushTagType(PushTagTypeEnum.PUSHSTAG); |
| 125 | tp1.tagPush(tpInner1); |
| 126 | |
| 127 | EvcPerUnin epun1 = new CustomEvcPerUnin(); |
| 128 | epun1.evcPerUniServiceType(EvcPerUniServiceTypeEnum.EVPL); |
| 129 | epun1.ceVlanMap(ServiceListType.fromString("10")); |
| 130 | epun1.ingressBwpGroupIndex("0"); |
| 131 | epun1.tagManipulation(tp1); |
| 132 | |
| 133 | EvcPerUnic epuc1 = new CustomEvcPerUnic(); |
| 134 | epuc1.ceVlanMap(new ServiceListType("11")); |
| 135 | epuc1.ingressBwpGroupIndex("0"); |
| 136 | |
| 137 | EvcPerUni epu1 = new DefaultEvcPerUni(); |
| 138 | epu1.evcPerUnic(epuc1); |
| 139 | epu1.evcPerUnin(epun1); |
| 140 | |
| 141 | List<Evc> evcList = new ArrayList<Evc>(); |
| 142 | Evc evc1 = new DefaultEvc(); |
| 143 | evc1.evcIndex(1); |
| 144 | evc1.name(new Identifier45("evc-1")); |
| 145 | evc1.evcPerUni(epu1); |
| 146 | |
| 147 | evcList.add(evc1); |
| 148 | |
| 149 | |
| 150 | EvcPerUnin epun2 = new CustomEvcPerUnin(); |
| 151 | epun2.ceVlanMap(ServiceListType.fromString("13")); |
| 152 | epun2.ingressBwpGroupIndex("0"); |
| 153 | |
| 154 | EvcPerUnic epuc2 = new CustomEvcPerUnic(); |
| 155 | epuc2.ceVlanMap(new ServiceListType("12")); |
| 156 | epuc2.ingressBwpGroupIndex("0"); |
| 157 | |
| 158 | EvcPerUni epu2 = new DefaultEvcPerUni(); |
| 159 | epu2.evcPerUnic(epuc2); |
| 160 | epu2.evcPerUnin(epun2); |
| 161 | |
| 162 | Evc evc2 = new DefaultEvc(); |
| 163 | evc2.evcIndex(2); |
| 164 | evc2.name(new Identifier45("evc-2")); |
| 165 | evc2.evcPerUni(epu2); |
| 166 | |
| 167 | evcList.add(evc2); |
| 168 | |
| 169 | Uni uni = new DefaultUni(); |
| 170 | uni.name(new Identifier45("testUni")); |
| 171 | uni.evc(evcList); |
| 172 | |
| 173 | MefServices mefServices = new DefaultMefServices(); |
| 174 | mefServices.uni(uni); |
| 175 | |
| 176 | MseaUniEvcServiceOpParam evcUni = new MseaUniEvcServiceOpParam(); |
| 177 | evcUni.mefServices(mefServices); |
| 178 | try { |
| 179 | mseaUniEvcServiceSvc.setMseaUniEvcService(evcUni, session, DatastoreId.RUNNING); |
| 180 | } catch (NetconfException e) { |
| 181 | // TODO Auto-generated catch block |
| 182 | e.printStackTrace(); |
| 183 | fail("Error: " + e.getMessage()); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void testSetMseaUniEvcServiceMseaUniEvcServiceOpParamProfiles() { |
| 189 | List<Cos> cosList = new ArrayList<Cos>(); |
| 190 | Cos cos0 = new DefaultCos(); |
| 191 | cos0.cosIndex(0); |
| 192 | cos0.name("cos0"); |
| 193 | cosList.add(cos0); |
| 194 | |
| 195 | Cos cos1 = new DefaultCos(); |
| 196 | cos1.cosIndex(1); |
| 197 | cos1.name("cos1"); |
| 198 | cosList.add(cos1); |
| 199 | |
| 200 | List<BwpGroup> bwpGroupList = new ArrayList<BwpGroup>(); |
| 201 | BwpGroup bwpGrp = new DefaultBwpGroup(); |
| 202 | bwpGrp.groupIndex((short) 0); |
| 203 | bwpGroupList.add(bwpGrp); |
| 204 | |
| 205 | List<Bwp> bwpList = new ArrayList<Bwp>(); |
| 206 | Bwp bwp1 = new DefaultBwp(); |
| 207 | bwp1.cosIndex(0); |
| 208 | bwp1.colorMode(ColorModeEnum.COLORAWARE); |
| 209 | bwpList.add(bwp1); |
| 210 | |
| 211 | Bwp bwp2 = new DefaultBwp(); |
| 212 | bwp2.cosIndex(1); |
| 213 | bwp2.colorMode(ColorModeEnum.COLORBLIND); |
| 214 | bwpList.add(bwp2); |
| 215 | |
| 216 | BwpGroup bwpGrp1 = new DefaultBwpGroup(); |
| 217 | bwpGrp1.groupIndex((short) 1); |
| 218 | bwpGrp1.bwp(bwpList); |
| 219 | bwpGroupList.add(bwpGrp1); |
| 220 | |
| 221 | Profiles profiles = new DefaultProfiles(); |
| 222 | profiles.bwpGroup(bwpGroupList); |
| 223 | |
| 224 | MefServices mefServices = new DefaultMefServices(); |
| 225 | mefServices.profiles(profiles); |
| 226 | |
| 227 | MseaUniEvcServiceOpParam evcUni = new MseaUniEvcServiceOpParam(); |
| 228 | evcUni.mefServices(mefServices); |
| 229 | try { |
| 230 | mseaUniEvcServiceSvc.setMseaUniEvcService(evcUni, session, DatastoreId.RUNNING); |
| 231 | } catch (NetconfException e) { |
| 232 | // TODO Auto-generated catch block |
| 233 | e.printStackTrace(); |
| 234 | fail("Error: " + e.getMessage()); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | @Test |
| 239 | public void testDeleteMseaUniEvcServiceMseaUniEvcServiceOpParamProfiles() { |
| 240 | List<Cos> cosList = new ArrayList<Cos>(); |
| 241 | Cos cos0 = new DefaultCos(); |
| 242 | cos0.cosIndex(0); |
| 243 | cos0.name("cos0"); |
| 244 | cosList.add(cos0); |
| 245 | |
| 246 | Cos cos1 = new DefaultCos(); |
| 247 | cos1.cosIndex(1); |
| 248 | cos1.name("cos1"); |
| 249 | cosList.add(cos1); |
| 250 | |
| 251 | List<BwpGroup> bwpGroupList = new ArrayList<BwpGroup>(); |
| 252 | BwpGroup bwpGrp = new DefaultBwpGroup(); |
| 253 | bwpGrp.groupIndex((short) 0); |
| 254 | bwpGroupList.add(bwpGrp); |
| 255 | |
| 256 | List<Bwp> bwpList = new ArrayList<Bwp>(); |
| 257 | Bwp bwp1 = new DefaultBwp(); |
| 258 | bwp1.cosIndex(0); |
| 259 | bwp1.colorMode(ColorModeEnum.COLORAWARE); |
| 260 | bwpList.add(bwp1); |
| 261 | |
| 262 | Bwp bwp2 = new DefaultBwp(); |
| 263 | bwp2.cosIndex(1); |
| 264 | bwp2.colorMode(ColorModeEnum.COLORBLIND); |
| 265 | bwpList.add(bwp2); |
| 266 | |
| 267 | BwpGroup bwpGrp1 = new DefaultBwpGroup(); |
| 268 | bwpGrp1.groupIndex((short) 1); |
| 269 | bwpGrp1.bwp(bwpList); |
| 270 | bwpGroupList.add(bwpGrp1); |
| 271 | |
| 272 | Profiles profiles = new DefaultProfiles(); |
| 273 | profiles.bwpGroup(bwpGroupList); |
| 274 | |
| 275 | MefServices mefServices = new DefaultMefServices(); |
| 276 | mefServices.profiles(profiles); |
| 277 | |
| 278 | MseaUniEvcServiceOpParam evcUni = new MseaUniEvcServiceOpParam(); |
| 279 | evcUni.mefServices(mefServices); |
| 280 | try { |
| 281 | mseaUniEvcServiceSvc.deleteMseaUniEvcService(evcUni, session, DatastoreId.RUNNING); |
| 282 | } catch (NetconfException e) { |
| 283 | // TODO Auto-generated catch block |
| 284 | e.printStackTrace(); |
| 285 | fail("Error: " + e.getMessage()); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testGetMseaUniEvcCeVlanMaps() { |
| 291 | |
| 292 | try { |
| 293 | MseaUniEvcService ceVlanMapsResult7 = |
| 294 | mseaUniEvcServiceSvc.getmseaUniEvcCeVlanMaps(session, DatastoreId.RUNNING); |
| 295 | |
| 296 | assertNotNull(ceVlanMapsResult7.mefServices().uni().evc()); |
| 297 | |
| 298 | List<Evc> evcList = ceVlanMapsResult7.mefServices().uni().evc(); |
| 299 | assertEquals(3, evcList.size()); |
| 300 | for (Evc evc : evcList) { |
| 301 | assertNotNull(evc.evcPerUni().evcPerUnic().ceVlanMap()); |
| 302 | assertNotNull(evc.evcPerUni().evcPerUnin().ceVlanMap()); |
| 303 | |
| 304 | if (evc.evcIndex() == 7) { |
| 305 | assertEquals("700,710,720", evc.evcPerUni().evcPerUnic().ceVlanMap().string()); |
| 306 | assertEquals("701:703", evc.evcPerUni().evcPerUnin().ceVlanMap().string()); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | } catch (NetconfException e) { |
| 311 | // TODO Auto-generated catch block |
| 312 | e.printStackTrace(); |
| 313 | fail("Error: " + e.getMessage()); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | @Test |
| 318 | public void testChangeEvcCeVlanMap() { |
| 319 | EvcPerUnin epun1 = new CustomEvcPerUnin(); |
| 320 | epun1.evcPerUniServiceType(EvcPerUniServiceTypeEnum.EVPL); |
| 321 | epun1.ceVlanMap(ServiceListType.fromString("10")); |
| 322 | epun1.ingressBwpGroupIndex("0"); |
| 323 | |
| 324 | EvcPerUnic epuc1 = new CustomEvcPerUnic(); |
| 325 | epuc1.ceVlanMap(new ServiceListType("11")); |
| 326 | epuc1.ingressBwpGroupIndex("0"); |
| 327 | |
| 328 | EvcPerUni epu = new DefaultEvcPerUni(); |
| 329 | epu.evcPerUnic(epuc1); |
| 330 | epu.evcPerUnin(epun1); |
| 331 | |
| 332 | Evc evc = new DefaultEvc(); |
| 333 | evc.evcPerUni(epu); |
| 334 | |
| 335 | assertEquals("10", evc.evcPerUni().evcPerUnin().ceVlanMap().string()); |
| 336 | assertEquals("11", evc.evcPerUni().evcPerUnic().ceVlanMap().string()); |
| 337 | |
| 338 | assertEquals("11", evc.evcPerUni().evcPerUnic().ceVlanMap().string()); |
| 339 | } |
| 340 | |
| 341 | @Test |
| 342 | public void testChangeEvcCeVlanMapNoValues() { |
| 343 | EvcPerUnin epun1 = new CustomEvcPerUnin(); |
| 344 | epun1.evcPerUniServiceType(EvcPerUniServiceTypeEnum.EVPL); |
| 345 | epun1.ingressBwpGroupIndex("0"); |
| 346 | |
| 347 | EvcPerUnic epuc1 = new CustomEvcPerUnic(); |
| 348 | epuc1.ingressBwpGroupIndex("0"); |
| 349 | |
| 350 | EvcPerUni epu = new DefaultEvcPerUni(); |
| 351 | epu.evcPerUnic(epuc1); |
| 352 | epu.evcPerUnin(epun1); |
| 353 | |
| 354 | Evc evc = new DefaultEvc(); |
| 355 | evc.evcIndex(1); |
| 356 | evc.evcPerUni(epu); |
| 357 | |
| 358 | assertEquals("0", evc.evcPerUni().evcPerUnin().ceVlanMap().string()); |
| 359 | assertEquals("0", evc.evcPerUni().evcPerUnic().ceVlanMap().string()); |
| 360 | } |
| 361 | |
| 362 | @Test |
| 363 | public void testRemoveEvcUniFlowEntries() { |
| 364 | |
| 365 | Map<Integer, String> ceVlanUpdates = new TreeMap<>(); |
| 366 | ceVlanUpdates.put((1 << 2), ""); |
| 367 | ceVlanUpdates.put((1 << 2) + 1, ""); |
| 368 | ceVlanUpdates.put((2 << 2), ""); |
| 369 | ceVlanUpdates.put((2 << 2) + 1, ""); |
| 370 | |
| 371 | ceVlanUpdates.put((7 << 2), "700,710,720"); |
| 372 | ceVlanUpdates.put((7 << 2) + 1, "701:703"); |
| 373 | ceVlanUpdates.put((8 << 2), "800,810,820"); |
| 374 | ceVlanUpdates.put((8 << 2) + 1, "801,802,803"); |
| 375 | |
| 376 | Map<Integer, List<Short>> flowVlanIdMap = new HashMap<>(); |
| 377 | //These should get ignored because whole EVC is being deleted |
| 378 | flowVlanIdMap.put(1 << 2, new ArrayList<Short>()); |
| 379 | flowVlanIdMap.get(1 << 2).add((short) 11); |
| 380 | |
| 381 | flowVlanIdMap.put((1 << 2) + 1, new ArrayList<Short>()); |
| 382 | flowVlanIdMap.get((1 << 2) + 1).add((short) 12L); |
| 383 | |
| 384 | //These are the EVCs being removed |
| 385 | flowVlanIdMap.put(7 << 2, new ArrayList<Short>()); |
| 386 | flowVlanIdMap.get(7 << 2).add((short) 730L); |
| 387 | flowVlanIdMap.get(7 << 2).add((short) 740L); |
| 388 | |
| 389 | flowVlanIdMap.put((7 << 2) + 1, new ArrayList<Short>()); |
| 390 | flowVlanIdMap.get((7 << 2) + 1).add((short) 705L); |
| 391 | flowVlanIdMap.get((7 << 2) + 1).add((short) 706L); |
| 392 | |
| 393 | flowVlanIdMap.put(8 << 2, new ArrayList<Short>()); |
| 394 | flowVlanIdMap.get(8 << 2).add((short) 830L); |
| 395 | flowVlanIdMap.get(8 << 2).add((short) 840L); |
| 396 | |
| 397 | flowVlanIdMap.put((8 << 2) + 1, new ArrayList<Short>()); |
| 398 | flowVlanIdMap.get((8 << 2) + 1).add((short) 805L); |
| 399 | flowVlanIdMap.get((8 << 2) + 1).add((short) 806L); |
| 400 | |
| 401 | try { |
| 402 | mseaUniEvcServiceSvc.removeEvcUniFlowEntries( |
| 403 | ceVlanUpdates, flowVlanIdMap, session, DatastoreId.RUNNING, |
| 404 | UniSideInterfaceAssignmentEnum.UNI_C_ON_OPTICS); |
| 405 | } catch (NetconfException e) { |
| 406 | // TODO Auto-generated catch block |
| 407 | e.printStackTrace(); |
| 408 | fail("Error: " + e.getMessage()); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | @Test |
| 413 | public void testGetVlanSet1() { |
| 414 | Short[] vlanIds = CeVlanMapUtils.getVlanSet("10"); |
| 415 | assertEquals(1, vlanIds.length); |
| 416 | } |
| 417 | |
| 418 | @Test |
| 419 | public void testGetVlanSet2() { |
| 420 | Short[] vlanIds = CeVlanMapUtils.getVlanSet("10:20"); |
| 421 | assertEquals(11, vlanIds.length); |
| 422 | assertEquals(10, vlanIds[0].shortValue()); |
| 423 | assertEquals(20, vlanIds[10].shortValue()); |
| 424 | } |
| 425 | |
| 426 | @Test |
| 427 | public void testGetVlanSet3() { |
| 428 | Short[] vlanIds = CeVlanMapUtils.getVlanSet("10:20,30:40"); |
| 429 | assertEquals(22, vlanIds.length); |
| 430 | assertEquals(10, vlanIds[0].shortValue()); |
| 431 | assertEquals(40, vlanIds[21].shortValue()); |
| 432 | } |
| 433 | |
| 434 | @Test |
| 435 | public void testGetVlanSet4() { |
| 436 | Short[] vlanIds = CeVlanMapUtils.getVlanSet("10,20,30"); |
| 437 | assertEquals(3, vlanIds.length); |
| 438 | assertEquals(10, vlanIds[0].shortValue()); |
| 439 | assertEquals(30, vlanIds[2].shortValue()); |
| 440 | } |
| 441 | |
| 442 | @Test |
| 443 | public void testVlanListAsString() { |
| 444 | assertEquals("20:22", CeVlanMapUtils.vlanListAsString(new Short[]{20, 21, 22})); |
| 445 | |
| 446 | assertEquals("20:22,24:25", |
| 447 | CeVlanMapUtils.vlanListAsString(new Short[]{20, 21, 22, 24, 25})); |
| 448 | |
| 449 | assertEquals("30,33,36:40", |
| 450 | CeVlanMapUtils.vlanListAsString(new Short[]{30, 33, 36, 37, 38, 39, 40})); |
| 451 | |
| 452 | assertEquals("20", CeVlanMapUtils.vlanListAsString(new Short[]{20})); |
| 453 | |
| 454 | assertEquals("20,22,24,26,28", |
| 455 | CeVlanMapUtils.vlanListAsString(new Short[]{20, 22, 24, 26, 28})); |
| 456 | } |
| 457 | |
| 458 | @Test |
| 459 | public void testAddtoCeVlanMap() { |
| 460 | assertEquals("20,22:24,26,28", |
| 461 | CeVlanMapUtils.addtoCeVlanMap("20,22,24,26,28", (short) 23)); |
| 462 | |
| 463 | assertEquals("20:26,28", |
| 464 | CeVlanMapUtils.addtoCeVlanMap("20,21,22,24,25,26,28", (short) 23)); |
| 465 | |
| 466 | assertEquals("20,23", |
| 467 | CeVlanMapUtils.addtoCeVlanMap("20", (short) 23)); |
| 468 | |
| 469 | assertEquals("20,22:23", |
| 470 | CeVlanMapUtils.addtoCeVlanMap("20,22", (short) 23)); |
| 471 | } |
| 472 | |
| 473 | @Test |
| 474 | public void testCombineVlanSets() { |
| 475 | assertEquals("10:11,13:14", CeVlanMapUtils.combineVlanSets("10:11", "13:14")); |
| 476 | |
| 477 | assertEquals("10:14", CeVlanMapUtils.combineVlanSets("10:11", "12:14")); |
| 478 | |
| 479 | assertEquals("10:11,14", CeVlanMapUtils.combineVlanSets("10:11", "14")); |
| 480 | |
| 481 | assertEquals("10:12", CeVlanMapUtils.combineVlanSets("10:11", "11:12")); |
| 482 | } |
| 483 | |
| 484 | @Test |
| 485 | public void testRemoveZeroIfPossible() { |
| 486 | assertEquals("0", CeVlanMapUtils.removeZeroIfPossible("")); |
| 487 | |
| 488 | assertEquals("0", CeVlanMapUtils.removeZeroIfPossible("0")); |
| 489 | |
| 490 | assertEquals("1,3", CeVlanMapUtils.removeZeroIfPossible("0:1,3")); |
| 491 | |
| 492 | assertEquals("1:2", CeVlanMapUtils.removeZeroIfPossible("0:2")); |
| 493 | |
| 494 | assertEquals("10:12", CeVlanMapUtils.removeZeroIfPossible("0,10:12")); |
| 495 | } |
| 496 | } |