Search in sources :

Example 31 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class InstancePortManagerTest method testRemoveInstanceFromTermination.

/**
 * Tests if it triggers the instance removal event from termination status.
 */
@Test
public void testRemoveInstanceFromTermination() {
    InstancePort instancePort = instancePort1;
    target.createInstancePort(instancePort);
    InstancePort inactiveInstancePort = instancePort.updateState(INACTIVE);
    target.updateInstancePort(inactiveInstancePort);
    assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
    assertNotNull("Instance port did not match", target.instancePort(PORT_ID_1));
    target.removeInstancePort(PORT_ID_1);
    assertEquals("Number of instance port did not match", 0, target.instancePorts().size());
    assertNull("Instance port did not match", target.instancePort(PORT_ID_1));
    validateEvents(OPENSTACK_INSTANCE_PORT_DETECTED, OPENSTACK_INSTANCE_TERMINATED, OPENSTACK_INSTANCE_PORT_VANISHED);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Test(org.junit.Test)

Example 32 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackVmStatsCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    InstancePortService osInstanceService = get(InstancePortService.class);
    DeviceService deviceService = get(DeviceService.class);
    Set<Port> ports = osNetService.ports().stream().filter(port -> port.getDeviceId().equals(vmDeviceId)).collect(Collectors.toSet());
    if (ports.isEmpty()) {
        print(NO_PORTS);
        return;
    }
    Set<InstancePort> instancePorts = getInstancePortFromNeutronPortList(ports, osInstanceService);
    if (instancePorts.isEmpty()) {
        print(NO_INSTANCE_PORTS);
        return;
    }
    Set<PortNumber> portNumbers = instancePorts.stream().map(InstancePort::portNumber).collect(Collectors.toSet());
    instancePorts.stream().findAny().ifPresent(instancePort -> {
        DeviceId deviceId = instancePort.deviceId();
        if (delta) {
            printPortStatsDelta(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            if (table) {
                printPortStatsDeltaTable(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            }
        } else {
            printPortStats(vmDeviceId, deviceService.getPortStatistics(deviceId), portNumbers);
        }
    });
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Command(org.apache.karaf.shell.api.action.Command) TimeUnit(java.util.concurrent.TimeUnit) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Comparator(java.util.Comparator) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) Port(org.openstack4j.model.network.Port) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) DeviceId(org.onosproject.net.DeviceId) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber)

Example 33 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class PurgeInstancePortsCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortAdminService service = get(InstancePortAdminService.class);
    if ((!isAll && !isInactive && !isPending && portIds == null) || (isAll && isInactive && isPending) || (isInactive && isPending && portIds != null) || (portIds != null && isAll && isPending) || (isAll && isInactive && portIds != null)) {
        print("Please specify one of portIds, --all or --inactive or --pending options.");
        return;
    }
    if (isAll) {
        portIds = service.instancePorts().stream().map(InstancePort::portId).toArray(String[]::new);
    } else if (isInactive) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == INACTIVE).map(InstancePort::portId).toArray(String[]::new);
    } else if (isPending) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == REMOVE_PENDING).map(InstancePort::portId).toArray(String[]::new);
    }
    for (String portId : portIds) {
        service.removeInstancePort(portId);
        print("Instance port %s has been removed!", portId);
    }
    print("Done.");
}
Also used : AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) REMOVE_PENDING(org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Service(org.apache.karaf.shell.api.action.lifecycle.Service) INACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.INACTIVE) Argument(org.apache.karaf.shell.api.action.Argument) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) Command(org.apache.karaf.shell.api.action.Command) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Example 34 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackNetworkingUtilTest method testSwapStaleLocation.

/**
 * Tests swapStaleLocation method.
 */
@Test
public void testSwapStaleLocation() {
    InstancePort swappedInstancePort = swapStaleLocation(instancePort3);
    assertEquals(instancePort3.oldDeviceId(), swappedInstancePort.deviceId());
    assertEquals(instancePort3.oldPortNumber(), swappedInstancePort.portNumber());
}
Also used : OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DefaultInstancePort(org.onosproject.openstacknetworking.impl.DefaultInstancePort) OpenstackNodeTest(org.onosproject.openstacknode.api.OpenstackNodeTest) Test(org.junit.Test) OpenstackFloatingIpWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackFloatingIpWebResourceTest) OpenstackNetworkWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackNetworkWebResourceTest)

Example 35 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackEastWestProbeCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
    InstancePortService instPortService = get(InstancePortService.class);
    MastershipService mastershipService = get(MastershipService.class);
    ClusterService clusterService = get(ClusterService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    if (tsService == 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 node : osNodeService.completeNodes(COMPUTE)) {
        if (!localNodeId.equals(mastershipService.getMasterFor(node.intgBridge()))) {
            error("Current node is not the master for all compute 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
        Set<InstancePort> activePorts = instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).collect(Collectors.toSet());
        activePorts.forEach(srcPort -> activePorts.forEach(dstPort -> printReachability(tsService.probeEastWest(srcPort, dstPort))));
    } else {
        if (vmIps.length > 2) {
            print("Too many VM IPs. The number of IP should be limited to 2.");
            return;
        }
        IpAddress srcIp = getIpAddress(vmIps[0]);
        if (srcIp == null) {
            return;
        }
        InstancePort srcPort = instPort(instPortService, srcIp);
        if (srcPort == null) {
            print("Specified source IP is not existing.");
            return;
        }
        final Set<IpAddress> dstIps = Sets.newConcurrentHashSet();
        if (vmIps.length == 2) {
            IpAddress dstIp = getIpAddress(vmIps[1]);
            if (dstIp == null) {
                return;
            }
            dstIps.add(dstIp);
        }
        if (vmIps.length == 1) {
            dstIps.addAll(instPortService.instancePorts().stream().filter(p -> !p.ipAddress().equals(srcIp)).filter(p -> p.state().equals(InstancePort.State.ACTIVE)).map(InstancePort::ipAddress).collect(Collectors.toSet()));
        }
        printHeader();
        dstIps.stream().filter(ip -> instPort(instPortService, ip) != null).map(ip -> instPort(instPortService, ip)).forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeEastWest(srcPort, port))));
    }
}
Also used : OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Command(org.apache.karaf.shell.api.action.Command) OpenstackTroubleshootService(org.onosproject.openstacktroubleshoot.api.OpenstackTroubleshootService) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) MastershipService(org.onosproject.mastership.MastershipService) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Reachability(org.onosproject.openstacktroubleshoot.api.Reachability) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) ClusterService(org.onosproject.cluster.ClusterService) Option(org.apache.karaf.shell.api.action.Option) 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) IpAddress(org.onlab.packet.IpAddress) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Aggregations

InstancePort (org.onosproject.openstacknetworking.api.InstancePort)36 Test (org.junit.Test)13 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)10 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 InstancePortService (org.onosproject.openstacknetworking.api.InstancePortService)9 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)9 Set (java.util.Set)7 Argument (org.apache.karaf.shell.api.action.Argument)7 Command (org.apache.karaf.shell.api.action.Command)7 Service (org.apache.karaf.shell.api.action.lifecycle.Service)7 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)7 PortNumber (org.onosproject.net.PortNumber)7 Port (org.openstack4j.model.network.Port)7 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)6 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)6