Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [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.utils; |
| 17 | |
| 18 | import org.onlab.util.HexString; |
| 19 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet; |
| 20 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId; |
| 24 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 25 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 26 | import org.onosproject.yang.gen.v1.ietfyangtypes.rev20130715.ietfyangtypes.YangIdentifier; |
| 27 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo; |
| 28 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameCharacterString; |
| 29 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNamePrimaryVid; |
| 30 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameRfc2685VpnId; |
| 31 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameUint16; |
| 32 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameY1731Icc; |
| 33 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.nameprimaryvid.NamePrimaryVidUnion; |
| 34 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.Identifier45; |
| 35 | |
| 36 | /** |
| 37 | * This is a workaround for Checkstyle issue. |
| 38 | * https://github.com/checkstyle/checkstyle/issues/3850 |
| 39 | * There are two types of DefaultNameCharacterString - one for MA and another for MD |
| 40 | * Putting both together in a file means that the full path has to be given which |
| 41 | * will then fail checkstyle |
| 42 | */ |
| 43 | public final class MaNameUtil { |
| 44 | |
| 45 | private MaNameUtil() { |
| 46 | //Hidden |
| 47 | } |
| 48 | |
| 49 | public static MaNameAndTypeCombo getYangMaNameFromApiMaId(MaIdShort maId) |
| 50 | throws CfmConfigException { |
| 51 | MaNameAndTypeCombo maName; |
| 52 | if (maId instanceof MaIdPrimaryVid) { |
| 53 | maName = new DefaultNamePrimaryVid(); |
| 54 | ((DefaultNamePrimaryVid) maName).namePrimaryVid(NamePrimaryVidUnion.fromString(maId.maName())); |
| 55 | } else if (maId instanceof MaId2Octet) { |
| 56 | maName = new DefaultNameUint16(); |
| 57 | ((DefaultNameUint16) maName).nameUint16(Integer.valueOf(maId.maName())); |
| 58 | } else if (maId instanceof MaIdRfc2685VpnId) { |
| 59 | maName = new DefaultNameRfc2685VpnId(); |
| 60 | ((DefaultNameRfc2685VpnId) maName).nameRfc2685VpnId(HexString.fromHexString(maId.maName())); |
| 61 | } else if (maId instanceof MaIdIccY1731) { |
| 62 | maName = new DefaultNameY1731Icc(); |
| 63 | ((DefaultNameY1731Icc) maName).nameY1731Icc(YangIdentifier.of(maId.maName())); |
| 64 | } else if (maId instanceof MaIdCharStr) { |
| 65 | maName = new DefaultNameCharacterString(); |
| 66 | ((DefaultNameCharacterString) maName).name(Identifier45.fromString(maId.maName())); |
| 67 | } else { |
| 68 | throw new CfmConfigException("Unexpected error creating MD " + |
| 69 | maId.getClass().getSimpleName()); |
| 70 | } |
| 71 | return maName; |
| 72 | } |
| 73 | } |