Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016 Open Networking Foundation |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 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.teyang.utils.topology; |
| 17 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 18 | import org.onosproject.tetopology.management.api.TeStatus; |
| 19 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus; |
| 20 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus; |
| 21 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.teadminstatus.TeAdminStatusEnum; |
| 22 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.teoperstatus.TeOperStatusEnum; |
| 23 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 24 | /** |
| 25 | * The Enum conversion functions. |
| 26 | */ |
| 27 | public final class EnumConverter { |
| 28 | |
| 29 | // no instantiation |
| 30 | private EnumConverter() { |
| 31 | } |
| 32 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 33 | /** |
| 34 | * Converts YANG Operation Status Enum to TE Topology TeStatus Enum. |
| 35 | * |
| 36 | * @param opStatus YANG Operation Status |
| 37 | * @return the equivalent Enum from TE Topology TeStatus or null if not |
| 38 | * found |
| 39 | */ |
| 40 | public static TeStatus yang2TeSubsystemOpStatus(TeOperStatus opStatus) { |
Henry Yu | 8ac364b | 2016-12-15 18:24:20 -0500 | [diff] [blame] | 41 | if (opStatus == null) { |
| 42 | return null; |
| 43 | } |
| 44 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 45 | switch (opStatus.enumeration()) { |
| 46 | case DOWN: |
| 47 | return TeStatus.DOWN; |
| 48 | case UP: |
| 49 | return TeStatus.UP; |
| 50 | case MAINTENANCE: |
| 51 | return TeStatus.MAINTENANCE; |
| 52 | case PREPARING_MAINTENANCE: |
| 53 | return TeStatus.PREPARING_MAINTENANCE; |
| 54 | case TESTING: |
| 55 | return TeStatus.TESTING; |
| 56 | case UNKNOWN: |
| 57 | return TeStatus.UNKNOWN; |
| 58 | default: |
| 59 | return null; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Converts YANG TeAdminStatus Enum to TE Topology TeStatus Enum. |
| 65 | * |
| 66 | * @param adminStatus YANG Admin Status |
| 67 | * @return the equivalent Enum from TE Topology TeStatus or null if not |
| 68 | * found |
| 69 | */ |
| 70 | public static TeStatus yang2TeSubsystemAdminStatus(TeAdminStatus adminStatus) { |
Henry Yu | 8ac364b | 2016-12-15 18:24:20 -0500 | [diff] [blame] | 71 | if (adminStatus == null) { |
| 72 | return TeStatus.UNKNOWN; |
| 73 | } |
| 74 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 75 | switch (adminStatus.enumeration()) { |
| 76 | case DOWN: |
| 77 | return TeStatus.DOWN; |
| 78 | case UP: |
| 79 | return TeStatus.UP; |
| 80 | case TESTING: |
| 81 | return TeStatus.TESTING; |
| 82 | case MAINTENANCE: |
| 83 | return TeStatus.MAINTENANCE; |
| 84 | case PREPARING_MAINTENANCE: |
| 85 | return TeStatus.PREPARING_MAINTENANCE; |
| 86 | default: |
| 87 | return TeStatus.UNKNOWN; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Converts TE Topology TeStatus Enum to YANG TeAdminStatus Enum. |
| 93 | * |
| 94 | * @param adminStatus TE Topology admin status |
| 95 | * @return the equivalent Enum from YANG TeAdminStatus or null if not found |
| 96 | */ |
| 97 | public static TeAdminStatus teSubsystem2YangAdminStatus(TeStatus adminStatus) { |
Henry Yu | 8ac364b | 2016-12-15 18:24:20 -0500 | [diff] [blame] | 98 | if (adminStatus == null) { |
| 99 | return null; |
| 100 | } |
| 101 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 102 | switch (adminStatus) { |
| 103 | case DOWN: |
| 104 | return TeAdminStatus.of(TeAdminStatusEnum.DOWN); |
| 105 | case UP: |
| 106 | return TeAdminStatus.of(TeAdminStatusEnum.UP); |
| 107 | case TESTING: |
| 108 | return TeAdminStatus.of(TeAdminStatusEnum.TESTING); |
| 109 | case MAINTENANCE: |
| 110 | return TeAdminStatus.of(TeAdminStatusEnum.MAINTENANCE); |
| 111 | case PREPARING_MAINTENANCE: |
| 112 | return TeAdminStatus.of(TeAdminStatusEnum.PREPARING_MAINTENANCE); |
| 113 | case UNKNOWN: |
| 114 | return null; |
| 115 | default: |
| 116 | return null; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Converts TE Topology TeStatus Enum to YANG TeOperStatus Enum. |
| 122 | * |
| 123 | * @param opStatus TE Topology operation status |
| 124 | * @return the equivalent Enum from YANG TeOperStatus or null if not found |
| 125 | */ |
| 126 | public static TeOperStatus teSubsystem2YangOperStatus(TeStatus opStatus) { |
Henry Yu | 8ac364b | 2016-12-15 18:24:20 -0500 | [diff] [blame] | 127 | if (opStatus == null) { |
| 128 | return null; |
| 129 | } |
| 130 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 131 | switch (opStatus) { |
| 132 | case DOWN: |
| 133 | return TeOperStatus.of(TeOperStatusEnum.DOWN); |
| 134 | case UP: |
| 135 | return TeOperStatus.of(TeOperStatusEnum.UP); |
| 136 | case TESTING: |
| 137 | return TeOperStatus.of(TeOperStatusEnum.TESTING); |
| 138 | case MAINTENANCE: |
| 139 | return TeOperStatus.of(TeOperStatusEnum.MAINTENANCE); |
| 140 | case PREPARING_MAINTENANCE: |
| 141 | return TeOperStatus.of(TeOperStatusEnum.PREPARING_MAINTENANCE); |
| 142 | case UNKNOWN: |
| 143 | return TeOperStatus.of(TeOperStatusEnum.UNKNOWN); |
| 144 | default: |
| 145 | return null; |
| 146 | } |
| 147 | } |
| 148 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 149 | } |