Sudeep Desai | f0911a7 | 2019-12-09 18:31:37 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | * |
| 16 | * This work was partially supported by EC H2020 project METRO-HAUL (761727). |
| 17 | */ |
| 18 | |
| 19 | package org.onosproject.drivers.odtn.openconfig; |
| 20 | |
| 21 | import com.google.common.collect.Range; |
| 22 | import org.apache.commons.configuration.ConfigurationException; |
| 23 | import org.apache.commons.configuration.HierarchicalConfiguration; |
| 24 | import org.apache.commons.configuration.XMLConfiguration; |
| 25 | import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine; |
| 26 | import org.onlab.osgi.DefaultServiceDirectory; |
| 27 | import org.onosproject.drivers.utilities.XmlConfigParser; |
| 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.net.behaviour.PowerConfig; |
| 31 | import org.onosproject.net.device.DeviceService; |
| 32 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 33 | import org.onosproject.netconf.DatastoreId; |
| 34 | import org.onosproject.netconf.NetconfController; |
| 35 | import org.onosproject.netconf.NetconfDevice; |
| 36 | import org.onosproject.netconf.NetconfException; |
| 37 | import org.onosproject.netconf.NetconfSession; |
| 38 | import org.slf4j.Logger; |
| 39 | |
| 40 | import java.io.StringWriter; |
| 41 | import java.util.ArrayList; |
| 42 | import java.util.HashMap; |
| 43 | import java.util.List; |
| 44 | import java.util.Map; |
| 45 | import java.util.Optional; |
| 46 | import java.util.concurrent.CompletableFuture; |
| 47 | import java.util.concurrent.ExecutionException; |
| 48 | |
| 49 | import static com.google.common.base.Preconditions.checkNotNull; |
| 50 | import static org.slf4j.LoggerFactory.getLogger; |
| 51 | |
| 52 | public class TerminalDevicePowerConfig<T> extends AbstractHandlerBehaviour implements PowerConfig<T> { |
| 53 | |
| 54 | public static final String RPC_TAG_NETCONF_BASE = |
| 55 | "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"; |
| 56 | |
| 57 | public static final String RPC_CLOSE_TAG = "</rpc>"; |
| 58 | |
| 59 | public static final String TARGET_POWER = "TargetPower"; |
| 60 | |
| 61 | public static final String CURRENT_POWER = "CurrentPower"; |
| 62 | |
| 63 | public static final String CURRENT_INPUT_POWER = "CurrentInputPower"; |
| 64 | |
| 65 | public static final Logger log = getLogger(TerminalDevicePowerConfig.class); |
| 66 | |
| 67 | public ComponentType state = ComponentType.DIRECTION; |
| 68 | |
| 69 | /** |
| 70 | * Returns the NetconfSession with the device for which the method was called. |
| 71 | * |
| 72 | * @param deviceId device indetifier |
| 73 | * @param userName username to access the device |
| 74 | * @param passwd password to access the device |
| 75 | * @return The netconf session or null |
| 76 | */ |
| 77 | public NetconfSession getNetconfSession(DeviceId deviceId, String userName, String passwd) { |
| 78 | NetconfController controller = handler().get(NetconfController.class); |
| 79 | NetconfDevice ncdev = controller.getDevicesMap().get(deviceId); |
| 80 | if (ncdev == null) { |
| 81 | log.trace("No netconf device, returning null session"); |
| 82 | return null; |
| 83 | } |
| 84 | return ncdev.getSession(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get the deviceId for which the methods apply. |
| 89 | * |
| 90 | * @return The deviceId as contained in the handler data |
| 91 | */ |
| 92 | public DeviceId did() { |
| 93 | return handler().data().deviceId(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Execute RPC request. |
| 98 | * |
| 99 | * @param session Netconf session |
| 100 | * @param message Netconf message in XML format |
| 101 | * @return XMLConfiguration object |
| 102 | */ |
| 103 | |
| 104 | public XMLConfiguration executeRpc(NetconfSession session, String message) { |
| 105 | try { |
| 106 | if (log.isDebugEnabled()) { |
| 107 | try { |
| 108 | StringWriter stringWriter = new StringWriter(); |
| 109 | XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(message); |
| 110 | xconf.setExpressionEngine(new XPathExpressionEngine()); |
| 111 | xconf.save(stringWriter); |
| 112 | log.debug("Request {}", stringWriter.toString()); |
| 113 | } catch (ConfigurationException e) { |
| 114 | log.error("XML Config Exception ", e); |
| 115 | } |
| 116 | } |
| 117 | CompletableFuture<String> fut = session.rpc(message); |
| 118 | String rpcReply = fut.get(); |
| 119 | XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply); |
| 120 | xconf.setExpressionEngine(new XPathExpressionEngine()); |
| 121 | if (log.isDebugEnabled()) { |
| 122 | try { |
| 123 | StringWriter stringWriter = new StringWriter(); |
| 124 | xconf.save(stringWriter); |
| 125 | log.debug("Response {}", stringWriter.toString()); |
| 126 | } catch (ConfigurationException e) { |
| 127 | log.error("XML Config Exception ", e); |
| 128 | } |
| 129 | } |
| 130 | return xconf; |
| 131 | } catch (NetconfException ne) { |
| 132 | log.error("Exception on Netconf protocol: {}.", ne); |
| 133 | } catch (InterruptedException ie) { |
| 134 | log.error("Interrupted Exception: {}.", ie); |
| 135 | } catch (ExecutionException ee) { |
| 136 | log.error("Concurrent Exception while executing Netconf operation: {}.", ee); |
| 137 | } |
| 138 | return null; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Construct a rpc target power message. |
| 143 | * |
| 144 | * @param filter to build rpc |
| 145 | * @return RPC payload |
| 146 | */ |
| 147 | public StringBuilder getTargetPowerRequestRpc(String filter) { |
| 148 | StringBuilder rpc = new StringBuilder(); |
| 149 | rpc.append("<get-config>") |
| 150 | .append("<source>") |
| 151 | .append("<" + DatastoreId.RUNNING + "/>") |
| 152 | .append("</source>") |
| 153 | .append("<filter type='subtree'>") |
| 154 | .append(filter) |
| 155 | .append("</filter>") |
| 156 | .append("</get-config>"); |
| 157 | return rpc; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Construct a rpc target power message. |
| 162 | * |
| 163 | * @return RPC payload |
| 164 | */ |
| 165 | public DatastoreId getDataStoreId() { |
| 166 | return DatastoreId.CANDIDATE; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Construct a rpc target power message. |
| 171 | * |
| 172 | * @param name for optical channel name |
| 173 | * @param underState to build rpc for setting configuration |
| 174 | * @return RPC payload |
| 175 | */ |
| 176 | public StringBuilder getOpticalChannelStateRequestRpc(String name, String underState) { |
| 177 | StringBuilder rpc = new StringBuilder(); |
| 178 | rpc.append("<name>").append(name).append("</name>") |
| 179 | .append("<optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">") |
| 180 | .append("<state>") |
| 181 | .append(underState) |
| 182 | .append("</state></optical-channel></component></components></filter></get>"); |
| 183 | return rpc; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Construct a rpc target power message. |
| 188 | * |
| 189 | * @param name for optical channel name |
| 190 | * @param power to build rpc for setting configuration |
| 191 | * @return RPC payload |
| 192 | */ |
| 193 | public StringBuilder parsePortRequestRpc(Double power, String name) { |
| 194 | StringBuilder rpc = new StringBuilder(); |
| 195 | rpc.append("<component>").append("<name>").append(name).append("</name>"). |
| 196 | append("<optical-channel xmlns=\"http://openconfig.net/yang/terminal-device\">") |
| 197 | .append("<config>") |
| 198 | .append("<target-output-power>") |
| 199 | .append(power) |
| 200 | .append("</target-output-power>") |
| 201 | .append("</config>") |
| 202 | .append("</optical-channel>"); |
| 203 | return rpc; |
| 204 | } |
| 205 | /** |
| 206 | * Get the target-output-power value on specific optical-channel. |
| 207 | * |
| 208 | * @param port the port |
| 209 | * @param component the port component. It should be 'oc-name' in the Annotations of Port. |
| 210 | * 'oc-name' could be mapped to '/component/name' in openconfig yang. |
| 211 | * @return target power value |
| 212 | */ |
| 213 | @Override |
| 214 | public Optional<Double> getTargetPower(PortNumber port, T component) { |
| 215 | checkState(component); |
| 216 | return state.getTargetPower(port, component); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void setTargetPower(PortNumber port, T component, double power) { |
| 221 | checkState(component); |
| 222 | state.setTargetPower(port, component, power); |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public Optional<Double> currentPower(PortNumber port, T component) { |
| 227 | checkState(component); |
| 228 | return state.currentPower(port, component); |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public Optional<Double> currentInputPower(PortNumber port, T component) { |
| 233 | checkState(component); |
| 234 | return state.currentInputPower(port, component); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public Optional<Range<Double>> getTargetPowerRange(PortNumber port, T component) { |
| 239 | checkState(component); |
| 240 | return state.getTargetPowerRange(port, component); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public Optional<Range<Double>> getInputPowerRange(PortNumber port, T component) { |
| 245 | checkState(component); |
| 246 | return state.getInputPowerRange(port, component); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public List<PortNumber> getPorts(T component) { |
| 251 | checkState(component); |
| 252 | return state.getPorts(component); |
| 253 | } |
| 254 | |
| 255 | |
| 256 | /** |
| 257 | * Set the ComponentType to invoke proper methods for different template T. |
| 258 | * |
| 259 | * @param component the component. |
| 260 | */ |
| 261 | public void checkState(Object component) { |
| 262 | String clsName = component.getClass().getName(); |
| 263 | switch (clsName) { |
| 264 | case "org.onosproject.net.Direction": |
| 265 | state = TerminalDevicePowerConfig.ComponentType.DIRECTION; |
| 266 | break; |
| 267 | case "org.onosproject.net.OchSignal": |
| 268 | state = TerminalDevicePowerConfig.ComponentType.OCHSIGNAL; |
| 269 | break; |
| 270 | default: |
| 271 | log.error("Cannot parse the component type {}.", clsName); |
| 272 | log.info("The component content is {}.", component.toString()); |
| 273 | } |
| 274 | state.driver = this; |
| 275 | } |
| 276 | /** |
| 277 | * |
| 278 | * @param param the config parameter. |
| 279 | * @return array of string |
| 280 | */ |
| 281 | public Map<String, String> buildRpcString(String param) { |
| 282 | Map<String, String> rpcMap = new HashMap<String, String>(); |
| 283 | switch (param) { |
| 284 | case TARGET_POWER: |
| 285 | rpcMap.put("TARGET_OUTPUT_PATH", "data/components/component/optical-channel/config"); |
| 286 | rpcMap.put("TARGET_OUTPUT_LEAF", "target-output-power"); |
| 287 | case CURRENT_POWER: |
| 288 | rpcMap.put("CURRENT_POWER_PATH", "data/components/component/optical-channel/state/output-power"); |
| 289 | rpcMap.put("CURRENT_POWER_ROUTE", "<output-power><instant/></output-power>"); |
| 290 | rpcMap.put("CURRENT_POWER_LEAF", "instant"); |
| 291 | default: |
| 292 | rpcMap.put("CURRENT_INPUT_POWER_PATH", "data/components/component/optical-channel/state/input-power"); |
| 293 | rpcMap.put("CURRENT_INPUT_POWER_ROUTE", "<input-power><instant/></input-power>"); |
| 294 | rpcMap.put("CURRENT_INPUT_POWER_LEAF", "instant"); |
| 295 | } |
| 296 | return rpcMap; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Component type. |
| 301 | */ |
| 302 | public enum ComponentType { |
| 303 | |
| 304 | /** |
| 305 | * Direction. |
| 306 | */ |
| 307 | DIRECTION() { |
| 308 | @Override |
| 309 | public Optional<Double> getTargetPower(PortNumber port, Object component) { |
| 310 | return super.getTargetPower(port, component); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public void setTargetPower(PortNumber port, Object component, double power) { |
| 315 | super.setTargetPower(port, component, power); |
| 316 | } |
| 317 | }, |
| 318 | |
| 319 | /** |
| 320 | * OchSignal. |
| 321 | */ |
| 322 | OCHSIGNAL() { |
| 323 | @Override |
| 324 | public Optional<Double> getTargetPower(PortNumber port, Object component) { |
| 325 | return super.getTargetPower(port, component); |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public void setTargetPower(PortNumber port, Object component, double power) { |
| 330 | super.setTargetPower(port, component, power); |
| 331 | } |
| 332 | }; |
| 333 | |
| 334 | |
| 335 | public TerminalDevicePowerConfig driver; |
| 336 | |
| 337 | /** |
| 338 | * mirror method in the internal class. |
| 339 | * |
| 340 | * @param port port |
| 341 | * @param component component |
| 342 | * @return target power |
| 343 | */ |
| 344 | public Optional<Double> getTargetPower(PortNumber port, Object component) { |
| 345 | NetconfSession session = driver.getNetconfSession(driver.did(), "", ""); |
| 346 | checkNotNull(session); |
| 347 | String filter = parsePort(driver, port, null, null); |
| 348 | StringBuilder rpcReq = new StringBuilder(); |
| 349 | rpcReq.append(RPC_TAG_NETCONF_BASE) |
| 350 | .append(driver.getTargetPowerRequestRpc(filter)) |
| 351 | .append(RPC_CLOSE_TAG); |
| 352 | XMLConfiguration xconf = driver.executeRpc(session, rpcReq.toString()); |
| 353 | if (xconf == null) { |
| 354 | log.error("Error in executingRpc"); |
| 355 | return Optional.empty(); |
| 356 | } |
| 357 | try { |
| 358 | Map<String, String> rpcMap = driver.buildRpcString(TARGET_POWER); |
| 359 | String configString = rpcMap.get("TARGET_OUTPUT_PATH"), |
| 360 | paramStr = rpcMap.get("TARGET_OUTPUT_LEAF"); |
| 361 | HierarchicalConfiguration config = |
| 362 | xconf.configurationAt(configString); |
| 363 | if (config == null || config.getString(paramStr) == null) { |
| 364 | return Optional.empty(); |
| 365 | } |
| 366 | double power = Float.valueOf(config.getString(paramStr)).doubleValue(); |
| 367 | return Optional.of(power); |
| 368 | } catch (IllegalArgumentException e) { |
| 369 | return Optional.empty(); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * mirror method in the internal class. |
| 375 | * |
| 376 | * @param port port |
| 377 | * @param component component |
| 378 | * @param power target value |
| 379 | */ |
| 380 | public void setTargetPower(PortNumber port, Object component, double power) { |
| 381 | NetconfSession session = driver.getNetconfSession(driver.did(), "", ""); |
| 382 | checkNotNull(session); |
| 383 | String editConfig = parsePort(driver, port, null, power); |
| 384 | StringBuilder rpcReq = new StringBuilder(); |
| 385 | rpcReq.append(RPC_TAG_NETCONF_BASE) |
| 386 | .append("<edit-config>") |
| 387 | .append("<target><" + driver.getDataStoreId() + "/></target>") |
| 388 | .append("<config>") |
| 389 | .append(editConfig) |
| 390 | .append("</config>") |
| 391 | .append("</edit-config>") |
| 392 | .append(RPC_CLOSE_TAG); |
| 393 | log.info("Setting power {}", rpcReq.toString()); |
| 394 | XMLConfiguration xconf = driver.executeRpc(session, rpcReq.toString()); |
| 395 | // The successful reply should be "<rpc-reply ...><ok /></rpc-reply>" |
| 396 | if (!xconf.getRoot().getChild(0).getName().equals("ok")) { |
| 397 | log.error("The <edit-config> operation to set target-output-power of Port({}:{}) is failed.", |
| 398 | port.toString(), component.toString()); |
| 399 | } |
| 400 | try { |
| 401 | session.commit(); |
| 402 | } catch (NetconfException e) { |
| 403 | log.error("error committing channel power", e); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * mirror method in the internal class. |
| 409 | * |
| 410 | * @param port port |
| 411 | * @param component the component. |
| 412 | * @return current output power. |
| 413 | */ |
| 414 | public Optional<Double> currentPower(PortNumber port, Object component) { |
| 415 | Map<String, String> rpcMap = driver.buildRpcString(CURRENT_POWER); |
| 416 | String configString = rpcMap.get("CURRENT_POWER_PATH"), |
| 417 | queryStr = rpcMap.get("CURRENT_POWER_ROUTE"), |
| 418 | paramStr = rpcMap.get("CURRENT_POWER_LEAF"); |
| 419 | XMLConfiguration xconf = getOpticalChannelState( |
| 420 | driver, port, queryStr); |
| 421 | try { |
| 422 | HierarchicalConfiguration config = |
| 423 | xconf.configurationAt(configString); |
| 424 | if (config == null || config.getString(paramStr) == null) { |
| 425 | return Optional.empty(); |
| 426 | } |
| 427 | double currentPower = Float.valueOf(config.getString(paramStr)).doubleValue(); |
| 428 | return Optional.of(currentPower); |
| 429 | } catch (IllegalArgumentException e) { |
| 430 | return Optional.empty(); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * mirror method in the internal class. |
| 436 | * |
| 437 | * @param port port |
| 438 | * @param component the component |
| 439 | * @return current input power |
| 440 | */ |
| 441 | public Optional<Double> currentInputPower(PortNumber port, Object component) { |
| 442 | Map<String, String> rpcMap = driver.buildRpcString(CURRENT_INPUT_POWER); |
| 443 | String configString = rpcMap.get("CURRENT_INPUT_POWER_PATH"), |
| 444 | queryStr = rpcMap.get("CURRENT_INPUT_POWER_ROUTE"), |
| 445 | paramStr = rpcMap.get("CURRENT_INPUT_POWER_LEAF"); |
| 446 | XMLConfiguration xconf = getOpticalChannelState( |
| 447 | driver, port, queryStr); |
| 448 | try { |
| 449 | HierarchicalConfiguration config = |
| 450 | xconf.configurationAt(configString); |
| 451 | if (config == null || config.getString(paramStr) == null) { |
| 452 | return Optional.empty(); |
| 453 | } |
| 454 | double currentPower = Float.valueOf(config.getString(paramStr)).doubleValue(); |
| 455 | return Optional.of(currentPower); |
| 456 | } catch (IllegalArgumentException e) { |
| 457 | return Optional.empty(); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | public Optional<Range<Double>> getTargetPowerRange(PortNumber port, Object component) { |
| 462 | XMLConfiguration xconf = getOpticalChannelState( |
| 463 | driver, port, "<target-power-range/>"); |
| 464 | try { |
| 465 | HierarchicalConfiguration config = |
| 466 | xconf.configurationAt("data/components/component/optical-channel/state/target-power-range"); |
| 467 | double targetMin = Float.valueOf(config.getString("min")).doubleValue(); |
| 468 | double targetMax = Float.valueOf(config.getString("max")).doubleValue(); |
| 469 | return Optional.of(Range.open(targetMin, targetMax)); |
| 470 | } catch (IllegalArgumentException e) { |
| 471 | return Optional.empty(); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | public Optional<Range<Double>> getInputPowerRange(PortNumber port, Object component) { |
| 476 | XMLConfiguration xconf = getOpticalChannelState( |
| 477 | driver, port, "<input-power-range/>"); |
| 478 | try { |
| 479 | HierarchicalConfiguration config = |
| 480 | xconf.configurationAt("data/components/component/optical-channel/state/input-power-range"); |
| 481 | double inputMin = Float.valueOf(config.getString("min")).doubleValue(); |
| 482 | double inputMax = Float.valueOf(config.getString("max")).doubleValue(); |
| 483 | return Optional.of(Range.open(inputMin, inputMax)); |
| 484 | } catch (IllegalArgumentException e) { |
| 485 | return Optional.empty(); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | public List<PortNumber> getPorts(Object component) { |
| 490 | // FIXME |
| 491 | log.warn("Not Implemented Yet!"); |
| 492 | return new ArrayList<PortNumber>(); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Get filtered content under <optical-channel><state>. |
| 497 | * |
| 498 | * @param pc power config instance |
| 499 | * @param port the port number |
| 500 | * @param underState the filter condition |
| 501 | * @return RPC reply |
| 502 | */ |
| 503 | public static XMLConfiguration getOpticalChannelState(TerminalDevicePowerConfig pc, |
| 504 | PortNumber port, String underState) { |
| 505 | NetconfSession session = pc.getNetconfSession(pc.did(), "", ""); |
| 506 | checkNotNull(session); |
| 507 | String name = ocName(pc, port); |
| 508 | StringBuilder rpcReq = new StringBuilder(RPC_TAG_NETCONF_BASE); |
| 509 | rpcReq.append("<get><filter><components xmlns=\"http://openconfig.net/yang/platform\"><component>") |
| 510 | .append(pc.getOpticalChannelStateRequestRpc(name, underState)) |
| 511 | .append(RPC_CLOSE_TAG); |
| 512 | XMLConfiguration xconf = pc.executeRpc(session, rpcReq.toString()); |
| 513 | return xconf; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | /** |
| 518 | * Extract component name from portNumber's annotations. |
| 519 | * |
| 520 | * @param pc power config instance |
| 521 | * @param portNumber the port number |
| 522 | * @return the component name |
| 523 | */ |
| 524 | public static String ocName(TerminalDevicePowerConfig pc, PortNumber portNumber) { |
| 525 | DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class); |
| 526 | DeviceId deviceId = pc.handler().data().deviceId(); |
| 527 | return deviceService.getPort(deviceId, portNumber).annotations().value("oc-name"); |
| 528 | } |
| 529 | |
| 530 | |
| 531 | /** |
| 532 | * Parse filtering string from port and component. |
| 533 | * |
| 534 | * @param portNumber Port Number |
| 535 | * @param component port component (optical-channel) |
| 536 | * @param power power value set |
| 537 | * @param pc instance of Power config implementation |
| 538 | * @return filtering string in xml format |
| 539 | */ |
| 540 | public static String parsePort(TerminalDevicePowerConfig pc, PortNumber portNumber, |
| 541 | Object component, Double power) { |
| 542 | if (component == null) { |
| 543 | String name = ocName(pc, portNumber); |
| 544 | StringBuilder sb = new StringBuilder("<components xmlns=\"http://openconfig.net/yang/platform\">"); |
| 545 | if (power != null) { |
| 546 | // This is an edit-config operation. |
| 547 | sb.append(pc.parsePortRequestRpc(power, name)); |
| 548 | } |
| 549 | sb.append("</component>").append("</components>"); |
| 550 | return sb.toString(); |
| 551 | } else { |
| 552 | log.error("Cannot process the component {}.", component.getClass()); |
| 553 | return null; |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | } |
| 559 | |