本文整理汇总了Java中org.onosproject.net.Device.as方法的典型用法代码示例。如果您正苦于以下问题:Java Device.as方法的具体用法?Java Device.as怎么用?Java Device.as使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.net.Device
的用法示例。
在下文中一共展示了Device.as方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDeviceDescription
import org.onosproject.net.Device; //导入方法依赖的package包/类
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();
}
}
示例2: updatePortsAndStats
import org.onosproject.net.Device; //导入方法依赖的package包/类
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());
}
}
示例3: encodeExtension
import org.onosproject.net.Device; //导入方法依赖的package包/类
/**
* 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.is(ExtensionTreatmentCodec.class)) {
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
result.set(InstructionCodec.EXTENSION, node);
} else {
log.warn("There is no codec to encode extension for device {}", deviceId.toString());
}
}
示例4: decodeExtension
import org.onosproject.net.Device; //导入方法依赖的package包/类
/**
* 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.is(ExtensionTreatmentCodec.class)) {
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ExtensionTreatment treatment = treatmentCodec.decode(node, null);
return Instructions.extension(treatment, deviceId);
} else {
log.warn("There is no codec to decode extension for device {}", deviceId.toString());
}
}
return null;
}
示例5: discoverPorts
import org.onosproject.net.Device; //导入方法依赖的package包/类
private void discoverPorts(DeviceId deviceId) {
Device device = deviceService.getDevice(deviceId);
if (device.is(PortDiscovery.class)) {
PortDiscovery portConfig = device.as(PortDiscovery.class);
providerService.updatePorts(deviceId,
portConfig.getPorts());
} else {
log.warn("No portGetter behaviour for device {}", deviceId);
}
}
示例6: emit
import org.onosproject.net.Device; //导入方法依赖的package包/类
@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);
}
}
}
示例7: getFlowRuleProgrammable
import org.onosproject.net.Device; //导入方法依赖的package包/类
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;
}
}
示例8: getGroupProgrammable
import org.onosproject.net.Device; //导入方法依赖的package包/类
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;
}
}
示例9: getPacketProgrammable
import org.onosproject.net.Device; //导入方法依赖的package包/类
private PacketProgrammable getPacketProgrammable(DeviceId deviceId) {
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;
}
}
示例10: advertiseDevices
import org.onosproject.net.Device; //导入方法依赖的package包/类
/**
* Initialize SNMP Device object, and notify core saying device connected.
*/
private void advertiseDevices() {
try {
if (device == null) {
log.warn("The Request SNMP Device is null, cannot proceed further");
return;
}
DeviceId did = device.deviceId();
ChassisId cid = new ChassisId();
SparseAnnotations annotations = DefaultAnnotations.builder()
.set(AnnotationKeys.PROTOCOL, SCHEME.toUpperCase())
.build();
DeviceDescription desc = new DefaultDeviceDescription(
did.uri(), Device.Type.OTHER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations);
log.debug("Persisting Device " + did.uri().toString());
controller.addDevice(did, device);
providerService.deviceConnected(did, desc);
log.info("Added device to ONOS core. Device Info: "
+ device.deviceInfo() + " " + did.uri().toString());
//FIXME this description will be populated only if driver is pushed from outside
// becuase otherwise default driver is used
Device d = deviceService.getDevice(did);
if (d.is(DeviceDescriptionDiscovery.class)) {
DeviceDescriptionDiscovery descriptionDiscovery = d.as(DeviceDescriptionDiscovery.class);
DeviceDescription description = descriptionDiscovery.discoverDeviceDetails();
deviceStore.createOrUpdateDevice(
new ProviderId("snmp", "org.onosproject.provider.device"),
did, description);
providerService.updatePorts(did, descriptionDiscovery.discoverPortDetails());
} else {
log.warn("No populate description and ports behaviour for device {}", did);
}
} catch (Exception e) {
log.error("Error while initializing session for the device: "
+ (device != null ? device.deviceInfo() : null), e);
}
}