Search in sources :

Example 6 with OpenstackVtap

use of org.onosproject.openstackvtap.api.OpenstackVtap in project onos by opennetworkinglab.

the class OpenstackVtapWebResource method createVtap.

/**
 * Creates an openstack vTap from the JSON input stream.
 *
 * @param input openstack vtap JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is invalid or duplicated vtap already exists
 *
 * @onos.rsModel OpenstackVtap
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVtap(InputStream input) {
    log.trace(String.format(MESSAGE_VTAP, CREATE));
    OpenstackVtap vtap = readAndCreateVtap(input);
    UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(VTAP).path(vtap.id().toString());
    return created(locationBuilder.build()).build();
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with OpenstackVtap

use of org.onosproject.openstackvtap.api.OpenstackVtap in project onos by opennetworkinglab.

the class OpenstackVtapManagerTest method testCreateAndRemoveVtap.

/**
 * Checks if creating and removing a openstack vtap work well with proper events.
 */
@Test
public void testCreateAndRemoveVtap() {
    OpenstackVtap vtap = target.createVtap(VTAP_TYPE_1, VTAP_CRITERION_1);
    assertEquals(ERR_SIZE, 2, target.getVtapCount(OpenstackVtap.Type.VTAP_ANY));
    assertNotNull(target.getVtap(vtap.id()));
    target.removeVtap(vtap.id());
    assertEquals(ERR_SIZE, 1, target.getVtapCount(OpenstackVtap.Type.VTAP_ANY));
    assertNull(target.getVtap(vtap.id()));
    validateEvents(VTAP_ADDED, VTAP_REMOVED);
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) Test(org.junit.Test)

Example 8 with OpenstackVtap

use of org.onosproject.openstackvtap.api.OpenstackVtap in project onos by opennetworkinglab.

the class OpenstackVtapManagerTest method testUpdateVtap.

/**
 * Checks if updating a openstack vtap works well with proper event.
 */
@Test
public void testUpdateVtap() {
    OpenstackVtap updated = DefaultOpenstackVtap.builder(VTAP_2).vtapCriterion(VTAP_CRITERION_1).build();
    target.updateVtap(updated);
    assertEquals(ERR_NOT_MATCH, updated.vtapCriterion(), target.getVtap(VTAP_ID_2).vtapCriterion());
    updated = DefaultOpenstackVtap.builder(VTAP_2).build();
    target.updateVtap(updated);
    validateEvents(VTAP_UPDATED, VTAP_UPDATED);
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) Test(org.junit.Test)

Example 9 with OpenstackVtap

use of org.onosproject.openstackvtap.api.OpenstackVtap in project onos by opennetworkinglab.

the class DefaultOpenstackVtapTest method testConstruction.

/**
 * Tests object construction.
 */
@Test
public void testConstruction() {
    OpenstackVtap vtap = vtap1;
    assertThat(vtap.id(), is(VTAP_ID_1));
    assertThat(vtap.vtapCriterion(), is(CRITERION_1));
    assertThat(vtap.type(), is(VTAP_TYPE_1));
    assertThat(vtap.txDeviceIds(), is(TX_DEVICE_IDS_1));
    assertThat(vtap.rxDeviceIds(), is(RX_DEVICE_IDS_1));
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) Test(org.junit.Test)

Example 10 with OpenstackVtap

use of org.onosproject.openstackvtap.api.OpenstackVtap in project onos by opennetworkinglab.

the class DistributedOpenstackVtapStore method addDeviceToVtap.

@Override
public boolean addDeviceToVtap(OpenstackVtapId vtapId, Type type, DeviceId deviceId) {
    OpenstackVtap result = vtapMap.compute(vtapId, (id, existing) -> {
        if (existing == null) {
            return null;
        }
        // Check type validate
        if (!existing.type().isValid(type)) {
            log.error("Not valid OpenstackVtap type {} for requested type {}", existing.type(), type);
            return existing;
        }
        // Add deviceId to txDeviceIds
        final Set<DeviceId> txDeviceIds;
        if (existing.type().isValid(Type.VTAP_TX) && (type.isValid(Type.VTAP_TX) || type == Type.VTAP_ANY) && !existing.txDeviceIds().contains(deviceId)) {
            txDeviceIds = Sets.newHashSet(existing.txDeviceIds());
            txDeviceIds.add(deviceId);
        } else {
            txDeviceIds = null;
        }
        // Add deviceId to rxDeviceIds
        final Set<DeviceId> rxDeviceIds;
        if (existing.type().isValid(Type.VTAP_RX) && (type.isValid(Type.VTAP_RX) || type == Type.VTAP_ANY) && !existing.rxDeviceIds().contains(deviceId)) {
            rxDeviceIds = Sets.newHashSet(existing.rxDeviceIds());
            rxDeviceIds.add(deviceId);
        } else {
            rxDeviceIds = null;
        }
        if (txDeviceIds != null || rxDeviceIds != null) {
            return DefaultOpenstackVtap.builder().id(id).type(existing.type()).vtapCriterion(existing.vtapCriterion()).txDeviceIds(txDeviceIds != null ? txDeviceIds : existing.txDeviceIds()).rxDeviceIds(rxDeviceIds != null ? rxDeviceIds : existing.rxDeviceIds()).annotations(existing.annotations()).build();
        } else {
            return existing;
        }
    });
    return Objects.nonNull(result);
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) DeviceId(org.onosproject.net.DeviceId)

Aggregations

OpenstackVtap (org.onosproject.openstackvtap.api.OpenstackVtap)11 Test (org.junit.Test)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Produces (javax.ws.rs.Produces)2 DeviceId (org.onosproject.net.DeviceId)2 OpenstackVtapCriterion (org.onosproject.openstackvtap.api.OpenstackVtapCriterion)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 OpenstackVtapUtil.getVtapTypeFromString (org.onosproject.openstackvtap.util.OpenstackVtapUtil.getVtapTypeFromString)1