use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class PortQueryVlansCommand method printVlans.
private void printVlans(Port port) {
DeviceService deviceService = get(DeviceService.class);
DriverService driverService = get(DriverService.class);
DeviceId deviceId = (DeviceId) port.element().id();
Device device = deviceService.getDevice(deviceId);
if (!device.is(VlanQuery.class)) {
// The relevant behavior is not supported by the device.
print(NO_SUPPORT);
return;
}
DriverHandler h = driverService.createHandler(deviceId);
VlanQuery vlanQuery = h.behaviour(VlanQuery.class);
try {
Set<VlanId> vlanIds = vlanQuery.queryVlanIds(port.number());
if (vlanIds.isEmpty()) {
print(VLAN_NOT_AVAILABLE);
} else {
print(AVAIL_VLANS, getRanges(vlanIds).toString());
}
} catch (Exception e) {
print(FAILURE + e.getMessage());
}
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method addAttenuation.
/**
* Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics.
*
* @param flowEntry flow entry
* @param power power value
*/
private void addAttenuation(FlowEntry flowEntry, long power) {
FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder().withCookie(flowEntry.id().value()).withPriority(flowEntry.priority()).forDevice(flowEntry.deviceId()).forTable(flowEntry.tableId());
if (flowEntry.isPermanent()) {
flowBuilder.makePermanent();
} else {
flowBuilder.makeTemporary(flowEntry.timeout());
}
flowBuilder.withSelector(flowEntry.selector());
// Copy original instructions and add attenuation instruction
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins));
final DriverHandler handler = behaviour.handler();
treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId()));
flowBuilder.withTreatment(treatmentBuilder.build());
FlowRuleService service = handler.get(FlowRuleService.class);
service.applyFlowRules(flowBuilder.build());
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getOpenFlowDevice.
/**
* Returns current switch known to this OF controller.
*
* @return current switch
*/
private OpenFlowSwitch getOpenFlowDevice() {
final DriverHandler handler = behaviour.handler();
final OpenFlowController controller = handler.get(OpenFlowController.class);
final Dpid dpid = Dpid.dpid(handler.data().deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null || !sw.isConnected()) {
log.warn("OpenFlow handshaker driver not found or device is not connected, dpid = {}", dpid);
return null;
}
return sw;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getPortPower.
/**
* Find specified port power from port description.
*
* @param portNum the port number
* @param annotation annotation in port description
* @return power value in 0.01 dBm
*/
private Long getPortPower(PortNumber portNum, String annotation) {
// Check if switch is connected, otherwise do not return value in store, which is obsolete.
if (getOpenFlowDevice() == null) {
// Warning already exists in method getOpenFlowDevice()
return null;
}
final DriverHandler handler = behaviour.handler();
DeviceService deviceService = handler.get(DeviceService.class);
Port port = deviceService.getPort(handler.data().deviceId(), portNum);
if (port == null) {
log.warn("Unexpected port: {}", portNum);
return null;
}
String power = port.annotations().value(annotation);
if (power == null) {
// Do not need warning here for port polling.
log.debug("Cannot get {} from port {}.", annotation, portNum);
return null;
}
return Long.valueOf(power);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method setChannelAttenuation.
/**
* Sets specified channle attenuation.
*
* @param portNum the port number
* @param och channel signal
* @param power attenuation in 0.01 dB
*/
private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry == null) {
log.warn("Target channel power not set");
return;
}
final DriverHandler handler = behaviour.handler();
for (Instruction ins : flowEntry.treatment().allInstructions()) {
if (ins.type() != Instruction.Type.EXTENSION) {
continue;
}
ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
((OplinkAttenuation) ext).setAttenuation((int) power);
FlowRuleService service = handler.get(FlowRuleService.class);
service.applyFlowRules(flowEntry);
return;
}
}
addAttenuation(flowEntry, power);
}
Aggregations