Search in sources :

Example 21 with Subnets

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

the class NeutronvpnNatManager method handleSubnetsForExternalRouter.

public void handleSubnetsForExternalRouter(Uuid routerId) {
    InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
    try {
        Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
        LOG.trace("Updating Internal subnets for Routers node: {}", routerId.getValue());
        RoutersBuilder builder = null;
        if (optionalRouters.isPresent()) {
            builder = new RoutersBuilder(optionalRouters.get());
        } else {
            LOG.debug("No Routers element found for router {}", routerId.getValue());
            return;
        }
        List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
        builder.setSubnetIds(subList);
        Routers routerss = builder.build();
        // Add Routers object to the ExtRouters list
        LOG.trace("Updating extrouters {}", routerss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
        LOG.trace("Updated successfully Routers to CONFIG Datastore");
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Updation of internal subnets for extrouters failed for router {}", routerId.getValue(), ex);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) RoutersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)

Example 22 with Subnets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets 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 23 with Subnets

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

the class NeutronvpnManager method associateRouterToVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void associateRouterToVpn(Uuid vpnId, Uuid routerId) {
    updateVpnMaps(vpnId, null, routerId, null, null);
    LOG.debug("Updating association of subnets to external vpn {}", vpnId.getValue());
    List<Uuid> routerSubnets = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
    for (Uuid subnetId : routerSubnets) {
        Subnetmap sn = updateVpnForSubnet(routerId, vpnId, subnetId, true);
        if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sn, vpnId)) {
            neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), NeutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()), true);
        }
    }
    try {
        checkAndPublishRouterAssociatedtoVpnNotification(routerId, vpnId);
        LOG.debug("notification upon association of router {} to VPN {} published", routerId.getValue(), vpnId.getValue());
    } catch (Exception e) {
        LOG.error("publishing of notification upon association of router {} to VPN {} failed : ", routerId.getValue(), vpnId.getValue(), e);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 24 with Subnets

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

the class SubnetDataProcessor method create.

/**
 * Method adds the newly created subnet as an EID prefix to the
 * MappingService. The subnet's network UUID is used as the key for this EID
 * prefix.
 */
@Override
public void create(Subnet subnet) {
    // TODO update for multi-tenancy
    LOG.info("Neutron Subnet Created request : Subnet name: " + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
    LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
    // Determine the IANA code for the subnet IP version
    // Default is set to IPv4 for neutron subnets
    final Eid eid = LispAddressUtil.asIpv4PrefixEid(String.valueOf(subnet.getCidr().getValue()));
    try {
        final OdlMappingserviceService lfmdb = lispNeutronService.getMappingDbService();
        if (lfmdb == null) {
            LOG.debug("lfmdb is null!!!");
            return;
        }
        final AddKeyInput addKeyInput = LispUtil.buildAddKeyInput(eid, subnet.getUuid().getValue());
        final Future<RpcResult<Void>> result = lfmdb.addKey(addKeyInput);
        final Boolean isSuccessful = result.get().isSuccessful();
        if (isSuccessful) {
            LOG.debug("Neutron Subnet Added to MapServer : Subnet name: " + subnet.getName() + " EID Prefix: " + subnet.getCidr() + " Key: " + subnet.getUuid());
        }
        LOG.info("Neutron Subnet Created request : Subnet name: " + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : " + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) AddKeyInput(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) OdlMappingserviceService(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with Subnets

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets 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)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)30 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets)23 ArrayList (java.util.ArrayList)22 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)18 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)17 TransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZoneKey)16 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)15 BigInteger (java.math.BigInteger)14 List (java.util.List)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 DeviceVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps)10 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)9 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)9 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)8 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)8 HashMap (java.util.HashMap)7 ExecutionException (java.util.concurrent.ExecutionException)7 Map (java.util.Map)6