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