本文整理了Java中org.onosproject.net.Device.is()
方法的一些代码示例,展示了Device.is()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Device.is()
方法的具体详情如下:
包路径:org.onosproject.net.Device
类名称:Device
方法名:is
暂无
代码示例来源:origin: org.onosproject/onos-core-net
/**
* {@inheritDoc}
* if the Device does not support {@link FlowRuleProgrammable}.
*/
@Override
protected synchronized FlowRuleProvider getProvider(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
// if device supports FlowRuleProgrammable,
// use FlowRuleProgrammable via FlowRuleDriverProvider
return Optional.ofNullable(deviceService.getDevice(deviceId))
.filter(dev -> dev.is(FlowRuleProgrammable.class))
.<FlowRuleProvider>map(x -> driverProvider)
.orElseGet(() -> super.getProvider(deviceId));
}
代码示例来源:origin: org.onosproject/onos-core-net
private FlowRuleProgrammable getFlowRuleProgrammable(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (device.is(FlowRuleProgrammable.class)) {
return device.as(FlowRuleProgrammable.class);
} else {
log.debug("Device {} is not flow rule programmable", deviceId);
return null;
}
}
代码示例来源:origin: org.onosproject/onos-core-net
@Override
public boolean isRelevant(DeviceEvent event) {
Device device = event.subject();
return POSITIVE_DEVICE_EVENT.contains(event.type()) &&
device.is(MeterProgrammable.class);
}
代码示例来源:origin: org.onosproject/onos-core-net
private GroupProgrammable getGroupProgrammable(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (device.is(GroupProgrammable.class)) {
return device.as(GroupProgrammable.class);
} else {
log.debug("Device {} is not group programmable", deviceId);
return null;
}
}
代码示例来源:origin: org.onosproject/onos-core-net
@Override
public boolean isRelevant(DeviceEvent event) {
Device device = event.subject();
return POSITIVE_DEVICE_EVENT.contains(event.type()) &&
device.is(GroupProgrammable.class);
}
代码示例来源:origin: org.onosproject/onos-core-net
@Override
public boolean isRelevant(DeviceEvent event) {
Device device = event.subject();
return POSITIVE_DEVICE_EVENT.contains(event.type()) &&
device.is(FlowRuleProgrammable.class);
}
代码示例来源:origin: org.onosproject/onos-core-net
private MeterProgrammable getMeterProgrammable(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (device.is(MeterProgrammable.class)) {
return device.as(MeterProgrammable.class);
} else {
log.debug("Device {} is not meter programmable", deviceId);
return null;
}
}
代码示例来源:origin: org.onosproject/onos-core-net
private PacketProgrammable getPacketProgrammable(DeviceId deviceId) {
if (deviceService == null) {
log.debug("Packet encountered but device service is not ready, dropping");
return null;
}
Device device = deviceService.getDevice(deviceId);
if (device.is(PacketProgrammable.class)) {
return device.as(PacketProgrammable.class);
} else {
log.debug("Device {} is not packet programmable", deviceId);
return null;
}
}
}
代码示例来源:origin: org.onosproject/onos-core-net
static PiPipelineInterpreter getInterpreterOrNull(Device device, PiPipeconf pipeconf) {
if (device != null) {
return device.is(PiPipelineInterpreter.class) ? device.as(PiPipelineInterpreter.class) : null;
} else {
// The case of device == null should be admitted only during unit testing.
// In any other case, the interpreter should be constructed using the device.as() method to make sure that
// behaviour's handler/data attributes are correctly populated.
// FIXME: modify test class PiFlowRuleTranslatorTest to avoid passing null device
// I.e. we need to create a device object that supports is/as method for obtaining the interpreter.
log.warn("getInterpreterOrNull() called with device == null, is this a unit test?");
try {
return (PiPipelineInterpreter) pipeconf.implementation(PiPipelineInterpreter.class)
.orElse(null)
.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException(format("Unable to instantiate interpreter of pipeconf %s",
pipeconf.id()));
}
}
}
代码示例来源:origin: org.onosproject/onos-core-net
private void pollFlowEntries() {
try {
deviceService.getAvailableDevices().forEach(device -> {
if (mastershipService.isLocalMaster(device.id()) && device.is(FlowRuleProgrammable.class)) {
pollDeviceFlowEntries(device);
}
if (mastershipService.isLocalMaster(device.id()) && device.is(TableStatisticsDiscovery.class)) {
pollTableStatistics(device);
}
});
} catch (Exception e) {
log.warn("Exception thrown while polling flows", e);
}
}
代码示例来源:origin: org.onosproject/onos-bmv2-provider-packet
@Override
public void emit(OutboundPacket packet) {
if (packet != null) {
DeviceId deviceId = packet.sendThrough();
Device device = deviceService.getDevice(deviceId);
if (device.is(PacketProgrammable.class)) {
PacketProgrammable packetProgrammable = device.as(PacketProgrammable.class);
packetProgrammable.emit(packet);
} else {
log.info("No PacketProgrammable behavior for device {}", deviceId);
}
}
}
代码示例来源:origin: org.onosproject/onos-app-fm-mgr
private void consumeAlarms(Device device) {
if (device.is(AlarmConsumer.class)) {
providerService.updateAlarmList(device.id(),
device.as(AlarmConsumer.class).consumeAlarms());
} else {
log.info("Device {} does not support alarm consumer behaviour", device.id());
}
}
代码示例来源:origin: org.onosproject/onos-core-net
private void pollMeters() {
deviceService.getAvailableDevices().forEach(device -> {
if (mastershipService.isLocalMaster(device.id()) &&
device.is(MeterProgrammable.class)) {
pollDeviceMeters(device.id());
}
});
}
代码示例来源:origin: org.onosproject/onos-core-net
private void pollGroups() {
deviceService.getAvailableDevices().forEach(device -> {
if (mastershipService.isLocalMaster(device.id()) &&
device.is(GroupProgrammable.class)) {
pollDeviceGroups(device.id());
}
});
}
代码示例来源:origin: org.onosproject/onos-core-net
private static PortNumber logicalToPipelineSpecific(
PortNumber logicalPort, Device device)
throws PiTranslationException {
if (!device.is(PiPipelineInterpreter.class)) {
throw new PiTranslationException(
"missing interpreter, cannot map logical port " + logicalPort.toString());
}
final PiPipelineInterpreter interpreter = device.as(PiPipelineInterpreter.class);
Optional<Integer> mappedPort = interpreter.mapLogicalPortNumber(logicalPort);
if (!mappedPort.isPresent()) {
throw new PiTranslationException(
"interpreter cannot map logical port " + logicalPort.toString());
}
return PortNumber.portNumber(mappedPort.get());
}
}
代码示例来源:origin: org.onosproject/onos-core-common
/**
* Encodes a extension instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodeExtension(ObjectNode result) {
final Instructions.ExtensionInstructionWrapper extensionInstruction =
(Instructions.ExtensionInstructionWrapper) instruction;
DeviceId deviceId = extensionInstruction.deviceId();
ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
DeviceService deviceService = serviceDirectory.get(DeviceService.class);
Device device = deviceService.getDevice(deviceId);
if (device == null) {
throw new IllegalArgumentException("Device not found");
}
if (device.is(ExtensionTreatmentCodec.class)) {
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
result.set(InstructionCodec.EXTENSION, node);
} else {
throw new IllegalArgumentException(
"There is no codec to encode extension for device " + deviceId.toString());
}
}
代码示例来源:origin: org.onosproject/onos-core-net
private boolean isLocalMaster(Device device) {
if (mastershipService.isLocalMaster(device.id())) {
return true;
}
// The device might have no master (e.g. after it has been disconnected
// from core), hence we use device mastership state.
final MastershipInfo info = mastershipService.getMastershipFor(device.id());
return !info.master().isPresent() &&
device.is(DeviceHandshaker.class) &&
device.as(DeviceHandshaker.class).getRole()
.equals(MastershipRole.MASTER);
}
代码示例来源:origin: org.onosproject/onos-cli
private void printDevice(DeviceService deviceService,
DriverService driverService,
Device device) {
super.printDevice(deviceService, device);
if (!device.is(InterfaceConfig.class)) {
// The relevant behavior is not supported by the device.
print(ERROR_RESULT);
return;
}
DriverHandler h = driverService.createHandler(device.id());
InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
List<DeviceInterfaceDescription> interfaces =
interfaceConfig.getInterfaces();
if (interfaces == null) {
print(ERROR_RESULT);
} else if (interfaces.isEmpty()) {
print(NO_INTERFACES);
} else {
interfaces.forEach(this::printInterface);
}
}
代码示例来源:origin: org.onosproject/onos-bmv2-provider-device
private void updatePortsAndStats(DeviceId did) {
Device device = deviceService.getDevice(did);
if (device.is(DeviceDescriptionDiscovery.class)) {
DeviceDescriptionDiscovery discovery = device.as(DeviceDescriptionDiscovery.class);
List<PortDescription> portDescriptions = discovery.discoverPortDetails();
if (portDescriptions != null) {
providerService.updatePorts(did, portDescriptions);
}
} else {
log.warn("No DeviceDescriptionDiscovery behavior for device {}", did);
}
try {
Collection<PortStatistics> portStats = getPortStatistics(controller.getAgent(did),
deviceService.getPorts(did));
providerService.updatePortStatistics(did, portStats);
} catch (Bmv2RuntimeException e) {
log.warn("Unable to get port statistics for {}: {}", did, e.explain());
}
}
代码示例来源:origin: org.onosproject/onos-bmv2-provider-device
private DeviceDescription getDeviceDescription(DeviceId did) {
Device device = deviceService.getDevice(did);
DeviceDescriptionDiscovery discovery = null;
if (device == null) {
// Device not yet in the core. Manually get a driver.
Driver driver = driverService.getDriver(MANUFACTURER, HW_VERSION, SW_VERSION);
if (driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
discovery = driver.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(driver, did)),
DeviceDescriptionDiscovery.class);
}
} else if (device.is(DeviceDescriptionDiscovery.class)) {
discovery = device.as(DeviceDescriptionDiscovery.class);
}
if (discovery == null) {
log.warn("No DeviceDescriptionDiscovery behavior for device {}", did);
return null;
} else {
return discovery.discoverDeviceDetails();
}
}
内容来源于网络,如有侵权,请联系作者删除!