本文整理了Java中org.onosproject.net.Device.as()
方法的一些代码示例,展示了Device.as()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Device.as()
方法的具体详情如下:
包路径:org.onosproject.net.Device
类名称:Device
方法名:as
暂无
代码示例来源: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 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
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
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 pollTableStatistics(Device device) {
try {
List<TableStatisticsEntry> tableStatsList = newArrayList(device.as(TableStatisticsDiscovery.class)
.getTableStatistics());
providerService.pushTableStatistics(device.id(), tableStatsList);
} catch (Exception e) {
log.warn("Exception thrown while polling table statistics for {}", device.id(), e);
}
}
代码示例来源:origin: org.onosproject/onos-core-net
private void pollDeviceFlowEntries(Device device) {
try {
providerService.pushFlowMetrics(device.id(), device.as(FlowRuleProgrammable.class).getFlowEntries());
} catch (Exception e) {
log.warn("Exception thrown while polling {}", device.id(), 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
final PiPipelineProgrammable pipelineProg = device.as(PiPipelineProgrammable.class);
final DeviceHandshaker handshaker = device.as(DeviceHandshaker.class);
if (!handshaker.isConnected()) {
return false;
代码示例来源: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-apps-openstacknetworking-api
/**
* Returns tunnel destination extension treatment object.
*
* @param deviceService driver service
* @param deviceId device id to apply this treatment
* @param remoteIp tunnel destination ip address
* @return extension treatment
*/
public static ExtensionTreatment buildExtension(DeviceService deviceService,
DeviceId deviceId,
Ip4Address remoteIp) {
Device device = deviceService.getDevice(deviceId);
if (device != null && !device.is(ExtensionTreatmentResolver.class)) {
log.error("The extension treatment is not supported");
return null;
}
ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
try {
treatment.setPropertyValue(TUNNEL_DST, remoteIp);
return treatment;
} catch (ExtensionPropertyException e) {
log.warn("Failed to get tunnelDst extension treatment for {}", deviceId);
return null;
}
}
代码示例来源: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-common
/**
* Decodes a extension instruction.
*
* @return extension treatment
*/
private Instruction decodeExtension() {
ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION);
if (node != null) {
DeviceId deviceId = getDeviceId();
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);
ExtensionTreatment treatment = treatmentCodec.decode(node, context);
return Instructions.extension(treatment, deviceId);
} else {
throw new IllegalArgumentException(
"There is no codec to decode extension for device " + deviceId.toString());
}
}
return null;
}
代码示例来源: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-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-snmp-provider-device
DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class);
DeviceDescription description = descriptionDiscovery.discoverDeviceDetails();
deviceStore.createOrUpdateDevice(
代码示例来源: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();
}
}
内容来源于网络,如有侵权,请联系作者删除!