Search in sources :

Example 56 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNorthSouthProbeCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
    InstancePortService instPortService = get(InstancePortService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    MastershipService mastershipService = get(MastershipService.class);
    ClusterService clusterService = get(ClusterService.class);
    if (tsService == null || osNodeService == null || instPortService == null || mastershipService == null) {
        error("Failed to troubleshoot openstack networking.");
        return;
    }
    if ((!isAll && vmIps == null) || (isAll && vmIps != null)) {
        print("Please specify one of VM IP address or -a option.");
        return;
    }
    NodeId localNodeId = clusterService.getLocalNode().id();
    for (OpenstackNode gw : osNodeService.completeNodes(GATEWAY)) {
        if (!localNodeId.equals(mastershipService.getMasterFor(gw.intgBridge()))) {
            error("Current node is not the master for all gateway nodes. " + "Please enforce mastership first using openstack-reset-mastership -c !");
            return;
        }
    }
    if (isAll) {
        printHeader();
        // send ICMP PACKET_OUT to all connect VMs whose instance port state is ACTIVE
        instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).filter(p -> instPortService.floatingIp(p.portId()) != null).forEach(port -> printReachability(tsService.probeNorthSouth(port)));
    } else {
        final Set<InstancePort> ports = Sets.newConcurrentHashSet();
        for (String ip : vmIps) {
            instPortService.instancePorts().stream().filter(p -> p.state().equals(InstancePort.State.ACTIVE)).filter(p -> instPortService.floatingIp(p.portId()) != null).filter(p -> ip.equals(instPortService.floatingIp(p.portId()).toString())).forEach(ports::add);
        }
        printHeader();
        ports.forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeNorthSouth(port))));
    }
}
Also used : NodeId(org.onosproject.cluster.NodeId) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Sets(com.google.common.collect.Sets) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Reachability(org.onosproject.openstacktroubleshoot.api.Reachability) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) ClusterService(org.onosproject.cluster.ClusterService) Option(org.apache.karaf.shell.api.action.Option) MastershipService(org.onosproject.mastership.MastershipService) ExecutorService(java.util.concurrent.ExecutorService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ClusterService(org.onosproject.cluster.ClusterService) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 57 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 58 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 59 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 60 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