本文整理汇总了Java中org.onosproject.protocol.rest.RestSBController类的典型用法代码示例。如果您正苦于以下问题:Java RestSBController类的具体用法?Java RestSBController怎么用?Java RestSBController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestSBController类属于org.onosproject.protocol.rest包,在下文中一共展示了RestSBController类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discoverPortStatistics
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
@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);
}
示例2: discoverSpecifiedPortStatistics
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
private PortStatistics discoverSpecifiedPortStatistics(Port port,
RestSBController controller,
DeviceId deviceId) {
String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
ArrayList<String> cmd = Lists.newArrayList();
cmd.add(String.format(WHITE_SPACE_FORMAT, SHOW_INTERFACE_CMD, portName));
String request = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
String response = NxApiRequest.post(controller, deviceId, request);
return buildStatisticsFromResponse(response, port.number(), deviceId);
}
示例3: post
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
/**
* Sends NX-API request message to the device.
* @param controller RestSBController for Cisco REST device
* @param deviceId DeviceId for Cisco REST device
* @param request NX-API request string
* @return the response string
*/
public static String post(RestSBController controller, DeviceId deviceId, String request) {
InputStream stream = new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8));
String response = controller.post(deviceId, API_URI, stream,
MediaType.valueOf(APP_JSON_RPC), String.class);
return response;
}
示例4: discoverDeviceDetails
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
@Override
public DeviceDescription discoverDeviceDetails() {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
ArrayList<String> cmd = new ArrayList<>();
cmd.add(SHOW_VERSION_CMD);
String req = NxApiRequest.generate(cmd, NxApiRequest.CommandType.CLI);
String response = NxApiRequest.post(controller, deviceId, req);
String mrf = UNKNOWN;
String hwVer = UNKNOWN;
String swVer = UNKNOWN;
String serialNum = UNKNOWN;
try {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(response);
JsonNode body = json.findValue("body");
if (body != null) {
mrf = body.get(MANUFACTURER).asText();
hwVer = body.get(CHASSIS_ID).asText();
swVer = body.get(KICKSTART_VER).asText();
}
} catch (IOException e) {
log.error("Failed to to retrieve Device Information {}", e);
}
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
Device device = deviceService.getDevice(deviceId);
return new DefaultDeviceDescription(device.id().uri(), Device.Type.SWITCH,
mrf, hwVer, swVer, serialNum,
new ChassisId(), (SparseAnnotations) device.annotations());
}
示例5: discoverPortDetails
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
@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);
long portSpeed = itf.get(ETH_BW).asLong() / ONE_THOUSAND; //in Mbps
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
.set(AnnotationKeys.PORT_NAME, ifName);
PortDescription desc = new DefaultPortDescription(PortNumber.portNumber(ifNum), state,
Port.Type.FIBER, portSpeed, annotations.build());
ports.add(desc);
}
});
}
} catch (IOException e) {
log.error("Failed to to retrieve Interfaces {}", e);
}
return ports;
}
示例6: getPorts
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
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, XML));
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);
}
示例7: CienaRestDevice
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
public CienaRestDevice(DriverHandler handler) throws NullPointerException {
deviceId = handler.data().deviceId();
controller = checkNotNull(handler.get(RestSBController.class));
crossConnectCache = checkNotNull(handler.get(CrossConnectCache.class));
deviceService = checkNotNull(handler.get(DeviceService.class));
}
示例8: discoverPortDetails
import org.onosproject.protocol.rest.RestSBController; //导入依赖的package包/类
@Override
public List<PortDescription> discoverPortDetails() {
List<PortDescription> ports = Lists.newArrayList();
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
ObjectMapper mapper = new ObjectMapper();
ObjectNode sendObjNode = mapper.createObjectNode();
sendObjNode.put(JSONRPC, TWO_POINT_ZERO)
.put(METHOD, RUN_CMDS)
.put(ID, GET_PORT)
.putObject(PARAMS)
.put(FORMAT, JSON)
.put(TIMESTAMPS, false)
.put(VERSION, 1)
.putArray(CMDS).add(SHOW_INTERFACES_STATUS);
String response = controller.post(deviceId, API_ENDPOINT,
new ByteArrayInputStream(sendObjNode.toString().getBytes()),
MediaType.APPLICATION_JSON_TYPE, String.class);
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode arrayNode = (ArrayNode) node.get(RESULT);
JsonNode jsonNode = arrayNode.iterator().next().get(INTERFACE_STATUSES);
jsonNode.fieldNames().forEachRemaining(name -> {
JsonNode interfaceNode = jsonNode.get(name);
Long bandwidth = interfaceNode.path(BANDWIDTH).asLong() / MBPS;
SparseAnnotations annotations = DefaultAnnotations.builder()
.set(AnnotationKeys.BANDWIDTH, bandwidth.toString())
.set(AnnotationKeys.NAME, name)
.set(LINK_STATUS, interfaceNode.path(LINK_STATUS).asText())
.set(LINE_PROTOCOL_STATUS, interfaceNode.path(LINE_PROTOCOL_STATUS).asText())
.set(INTERFACE_TYPE, interfaceNode.path(INTERFACE_TYPE).asText())
.build();
PortDescription portDescription = new DefaultPortDescription(PortNumber
.portNumber(getPortNumber(name)),
true, Port.Type.FIBER, bandwidth, annotations);
ports.add(portDescription);
});
} catch (IOException e) {
log.warn("IO exception occurred because of ", e);
}
return ports;
}