From 8d3a9d3a723489f1adfa6faf4ed2eaba51734a7d Mon Sep 17 00:00:00 2001 From: Akihiro Yamanouchi Date: Tue, 12 Jul 2016 11:41:44 +0900 Subject: [PATCH] [ONOS-4837] NETCONF function for FUJITSU OLT #4 and #5 - Add the following commands for FJ OLT volt-onus volt-setonu volt-onustats {ONU-ID} volt-rebootonu volt-ethloopback - Add the method of doUserRpc() in Netconfsession/NetconfSessionImpl *If you dont allow to implement the method, i can move it to our XmlUtility method. - Add new behaviours in /core/.../net/behaviour, and @Beta in the interface. - Move those behaviour interface to fujitsu driver directory. * VoltPonLinkConfig.java as well. - Update fujitsu-drivers.xml - Change the method name from doUserRpc to doWrappedRpc Change-Id: Ic39d3a11ba35d2377e552af097eda65c5554c63f --- .../drivers/fujitsu/FujitsuVoltOnuConfig.java | 281 ++++++++++++++++++ .../fujitsu/FujitsuVoltOnuOperConfig.java | 155 ++++++++++ .../fujitsu/FujitsuVoltPonLinkConfig.java | 2 +- .../fujitsu/behaviour/VoltOnuConfig.java | 51 ++++ .../fujitsu/behaviour/VoltOnuOperConfig.java | 41 +++ .../fujitsu}/behaviour/VoltPonLinkConfig.java | 4 +- .../fujitsu/behaviour/package-info.java | 22 ++ .../fujitsu/cli/VoltEthLoopbackCommand.java | 57 ++++ .../fujitsu/cli/VoltGetOnuStatsCommand.java | 57 ++++ .../fujitsu/cli/VoltGetOnusCommand.java | 57 ++++ .../fujitsu/cli/VoltGetPonLinksCommand.java | 2 +- .../fujitsu/cli/VoltRebootOnuCommand.java | 57 ++++ .../fujitsu/cli/VoltSetOnuCommand.java | 57 ++++ .../fujitsu/cli/VoltSetPonLinkCommand.java | 2 +- .../OSGI-INF/blueprint/shell-config.xml | 31 +- .../src/main/resources/fujitsu-drivers.xml | 6 +- .../onosproject/netconf/NetconfSession.java | 10 + .../netconf/ctl/NetconfSessionImpl.java | 18 ++ 18 files changed, 904 insertions(+), 6 deletions(-) create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfig.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuConfig.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuOperConfig.java rename {core/api/src/main/java/org/onosproject/net => drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu}/behaviour/VoltPonLinkConfig.java (92%) create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/package-info.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltEthLoopbackCommand.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnuStatsCommand.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnusCommand.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltRebootOnuCommand.java create mode 100644 drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetOnuCommand.java diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java new file mode 100644 index 0000000000..c38c46d979 --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuConfig.java @@ -0,0 +1,281 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.drivers.fujitsu; + +import com.google.common.collect.ImmutableSet; +import org.onosproject.mastership.MastershipService; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuConfig; +import org.onosproject.net.driver.AbstractHandlerBehaviour; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.netconf.NetconfController; +import org.slf4j.Logger; + +import java.io.IOException; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Implementation to get and set parameters available in vOLT + * through the Netconf protocol. + */ +public class FujitsuVoltOnuConfig extends AbstractHandlerBehaviour + implements VoltOnuConfig { + + private final Logger log = getLogger(FujitsuVoltOnuConfig.class); + private final Set onuConfigParams = ImmutableSet.of( + "admin-state", "pm-enable", "fec-enable", + "security-enable", "password"); + private static final String VOLT_ONUS = "volt-onus"; + private static final String ONUS_PERLINK = "onus-perlink"; + private static final String ONUS_LIST = "onus-list"; + private static final String ONU_INFO = "onu-info"; + private static final String ONU_SET_CONFIG = "onu-set-config"; + private static final String CONFIG_INFO = "config-info"; + private static final String VOLT_STATISTICS = "volt-statistics"; + private static final String ONU_STATISTICS = "onu-statistics"; + private static final String ONU_ETH_STATS = "onu-eth-stats"; + private static final String ETH_STATS = "eth-stats"; + private static final String ONU_GEM_STATS = "onu-gem-stats"; + private static final String GEM_STATS = "gem-stats"; + private int pon; + private int onu; + + + @Override + public String getOnus(String target) { + DriverHandler handler = handler(); + NetconfController controller = handler.get(NetconfController.class); + MastershipService mastershipService = handler.get(MastershipService.class); + DeviceId ncDeviceId = handler.data().deviceId(); + checkNotNull(controller, "Netconf controller is null"); + String reply = null; + String[] onuId = null; + + if (!mastershipService.isLocalMaster(ncDeviceId)) { + log.warn("Not master for {} Use {} to execute command", + ncDeviceId, + mastershipService.getMasterFor(ncDeviceId)); + return reply; + } + + if (target != null) { + onuId = target.split(HYPHEN); + if (onuId.length > 2) { + log.error("Invalid number of arguments"); + return reply; + } + try { + pon = Integer.parseInt(onuId[0]); + if (onuId.length > 1) { + onu = Integer.parseInt(onuId[1]); + } + } catch (NumberFormatException e) { + log.error("Non-number input"); + return reply; + } + } + + try { + StringBuilder request = new StringBuilder(); + request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); + request.append(ANGLE_RIGHT).append(NEW_LINE); + if (onuId != null) { + request.append(buildStartTag(VOLT_ONUS)); + request.append(buildStartTag(ONUS_PERLINK)); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(onuId[0]); + request.append(buildEndTag(PONLINK_ID)); + if (onuId.length > 1) { + request.append(buildStartTag(ONUS_LIST)); + request.append(buildStartTag(ONU_INFO)); + request.append(buildStartTag(ONU_ID, false)); + request.append(onuId[1]); + request.append(buildEndTag(ONU_ID)); + request.append(buildEndTag(ONU_INFO)); + request.append(buildEndTag(ONUS_LIST)); + } + request.append(buildEndTag(ONUS_PERLINK)); + request.append(buildEndTag(VOLT_ONUS)); + } else { + request.append(buildEmptyTag(VOLT_ONUS)); + } + request.append(VOLT_NE_CLOSE); + + reply = controller. + getDevicesMap().get(ncDeviceId).getSession(). + get(request.toString(), REPORT_ALL); + } catch (IOException e) { + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); + } + return reply; + } + + @Override + public String setOnu(String target) { + DriverHandler handler = handler(); + NetconfController controller = handler.get(NetconfController.class); + MastershipService mastershipService = handler.get(MastershipService.class); + DeviceId ncDeviceId = handler.data().deviceId(); + checkNotNull(controller, "Netconf controller is null"); + String reply = null; + + if (!mastershipService.isLocalMaster(ncDeviceId)) { + log.warn("Not master for {} Use {} to execute command", + ncDeviceId, + mastershipService.getMasterFor(ncDeviceId)); + return reply; + } + + String[] data = target.split(COLON); + if (data.length != 3) { + log.error("Invalid number of arguments"); + return reply; + } + + String[] onuId = data[0].split(HYPHEN); + if (onuId.length != 2) { + log.error("Invalid ONU identifier"); + return reply; + } + + try { + pon = Integer.parseInt(onuId[0]); + onu = Integer.parseInt(onuId[1]); + } catch (NumberFormatException e) { + log.error("Non-number input"); + return reply; + } + + if (!onuConfigParams.contains(data[1])) { + log.error("Unsupported parameter: " + data[1]); + return reply; + } + + try { + StringBuilder request = new StringBuilder(); + request.append(ANGLE_LEFT).append(ONU_SET_CONFIG).append(SPACE); + request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(onuId[0]); + request.append(buildEndTag(PONLINK_ID)); + request.append(buildStartTag(ONU_ID, false)); + request.append(onuId[1]); + request.append(buildEndTag(ONU_ID)); + request.append(buildStartTag(CONFIG_INFO)); + request.append(buildStartTag(data[1], false)); + request.append(data[2]); + request.append(buildEndTag(data[1])); + request.append(buildEndTag(CONFIG_INFO)); + request.append(buildEndTag(ONU_SET_CONFIG)); + + reply = controller. + getDevicesMap().get(ncDeviceId).getSession(). + doWrappedRpc(request.toString()); + } catch (IOException e) { + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); + } + return reply; + } + + @Override + public String getOnuStatistics(String target) { + DriverHandler handler = handler(); + NetconfController controller = handler.get(NetconfController.class); + MastershipService mastershipService = handler.get(MastershipService.class); + DeviceId ncDeviceId = handler.data().deviceId(); + checkNotNull(controller, "Netconf controller is null"); + String reply = null; + String[] onuId = null; + + if (!mastershipService.isLocalMaster(ncDeviceId)) { + log.warn("Not master for {} Use {} to execute command", + ncDeviceId, + mastershipService.getMasterFor(ncDeviceId)); + return reply; + } + + if (target != null) { + onuId = target.split(HYPHEN); + if (onuId.length > 2) { + log.error("Invalid number of arguments:" + onuId.length); + return reply; + } + try { + pon = Integer.parseInt(onuId[0]); + if (onuId.length > 1) { + onu = Integer.parseInt(onuId[1]); + } + } catch (NumberFormatException e) { + log.error("Non-number input"); + return reply; + } + } + + try { + StringBuilder request = new StringBuilder(); + request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); + request.append(ANGLE_RIGHT).append(NEW_LINE); + request.append(buildStartTag(VOLT_STATISTICS)); + if (onuId != null) { + request.append(buildStartTag(ONU_STATISTICS)); + request.append(buildStartTag(ONU_GEM_STATS)); + request.append(buildStartTag(GEM_STATS)); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(onuId[0]); + request.append(buildEndTag(PONLINK_ID)); + if (onuId.length > 1) { + request.append(buildStartTag(ONU_ID, false)); + request.append(onuId[1]); + request.append(buildEndTag(ONU_ID)); + } + request.append(buildEndTag(GEM_STATS)); + request.append(buildEndTag(ONU_GEM_STATS)); + + request.append(buildStartTag(ONU_ETH_STATS)); + request.append(buildStartTag(ETH_STATS)); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(onuId[0]); + request.append(buildEndTag(PONLINK_ID)); + if (onuId.length > 1) { + request.append(buildStartTag(ONU_ID, false)); + request.append(onuId[1]); + request.append(buildEndTag(ONU_ID)); + } + request.append(buildEndTag(ETH_STATS)); + request.append(buildEndTag(ONU_ETH_STATS)); + + request.append(buildEndTag(ONU_STATISTICS)); + } else { + request.append(buildEmptyTag(ONU_STATISTICS)); + } + request.append(buildEndTag(VOLT_STATISTICS)); + request.append(VOLT_NE_CLOSE); + + reply = controller. + getDevicesMap().get(ncDeviceId).getSession(). + get(request.toString(), REPORT_ALL); + } catch (IOException e) { + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); + } + return reply; + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfig.java new file mode 100644 index 0000000000..67f1db2922 --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfig.java @@ -0,0 +1,155 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.drivers.fujitsu; + +import org.onosproject.mastership.MastershipService; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig; +import org.onosproject.net.driver.AbstractHandlerBehaviour; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.netconf.NetconfController; +import org.slf4j.Logger; + +import java.io.IOException; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Implementation to take actions on ONU available in vOLT + * through the Netconf protocol. + */ +public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour + implements VoltOnuOperConfig { + + private final Logger log = getLogger(FujitsuVoltOnuOperConfig.class); + private static final String ONU_REBOOT = "onu-reboot"; + private static final String ONU_ETHPORT_LOOPBACK = "onu-ethport-loopback"; + private static final String ETHPORT_ID = "ethport-id"; + private int pon; + private int onu; + private int eth; + + + @Override + public String rebootOnu(String target) { + DriverHandler handler = handler(); + NetconfController controller = handler.get(NetconfController.class); + MastershipService mastershipService = handler.get(MastershipService.class); + DeviceId ncDeviceId = handler.data().deviceId(); + checkNotNull(controller, "Netconf controller is null"); + String reply = null; + String[] onuId = null; + + if (!mastershipService.isLocalMaster(ncDeviceId)) { + log.warn("Not master for {} Use {} to execute command", + ncDeviceId, + mastershipService.getMasterFor(ncDeviceId)); + return reply; + } + + onuId = target.split(HYPHEN); + if (onuId.length != 2) { + log.error("Invalid number of arguments"); + return reply; + } + try { + pon = Integer.parseInt(onuId[0]); + onu = Integer.parseInt(onuId[1]); + } catch (NumberFormatException e) { + log.error("Non-number input"); + return reply; + } + + try { + StringBuilder request = new StringBuilder(); + request.append(ANGLE_LEFT).append(ONU_REBOOT).append(SPACE); + request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(onuId[0]); + request.append(buildEndTag(PONLINK_ID)); + request.append(buildStartTag(ONU_ID, false)); + request.append(onuId[1]); + request.append(buildEndTag(ONU_ID)); + request.append(buildEndTag(ONU_REBOOT)); + + reply = controller. + getDevicesMap().get(ncDeviceId).getSession(). + doWrappedRpc(request.toString()); + } catch (IOException e) { + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); + } + return reply; + } + + @Override + public String loopbackEthOnu(String target) { + DriverHandler handler = handler(); + NetconfController controller = handler.get(NetconfController.class); + MastershipService mastershipService = handler.get(MastershipService.class); + DeviceId ncDeviceId = handler.data().deviceId(); + checkNotNull(controller, "Netconf controller is null"); + String reply = null; + String[] ethId = null; + + if (!mastershipService.isLocalMaster(ncDeviceId)) { + log.warn("Not master for {} Use {} to execute command", + ncDeviceId, + mastershipService.getMasterFor(ncDeviceId)); + return reply; + } + + ethId = target.split(HYPHEN); + if (ethId.length != 3) { + log.error("Invalid number of arguments"); + return reply; + } + try { + pon = Integer.parseInt(ethId[0]); + onu = Integer.parseInt(ethId[1]); + eth = Integer.parseInt(ethId[2]); + } catch (NumberFormatException e) { + log.error("Non-number input"); + return reply; + } + + try { + StringBuilder request = new StringBuilder(); + request.append(ANGLE_LEFT).append(ONU_ETHPORT_LOOPBACK).append(SPACE); + request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); + request.append(buildStartTag(PONLINK_ID, false)); + request.append(ethId[0]); + request.append(buildEndTag(PONLINK_ID)); + request.append(buildStartTag(ONU_ID, false)); + request.append(ethId[1]); + request.append(buildEndTag(ONU_ID)); + request.append(buildStartTag(ETHPORT_ID, false)); + request.append(ethId[2]); + request.append(buildEndTag(ETHPORT_ID)); + request.append(buildEndTag(ONU_ETHPORT_LOOPBACK)); + + reply = controller. + getDevicesMap().get(ncDeviceId).getSession(). + doWrappedRpc(request.toString()); + } catch (IOException e) { + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); + } + return reply; + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java index 662c1ee6a8..6978803d44 100644 --- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfig.java @@ -18,7 +18,7 @@ package org.onosproject.drivers.fujitsu; import org.onosproject.mastership.MastershipService; import org.onosproject.net.DeviceId; -import org.onosproject.net.behaviour.VoltPonLinkConfig; +import org.onosproject.drivers.fujitsu.behaviour.VoltPonLinkConfig; import org.onosproject.net.driver.AbstractHandlerBehaviour; import org.onosproject.net.driver.DriverHandler; import org.onosproject.netconf.NetconfController; diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuConfig.java new file mode 100644 index 0000000000..ab7787762d --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuConfig.java @@ -0,0 +1,51 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.behaviour; + +import com.google.common.annotations.Beta; +import org.onosproject.net.driver.HandlerBehaviour; + +/** + * Device behaviour to obtain and set parameters of ONUs in vOLT. + */ +@Beta +public interface VoltOnuConfig extends HandlerBehaviour { + + /** + * Obtain all ONUs or a specific ONU in the device. + * + * @param target input data in string + * @return response string + */ + String getOnus(String target); + + /** + * Set a parameter value of an ONU in the device. + * + * @param target input data in string + * @return response string + */ + String setOnu(String target); + + /** + * Obtain all or a specific ONU statistics in the device. + * + * @param target input data in string + * @return response string + */ + String getOnuStatistics(String target); + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuOperConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuOperConfig.java new file mode 100644 index 0000000000..996d5ca91b --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltOnuOperConfig.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.behaviour; + +import com.google.common.annotations.Beta; +import org.onosproject.net.driver.HandlerBehaviour; + +/** + * Device behaviour to perform actions in an ONU in vOLT. + */ +@Beta +public interface VoltOnuOperConfig extends HandlerBehaviour { + + /** + * Reboot an ONU in the device. + * + * @param target input data in string + */ + String rebootOnu(String target); + + /** + * Operate/release loopback on Ethernet port an ONU in the device. + * + * @param target input data in string + */ + String loopbackEthOnu(String target); + +} diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/VoltPonLinkConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltPonLinkConfig.java similarity index 92% rename from core/api/src/main/java/org/onosproject/net/behaviour/VoltPonLinkConfig.java rename to drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltPonLinkConfig.java index eeb3c01282..dfd281212a 100644 --- a/core/api/src/main/java/org/onosproject/net/behaviour/VoltPonLinkConfig.java +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltPonLinkConfig.java @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.net.behaviour; +package org.onosproject.drivers.fujitsu.behaviour; +import com.google.common.annotations.Beta; import org.onosproject.net.driver.HandlerBehaviour; /** * Device behaviour to obtain and set parameters of PON links in vOLT. */ +@Beta public interface VoltPonLinkConfig extends HandlerBehaviour { /** diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/package-info.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/package-info.java new file mode 100644 index 0000000000..c9b325631e --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/package-info.java @@ -0,0 +1,22 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * Abstractions of various device configuration or device adaptation behaviours; + * counterpart to the device driver subsystem. -vOLT + */ +package org.onosproject.drivers.fujitsu.behaviour; diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltEthLoopbackCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltEthLoopbackCommand.java new file mode 100644 index 0000000000..630a5465ba --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltEthLoopbackCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Operates/releases loopback on Ethernet port of an ONU in vOLT. + */ +@Command(scope = "onos", name = "volt-ethloopback", + description = "Operates/releases loopback on Ethernet port of an ONU in vOLT") +public class VoltEthLoopbackCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "uri", description = "Device ID", + required = true, multiValued = false) + String uri = null; + + @Argument(index = 1, name = "target", description = "PON link ID-ONU ID-Eth port ID[:(operate:release)]", + required = true, multiValued = false) + String target = null; + + private DeviceId deviceId; + + @Override + protected void execute() { + DriverService service = get(DriverService.class); + deviceId = DeviceId.deviceId(uri); + DriverHandler h = service.createHandler(deviceId); + VoltOnuOperConfig volt = h.behaviour(VoltOnuOperConfig.class); + String reply = volt.loopbackEthOnu(target); + if (reply != null) { + print("%s", reply); + } else { + print("No reply from %s", deviceId.toString()); + } + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnuStatsCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnuStatsCommand.java new file mode 100644 index 0000000000..0888af104f --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnuStatsCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present Open tworking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuConfig; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Gets ONU statistics in vOLT. + */ +@Command(scope = "onos", name = "volt-onustats", + description = "Gets ONU statistics in vOLT") +public class VoltGetOnuStatsCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "uri", description = "Device ID", + required = true, multiValued = false) + String uri = null; + + @Argument(index = 1, name = "target", description = "PON link ID-ONU ID", + required = false, multiValued = false) + String target = null; + + private DeviceId deviceId; + + @Override + protected void execute() { + DriverService service = get(DriverService.class); + deviceId = DeviceId.deviceId(uri); + DriverHandler h = service.createHandler(deviceId); + VoltOnuConfig volt = h.behaviour(VoltOnuConfig.class); + String reply = volt.getOnuStatistics(target); + if (reply != null) { + print("%s", reply); + } else { + print("No reply from %s", deviceId.toString()); + } + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnusCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnusCommand.java new file mode 100644 index 0000000000..cd8076f231 --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetOnusCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present Open tworking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuConfig; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Gets ONUs available in vOLT. + */ +@Command(scope = "onos", name = "volt-onus", + description = "Gets ONUs available in vOLT") +public class VoltGetOnusCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "uri", description = "Device ID", + required = true, multiValued = false) + String uri = null; + + @Argument(index = 1, name = "target", description = "PON link ID or PON link ID-ONU ID", + required = false, multiValued = false) + String target = null; + + private DeviceId deviceId; + + @Override + protected void execute() { + DriverService service = get(DriverService.class); + deviceId = DeviceId.deviceId(uri); + DriverHandler h = service.createHandler(deviceId); + VoltOnuConfig volt = h.behaviour(VoltOnuConfig.class); + String reply = volt.getOnus(target); + if (reply != null) { + print("%s", reply); + } else { + print("No reply from %s", deviceId.toString()); + } + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetPonLinksCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetPonLinksCommand.java index 2aacf15bde..9129d94f22 100644 --- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetPonLinksCommand.java +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetPonLinksCommand.java @@ -19,7 +19,7 @@ import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onosproject.cli.AbstractShellCommand; import org.onosproject.net.DeviceId; -import org.onosproject.net.behaviour.VoltPonLinkConfig; +import org.onosproject.drivers.fujitsu.behaviour.VoltPonLinkConfig; import org.onosproject.net.driver.DriverHandler; import org.onosproject.net.driver.DriverService; diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltRebootOnuCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltRebootOnuCommand.java new file mode 100644 index 0000000000..2d973ddfa2 --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltRebootOnuCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Reboots an ONU in vOLT. + */ +@Command(scope = "onos", name = "volt-rebootonu", + description = "Reboots an ONU in vOLT") +public class VoltRebootOnuCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "uri", description = "Device ID", + required = true, multiValued = false) + String uri = null; + + @Argument(index = 1, name = "target", description = "PON link ID-ONU ID", + required = true, multiValued = false) + String target = null; + + private DeviceId deviceId; + + @Override + protected void execute() { + DriverService service = get(DriverService.class); + deviceId = DeviceId.deviceId(uri); + DriverHandler h = service.createHandler(deviceId); + VoltOnuOperConfig volt = h.behaviour(VoltOnuOperConfig.class); + String reply = volt.rebootOnu(target); + if (reply != null) { + print("%s", reply); + } else { + print("No reply from %s", deviceId.toString()); + } + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetOnuCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetOnuCommand.java new file mode 100644 index 0000000000..4b82cd3c9a --- /dev/null +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetOnuCommand.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016-present Open tworking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.drivers.fujitsu.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.drivers.fujitsu.behaviour.VoltOnuConfig; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Sets a parameter value of an ONU in vOLT. + */ +@Command(scope = "onos", name = "volt-setonu", + description = "Sets a parameter value of an ONU in vOLT") +public class VoltSetOnuCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "uri", description = "Device ID", + required = true, multiValued = false) + String uri = null; + + @Argument(index = 1, name = "target", description = "PON link ID-ONU ID:parameter:value", + required = true, multiValued = false) + String target = null; + + private DeviceId deviceId; + + @Override + protected void execute() { + DriverService service = get(DriverService.class); + deviceId = DeviceId.deviceId(uri); + DriverHandler h = service.createHandler(deviceId); + VoltOnuConfig volt = h.behaviour(VoltOnuConfig.class); + String reply = volt.setOnu(target); + if (reply != null) { + print("%s", reply); + } else { + print("No reply from %s", deviceId.toString()); + } + } + +} diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetPonLinkCommand.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetPonLinkCommand.java index 46b7f9c9e8..94565c5803 100644 --- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetPonLinkCommand.java +++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetPonLinkCommand.java @@ -19,7 +19,7 @@ import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onosproject.cli.AbstractShellCommand; import org.onosproject.net.DeviceId; -import org.onosproject.net.behaviour.VoltPonLinkConfig; +import org.onosproject.drivers.fujitsu.behaviour.VoltPonLinkConfig; import org.onosproject.net.driver.DriverHandler; import org.onosproject.net.driver.DriverService; diff --git a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml index 4b65abfc6f..1f72cc6431 100644 --- a/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml +++ b/drivers/fujitsu/src/main/resources/OSGI-INF/blueprint/shell-config.xml @@ -23,13 +23,42 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml index d4666e3983..46cb697fb5 100644 --- a/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml +++ b/drivers/fujitsu/src/main/resources/fujitsu-drivers.xml @@ -24,7 +24,11 @@ - + + \ No newline at end of file diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java index daab1b50af..3e35b5acf3 100644 --- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java +++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSession.java @@ -59,6 +59,16 @@ public interface NetconfSession { String get(String filterSchema, String withDefaultsMode) throws NetconfException; + /** + * Executes an RPC to the server and wrap the request in RPC header. + * + * @param request the XML containing the request to the server. + * @return Server response or ERROR + * @throws NetconfException when there is a problem in the communication process on + * the underlying connection + */ + String doWrappedRpc(String request) throws NetconfException; + /** * Executes an synchronous RPC to the server. * diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java index 8c0f6b72f4..e35964165e 100644 --- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java +++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java @@ -288,6 +288,24 @@ public class NetconfSessionImpl implements NetconfSession { return request; } + @Override + public String doWrappedRpc(String request) throws NetconfException { + StringBuilder rpc = new StringBuilder(XML_HEADER); + rpc.append(RPC_OPEN); + rpc.append(MESSAGE_ID_STRING); + rpc.append(EQUAL); + rpc.append("\""); + rpc.append(messageIdInteger.get()); + rpc.append("\" "); + rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); + rpc.append(request); + rpc.append(RPC_CLOSE).append(NEW_LINE); + rpc.append(ENDPATTERN); + String reply = sendRequest(rpc.toString()); + checkReply(reply); + return reply; + } + @Override public String get(String request) throws NetconfException { return requestSync(request);