Search in sources :

Example 1 with ExternalNetworks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks in project netvirt by opendaylight.

the class NatUtil method getRouterUuIdsForVpn.

@Nonnull
public static List<Uuid> getRouterUuIdsForVpn(DataBroker broker, Uuid vpnUuid) {
    InstanceIdentifier<ExternalNetworks> externalNwIdentifier = InstanceIdentifier.create(ExternalNetworks.class);
    Optional<ExternalNetworks> externalNwData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, externalNwIdentifier);
    if (externalNwData.isPresent()) {
        for (Networks externalNw : externalNwData.get().getNetworks()) {
            if (externalNw.getVpnid() != null && externalNw.getVpnid().equals(vpnUuid)) {
                return externalNw.getRouterIds();
            }
        }
    }
    return Collections.emptyList();
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) Nonnull(javax.annotation.Nonnull)

Example 2 with ExternalNetworks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks in project netvirt by opendaylight.

the class NeutronvpnNatManager method addExternalNetworkToRouter.

private void addExternalNetworkToRouter(Router update) {
    Uuid routerId = update.getUuid();
    Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
    List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
    try {
        Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
        ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
        if (providerNwType == null) {
            LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
            return;
        }
        // Add this router to the ExtRouters list
        addExternalRouter(update);
        // Update External Subnets for this router
        updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
        // Create and add Networks object for this External Network to the ExternalNetworks list
        InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
            return;
        }
        NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
        List<Uuid> rtrList = builder.getRouterIds();
        if (rtrList == null) {
            rtrList = new ArrayList<>();
        }
        rtrList.add(routerId);
        builder.setRouterIds(rtrList);
        if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
            builder.setVpnid(extNetId);
        }
        Networks networkss = builder.build();
        // Add Networks object to the ExternalNetworks list
        LOG.trace("Updating externalnetworks {}", networkss);
        SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
        LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
        // get vpn external form this network external to setup vpnInternet for ipv6
        Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
        if (vpnExternal == null) {
            LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
        }
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
        // get subnetmap associate to the router, any subnetmap "external" could be existing
        List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
        LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
        for (Subnetmap sn : snList) {
            if (sn.getInternetVpnId() == null) {
                continue;
            }
            IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
            if (ipVers == IpVersionChoice.IPV6) {
                LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
                nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
            }
        }
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) ExternalFixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 3 with ExternalNetworks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks in project netvirt by opendaylight.

the class NeutronvpnNatManager method removeExternalNetwork.

public void removeExternalNetwork(Network net) {
    Uuid extNetId = net.getUuid();
    // Create and add Networks object for this External Network to the ExternalNetworks list
    InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
    try {
        Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        LOG.trace("Removing Networks node {}", extNetId.getValue());
        if (!optionalNets.isPresent()) {
            LOG.error("External Network {} not available in the datastore", extNetId.getValue());
            return;
        }
        // Delete Networks object from the ExternalNetworks list
        LOG.trace("Deleting External Network {}", extNetId.getValue());
        SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
        LOG.trace("Deleted External Network {} successfully from CONFIG Datastore", extNetId.getValue());
    } catch (TransactionCommitFailedException | ReadFailedException ex) {
        LOG.error("Deletion of External Network {} failed", extNetId.getValue(), ex);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 4 with ExternalNetworks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks in project netvirt by opendaylight.

the class NatUtil method getNetworkVpnIdFromRouterId.

public static Long getNetworkVpnIdFromRouterId(DataBroker broker, long routerId) {
    // Get the external network ID from the ExternalRouter model
    Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
    if (networkId == null) {
        LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
        return NatConstants.INVALID_ID;
    }
    // Get the VPN ID from the ExternalNetworks model
    Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
    if (vpnUuid == null) {
        LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
        return NatConstants.INVALID_ID;
    }
    Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
    return vpnId;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 5 with ExternalNetworks

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks in project netvirt by opendaylight.

the class NaptEventHandler method handleEvent.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleEvent(final NAPTEntryEvent naptEntryEvent) {
    /*
            Flow programming logic of the OUTBOUND NAPT TABLE :
            1) Get the internal IP address, port number, router ID from the event.
            2) Use the NAPT service getExternalAddressMapping() to get the External IP and the port.
            3) Build the flow for replacing the Internal IP and port with the External IP and port.
              a) Write the matching criteria.
              b) Match the router ID in the metadata.
              d) Write the VPN ID to the metadata.
              e) Write the other data.
              f) Set the apply actions instruction with the action setfield.
            4) Write the flow to the OUTBOUND NAPT Table and forward to FIB table for routing the traffic.

            Flow programming logic of the INBOUND NAPT TABLE :
            Same as Outbound table logic except that :
            1) Build the flow for replacing the External IP and port with the Internal IP and port.
            2) Match the VPN ID in the metadata.
            3) Write the router ID to the metadata.
            5) Write the flow to the INBOUND NAPT Table and forward to FIB table for routing the traffic.
    */
    try {
        Long routerId = naptEntryEvent.getRouterId();
        LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms," + "routerId: {},isPktProcessed:{}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), routerId, naptEntryEvent.isPktProcessed());
        // Get the DPN ID
        BigInteger dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
        long bgpVpnId = NatConstants.INVALID_ID;
        if (dpnId == null) {
            LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and proceeding....", routerId);
            bgpVpnId = routerId;
            LOG.debug("handleEvent : BGP VPN ID {}", bgpVpnId);
            String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
            String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
            if (routerName == null) {
                LOG.error("handleEvent : Unable to find router for VpnName {}", vpnName);
                return;
            }
            routerId = NatUtil.getVpnId(dataBroker, routerName);
            LOG.debug("handleEvent : Router ID {}", routerId);
            dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
            if (dpnId == null) {
                LOG.error("handleEvent : dpnId is null for the router {}", routerId);
                return;
            }
        }
        if (naptEntryEvent.getOperation() == NAPTEntryEvent.Operation.ADD) {
            LOG.debug("handleEvent : Inside Add operation of NaptEventHandler");
            // Build and install the NAPT translation flows in the Outbound and Inbound NAPT tables
            if (!naptEntryEvent.isPktProcessed()) {
                // Get the External Gateway MAC Address
                String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
                if (extGwMacAddress != null) {
                    LOG.debug("handleEvent : External Gateway MAC address {} found for External Router ID {}", extGwMacAddress, routerId);
                } else {
                    LOG.error("handleEvent : No External Gateway MAC address found for External Router ID {}", routerId);
                    return;
                }
                // Get the external network ID from the ExternalRouter model
                Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
                if (networkId == null) {
                    LOG.error("handleEvent : networkId is null");
                    return;
                }
                // Get the VPN ID from the ExternalNetworks model
                Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                if (vpnUuid == null) {
                    LOG.error("handleEvent : vpnUuid is null");
                    return;
                }
                Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
                // Get the internal IpAddress, internal port number from the event
                String internalIpAddress = naptEntryEvent.getIpAddress();
                int internalPort = naptEntryEvent.getPortNumber();
                SessionAddress internalAddress = new SessionAddress(internalIpAddress, internalPort);
                NAPTEntryEvent.Protocol protocol = naptEntryEvent.getProtocol();
                // Get the external IP address for the corresponding internal IP address
                SessionAddress externalAddress = naptManager.getExternalAddressMapping(routerId, internalAddress, naptEntryEvent.getProtocol());
                if (externalAddress == null) {
                    LOG.error("handleEvent : externalAddress is null");
                    return;
                }
                Long vpnIdFromExternalSubnet = getVpnIdFromExternalSubnet(routerId, externalAddress.getIpAddress());
                if (vpnIdFromExternalSubnet != NatConstants.INVALID_ID) {
                    vpnId = vpnIdFromExternalSubnet;
                }
                // Added External Gateway MAC Address
                Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, externalAddress, internalAddress, protocol, extGwMacAddress, true);
                final BigInteger finalDpnId = dpnId;
                final Long finalVpnId = vpnId;
                final Long finalRouterId = routerId;
                final long finalBgpVpnId = bgpVpnId;
                Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                    @Override
                    public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                        LOG.debug("handleEvent : Configured inbound rule for {} to {}", internalAddress, externalAddress);
                        Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(finalDpnId, NwConstants.OUTBOUND_NAPT_TABLE, finalVpnId, finalRouterId, finalBgpVpnId, internalAddress, externalAddress, protocol, extGwMacAddress, true);
                        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                            @Override
                            public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                                LOG.debug("handleEvent : Configured outbound rule, sending packet out" + "from {} to {}", internalAddress, externalAddress);
                                prepareAndSendPacketOut(naptEntryEvent, finalRouterId);
                            }

                            @Override
                            public void onFailure(@Nonnull Throwable throwable) {
                                LOG.error("handleEvent : Error configuring outbound " + "SNAT flows using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                            }
                        }, MoreExecutors.directExecutor());
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable throwable) {
                        LOG.error("handleEvent : Error configuring inbound SNAT flows " + "using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                    }
                }, MoreExecutors.directExecutor());
                NatPacketProcessingState state = naptEntryEvent.getState();
                if (state != null) {
                    state.setFlowInstalledTime(System.currentTimeMillis());
                }
            } else {
                prepareAndSendPacketOut(naptEntryEvent, routerId);
            }
            LOG.trace("handleEvent : Time elapsed after Processsing snat ({}:{}) packet: {}ms,isPktProcessed:{} ", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), naptEntryEvent.isPktProcessed());
        } else {
            LOG.debug("handleEvent : Inside delete Operation of NaptEventHandler");
            removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber());
            LOG.info("handleEvent : exited for removeEvent for IP {}, port {}, routerID : {}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), routerId);
        }
    } catch (Exception e) {
        LOG.error("handleEvent :Exception in NaptEventHandler.handleEvent() payload {}", naptEntryEvent, e);
    }
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NatPacketProcessingState(org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Future(java.util.concurrent.Future) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(javax.annotation.Nullable)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)8 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)6 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5 NetworksKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey)5 NetworksBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksBuilder)4 BigInteger (java.math.BigInteger)2 Nonnull (javax.annotation.Nonnull)2 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)2 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)2 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)2 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 Nullable (javax.annotation.Nullable)1 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)1 NatPacketProcessingState (org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState)1