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);
}
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);
}
});
}
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.");
}
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());
}
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))));
}
}
Aggregations