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