Search in sources :

Example 1 with SubnetsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey in project netvirt by opendaylight.

the class NeutronvpnNatManager method createSubnets.

private Subnets createSubnets(Uuid subnetId, Uuid networkId, List<Uuid> routerIds) {
    SubnetsBuilder subnetsBuilder = new SubnetsBuilder();
    subnetsBuilder.setKey(new SubnetsKey(subnetId));
    subnetsBuilder.setId(subnetId);
    subnetsBuilder.setVpnId(subnetId);
    subnetsBuilder.setExternalNetworkId(networkId);
    if (routerIds != null) {
        subnetsBuilder.setRouterIds(routerIds);
    }
    return subnetsBuilder.build();
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey) SubnetsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsBuilder)

Example 2 with SubnetsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey in project netvirt by opendaylight.

the class NeutronvpnNatManager method updateExternalSubnet.

public void updateExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
    InstanceIdentifier<Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class).child(Subnets.class, new SubnetsKey(subnetId)).build();
    try {
        Subnets newExternalSubnets = createSubnets(subnetId, networkId, routerIds);
        LOG.debug("Updating external subnet {}", newExternalSubnets);
        SingleTransactionDataBroker.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetsIdentifier, newExternalSubnets);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("Update of External Subnets {} failed", subnetId, ex);
    }
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)

Example 3 with SubnetsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey in project genius by opendaylight.

the class ItmManagerRpcService method addL2GwMlagDevice.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> addL2GwMlagDevice(AddL2GwMlagDeviceInput 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 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;
            }
            String transportZone = transportZones.getTransportZone().get(0).getZoneName();
            if (transportZones.getTransportZone().get(0).getSubnets() == null || transportZones.getTransportZone().get(0).getSubnets().isEmpty()) {
                result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No subnets Configured").build());
                return result;
            }
            SubnetsKey subnetsKey = transportZones.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();
            DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(nodeId.get(0)).setTopologyId(input.getTopologyId()).build();
            WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
            // TO DO: add retry if it fails
            LOG.trace("writing hWvtep{}", deviceVtep);
            writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
            if (nodeId.size() == 2) {
                LOG.trace("second node-id {}", nodeId.get(1));
                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();
                DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().setKey(deviceVtepKey2).setIpAddress(hwIp).setNodeId(nodeId.get(1)).setTopologyId(input.getTopologyId()).build();
                // TO DO: add retry if it fails
                LOG.trace("writing {}", deviceVtep2);
                writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
            }
            ListenableFuture<Void> futureCheck = writeTransaction.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());
                }
            }, MoreExecutors.directExecutor());
        }
        return result;
    } catch (RuntimeException e) {
        RpcResultBuilder<java.lang.Void> resultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "Adding l2 Gateway to DS Failed", e);
        return Futures.immediateFuture(resultBuilder.build());
    }
}
Also used : DeviceVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DeviceVtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) DeviceVtepsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Example 4 with SubnetsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey in project genius by opendaylight.

the class ItmManagerRpcService method addL2GwDevice.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<java.lang.Void>> addL2GwDevice(AddL2GwDeviceInput input) {
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    boolean foundVxlanTzone = false;
    try {
        final IpAddress hwIp = input.getIpAddress();
        final String nodeId = input.getNodeId();
        // iterate through all transport zones and put TORs under vxlan
        // if no vxlan tzone is cnfigured, return an error.
        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 transportZone configured");
                result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, "No transportZone Configured").build());
                return result;
            }
            for (TransportZone tzone : transportZones.getTransportZone()) {
                if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
                    continue;
                }
                String transportZone = tzone.getZoneName();
                if (tzone.getSubnets() == null || tzone.getSubnets().isEmpty()) {
                    continue;
                }
                foundVxlanTzone = true;
                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();
                DeviceVteps deviceVtep = new DeviceVtepsBuilder().setKey(deviceVtepKey).setIpAddress(hwIp).setNodeId(nodeId).setTopologyId(input.getTopologyId()).build();
                WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
                // TO DO: add retry if it fails
                transaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
                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());
                    }
                });
            }
        } 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, "Adding l2 Gateway to DS Failed", e);
        return Futures.immediateFuture(resultBuilder.build());
    }
}
Also used : SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) DeviceVtepsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey) TunnelTypeVxlan(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan) TransportZones(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones) DeviceVteps(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TransportZone(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DeviceVtepsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) TransportZoneKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)

Example 5 with SubnetsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.SubnetsKey in project genius by opendaylight.

the class TepCommandHelperTest method testCreateLocalCacheWithoutcheckExistingSubnet.

@Test
public void testCreateLocalCacheWithoutcheckExistingSubnet() {
    IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
    IpPrefix subnetMaskObj = ipPrefixTest;
    SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
    SubnetObject subObCli = new SubnetObject(gatewayIpObj, subnetsKey, subnetMaskObj, vlanId);
    Map<SubnetObject, List<Vteps>> subVtepMapTemp = new HashMap<>();
    subVtepMapTemp.put(subObCli, vtepsList);
    transportZoneNew = new TransportZoneBuilder().setZoneName(transportZone1).setTunnelType(tunnelType2).build();
    doReturn(Futures.immediateCheckedFuture(Optional.of(transportZoneNew))).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION, transportZoneIdentifier);
    doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION, transportZonesIdentifier);
    try {
        tepCommandHelper.createLocalCache(dpId1, portName1, vlanId, tepIp1, subnetMask, gwyIp1, transportZone1, null);
        tepCommandHelper.createLocalCache(dpId2, portName1, vlanId, tepIp1, subnetMask, gwyIp1, transportZone1, null);
    } catch (TepException e) {
        LOG.error(e.getMessage());
    }
    verify(mockReadTx, times(2)).read(LogicalDatastoreType.CONFIGURATION, transportZoneIdentifier);
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) SubnetsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey) HashMap(java.util.HashMap) TransportZoneBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SubnetsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsKey)18 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)15 VtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsKey)11 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)10 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)10 DeviceVtepsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsKey)9 TransportZoneBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneBuilder)7 DeviceVtepsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVtepsBuilder)7 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)7 SubnetsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.SubnetsBuilder)6 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)5 TransportZones (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones)5 DeviceVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps)5 VtepsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.VtepsBuilder)5 ArrayList (java.util.ArrayList)4 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 DPNTEPsInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder)4 DPNTEPsInfoKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey)4 TunnelEndPointsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPointsBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4