use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class DomainIntentManager method initDomainIntentDriver.
private DomainIntentConfigurable initDomainIntentDriver(DeviceId deviceId) {
// Attempt to lookup the handler in the cache
DriverHandler handler = driverHandlers.get(deviceId);
if (handler == null) {
try {
// Otherwise create it and if it has DomainIntentConfig behaviour, cache it
handler = driverService.createHandler(deviceId);
if (!handler.driver().hasBehaviour(DomainIntentConfigurable.class)) {
log.warn("DomainIntentConfig behaviour not supported for device {}", deviceId);
return null;
}
} catch (ItemNotFoundException e) {
log.warn("No applicable driver for device {}", deviceId);
return null;
}
driverHandlers.put(deviceId, handler);
}
// Always (re)initialize the pipeline behaviour
log.info("Driver {} bound to device {} ... initializing driver", handler.driver().name(), deviceId);
return handler.behaviour(DomainIntentConfigurable.class);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class NetconfDeviceProvider method getDeviceDescription.
private DeviceDescription getDeviceDescription(DeviceId deviceId, NetconfDeviceConfig config) {
Driver driver = driverService.getDriver(deviceId);
if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
final DriverData data = new DefaultDriverData(driver, deviceId);
final DriverHandler handler = new DefaultDriverHandler(data);
// creating the behaviour because the core has yet no notion of device.
DeviceDescriptionDiscovery deviceDescriptionDiscovery = driver.createBehaviour(handler, DeviceDescriptionDiscovery.class);
return getDeviceRepresentation(deviceId, config, deviceDescriptionDiscovery);
} else {
return existingOrEmptyDescription(deviceId, config);
}
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OpenFlowPolicerConfigurable method allocatePolicerId.
@Override
public PolicerId allocatePolicerId() {
// Init step
DriverHandler handler = handler();
// First step is to get MeterService
MeterService meterService = handler.get(MeterService.class);
// There was a problem, return none
if (meterService == null) {
log.warn("MeterService is null");
return PolicerId.NONE;
}
// Let's get the device id
DeviceId deviceId = handler.data().deviceId();
// Double check correspondence between schemas
if (!deviceId.uri().getScheme().equals(OF_SCHEME)) {
log.warn("The device {} does not seem to be managed by OpenFlow", deviceId);
return PolicerId.NONE;
}
// Get a new meter id
MeterId meterId = meterService.allocateMeterId(deviceId);
// There was a problem
if (meterId == null) {
log.warn("MeterService does not provide valid ids");
return PolicerId.NONE;
}
// Create a policer id from the meter id
return getPolicerIdFromMeterId(meterId);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltAlarmConsumer method consumeAlarms.
@Override
public List<Alarm> consumeAlarms() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
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 null;
}
dateFormat.setTimeZone(ZONE);
List<Alarm> alarms = new ArrayList<>();
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_ALERTS)).append(buildEmptyTag(OLT_ACTIVE_ALERTS)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
String reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), null);
if (reply != null) {
alarms = parseVoltActiveAlerts(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
} catch (NetconfException e) {
log.error("Error reading alarms for device {} exception {}", ncDeviceId, e);
}
return ImmutableList.copyOf(alarms);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class FujitsuVoltAlertConfig method setAlertFilter.
@Override
public boolean setAlertFilter(String severity) {
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 (!SEVERITYLEVELS.contains(severity)) {
log.error("Invalid severity level: {}", severity);
return false;
}
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(buildStartTag(ALERT_FILTER, false)).append(severity).append(buildEndTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).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;
}
Aggregations