use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class AristaUtils method getWithChecking.
public static boolean getWithChecking(DriverHandler handler, List<String> commands) {
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = checkNotNull(handler.data()).deviceId();
String response = generate(commands);
log.debug("request :{}", response);
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
JsonNode errNode = json.findPath(ERROR);
if (errNode.isMissingNode()) {
return true;
}
log.error("Error get with checking {}", errNode.asText(""));
for (String str : commands) {
log.error("Command Failed due to Cmd : {}", str);
}
return false;
} catch (IOException e) {
log.error("IO exception occured because of ", e);
return false;
}
}
use of org.onosproject.protocol.rest.RestSBController in project onos by opennetworkinglab.
the class CienaWaveserverDeviceDescription method getPorts.
private List<PortDescription> getPorts() {
/*
* Relationship between ptp-index and port number shown in Ciena Wave Server
* CLI:
* ptp-index = 4 * port_number (without decimal) + decimal
* e.g
* if port_number is 5 then ptp-index = 5 * 4 + 0 = 20
* if port_number is 5.1 then ptp-index = 5 * 4 + 1 = 21
*
* Relationship between channelId and in/out port:
* in_port = channelId * 2
* out_port = channelId * 2 -1
*/
List<PortDescription> ports = Lists.newArrayList();
RestSBController controller = checkNotNull(handler().get(RestSBController.class));
DeviceId deviceId = handler().data().deviceId();
HierarchicalConfiguration config = XmlConfigParser.loadXml(controller.get(deviceId, PORT_REQUEST, MediaType.APPLICATION_XML_TYPE));
List<HierarchicalConfiguration> portsConfig = parseWaveServerCienaPorts(config);
portsConfig.forEach(sub -> {
String portId = sub.getString(PORT_ID);
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
if (CienaRestDevice.getLinesidePortId().contains(portId)) {
annotations.set(AnnotationKeys.CHANNEL_ID, sub.getString(CHANNEL_ID));
// TX/OUT and RX/IN ports
annotations.set(AnnotationKeys.PORT_OUT, sub.getString(PORT_OUT));
annotations.set(AnnotationKeys.PORT_IN, sub.getString(PORT_IN));
ports.add(parseWaveServerCienaOchPorts(Long.valueOf(portId), sub, annotations.build()));
} else if (!portId.equals("5") && !portId.equals("49")) {
DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portId);
// FIXME change when all optical types have two way information methods, see jira tickets
ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), sub.getString(ADMIN_STATE).equals(ENABLED), CltSignalType.CLT_100GBE, annotations.build()));
}
});
return ImmutableList.copyOf(ports);
}
use of org.onosproject.protocol.rest.RestSBController 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.protocol.rest.RestSBController 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.protocol.rest.RestSBController 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;
}
Aggregations