Search in sources :

Example 1 with OpenstackVtap

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

the class OpenstackVtapListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackVtap.Type type = getVtapTypeFromString(vtapType);
    Set<OpenstackVtap> openstackVtaps = vtapService.getVtaps(type);
    for (OpenstackVtap vtap : openstackVtaps) {
        print(FORMAT, vtap.id().toString(), vtap.type().toString(), vtap.vtapCriterion().srcIpPrefix().toString(), vtap.vtapCriterion().dstIpPrefix().toString());
        print(FORMAT_TX_NODES, osNodeNames(vtap.txDeviceIds()));
        print(FORMAT_RX_NODES, osNodeNames(vtap.rxDeviceIds()));
    }
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap)

Example 2 with OpenstackVtap

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

the class DistributedOpenstackVtapStore method removeDeviceFromVtap.

@Override
public boolean removeDeviceFromVtap(OpenstackVtapId vtapId, OpenstackVtap.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;
        }
        // Remove deviceId from 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.remove(deviceId);
        } else {
            txDeviceIds = null;
        }
        // Remove deviceId from 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.remove(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)

Example 3 with OpenstackVtap

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

the class OpenstackVtapStoreTest method testCreateUpdateAndRemoveVtap.

/**
 * Create, update and remove a openstack vtap to the store;
 * checks if openstack vtap store is correct.
 */
@Test
public void testCreateUpdateAndRemoveVtap() {
    store.createVtap(VTAP_1);
    assertTrue(ERR_NOT_FOUND, store.getVtaps(OpenstackVtap.Type.VTAP_ANY).contains(VTAP_1));
    assertEquals(ERR_NOT_MATCH, store.getVtap(VTAP_ID_1), VTAP_1);
    OpenstackVtap updated = DefaultOpenstackVtap.builder(VTAP_1).vtapCriterion(VTAP_CRITERION_2).build();
    store.updateVtap(updated, true);
    assertEquals(ERR_NOT_MATCH, updated, store.getVtap(VTAP_ID_1));
    store.removeVtap(VTAP_ID_1);
    assertNull(store.getVtap(VTAP_ID_1));
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) Test(org.junit.Test)

Example 4 with OpenstackVtap

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

the class OpenstackVtapAddCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackVtapCriterion criterion = makeVtapCriterion(srcIp, dstIp, ipProto, srcTpPort, dstTpPort);
    OpenstackVtap.Type type = getVtapTypeFromString(vtapTypeStr);
    if (type == null) {
        print("Invalid vtap type");
        return;
    }
    OpenstackVtap vtap = vtapService.createVtap(type, criterion);
    if (vtap != null) {
        print("Created OpenstackVtap with id { %s }", vtap.id().toString());
    } else {
        print("Failed to create OpenstackVtap");
    }
}
Also used : OpenstackVtap(org.onosproject.openstackvtap.api.OpenstackVtap) OpenstackVtapCriterion(org.onosproject.openstackvtap.api.OpenstackVtapCriterion)

Example 5 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