blob: d98cade4130f7700be6005327a6048cc40e5a42e [file] [log] [blame]
Yixiao Chen39828a62016-09-14 14:37:06 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Yixiao Chen39828a62016-09-14 14:37:06 -04003 *
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
Hesam Rahimi39bdc002016-11-10 15:01:26 -050018import org.onosproject.tetopology.management.api.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
Yixiao Chen39828a62016-09-14 14:37:06 -040024/**
25 * The Enum conversion functions.
26 */
27public final class EnumConverter {
28
29 // no instantiation
30 private EnumConverter() {
31 }
32
Hesam Rahimi39bdc002016-11-10 15:01:26 -050033 /**
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 Yu8ac364b2016-12-15 18:24:20 -050041 if (opStatus == null) {
42 return null;
43 }
44
Hesam Rahimi39bdc002016-11-10 15:01:26 -050045 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 Yu8ac364b2016-12-15 18:24:20 -050071 if (adminStatus == null) {
72 return TeStatus.UNKNOWN;
73 }
74
Hesam Rahimi39bdc002016-11-10 15:01:26 -050075 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 Yu8ac364b2016-12-15 18:24:20 -050098 if (adminStatus == null) {
99 return null;
100 }
101
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500102 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 Yu8ac364b2016-12-15 18:24:20 -0500127 if (opStatus == null) {
128 return null;
129 }
130
Hesam Rahimi39bdc002016-11-10 15:01:26 -0500131 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 Chen265b3bb2017-01-13 10:17:03 -0500149}