Committed by
Gerrit Code Review
[ONOS-5269] JUNIT Test cases for volt-ponlinks and volt-setponlink for FUJITSU NETCONF
Change-Id: Iaff73d2eb1a617a97ebb1dcd8ccad7c0b809ea41
Showing
3 changed files
with
164 additions
and
36 deletions
... | @@ -25,6 +25,10 @@ import org.onosproject.netconf.NetconfController; | ... | @@ -25,6 +25,10 @@ import org.onosproject.netconf.NetconfController; |
25 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
26 | 26 | ||
27 | import java.io.IOException; | 27 | import java.io.IOException; |
28 | +import java.util.Arrays; | ||
29 | +import java.util.List; | ||
30 | +import java.util.HashMap; | ||
31 | +import java.util.Map; | ||
28 | import java.util.Set; | 32 | import java.util.Set; |
29 | 33 | ||
30 | import com.google.common.collect.ImmutableSet; | 34 | import com.google.common.collect.ImmutableSet; |
... | @@ -40,14 +44,48 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -40,14 +44,48 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
40 | implements VoltPonLinkConfig { | 44 | implements VoltPonLinkConfig { |
41 | 45 | ||
42 | private final Logger log = getLogger(FujitsuVoltPonLinkConfig.class); | 46 | private final Logger log = getLogger(FujitsuVoltPonLinkConfig.class); |
43 | - private final Set<String> ponLinkParams = ImmutableSet.of( | 47 | + private static final Map<String, List<Integer>> PON_LINK_PARAMS = new HashMap<String, List<Integer>>() { |
44 | - "admin-state", "onu-discovery-mode", "onu-discovery-interval", | 48 | + { |
45 | - "dba-cycle-time", "mac-age-time", "lof-threshold", | 49 | + put("onu-discovery-interval", Arrays.asList(ONU_DISCOVERY_INTERVAL_MIN, ONU_DISCOVERY_INTERVAL_MAX)); |
46 | - "los-threshold", "pm-enable"); | 50 | + put("dba-cycle-time", Arrays.asList(DBA_CYCLE_TIME_MIN, DBA_CYCLE_TIME_MAX)); |
51 | + put("mac-age-time", Arrays.asList(MAC_AGE_TIME_MIN, MAC_AGE_TIME_MAX)); | ||
52 | + put("lof-threshold", Arrays.asList(LOF_THRESHOLD_MIN, LOF_THRESHOLD_MAX)); | ||
53 | + put("los-threshold", Arrays.asList(LOS_THRESHOLD_MIN, LOS_THRESHOLD_MAX)); | ||
54 | + put(ONU_DISCOVERY_MODE, null); | ||
55 | + put(PM_ENABLE, null); | ||
56 | + put(ADMIN_STATE, null); | ||
57 | + } | ||
58 | + }; | ||
47 | private static final String VOLT_PORTS = "volt-ports"; | 59 | private static final String VOLT_PORTS = "volt-ports"; |
48 | private static final String GPON_PONLINK_PORTS = "gpon-ponlink-ports"; | 60 | private static final String GPON_PONLINK_PORTS = "gpon-ponlink-ports"; |
49 | private static final String GPON_PONLINK_PORT = "gpon-ponlink-port"; | 61 | private static final String GPON_PONLINK_PORT = "gpon-ponlink-port"; |
50 | - private int pon; | 62 | + private static final String ADMIN_STATE = "admin-state"; |
63 | + private static final String ONU_DISCOVERY_MODE = "onu-discovery-mode"; | ||
64 | + private static final String PM_ENABLE = "pm-enable"; | ||
65 | + private static final Set<String> ADMINSTATES = | ||
66 | + ImmutableSet.of("enable", "disable"); | ||
67 | + private static final Set<String> ONUDISCOVERYMODES = | ||
68 | + ImmutableSet.of("auto", "manual", "disabled"); | ||
69 | + private static final Set<String> PMENABLES = | ||
70 | + ImmutableSet.of("true", "false"); | ||
71 | + | ||
72 | + private static final int ONU_DISCOVERY_INTERVAL_MIN = 1; | ||
73 | + private static final int ONU_DISCOVERY_INTERVAL_MAX = 3600; | ||
74 | + private static final int DBA_CYCLE_TIME_MIN = 2; | ||
75 | + private static final int DBA_CYCLE_TIME_MAX = 40; | ||
76 | + private static final int MAC_AGE_TIME_MIN = 1000; | ||
77 | + private static final int MAC_AGE_TIME_MAX = 3600000; | ||
78 | + private static final int LOF_THRESHOLD_MIN = 1; | ||
79 | + private static final int LOF_THRESHOLD_MAX = 10; | ||
80 | + private static final int LOS_THRESHOLD_MIN = 1; | ||
81 | + private static final int LOS_THRESHOLD_MAX = 10; | ||
82 | + private static final int FIRST_PART = 0; | ||
83 | + private static final int SECOND_PART = 1; | ||
84 | + private static final int THIRD_PART = 2; | ||
85 | + private static final int RANGE_MIN = 0; | ||
86 | + private static final int RANGE_MAX = 1; | ||
87 | + private static final int ZERO = 0; | ||
88 | + private static final int THREE = 3; | ||
51 | 89 | ||
52 | @Override | 90 | @Override |
53 | public String getPonLinks(String target) { | 91 | public String getPonLinks(String target) { |
... | @@ -71,10 +109,15 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -71,10 +109,15 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
71 | request.append(ANGLE_RIGHT).append(NEW_LINE); | 109 | request.append(ANGLE_RIGHT).append(NEW_LINE); |
72 | request.append(buildStartTag(VOLT_PORTS)); | 110 | request.append(buildStartTag(VOLT_PORTS)); |
73 | if (target != null) { | 111 | if (target != null) { |
112 | + int pon; | ||
74 | try { | 113 | try { |
75 | pon = Integer.parseInt(target); | 114 | pon = Integer.parseInt(target); |
115 | + if (pon <= ZERO) { | ||
116 | + log.error("Invalid integer for ponlink-id:{}", target); | ||
117 | + return reply; | ||
118 | + } | ||
76 | } catch (NumberFormatException e) { | 119 | } catch (NumberFormatException e) { |
77 | - log.error("Non-number input"); | 120 | + log.error("Non-number input for ponlink-id:{}", target); |
78 | return reply; | 121 | return reply; |
79 | } | 122 | } |
80 | request.append(buildStartTag(GPON_PONLINK_PORTS)); | 123 | request.append(buildStartTag(GPON_PONLINK_PORTS)); |
... | @@ -91,17 +134,19 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -91,17 +134,19 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
91 | request.append(buildEndTag(VOLT_PORTS)); | 134 | request.append(buildEndTag(VOLT_PORTS)); |
92 | request.append(VOLT_NE_CLOSE); | 135 | request.append(VOLT_NE_CLOSE); |
93 | 136 | ||
94 | - reply = controller. | 137 | + reply = controller |
95 | - getDevicesMap().get(ncDeviceId).getSession(). | 138 | + .getDevicesMap() |
96 | - get(request.toString(), REPORT_ALL); | 139 | + .get(ncDeviceId) |
140 | + .getSession() | ||
141 | + .get(request.toString(), REPORT_ALL); | ||
97 | } catch (IOException e) { | 142 | } catch (IOException e) { |
98 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 143 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
99 | } | 144 | } |
100 | return reply; | 145 | return reply; |
101 | } | 146 | } |
102 | 147 | ||
103 | @Override | 148 | @Override |
104 | - public void setPonLink(String target) { | 149 | + public boolean setPonLink(String target) { |
105 | DriverHandler handler = handler(); | 150 | DriverHandler handler = handler(); |
106 | NetconfController controller = handler.get(NetconfController.class); | 151 | NetconfController controller = handler.get(NetconfController.class); |
107 | MastershipService mastershipService = handler.get(MastershipService.class); | 152 | MastershipService mastershipService = handler.get(MastershipService.class); |
... | @@ -112,27 +157,16 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -112,27 +157,16 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
112 | log.warn("Not master for {} Use {} to execute command", | 157 | log.warn("Not master for {} Use {} to execute command", |
113 | ncDeviceId, | 158 | ncDeviceId, |
114 | mastershipService.getMasterFor(ncDeviceId)); | 159 | mastershipService.getMasterFor(ncDeviceId)); |
115 | - return; | 160 | + return false; |
116 | - } | ||
117 | - | ||
118 | - String[] data = target.split(COLON); | ||
119 | - if (data.length != 3) { | ||
120 | - log.error("Invalid number of arguments"); | ||
121 | - return; | ||
122 | - } | ||
123 | - | ||
124 | - try { | ||
125 | - pon = Integer.parseInt(data[0]); | ||
126 | - } catch (NumberFormatException e) { | ||
127 | - log.error("Non-number input"); | ||
128 | - return; | ||
129 | } | 161 | } |
130 | 162 | ||
131 | - if (!ponLinkParams.contains(data[1])) { | 163 | + String[] data = checkSetInput(target); |
132 | - log.error("Unsupported parameter: {} ", data[1]); | 164 | + if (data == null) { |
133 | - return; | 165 | + log.error("Failed to check input: {}", target); |
166 | + return false; | ||
134 | } | 167 | } |
135 | 168 | ||
169 | + boolean result = false; | ||
136 | try { | 170 | try { |
137 | StringBuilder request = new StringBuilder(); | 171 | StringBuilder request = new StringBuilder(); |
138 | request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); | 172 | request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); |
... | @@ -141,23 +175,117 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -141,23 +175,117 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
141 | request.append(buildStartTag(GPON_PONLINK_PORTS)); | 175 | request.append(buildStartTag(GPON_PONLINK_PORTS)); |
142 | request.append(buildStartTag(GPON_PONLINK_PORT)); | 176 | request.append(buildStartTag(GPON_PONLINK_PORT)); |
143 | request.append(buildStartTag(PONLINK_ID, false)); | 177 | request.append(buildStartTag(PONLINK_ID, false)); |
144 | - request.append(data[0]); | 178 | + request.append(data[FIRST_PART]); |
145 | request.append(buildEndTag(PONLINK_ID)); | 179 | request.append(buildEndTag(PONLINK_ID)); |
146 | 180 | ||
147 | - request.append(buildStartTag(data[1], false)); | 181 | + request.append(buildStartTag(data[SECOND_PART], false)); |
148 | - request.append(data[2]); | 182 | + request.append(data[THIRD_PART]); |
149 | - request.append(buildEndTag(data[1])); | 183 | + request.append(buildEndTag(data[SECOND_PART])); |
150 | 184 | ||
151 | request.append(buildEndTag(GPON_PONLINK_PORT)); | 185 | request.append(buildEndTag(GPON_PONLINK_PORT)); |
152 | request.append(buildEndTag(GPON_PONLINK_PORTS)); | 186 | request.append(buildEndTag(GPON_PONLINK_PORTS)); |
153 | request.append(buildEndTag(VOLT_PORTS)); | 187 | request.append(buildEndTag(VOLT_PORTS)); |
154 | request.append(VOLT_NE_CLOSE); | 188 | request.append(VOLT_NE_CLOSE); |
155 | 189 | ||
156 | - controller.getDevicesMap().get(ncDeviceId).getSession(). | 190 | + result = controller.getDevicesMap().get(ncDeviceId).getSession(). |
157 | editConfig(RUNNING, null, request.toString()); | 191 | editConfig(RUNNING, null, request.toString()); |
158 | } catch (IOException e) { | 192 | } catch (IOException e) { |
159 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 193 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
160 | } | 194 | } |
195 | + return result; | ||
161 | } | 196 | } |
162 | 197 | ||
198 | + /** | ||
199 | + * Verifies input string for valid options. | ||
200 | + * | ||
201 | + * @param target input data in string | ||
202 | + * @return String array | ||
203 | + * @return null if an error condition is detected | ||
204 | + */ | ||
205 | + private String[] checkSetInput(String target) { | ||
206 | + String[] data = target.split(COLON); | ||
207 | + String paramName = data[SECOND_PART]; | ||
208 | + String paramValue = data[THIRD_PART]; | ||
209 | + int pon; | ||
210 | + | ||
211 | + if (data.length != THREE) { | ||
212 | + log.error("Invalid number of arguments {}", data.length); | ||
213 | + return null; | ||
214 | + } | ||
215 | + | ||
216 | + try { | ||
217 | + pon = Integer.parseInt(data[FIRST_PART]); | ||
218 | + if (pon <= ZERO) { | ||
219 | + log.error("Invalid integer for ponlink-id: {}", | ||
220 | + data[FIRST_PART]); | ||
221 | + return null; | ||
222 | + } | ||
223 | + } catch (NumberFormatException e) { | ||
224 | + log.error("Non-number input for ponlink-id: {}", | ||
225 | + data[FIRST_PART]); | ||
226 | + return null; | ||
227 | + } | ||
228 | + | ||
229 | + if (!PON_LINK_PARAMS.containsKey(paramName)) { | ||
230 | + log.error("Unsupported parameter: {}", paramName); | ||
231 | + return null; | ||
232 | + } | ||
233 | + | ||
234 | + List<Integer> range = PON_LINK_PARAMS.get(paramName); | ||
235 | + if (range == null) { | ||
236 | + switch (paramName) { | ||
237 | + case ADMIN_STATE: | ||
238 | + if (!validState(ADMINSTATES, paramName, paramValue)) { | ||
239 | + return null; | ||
240 | + } | ||
241 | + break; | ||
242 | + case ONU_DISCOVERY_MODE: | ||
243 | + if (!validState(ONUDISCOVERYMODES, paramName, paramValue)) { | ||
244 | + return null; | ||
245 | + } | ||
246 | + break; | ||
247 | + default: | ||
248 | + if (!validState(PMENABLES, paramName, paramValue)) { | ||
249 | + return null; | ||
250 | + } | ||
251 | + break; | ||
252 | + } | ||
253 | + } else { | ||
254 | + int value; | ||
255 | + | ||
256 | + try { | ||
257 | + value = Integer.parseInt(paramValue); | ||
258 | + } catch (NumberFormatException e) { | ||
259 | + log.error("Non-number input for Name {} : Value {}.", | ||
260 | + paramName, paramValue); | ||
261 | + return null; | ||
262 | + } | ||
263 | + | ||
264 | + if ((value < range.get(RANGE_MIN)) || | ||
265 | + (value > range.get(RANGE_MAX))) { | ||
266 | + log.error("Out of value range for Name {} : Value {}.", | ||
267 | + paramName, paramValue); | ||
268 | + return null; | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
272 | + return data; | ||
273 | + } | ||
274 | + | ||
275 | + /** | ||
276 | + * Verifies input string for valid options. | ||
277 | + * | ||
278 | + * @param states input data in string for parameter state | ||
279 | + * @param name input data in string for parameter name | ||
280 | + * @param value input data in string for parameter value | ||
281 | + * @return true if the param is valid | ||
282 | + * @return false if the param is invalid | ||
283 | + */ | ||
284 | + private boolean validState(Set<String> states, String name, String value) { | ||
285 | + if (!states.contains(value)) { | ||
286 | + log.error("Invalid value for Name {} : Value {}.", name, value); | ||
287 | + return false; | ||
288 | + } | ||
289 | + return true; | ||
290 | + } | ||
163 | } | 291 | } | ... | ... |
... | @@ -36,8 +36,8 @@ public interface VoltPonLinkConfig extends HandlerBehaviour { | ... | @@ -36,8 +36,8 @@ public interface VoltPonLinkConfig extends HandlerBehaviour { |
36 | * Set a parameter value of PON link in the device. | 36 | * Set a parameter value of PON link in the device. |
37 | * | 37 | * |
38 | * @param target input data in string | 38 | * @param target input data in string |
39 | - * | 39 | + * @return true if the operation is successful |
40 | */ | 40 | */ |
41 | - void setPonLink(String target); | 41 | + boolean setPonLink(String target); |
42 | 42 | ||
43 | } | 43 | } | ... | ... |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment