Search in sources :

Example 31 with DriverHandler

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

the class ControllerConfigCiscoImpl method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    DriverHandler handler = handler();
    DeviceId deviceId = handler.data().deviceId();
    List<String> cmds = new ArrayList<>();
    cmds.add(OPENFLOW_CMD);
    cmds.add(DELETE_OF_CONFIG);
    cmds.add(SW1_CMD);
    cmds.add(PROTO_VER_CMD);
    if (checkSwitchN7K(handler)) {
        cmds.add(N7K_PIPELINE_CMD);
        log.info("This is N7K Switch");
    } else {
        cmds.add(N9K_PIPELINE_CMD);
        log.info("This is N9K Switch");
    }
    // can configure up to eight controllers
    controllers.stream().limit(8).forEach(c -> cmds.add(String.format(OF_CONTROLLER_CONF_CMD, c.ip().toString(), c.port(), "management")));
    cmds.add(NO_SHUTDOWN_CMD);
    cmds.add(COPY_RUNNING_CONFIG);
    String response = NxApiRequest.postClis(handler, cmds);
    if (Objects.isNull(response)) {
        throw new NullPointerException("Response is null");
    }
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        // TODO parse error messages.
        if (json.has("error")) {
            log.error("{} Response has IllegalStateException Error", deviceId);
            return;
        }
    } catch (IOException e) {
        log.error("Exception thrown", e);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 32 with DriverHandler

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

the class ControllerConfigCiscoImpl method removeControllers.

@Override
public void removeControllers(List<ControllerInfo> controllers) {
    DriverHandler handler = handler();
    DeviceId deviceId = handler.data().deviceId();
    List<String> cmds = new ArrayList<>();
    cmds.add(OPENFLOW_CMD);
    cmds.add(DELETE_OF_CONFIG);
    cmds.add(COPY_RUNNING_CONFIG);
    String response = NxApiRequest.postClis(handler, cmds);
    if (Objects.isNull(response)) {
        log.error(" Device {} Response is null", deviceId);
        return;
    }
    try {
        ObjectMapper om = new ObjectMapper();
        JsonNode json = om.readTree(response);
        if (json.has("errors")) {
            log.error("{} Response has JSON Format Error {}", deviceId, json);
            return;
        }
    // TODO parse error messages.
    } catch (IOException e) {
        log.error("Exception thrown", e);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with DriverHandler

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

the class GroupBucketEntryBuilder method getDriver.

private DriverHandler getDriver(Dpid dpid) {
    DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
    Driver driver = driverService.getDriver(deviceId);
    DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
    return handler;
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) Driver(org.onosproject.net.driver.Driver) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 34 with DriverHandler

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

the class GroupBucketEntryBuilder method buildTreatment.

private TrafficTreatment buildTreatment(List<OFAction> actions) {
    DriverHandler driverHandler = getDriver(dpid);
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    // If this is a drop rule
    if (actions.isEmpty()) {
        builder.drop();
        return builder.build();
    }
    return FlowEntryBuilder.configureTreatmentBuilder(actions, builder, driverHandler, DeviceId.deviceId(Dpid.uri(dpid))).build();
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment)

Example 35 with DriverHandler

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

the class PolatisAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    MastershipService mastershipService = handler.get(MastershipService.class);
    deviceId = handler.data().deviceId();
    List<Alarm> alarms = new ArrayList<>();
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("Not master for {} Use {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
        return ImmutableList.copyOf(alarms);
    }
    try {
        String request = xmlEmpty(KEY_SYSTEMALARMS_XMLNS);
        String reply = controller.getDevicesMap().get(deviceId).getSession().get(request, null);
        if (reply != null) {
            alarms = parseAlarms(reply);
        }
    } catch (NetconfException e) {
        log.error("Error reading alarms for device {} exception {}", deviceId, e);
    }
    return ImmutableList.copyOf(alarms);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) 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