Search in sources :

Example 26 with InstancePort

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

the class OpenstackResetPortsCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortAdminService service = get(InstancePortAdminService.class);
    if ((!isAll && !isInactive && portIds == null) || (isAll && isInactive) || (isInactive && portIds != null) || (portIds != null && isAll)) {
        print("Please specify one of portIds, --all, and --inactive 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);
    }
    for (String portId : portIds) {
        resetPort(service, portId);
        print("Successfully requested re-installing flow rules for port %s!", portId);
    }
    print("Done.");
}
Also used : InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Example 27 with InstancePort

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

the class InstancePortCodecTest method testInstancePortEncode.

/**
 * Tests the instance port encoding.
 */
@Test
public void testInstancePortEncode() {
    InstancePort port = DefaultInstancePort.builder().networkId("net-id-1").portId("port-id-1").deviceId(DeviceId.deviceId("of:000000000000000a")).portNumber(PortNumber.portNumber(1, "tap-1")).ipAddress(IpAddress.valueOf("10.10.10.1")).macAddress(MacAddress.valueOf("11:22:33:44:55:66")).state(InstancePort.State.valueOf("ACTIVE")).build();
    ObjectNode portJson = instancePortCodec.encode(port, context);
    assertThat(portJson, matchesInstancePort(port));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DefaultInstancePort(org.onosproject.openstacknetworking.impl.DefaultInstancePort) InstancePortJsonMatcher.matchesInstancePort(org.onosproject.openstacknetworking.codec.InstancePortJsonMatcher.matchesInstancePort) Test(org.junit.Test)

Example 28 with InstancePort

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

the class InstancePortCodecTest method getInstancePort.

/**
 * Reads in an instance port from the given resource and decodes it.
 *
 * @param resourceName resource to use to read the JSON for the rule
 * @return decoded instance port
 * @throws IOException if processing the resource fails
 */
private InstancePort getInstancePort(String resourceName) throws IOException {
    InputStream jsonStream = InstancePortCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    InstancePort port = instancePortCodec.decode((ObjectNode) json, context);
    assertThat(port, notNullValue());
    return port;
}
Also used : InputStream(java.io.InputStream) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DefaultInstancePort(org.onosproject.openstacknetworking.impl.DefaultInstancePort) InstancePortJsonMatcher.matchesInstancePort(org.onosproject.openstacknetworking.codec.InstancePortJsonMatcher.matchesInstancePort) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 29 with InstancePort

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

the class InstancePortManagerTest method testMigrateInstanceEnd.

/**
 * Tests if it triggers the instance migration end event.
 */
@Test
public void testMigrateInstanceEnd() {
    InstancePort instancePort = instancePort1;
    InstancePort migratingPort = instancePort.updateState(MIGRATING);
    target.createInstancePort(migratingPort);
    InstancePort migratedPort = instancePort.updateState(MIGRATED);
    target.updateInstancePort(migratedPort);
    assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
    assertNotNull("Instance port did not match", target.instancePort(PORT_ID_1));
    validateEvents(OPENSTACK_INSTANCE_PORT_DETECTED, OPENSTACK_INSTANCE_MIGRATION_ENDED);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Test(org.junit.Test)

Example 30 with InstancePort

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

the class InstancePortManagerTest method testRestartInstance.

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

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