/* * 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.drivers.fujitsu.behaviour.VoltNeConfig; import org.onosproject.mastership.MastershipService; import org.onosproject.net.DeviceId; 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 get all available data in vOLT * through the Netconf protocol. */ public class FujitsuVoltNeConfig extends AbstractHandlerBehaviour implements VoltNeConfig { private final Logger log = getLogger(FujitsuVoltNeConfig.class); @Override public String getAll() { 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 null; } try { StringBuilder request = new StringBuilder(); request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE); request.append(ANGLE_RIGHT + NEW_LINE); 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; } }