blob: 16e968691d25bbc56f09020158fc86ace789ed70 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
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 */
16package org.onosproject.drivers.microsemi.yang.utils;
17
18import org.onlab.util.HexString;
19import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaId2Octet;
20import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr;
21import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdIccY1731;
22import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdPrimaryVid;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdRfc2685VpnId;
24import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
25import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
26import org.onosproject.yang.gen.v1.ietfyangtypes.rev20130715.ietfyangtypes.YangIdentifier;
27import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaNameAndTypeCombo;
28import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameCharacterString;
29import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNamePrimaryVid;
30import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameRfc2685VpnId;
31import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameUint16;
32import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.DefaultNameY1731Icc;
33import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.manameandtypecombo.nameprimaryvid.NamePrimaryVidUnion;
34import 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 */
43public 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}