Search in sources :

Example 66 with DriverHandler

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

the class DellRestPortDiscovery method getPorts.

@Deprecated
public List<PortDescription> getPorts() {
    List<PortDescription> ports = Lists.newArrayList();
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    String remotePortName = "";
    // read configuration from REST API
    HierarchicalConfiguration config = XmlConfigParser.loadXml(controller.get(deviceId, INTERFACES_REQUEST, MediaType.valueOf("*/*")));
    // get the interfaces part
    List<HierarchicalConfiguration> portsConfig = parseDellPorts(config);
    portsConfig.stream().forEach(sub -> {
        String portName = sub.getString(NAME);
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portName);
        // TODO: obtain proper port speed and type
        long portSpeed = 10_000;
        Port.Type portType = Port.Type.COPPER;
        PortNumber portNumber = PortNumber.fromString(remotePortName.replaceAll(TENGINTERFACENAME, ""));
        ports.add(DefaultPortDescription.builder().withPortNumber(portNumber).isEnabled(true).type(portType).portSpeed(portSpeed).annotations(annotations.build()).build());
    });
    return ImmutableList.copyOf(ports);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) RestSBController(org.onosproject.protocol.rest.RestSBController) DriverHandler(org.onosproject.net.driver.DriverHandler) PortNumber(org.onosproject.net.PortNumber)

Example 67 with DriverHandler

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

the class FujitsuVoltNniLinkConfig method setNniLink.

@Override
public boolean setNniLink(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");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    String[] data = target.split(COLON);
    if (data.length != THREE) {
        log.error("Invalid number of arguments {}", target);
        return false;
    }
    try {
        int nni = Integer.parseInt(data[FIRST_PART]);
        if (nni <= ZERO) {
            log.error("Invalid integer for nnilink-id:{}", target);
            return false;
        }
    } catch (NumberFormatException e) {
        log.error("Non-number input for nnilink-id:{}", target);
        return false;
    }
    if (!checkSetParam(data[SECOND_PART], data[THIRD_PART])) {
        log.error("Failed to check input {}", target);
        return false;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_PORTS)).append(buildStartTag(ETH_NNILINK_PORTS)).append(buildStartTag(ETH_NNILINK_PORT)).append(buildStartTag(NNILINK_ID, false)).append(data[FIRST_PART]).append(buildEndTag(NNILINK_ID)).append(buildStartTag(data[SECOND_PART], false)).append(data[THIRD_PART]).append(buildEndTag(data[SECOND_PART])).append(buildEndTag(ETH_NNILINK_PORT)).append(buildEndTag(ETH_NNILINK_PORTS)).append(buildEndTag(VOLT_PORTS)).append(VOLT_NE_CLOSE);
        controller.getDevicesMap().get(ncDeviceId).getSession().editConfig(RUNNING, null, 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 68 with DriverHandler

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

the class FujitsuVoltOnuConfig method getOnus.

@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 null;
    }
    if (target != null) {
        onuId = checkIdString(target);
        if (onuId == null) {
            log.error("Invalid ONU identifier {}", target);
            return null;
        }
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        if (onuId != null) {
            request.append(buildStartTag(VOLT_ONUS)).append(buildStartTag(ONUS_PERLINK)).append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID));
            if (onuId.length > ONE) {
                request.append(buildStartTag(ONUS_LIST)).append(buildStartTag(ONU_INFO)).append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(ONU_INFO)).append(buildEndTag(ONUS_LIST));
            }
            request.append(buildEndTag(ONUS_PERLINK)).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 (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 69 with DriverHandler

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

the class FujitsuVoltOnuConfig method setOnu.

@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 null;
    }
    String[] data = target.split(COLON);
    if (data.length != THREE) {
        log.error("Invalid number of arguments");
        return null;
    }
    String[] onuId = checkIdString(data[FIRST_PART]);
    if ((onuId == null) || (onuId.length != TWO)) {
        log.error("Invalid ONU identifier {}", target);
        return null;
    }
    if (!checkSetParam(data[SECOND_PART], data[THIRD_PART])) {
        log.error("Failed to check input {}", target);
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(ANGLE_LEFT + ONU_SET_CONFIG + SPACE);
        request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildStartTag(CONFIG_INFO)).append(buildStartTag(data[SECOND_PART], false)).append(data[THIRD_PART]).append(buildEndTag(data[SECOND_PART])).append(buildEndTag(CONFIG_INFO)).append(buildEndTag(ONU_SET_CONFIG));
        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)

Example 70 with DriverHandler

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

the class FujitsuVoltOnuConfig method getOnuStatistics.

@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 null;
    }
    if (target != null) {
        onuId = checkIdString(target);
        if (onuId == null) {
            log.error("Failed to check ID: {}", target);
            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_STATISTICS));
        if (onuId != null) {
            request.append(buildStartTag(ONU_STATISTICS)).append(buildStartTag(ONU_GEM_STATS)).append(buildStartTag(GEM_STATS)).append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID));
            if (onuId.length > ONE) {
                request.append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID));
            }
            request.append(buildEndTag(GEM_STATS)).append(buildEndTag(ONU_GEM_STATS));
            request.append(buildStartTag(ONU_ETH_STATS)).append(buildStartTag(ETH_STATS)).append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID));
            if (onuId.length > ONE) {
                request.append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID));
            }
            request.append(buildEndTag(ETH_STATS)).append(buildEndTag(ONU_ETH_STATS)).append(buildEndTag(ONU_STATISTICS));
        } else {
            request.append(buildEmptyTag(ONU_STATISTICS));
        }
        request.append(buildEndTag(VOLT_STATISTICS)).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)

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