blob: 49b69a609a31f5b97f8ae2c83eddd7facdccc39b [file] [log] [blame]
Yixiao Chen39828a62016-09-14 14:37:06 -04001/*
2 * Copyright 2016 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 */
16package org.onosproject.teyang.utils.topology;
17
18import org.onosproject.tetopology.management.api.node.TeStatus;
19import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus;
20import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus;
21import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.teadminstatus.TeAdminStatusEnum;
22import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.teoperstatus.TeOperStatusEnum;
23
24/**
25 * The Enum conversion functions.
26 */
27public final class EnumConverter {
28
29 // no instantiation
30 private EnumConverter() {
31 }
32
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) {
41 switch (opStatus.enumeration()) {
42 case DOWN:
43 return TeStatus.DOWN;
44 case UP:
45 return TeStatus.UP;
46 case MAINTENANCE:
47 return TeStatus.MAINTENANCE;
48 case PREPARING_MAINTENANCE:
49 return TeStatus.PREPARING_MAINTENANCE;
50 case TESTING:
51 return TeStatus.TESTING;
52 case UNKNOWN:
53 return TeStatus.UNKNOWN;
54 default:
55 return null;
56 }
57 }
58
59 /**
60 * Converts YANG TeAdminStatus Enum to TE Topology TeStatus Enum.
61 *
62 * @param adminStatus YANG Admin Status
63 * @return the equivalent Enum from TE Topology TeStatus or null if not
64 * found
65 */
66 public static TeStatus yang2TeSubsystemAdminStatus(TeAdminStatus adminStatus) {
67 switch (adminStatus.enumeration()) {
68 case DOWN:
69 return TeStatus.DOWN;
70 case UP:
71 return TeStatus.UP;
72 case TESTING:
73 return TeStatus.TESTING;
74 case MAINTENANCE:
75 return TeStatus.MAINTENANCE;
76 case PREPARING_MAINTENANCE:
77 return TeStatus.PREPARING_MAINTENANCE;
78 default:
79 return TeStatus.UNKNOWN;
80 }
81 }
82
83 /**
84 * Converts TE Topology TeStatus Enum to YANG TeAdminStatus Enum.
85 *
86 * @param adminStatus TE Topology admin status
87 * @return the equivalent Enum from YANG TeAdminStatus or null if not found
88 */
89 public static TeAdminStatus teSubsystem2YangAdminStatus(TeStatus adminStatus) {
90 switch (adminStatus) {
91 case DOWN:
92 return TeAdminStatus.of(TeAdminStatusEnum.DOWN);
93 case UP:
94 return TeAdminStatus.of(TeAdminStatusEnum.UP);
95 case TESTING:
96 return TeAdminStatus.of(TeAdminStatusEnum.TESTING);
97 case MAINTENANCE:
98 return TeAdminStatus.of(TeAdminStatusEnum.MAINTENANCE);
99 case PREPARING_MAINTENANCE:
100 return TeAdminStatus.of(TeAdminStatusEnum.PREPARING_MAINTENANCE);
101 case UNKNOWN:
102 return null;
103 default:
104 return null;
105 }
106 }
107
108 /**
109 * Converts TE Topology TeStatus Enum to YANG TeOperStatus Enum.
110 *
111 * @param opStatus TE Topology operation status
112 * @return the equivalent Enum from YANG TeOperStatus or null if not found
113 */
114 public static TeOperStatus teSubsystem2YangOperStatus(TeStatus opStatus) {
115 switch (opStatus) {
116 case DOWN:
117 return TeOperStatus.of(TeOperStatusEnum.DOWN);
118 case UP:
119 return TeOperStatus.of(TeOperStatusEnum.UP);
120 case TESTING:
121 return TeOperStatus.of(TeOperStatusEnum.TESTING);
122 case MAINTENANCE:
123 return TeOperStatus.of(TeOperStatusEnum.MAINTENANCE);
124 case PREPARING_MAINTENANCE:
125 return TeOperStatus.of(TeOperStatusEnum.PREPARING_MAINTENANCE);
126 case UNKNOWN:
127 return TeOperStatus.of(TeOperStatusEnum.UNKNOWN);
128 default:
129 return null;
130 }
131 }
132
133}