Search in sources :

Example 66 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatUtil method buildDefaultNATFlowEntityForExternalSubnet.

@Nullable
static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(Uint64 dpId, Uint32 vpnId, String subnetId, IdManagerService idManager) {
    InetAddress defaultIP = null;
    try {
        defaultIP = InetAddress.getByName("0.0.0.0");
    } catch (UnknownHostException e) {
        LOG.error("buildDefaultNATFlowEntityForExternalSubnet : Failed to build FIB Table Flow for " + "Default Route to NAT.", e);
        return null;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    // add match for vrfid
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfo = new ArrayList<>();
    Uint32 groupId = getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(subnetId));
    if (groupId == NatConstants.INVALID_ID) {
        LOG.error("Unable to get groupId for subnet {} while building defauly flow entity", subnetId);
        return null;
    }
    actionsInfo.add(new ActionGroup(groupId.longValue()));
    String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
    instructions.add(new InstructionApplyActions(actionsInfo));
    return MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionGroup(org.opendaylight.genius.mdsalutil.actions.ActionGroup) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) InetAddress(java.net.InetAddress) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 67 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatUtil method handleSNATForDPN.

@SuppressWarnings("checkstyle:IllegalCatch")
public static void handleSNATForDPN(DataBroker dataBroker, IMdsalApiManager mdsalManager, IdManagerService idManager, NaptSwitchHA naptSwitchHA, Uint64 dpnId, Routers extRouters, Uint32 routerId, Uint32 routerVpnId, TypedReadWriteTransaction<Configuration> confTx, ProviderTypes extNwProvType, UpgradeState upgradeState) {
    // Check if primary and secondary switch are selected, If not select the role
    // Install select group to NAPT switch
    // Install default miss entry to NAPT switch
    Uint64 naptSwitch;
    String routerName = extRouters.getRouterName();
    Boolean upgradeInProgress = false;
    if (upgradeState != null) {
        upgradeInProgress = upgradeState.isUpgradeInProgress();
    }
    Uint64 naptId = NatUtil.getPrimaryNaptfromRouterName(dataBroker, routerName);
    if (naptId == null || naptId.equals(Uint64.ZERO) || !NatUtil.getSwitchStatus(dataBroker, naptId) && upgradeInProgress == false) {
        LOG.debug("handleSNATForDPN : NaptSwitch is down or not selected for router {},naptId {}", routerName, naptId);
        naptSwitch = dpnId;
        boolean naptstatus = naptSwitchHA.updateNaptSwitch(routerName, naptSwitch);
        if (!naptstatus) {
            LOG.error("handleSNATForDPN : Failed to update newNaptSwitch {} for routername {}", naptSwitch, routerName);
            return;
        }
        LOG.debug("handleSNATForDPN : Switch {} is elected as NaptSwitch for router {}", dpnId, routerName);
        String externalVpnName = null;
        NatUtil.createRouterIdsConfigDS(dataBroker, routerId, routerName);
        naptSwitchHA.subnetRegisterMapping(extRouters, routerId);
        Uuid extNwUuid = extRouters.getNetworkId();
        externalVpnName = NatUtil.getAssociatedVPN(dataBroker, extNwUuid);
        if (externalVpnName != null) {
            naptSwitchHA.installSnatFlows(routerName, routerId, naptSwitch, routerVpnId, extNwUuid, externalVpnName, confTx);
        }
        // Install miss entry (table 26) pointing to table 46
        FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntityForNaptSwitch(dpnId, routerName, routerVpnId, NatConstants.ADD_FLOW);
        if (flowEntity == null) {
            LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}", routerName, dpnId);
            return;
        }
        LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {}", dpnId, routerName);
        mdsalManager.addFlow(confTx, flowEntity);
        // Removing primary flows from old napt switch
        if (naptId != null && !naptId.equals(Uint64.ZERO)) {
            LOG.debug("handleSNATForDPN : Removing primary flows from old napt switch {} for router {}", naptId, routerName);
            try {
                naptSwitchHA.removeSnatFlowsInOldNaptSwitch(extRouters, routerId, naptId, null, externalVpnName, confTx);
            } catch (Exception e) {
                LOG.error("Exception while removing SnatFlows form OldNaptSwitch {}", naptId, e);
            }
        }
        naptSwitchHA.updateNaptSwitchBucketStatus(routerName, routerId, naptSwitch);
    } else if (naptId.equals(dpnId)) {
        LOG.error("handleSNATForDPN : NaptSwitch {} gone down during cluster reboot came alive", naptId);
    } else {
        naptSwitch = naptId;
        LOG.debug("handleSNATForDPN : Napt switch with Id {} is already elected for router {}", naptId, routerName);
        // installing group
        List<BucketInfo> bucketInfo = naptSwitchHA.handleGroupInNeighborSwitches(dpnId, routerName, routerId, naptSwitch);
        naptSwitchHA.installSnatGroupEntry(dpnId, bucketInfo, routerName);
        // Install miss entry (table 26) pointing to group
        Uint32 groupId = NatUtil.getUniqueId(idManager, NatConstants.SNAT_IDPOOL_NAME, NatUtil.getGroupIdKey(routerName));
        if (groupId != NatConstants.INVALID_ID) {
            FlowEntity flowEntity = naptSwitchHA.buildSnatFlowEntity(dpnId, routerName, groupId.longValue(), routerVpnId, NatConstants.ADD_FLOW);
            if (flowEntity == null) {
                LOG.error("handleSNATForDPN : Failed to populate flowentity for router {} with dpnId {}" + " groupId {}", routerName, dpnId, groupId);
                return;
            }
            LOG.debug("handleSNATForDPN : Successfully installed flow for dpnId {} router {} group {}", dpnId, routerName, groupId);
            mdsalManager.addFlow(confTx, flowEntity);
        } else {
            LOG.error("handleSNATForDPN: Unable to get groupId for router:{}", routerName);
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) RoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) ElanDpnInterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) ArrayList(java.util.ArrayList) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) Collections.emptyList(java.util.Collections.emptyList) DpnRoutersList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList) List(java.util.List) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExpectedDataObjectNotFoundException(org.opendaylight.genius.datastoreutils.ExpectedDataObjectNotFoundException) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 68 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatUtil method getExternalVpnIdForExtNetwork.

public static Uint32 getExternalVpnIdForExtNetwork(DataBroker broker, Uuid externalNwUuid) {
    // Get the VPN ID from the ExternalNetworks model
    if (externalNwUuid == null) {
        LOG.error("getExternalVpnIdForExtNetwork : externalNwUuid is null");
        return null;
    }
    Uuid vpnUuid = getVpnIdfromNetworkId(broker, externalNwUuid);
    if (vpnUuid == null) {
        LOG.error("NAT Service : vpnUuid is null");
        return null;
    }
    Uint32 vpnId = 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) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 69 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatUtil method getNetworkVpnIdFromRouterId.

public static Uint32 getNetworkVpnIdFromRouterId(DataBroker broker, Uint32 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;
    }
    Uint32 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) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 70 with Uint32

use of org.opendaylight.yangtools.yang.common.Uint32 in project netvirt by opendaylight.

the class NatVpnMapsChangeListener method onRouterAssociatedToVpn.

public void onRouterAssociatedToVpn(String vpnName, String routerName) {
    // check router is associated to external network
    String extNetwork = NatUtil.getAssociatedExternalNetwork(dataBroker, routerName);
    if (extNetwork != null) {
        try {
            LOG.debug("onRouterAssociatedToVpn : Router {} is associated with ext nw {}", routerName, extNetwork);
            handleDNATConfigurationForRouterAssociation(routerName, vpnName, extNetwork);
            Uuid extNetworkUuid = NatUtil.getNetworkIdFromRouterName(dataBroker, routerName);
            if (extNetworkUuid == null) {
                LOG.error("onRouterAssociatedToVpn : Unable to retrieve external network Uuid for router {}", routerName);
                return;
            }
            ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNetworkUuid);
            if (extNwProvType == null) {
                LOG.error("onRouterAssociatedToVpn : External Network Provider Type missing");
                return;
            }
            Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
            txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> externalRoutersListener.changeLocalVpnIdToBgpVpnId(routerName, routerId, extNetwork, vpnName, tx, extNwProvType)).get();
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("Error changling local VPN identifier to BGP VPN identifier", e);
        }
    } else {
        LOG.debug("onRouterAssociatedToVpn : Ignoring the Router {} association with VPN {} " + "since it is not external router", routerName, vpnName);
    }
}
Also used : CONFIGURATION(org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION) RouterIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap.RouterIds) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) LoggerFactory(org.slf4j.LoggerFactory) Executors(org.opendaylight.infrautils.utils.concurrent.Executors) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) PreDestroy(javax.annotation.PreDestroy) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) Uint32(org.opendaylight.yangtools.yang.common.Uint32) VpnMaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps) Logger(org.slf4j.Logger) AbstractAsyncDataTreeChangeListener(org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener) Collectors(java.util.stream.Collectors) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Optional(java.util.Optional) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.Ports) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ExecutionException(java.util.concurrent.ExecutionException) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Aggregations

Uint32 (org.opendaylight.yangtools.yang.common.Uint32)394 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)111 ArrayList (java.util.ArrayList)105 ExecutionException (java.util.concurrent.ExecutionException)79 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)68 List (java.util.List)60 Optional (java.util.Optional)52 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)51 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)51 Logger (org.slf4j.Logger)51 LoggerFactory (org.slf4j.LoggerFactory)51 ManagedNewTransactionRunner (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner)49 Inject (javax.inject.Inject)48 Singleton (javax.inject.Singleton)48 Test (org.junit.Test)48 ManagedNewTransactionRunnerImpl (org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl)48 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)46 Collections (java.util.Collections)44 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)43 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)38