use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackPortWebResource method updatePort.
/**
* Updates the port with the specified identifier.
*
* @param id port identifier
* @param input port JSON input stream
* @return 200 OK with the updated port, 400 BAD_REQUEST if the requested
* port does not exist
* @throws IOException exception
* @onos.rsModel NeutronPort
*/
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updatePort(@PathParam("id") String id, InputStream input) throws IOException {
log.trace(String.format(MESSAGE, "UPDATE " + id));
String inputStr = IOUtils.toString(input, REST_UTF8);
if (!haService.isActive() && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
return syncPut(haService, PORTS, id, inputStr);
}
final NeutronPort port = (NeutronPort) jsonToModelEntity(inputStr, NeutronPort.class);
adminService.updatePort(port);
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonNode = mapper.createObjectNode();
OpenstackNode node = nodeService.node(port.getHostId());
if (node == null) {
return status(Response.Status.OK).build();
} else if (node.datapathType().equals(DpdkConfig.DatapathType.NETDEV)) {
log.debug("UpdatePort for port {} called in netdev device {} " + "so sends vif type as a payload of the response", port.getId(), node.hostname());
jsonNode.put(VIF_TYPE, VHOSTUSER);
if (node.socketDir() != null) {
jsonNode.put(SOCKET_DIR, node.socketDir());
}
return status(Response.Status.OK).entity(jsonNode.toString()).build();
} else {
return status(Response.Status.OK).build();
}
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackConfigArpModeCommand method syncRules.
private void syncRules() {
// All handlers in this application reacts the node complete event and
// tries to re-configure flow rules for the complete node.
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
OpenstackNodeAdminService osNodeAdminService = get(OpenstackNodeAdminService.class);
if (osNodeService == null) {
error("Failed to re-install flow rules for OpenStack networking.");
return;
}
osNodeService.completeNodes().forEach(osNode -> {
OpenstackNode updated = osNode.updateState(NodeState.INIT);
osNodeAdminService.updateNode(updated);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackDetachedPortListCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNodeService nodeService = get(OpenstackNodeService.class);
OpenstackNetworkService networkService = get(OpenstackNetworkService.class);
DeviceService deviceService = get(DeviceService.class);
if (isAll) {
hostnames = nodeService.completeNodes().stream().map(OpenstackNode::hostname).toArray(String[]::new);
}
if (hostnames == null) {
print("Please specify one of hostname or --all options.");
return;
}
print(FORMAT, "Hostname", "Integration Bridge", "Detached Port");
for (String hostname : hostnames) {
networkService.ports().forEach(p -> {
if (hostname.equals(p.getHostId())) {
OpenstackNode osNode = nodeService.node(p.getHostId());
if (osNode != null) {
Set<String> detachedPortNames = detachedOvsPort(p, deviceService.getPorts(osNode.intgBridge()));
detachedPortNames.forEach(dp -> print(FORMAT, hostname, osNode.intgBridge().toString(), dp));
}
}
});
}
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackDirectPortAddCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
DeviceService deviceService = get(DeviceService.class);
Port port = osNetService.port(portId);
if (port == null) {
log.error("There's no port that matches the port ID {}", portId);
return;
}
Optional<OpenstackNode> osNode = osNodeService.completeNodes(COMPUTE).stream().filter(node -> node.hostname().equals(port.getHostId())).findAny();
if (!osNode.isPresent()) {
log.error("There's no openstackNode that matches hostname {}", port.getHostId());
return;
}
String intfName = getIntfNameFromPciAddress(port);
if (intfName == null) {
log.error("Failed to retrieve interface name from a port {}", portId);
return;
} else if (intfName.equals(UNSUPPORTED_VENDOR)) {
return;
}
if (OpenstackNetworkingUtil.hasIntfAleadyInDevice(osNode.get().intgBridge(), intfName, deviceService)) {
log.error("Interface {} is already added to the device {}", osNode.get().intgBridge());
return;
}
log.info("Adding interface {} to the device {}..", intfName, osNode.get().intgBridge());
osNodeService.addVfPort(osNode.get(), intfName);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackFlowTraceCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNodeAdminService osNodeService = get(OpenstackNodeAdminService.class);
InstancePortAdminService instancePortService = get(InstancePortAdminService.class);
OpenstackNetworkAdminService osNetService = get(OpenstackNetworkAdminService.class);
Optional<InstancePort> srcInstance = instancePortService.instancePorts().stream().filter(port -> port.ipAddress().toString().equals(srcIp)).findAny();
if (!srcInstance.isPresent()) {
print(NO_ELEMENT);
return;
}
OpenstackNode srcNode = osNodeService.node(srcInstance.get().deviceId());
if (srcNode == null || srcNode.sshAuthInfo() == null) {
log.error("Openstack node {} is null or has no SSH authentication information.\n" + " Please refers to the sample network-cfg.json in " + "OpenstackNode app to push SSH authentication information", srcNode == null ? "" : srcNode.hostname());
return;
}
if (dstIp.equals(osNetService.gatewayIp(srcInstance.get().portId()))) {
dstIp = srcIp;
}
// print uplink flow trace result
String requestStringUplink = traceRequestString(srcIp, dstIp, srcInstance.get(), osNetService, true);
print(FLOW_TRACE_REQUEST_STRING_UPLINK + requestStringUplink);
String requestStringDownlink = traceRequestString(srcIp, dstIp, srcInstance.get(), osNetService, false);
print(FLOW_TRACE_REQUEST_STRING_DOWNLINK + requestStringDownlink);
String traceResult = sendTraceRequestToNode(requestStringUplink + '\n' + requestStringDownlink, srcNode);
print(traceResult);
}
Aggregations