Search in sources :

Example 41 with OpenstackNode

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();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 42 with OpenstackNode

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);
    });
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 43 with OpenstackNode

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));
                }
            }
        });
    }
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) DeviceService(org.onosproject.net.device.DeviceService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 44 with OpenstackNode

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);
}
Also used : UNSUPPORTED_VENDOR(org.onosproject.openstacknetworking.api.Constants.UNSUPPORTED_VENDOR) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) OpenstackNetworkingUtil(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil) DeviceService(org.onosproject.net.device.DeviceService) Argument(org.apache.karaf.shell.api.action.Argument) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) Port(org.openstack4j.model.network.Port) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Port(org.openstack4j.model.network.Port) DeviceService(org.onosproject.net.device.DeviceService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 45 with OpenstackNode

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);
}
Also used : OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Argument(org.apache.karaf.shell.api.action.Argument) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) OpenstackNetworkingUtil.traceRequestString(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.traceRequestString) OpenstackNetworkingUtil.sendTraceRequestToNode(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.sendTraceRequestToNode) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackNetworkingUtil.traceRequestString(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.traceRequestString) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)

Aggregations

OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)76 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)22 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)19 PortNumber (org.onosproject.net.PortNumber)14 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)14 DeviceService (org.onosproject.net.device.DeviceService)13 Set (java.util.Set)12 Test (org.junit.Test)12 IpAddress (org.onlab.packet.IpAddress)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Objects (java.util.Objects)9 Optional (java.util.Optional)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)9 Produces (javax.ws.rs.Produces)8 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)7