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