use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class CiscoNxosDeviceDescription method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
ArrayList<String> cmd = new ArrayList<>();
cmd.add(SHOW_INTERFACES_CMD);
String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
String response = NxApiRequest.post(controller, deviceId, req);
// parse interface information from response
List<PortDescription> ports = Lists.newArrayList();
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
JsonNode interfaces = json.findValue(ROW_INTERFACE);
if (interfaces != null) {
interfaces.forEach(itf -> {
String ifName = itf.get(INTERFACE).asText();
if (ifName.startsWith(ETH)) {
String ifNum = ifName.substring(ETHERNET.length()).replace(SLASH, ZERO);
boolean state = itf.get(STATE).asText().equals(UP);
// in Mbps
long portSpeed = itf.get(ETH_BW).asLong() / ONE_THOUSAND;
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, ifName);
PortDescription desc = DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(ifNum)).isEnabled(state).type(Port.Type.FIBER).portSpeed(portSpeed).annotations(annotations.build()).build();
ports.add(desc);
}
});
}
} catch (IOException e) {
log.error("Failed to to retrieve Interfaces {}", e);
}
return ports;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class CiscoNxosPortStatistics method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Collection<PortStatistics> portStatistics = Lists.newArrayList();
ports.stream().filter(Port::isEnabled).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(port, controller, deviceId)));
return ImmutableList.copyOf(portStatistics);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class LinkDiscoveryCiscoImpl method retrieveResponse.
private String retrieveResponse(String command) {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
String req = NxApiRequest.generate(Lists.newArrayList(command), NxApiRequest.CommandType.CLI);
log.debug("request :" + req);
InputStream stream = new ByteArrayInputStream(req.getBytes(StandardCharsets.UTF_8));
return controller.post(deviceId, "/ins", stream, MediaType.valueOf("application/json-rpc"), String.class);
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method findFlow.
/**
* Find matching flow on device.
*
* @param portNum the port number
* @param och channel signal
* @return flow entry
*/
private FlowEntry findFlow(PortNumber portNum, OchSignal och) {
final DriverHandler handler = behaviour.handler();
FlowRuleService service = handler.get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = service.getFlowEntries(handler.data().deviceId());
// Return first matching flow
for (FlowEntry entry : flowEntries) {
TrafficSelector selector = entry.selector();
OchSignalCriterion entrySigid = (OchSignalCriterion) selector.getCriterion(Criterion.Type.OCH_SIGID);
// Check channel
if (entrySigid != null && och.equals(entrySigid.lambda())) {
// Check input port
PortCriterion entryPort = (PortCriterion) selector.getCriterion(Criterion.Type.IN_PORT);
if (entryPort != null && portNum.equals(entryPort.port())) {
return entry;
}
// Check output port
TrafficTreatment treatment = entry.treatment();
for (Instruction instruction : treatment.allInstructions()) {
if (instruction.type() == Instruction.Type.OUTPUT && ((Instructions.OutputInstruction) instruction).port().equals(portNum)) {
return entry;
}
}
}
}
log.warn("No matching flow found");
return null;
}
use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.
the class OvsdbBridgeConfig method getLocalPorts.
@Override
public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) {
List<PortNumber> ports = new ArrayList<>();
DriverHandler handler = handler();
OvsdbClientService client = getOvsdbClientService(handler);
if (client == null) {
return Collections.emptyList();
}
Set<OvsdbPort> ovsdbSet = client.getLocalPorts(ifaceIds);
ovsdbSet.forEach(o -> {
PortNumber port = PortNumber.portNumber(o.portNumber().value(), o.portName().value());
ports.add(port);
});
return ports;
}
Aggregations