use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class ExtensionInstructionSerializer method write.
@Override
public void write(Kryo kryo, Output output, Instructions.ExtensionInstructionWrapper object) {
kryo.writeClassAndObject(output, object.extensionInstruction().type());
kryo.writeClassAndObject(output, object.deviceId());
DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
// It raises ItemNotFoundException if it failed to find driver
Driver driver = driverService.getDriver(object.deviceId());
kryo.writeClassAndObject(output, driver.name());
kryo.writeClassAndObject(output, object.extensionInstruction().serialize());
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class NetconfSessionMinaImpl method createSubscriptionString.
@Beta
protected String createSubscriptionString(String filterSchema) {
StringBuilder subscriptionbuffer = new StringBuilder();
subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
subscriptionbuffer.append(" <create-subscription\n");
subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n");
DriverService driverService = directory.get(DriverService.class);
Driver driver = driverService.getDriver(deviceInfo.getDeviceId());
if (driver != null) {
String stream = driver.getProperty(NOTIFICATION_STREAM);
if (stream != null) {
subscriptionbuffer.append(" <stream>");
subscriptionbuffer.append(stream);
subscriptionbuffer.append("</stream>\n");
}
}
// FIXME Only subtree filtering supported at the moment.
if (filterSchema != null) {
subscriptionbuffer.append(" ");
subscriptionbuffer.append(SUBSCRIPTION_SUBTREE_FILTER_OPEN).append(NEW_LINE);
subscriptionbuffer.append(filterSchema).append(NEW_LINE);
subscriptionbuffer.append(" ");
subscriptionbuffer.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE);
}
subscriptionbuffer.append(" </create-subscription>\n");
subscriptionbuffer.append("</rpc>\n");
subscriptionbuffer.append(ENDPATTERN);
return subscriptionbuffer.toString();
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class NetconfSessionMinaImpl method getClientCapabilites.
/**
* Get the list of the netconf client capabilities from device driver property.
*
* @param deviceId the deviceID for which to recover the capabilities from the driver.
* @return the String list of clientCapability property, or null if it is not configured
*/
public Set<String> getClientCapabilites(DeviceId deviceId) {
Set<String> capabilities = new LinkedHashSet<>();
DriverService driverService = directory.get(DriverService.class);
try {
Driver driver = driverService.getDriver(deviceId);
if (driver == null) {
return capabilities;
}
String clientCapabilities = driver.getProperty(NETCONF_CLIENT_CAPABILITY);
if (clientCapabilities == null) {
return capabilities;
}
String[] textStr = clientCapabilities.split("\\|");
capabilities.addAll(Arrays.asList(textStr));
return capabilities;
} catch (ItemNotFoundException e) {
log.warn("Driver for device {} currently not available", deviceId);
return capabilities;
}
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class OpenFlowRuleProvider method executeBatch.
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
checkNotNull(batch);
Dpid dpid = Dpid.dpid(batch.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
// If switch no longer exists, simply return.
if (sw == null) {
Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
providerService.batchOperationCompleted(batch.id(), new CompletedBatchOperation(false, failures, batch.deviceId()));
return;
}
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
// Build a batch of flow mods - to reduce the number i/o asked to the SO
Set<OFFlowMod> mods = Sets.newHashSet();
OFFlowMod mod;
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw.factory(), Optional.of(batch.id()), Optional.of(driverService));
switch(fbe.operator()) {
case ADD:
mod = builder.buildFlowAdd();
break;
case REMOVE:
mod = builder.buildFlowDel();
break;
case MODIFY:
mod = builder.buildFlowMod();
break;
default:
log.error("Unsupported batch operation {}; skipping flowmod {}", fbe.operator(), fbe);
continue;
}
mods.add(mod);
}
// Build a list to mantain the order
List<OFMessage> modsTosend = Lists.newArrayList(mods);
OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest().setXid(batch.id());
// Adds finally the barrier request
modsTosend.add(builder.build());
sw.sendMsg(modsTosend);
// Take into account also the barrier request
recordEvents(dpid, (batch.getOperations().size() + 1));
}
use of org.onosproject.net.driver.DriverService in project onos by opennetworkinglab.
the class DeviceCodec method encode.
@Override
public ObjectNode encode(Device device, CodecContext context) {
checkNotNull(device, "Device cannot be null");
DeviceService service = context.getService(DeviceService.class);
DriverService driveService = context.getService(DriverService.class);
ObjectNode result = context.mapper().createObjectNode().put(ID, device.id().toString()).put(TYPE, device.type().name()).put(AVAILABLE, service.isAvailable(device.id())).put(ROLE, service.getRole(device.id()).toString()).put(MFR, device.manufacturer()).put(HW, device.hwVersion()).put(SW, device.swVersion()).put(SERIAL, device.serialNumber()).put(DRIVER, driveService.getDriver(device.id()).name()).put(CHASSIS_ID, device.chassisId().toString()).put(LAST_UPDATE, Long.toString(service.getLastUpdatedInstant(device.id()))).put(HUMAN_READABLE_LAST_UPDATE, service.localStatus(device.id()));
return annotate(result, device, context);
}
Aggregations