Search in sources :

Example 46 with Uint32

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

the class FloatingIPListener method buildPreSNATFlowEntity.

private FlowEntity buildPreSNATFlowEntity(Uint64 dpId, String internalIp, String externalIp, Uint32 vpnId, Uint32 routerId, Uint32 associatedVpn) {
    LOG.debug("buildPreSNATFlowEntity : Building PSNAT Flow entity for ip {} ", internalIp);
    Uint32 segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreSNATFlowEntity : Segment id {} in build preSNAT flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Source(internalIp, "32"));
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionSetSourceIp(externalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.SNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PSNAT_TABLE, routerId, internalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PSNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) ActionSetSourceIp(org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIp) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 47 with Uint32

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

the class FloatingIPListener method removeNATFlowEntries.

void removeNATFlowEntries(String interfaceName, final InternalToExternalPortMap mapping, InstanceIdentifier<RouterPorts> portIid, final String routerName, @Nullable Uint64 dpnId, TypedReadWriteTransaction<Configuration> removeFlowInvTx) throws ExecutionException, InterruptedException {
    Uuid extNwId = getExtNetworkId(portIid, LogicalDatastoreType.OPERATIONAL);
    if (extNwId == null) {
        LOG.error("removeNATFlowEntries : External network associated with interface {} could not be retrieved", interfaceName);
        return;
    }
    // For FLAT/VLAN Networks, get the DPN with provider_mappings for external network.
    if (dpnId == null) {
        dpnId = getAssociatedDpnWithExternalInterface(routerName, extNwId, NatUtil.getDpnForInterface(interfaceManager, interfaceName), interfaceName);
        if (dpnId == null || dpnId.equals(Uint64.ZERO)) {
            LOG.warn("removeNATFlowEntries: Abort processing Floating ip configuration. No DPN for port: {}", interfaceName);
            return;
        }
    }
    Uint32 routerId = NatUtil.getVpnId(dataBroker, routerName);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("removeNATFlowEntries : Could not retrieve router id for {} to remove NAT Flow entries", routerName);
        return;
    }
    String internalIp = mapping.getInternalIp();
    String externalIp = mapping.getExternalIp();
    // Delete the DNAT and SNAT table entries
    removeDNATTblEntry(dpnId, internalIp, externalIp, routerId, removeFlowInvTx);
    Uuid vpnUuid = getVpnUuid(extNwId, mapping.getExternalId());
    if (vpnUuid == null) {
        LOG.error("removeNATFlowEntries : No VPN associated with Ext nw {}. Unable to remove SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    VpnInstance vpnInstance = NatUtil.getVpnIdToVpnInstance(dataBroker, vpnUuid.getValue());
    if (vpnInstance == null || vpnInstance.getVpnId() == null) {
        LOG.error("removeNATFlowEntries: No VPN associated with Ext nw {}. Unable to create SNAT table entry " + "for fixed ip {}", extNwId, mapping.getInternalIp());
        return;
    }
    Uint32 vpnId = vpnInstance.getVpnId();
    String vrfId = vpnInstance.getVrfId();
    removeSNATTblEntry(dpnId, internalIp, externalIp, routerId, vpnId, removeFlowInvTx);
    // Remove the DNAT default FIB flow L3_FIB_TABLE (21) -> PSNAT_TABLE (26) if SNAT is disabled
    boolean isSnatEnabled = NatUtil.isSnatEnabledForRouterId(dataBroker, routerName);
    if (!isSnatEnabled) {
        addOrDelDefaultFibRouteForDnat(dpnId, routerName, routerId, removeFlowInvTx, false);
    }
    ProviderTypes provType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName, extNwId);
    if (provType == null) {
        LOG.error("removeNATFlowEntries : External Network Provider Type missing");
        return;
    }
    if (provType == ProviderTypes.VXLAN) {
        floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, NatConstants.DEFAULT_L3VNI_VALUE, vrfId, removeFlowInvTx);
        removeOperationalDS(routerName, interfaceName, internalIp);
        return;
    }
    Uint32 label = getOperationalIpMapping(routerName, interfaceName, internalIp);
    if (label.longValue() < 0) {
        LOG.error("removeNATFlowEntries : Could not retrieve label for prefix {} in router {}", internalIp, routerId);
        return;
    }
    floatingIPHandler.onRemoveFloatingIp(dpnId, routerName, routerId, extNwId, mapping, label, vrfId, removeFlowInvTx);
    removeOperationalDS(routerName, interfaceName, internalIp);
}
Also used : 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) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) Uint32(org.opendaylight.yangtools.yang.common.Uint32)

Example 48 with Uint32

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

the class FloatingIPListener method buildPreDNATFlowEntity.

@Nullable
private FlowEntity buildPreDNATFlowEntity(Uint64 dpId, InternalToExternalPortMap mapping, Uint32 routerId, Uint32 associatedVpn) {
    String externalIp = mapping.getExternalIp();
    Uuid floatingIpId = mapping.getExternalId();
    // Get the FIP MAC address for DNAT
    String floatingIpPortMacAddress = NatUtil.getFloatingIpPortMacFromFloatingIpId(dataBroker, floatingIpId);
    if (floatingIpPortMacAddress == null) {
        LOG.error("buildPreDNATFlowEntity : Unable to retrieve floatingIpPortMacAddress from floating IP UUID {} " + "for floating IP {}", floatingIpId, externalIp);
        return null;
    }
    LOG.debug("buildPreDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
    Uint32 segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildPreDNATFlowEntity : Segment id {} in build preDNAT Flow", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchIpv4Destination(externalIp, "32"));
    // Match Destination Floating IP MAC Address on table = 25 (PDNAT_TABLE)
    matches.add(new MatchEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
    // matches.add(new MatchMetadata(
    // BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    String internalIp = mapping.getInternalIp();
    actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionWriteMetadata(MetaDataUtil.getVpnIdMetadata(segmentId.longValue()), MetaDataUtil.METADATA_MASK_VRFID));
    instructions.add(new InstructionApplyActions(actionsInfos));
    instructions.add(new InstructionGotoTable(NwConstants.DNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.PDNAT_TABLE, routerId, externalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.PDNAT_TABLE, flowRef, NatConstants.DEFAULT_DNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_DNAT_TABLE, matches, instructions);
    return flowEntity;
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionSetDestinationIp(org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp) InstructionWriteMetadata(org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 49 with Uint32

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

the class NAPTSwitchSelector method getDpnsForVpn.

@NonNull
public List<Uint64> getDpnsForVpn(String routerName) {
    LOG.debug("getDpnsForVpn: called for RouterName {}", routerName);
    Uint32 bgpVpnId = NatUtil.getBgpVpnId(dataBroker, routerName);
    // TODO Why?
    if (bgpVpnId != NatConstants.INVALID_ID) {
        return NatUtil.getDpnsForRouter(dataBroker, routerName);
    }
    return NatUtil.getDpnsForRouter(dataBroker, routerName);
}
Also used : Uint32(org.opendaylight.yangtools.yang.common.Uint32) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 50 with Uint32

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

the class NaptFlowRemovedEventHandler method onFlowRemoved.

@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
    /*
        If the removed flow is from the OUTBOUND NAPT table :
        1) Get the ActionInfo of the flow.
        2) From the ActionInfo of the flow get the internal IP address, port and the protocol.
        3) Get the Metadata matching info of the flow.
        4) From the Metadata matching info of the flow get router ID.
        5) Querry the container intext-ip-port-map using the router ID
           and the internal IP address, port to get the external IP address, port
        6) Instantiate an NaptEntry event and populate the external IP address, port and the router ID.
        7) Place the NaptEntry event to the queue.
*/
    short tableId = flowRemoved.getTableId().toJava();
    RemovedFlowReason removedReasonFlag = flowRemoved.getReason();
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE && RemovedFlowReason.OFPRRIDLETIMEOUT.equals(removedReasonFlag)) {
        LOG.info("onFlowRemoved : triggered for table-{} entry", tableId);
        // Get the internal internal IP address and the port number from the IPv4 match.
        Ipv4Prefix internalIpv4Address = null;
        Layer3Match layer3Match = flowRemoved.getMatch().getLayer3Match();
        if (layer3Match instanceof Ipv4Match) {
            Ipv4Match internalIpv4Match = (Ipv4Match) layer3Match;
            internalIpv4Address = internalIpv4Match.getIpv4Source();
        }
        if (internalIpv4Address == null) {
            LOG.error("onFlowRemoved : Matching internal IP is null while retrieving the " + "value from the Outbound NAPT flow");
            return;
        }
        // Get the internal IP as a string
        String internalIpv4AddressAsString = internalIpv4Address.getValue();
        String[] internalIpv4AddressParts = internalIpv4AddressAsString.split("/");
        String internalIpv4HostAddress = null;
        if (internalIpv4AddressParts.length >= 1) {
            internalIpv4HostAddress = internalIpv4AddressParts[0];
        }
        // Get the protocol from the layer4 match
        NAPTEntryEvent.Protocol protocol = null;
        Integer internalPortNumber = null;
        Layer4Match layer4Match = flowRemoved.getMatch().getLayer4Match();
        if (layer4Match instanceof TcpMatch) {
            TcpMatchFields tcpMatchFields = (TcpMatchFields) layer4Match;
            internalPortNumber = tcpMatchFields.getTcpSourcePort().getValue().toJava();
            protocol = NAPTEntryEvent.Protocol.TCP;
        } else if (layer4Match instanceof UdpMatch) {
            UdpMatchFields udpMatchFields = (UdpMatchFields) layer4Match;
            internalPortNumber = udpMatchFields.getUdpSourcePort().getValue().toJava();
            protocol = NAPTEntryEvent.Protocol.UDP;
        }
        if (protocol == null) {
            LOG.error("onFlowRemoved : Matching protocol is null while retrieving the value " + "from the Outbound NAPT flow");
            return;
        }
        // Get the router ID from the metadata.
        Uint32 routerId;
        Uint64 metadata = flowRemoved.getMatch().getMetadata().getMetadata();
        if (MetaDataUtil.getNatRouterIdFromMetadata(metadata) != 0) {
            routerId = Uint32.valueOf(MetaDataUtil.getNatRouterIdFromMetadata(metadata));
        } else {
            LOG.error("onFlowRemoved : Null exception while retrieving routerId");
            return;
        }
        String flowDpn = NatUtil.getDpnFromNodeRef(flowRemoved.getNode());
        NAPTEntryEvent naptEntryEvent = new NAPTEntryEvent(internalIpv4HostAddress, internalPortNumber, flowDpn, routerId, NAPTEntryEvent.Operation.DELETE, protocol);
        naptEventdispatcher.addFlowRemovedNaptEvent(naptEntryEvent);
    } else {
        LOG.debug("onFlowRemoved : Received flow removed notification due to flowdelete from switch for flowref");
    }
}
Also used : Layer3Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match) UdpMatchFields(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.UdpMatchFields) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) TcpMatchFields(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.TcpMatchFields) RemovedFlowReason(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedFlowReason) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) Layer4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

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