use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones in project genius by opendaylight.
the class ItmManagerRpcService method deleteL2GwMlagDevice.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<Void>> deleteL2GwMlagDevice(DeleteL2GwMlagDeviceInput input) {
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
try {
final IpAddress hwIp = input.getIpAddress();
final List<String> nodeId = input.getNodeId();
InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones tzones = transportZonesOptional.get();
if (tzones.getTransportZone() == null || tzones.getTransportZone().isEmpty()) {
LOG.error("No teps configured");
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
return result;
}
String transportZone = tzones.getTransportZone().get(0).getZoneName();
if (tzones.getTransportZone().get(0).getSubnets() == null || tzones.getTransportZone().get(0).getSubnets().isEmpty()) {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
return result;
}
SubnetsKey subnetsKey = tzones.getTransportZone().get(0).getSubnets().get(0).getKey();
DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId.get(0));
InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
// TO DO: add retry if it fails
transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
// TO DO: add retry if it fails
transaction.delete(LogicalDatastoreType.CONFIGURATION, path2);
ListenableFuture<Void> futureCheck = transaction.submit();
Futures.addCallback(futureCheck, new FutureCallback<Void>() {
@Override
public void onSuccess(Void voidInstance) {
result.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to write HwVtep %s to datastore", nodeId);
LOG.error("Unable to write HwVtep {}, {} to datastore", nodeId, hwIp);
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
});
}
return result;
} catch (Exception e) {
RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Deleting l2 Gateway to DS Failed", e);
return Futures.immediateFuture(resultBuilder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones in project genius by opendaylight.
the class ItmManagerRpcService method deleteL2GwDevice.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> deleteL2GwDevice(DeleteL2GwDeviceInput input) {
final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
boolean foundVxlanTzone = false;
try {
final IpAddress hwIp = input.getIpAddress();
final String nodeId = input.getNodeId();
InstanceIdentifier<TransportZones> containerPath = InstanceIdentifier.create(TransportZones.class);
Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, containerPath, dataBroker);
if (transportZonesOptional.isPresent()) {
TransportZones transportZones = transportZonesOptional.get();
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
LOG.error("No teps configured");
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No teps Configured").build());
return result;
}
for (TransportZone tzone : transportZones.getTransportZone()) {
if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
continue;
}
foundVxlanTzone = true;
String transportZone = tzone.getZoneName();
if (tzone.getSubnets() == null || tzone.getSubnets().isEmpty()) {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
return result;
}
SubnetsKey subnetsKey = tzone.getSubnets().get(0).getKey();
DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId);
InstanceIdentifier<DeviceVteps> path = InstanceIdentifier.builder(TransportZones.class).child(TransportZone.class, new TransportZoneKey(transportZone)).child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
// TO DO: add retry if it fails
transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
ListenableFuture<Void> futureCheck = transaction.submit();
Futures.addCallback(futureCheck, new FutureCallback<Void>() {
@Override
public void onSuccess(Void voidInstance) {
result.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(Throwable error) {
String msg = String.format("Unable to delete HwVtep %s from datastore", nodeId);
LOG.error("Unable to delete HwVtep {}, {} from datastore", nodeId, hwIp);
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
});
}
} else {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No TransportZones configured").build());
return result;
}
if (!foundVxlanTzone) {
result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No VxLan TransportZones configured").build());
}
return result;
} catch (Exception e) {
RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Deleting l2 Gateway to DS Failed", e);
return Futures.immediateFuture(resultBuilder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones in project genius by opendaylight.
the class ItmManagerRpcService method getTunnelEndPointByDpnIdFromTranPortZone.
private Map<BigInteger, ComputesBuilder> getTunnelEndPointByDpnIdFromTranPortZone(Collection<BigInteger> dpnIds) throws ReadFailedException {
TransportZones transportZones = singleTransactionDataBroker.syncRead(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(TransportZones.class).build());
if (transportZones.getTransportZone() == null || transportZones.getTransportZone().isEmpty()) {
throw new IllegalStateException("Failed to find transport zones in config datastore");
}
Map<BigInteger, ComputesBuilder> result = new HashMap<>();
for (TransportZone transportZone : transportZones.getTransportZone()) {
if (transportZone.getSubnets() == null || transportZone.getSubnets().isEmpty()) {
LOG.debug("Transport Zone {} has no subnets", transportZone.getZoneName());
continue;
}
for (Subnets sub : transportZone.getSubnets()) {
if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
LOG.debug("Transport Zone {} subnet {} has no vteps configured", transportZone.getZoneName(), sub.getPrefix());
continue;
}
for (Vteps vtep : sub.getVteps()) {
if (dpnIds.contains(vtep.getDpnId())) {
result.putIfAbsent(vtep.getDpnId(), new ComputesBuilder().setZoneName(transportZone.getZoneName()).setPrefix(sub.getPrefix()).setDpnId(vtep.getDpnId()).setPortName(vtep.getPortname()).setNodeId(getNodeId(vtep.getDpnId())).setTepIp(Collections.singletonList(vtep.getIpAddress())));
}
}
}
}
for (BigInteger dpnId : dpnIds) {
if (!result.containsKey(dpnId)) {
throw new IllegalStateException("Failed to find dpn id " + dpnId + " in transport zone");
}
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones in project genius by opendaylight.
the class TepCommandHelperTest method setupMocks.
private void setupMocks() {
System.setOut(new PrintStream(outContent));
instanceIdentifierList.add(transportZoneIdentifier);
instanceIdentifierList.add(vtepsIdentifier);
instanceIdentifierList.add(subnetsIdentifier);
DeviceVteps deviceVteps = new DeviceVtepsBuilder().setIpAddress(ipAddress1).setKey(new DeviceVtepsKey(ipAddress1, sourceDevice)).setNodeId(sourceDevice).setTopologyId(destinationDevice).build();
vteps = new VtepsBuilder().setPortname(portName1).setDpnId(dpId2).setIpAddress(ipAddress1).setKey(new VtepsKey(dpId2, portName1)).build();
vtepsTest = new VtepsBuilder().build();
deviceVtepsList.add(deviceVteps);
vtepsList.add(vteps);
subnetsTest = new SubnetsBuilder().setGatewayIp(gtwyIp1).setVlanId(vlanId).setKey(new SubnetsKey(ipPrefixTest)).setDeviceVteps(deviceVtepsList).setVteps(vtepsList).build();
subnetsList.add(subnetsTest);
transportZone = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType1).setKey(new TransportZoneKey(transportZone1)).setSubnets(subnetsList).build();
transportZoneNew = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType2).setKey(new TransportZoneKey(transportZone1)).setSubnets(subnetsList).build();
transportZoneList.add(transportZone);
transportZones = new TransportZonesBuilder().setTransportZone(transportZoneList).build();
transportZonesNew = new TransportZonesBuilder().setTransportZone(transportZoneListNew).build();
tunnelMonitorInterval = new TunnelMonitorIntervalBuilder().setInterval(10000).build();
tunnelMonitorParams = new TunnelMonitorParamsBuilder().setEnabled(true).build();
InternalTunnel internalTunnelTest = new InternalTunnelBuilder().setSourceDPN(dpId1).setDestinationDPN(dpId2).setTunnelInterfaceNames(Collections.singletonList(tunnelInterfaceName)).setKey(new InternalTunnelKey(dpId1, dpId2, tunnelType1)).setTransportType(tunnelType1).build();
internalTunnelList.add(internalTunnelTest);
StateTunnelList stateTunnelListTest = new StateTunnelListBuilder().setTunnelInterfaceName(tunnelInterfaceName).setOperState(TunnelOperStatus.Up).build();
stateTunnelList.add(stateTunnelListTest);
lowerLayerIfList.add(dpId1.toString());
interfaceTest = new InterfaceBuilder().setOperStatus(Interface.OperStatus.Up).setAdminStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus.Up).setPhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress.getDefaultInstance("AA:AA:AA:AA:AA:AA")).setIfIndex(100).setLowerLayerIf(lowerLayerIfList).setType(L2vlan.class).build();
interfaceTestNew = ItmUtils.buildTunnelInterface(dpId1, tunnelInterfaceName, destinationDevice, enabled, TunnelTypeVxlan.class, ipAddress1, ipAddress2, gtwyIp1, vlanId, true, enabled, monitorProtocol, interval, false, null);
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones in project genius by opendaylight.
the class TransportZoneListener method initializeTZNode.
@SuppressWarnings("checkstyle:IllegalCatch")
private void initializeTZNode(DataBroker db) {
ReadWriteTransaction transaction = db.newReadWriteTransaction();
InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
CheckedFuture<Optional<TransportZones>, ReadFailedException> tzones = transaction.read(LogicalDatastoreType.CONFIGURATION, path);
try {
if (!tzones.get().isPresent()) {
TransportZonesBuilder tzb = new TransportZonesBuilder();
transaction.put(LogicalDatastoreType.CONFIGURATION, path, tzb.build());
transaction.submit();
} else {
transaction.cancel();
}
} catch (Exception e) {
LOG.error("Error initializing TransportZones {}", e);
}
}
Aggregations