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);
}
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations