Search in sources :

Example 56 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltAlertConfig method subscribe.

@Override
public boolean subscribe(String mode) {
    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");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    if (mode != null) {
        if (!DISABLE.equals(mode)) {
            log.error("Invalid mode: {}", mode);
            return false;
        }
    }
    try {
        if (mode != null) {
            controller.getDevicesMap().get(ncDeviceId).getSession().endSubscription();
        } else {
            StringBuilder request = new StringBuilder();
            request.append(ANGLE_LEFT + NOTIFY_ALERT + SPACE);
            request.append(VOLT_NE_NAMESPACE + SLASH + ANGLE_RIGHT);
            controller.getDevicesMap().get(ncDeviceId).getSession().startSubscription(request.toString());
        }
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
        return false;
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 57 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltAlertConfig method getAlertFilter.

@Override
public String getAlertFilter() {
    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(buildStartTag(VOLT_ALERTS)).append(buildEmptyTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
    }
    return reply;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 58 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    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");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(ncDeviceId)) {
        try {
            StringBuilder request = new StringBuilder();
            request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
            request.append(buildEmptyTag(VOLT_OFCONFIG));
            request.append(VOLT_NE_CLOSE);
            String reply;
            reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
            log.debug("Reply XML {}", reply);
            controllers.addAll(parseStreamVoltControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} ", ncDeviceId);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
    }
    return ImmutableList.copyOf(controllers);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 59 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltControllerConfig method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    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");
    if (mastershipService.isLocalMaster(ncdeviceId)) {
        try {
            NetconfDevice device = controller.getNetconfDevice(ncdeviceId);
            String config = createVoltControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream(RESOURCE_XML)), RUNNING, MERGE, controllers);
            device.getSession().editConfig(config.substring(config.indexOf(END_LICENSE_HEADER) + END_LICENSE_HEADER.length()));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} , exception {}", ncdeviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", ncdeviceId, mastershipService.getMasterFor(ncdeviceId));
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 60 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltFwdlConfig method upgradeFirmwareOndemand.

@Override
public String upgradeFirmwareOndemand(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;
    int count;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    String[] data = target.split(COLON);
    if ((data.length < TWO) || (data.length > THREE)) {
        log.error("Invalid number of arguments");
        return null;
    }
    String[] onuList = data[SECOND_PART].split(COMMA);
    if (onuList.length == ZERO) {
        log.error("No ONU listed");
        return null;
    }
    if ((data.length > TWO) && (!AUTO.equals(data[THIRD_PART]))) {
        log.error("Invalid reboot-mode {}", data[THIRD_PART]);
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(ANGLE_LEFT + ONDEMAND_FIRMWARE_UPGRADE + SPACE);
        request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(PARTICIPANT_LIST));
        for (count = ZERO; count < onuList.length; count++) {
            String[] onuId = onuList[count].split(HYPHEN);
            if (onuId.length != TWO) {
                log.error("Invalid ONU identifier");
                return null;
            }
            try {
                int pon;
                pon = Integer.parseInt(onuId[FIRST_PART]);
                if (pon <= ZERO) {
                    log.error("Invalid integer for ponlink-id:{}", onuId[FIRST_PART]);
                    return null;
                }
                int onu;
                onu = Integer.parseInt(onuId[SECOND_PART]);
                if (onu <= ZERO) {
                    log.error("Invalid integer for onu-id:{}", onuId[SECOND_PART]);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input");
                return null;
            }
            request.append(buildStartTag(MEMBER)).append(buildStartTag(PONLINK_ID)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(MEMBER));
        }
        request.append(buildEndTag(PARTICIPANT_LIST)).append(buildStartTag(IMAGE_NAME)).append(data[FIRST_PART]).append(buildEndTag(IMAGE_NAME));
        if (data.length == THREE) {
            request.append(buildStartTag(REBOOT_MODE)).append(data[THIRD_PART]).append(buildEndTag(REBOOT_MODE));
        }
        request.append(buildEndTag(ONDEMAND_FIRMWARE_UPGRADE));
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().doWrappedRpc(request.toString());
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
    }
    return reply;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5