Search in sources :

Example 16 with MatchInfo

use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.

the class FloatingIPListener method buildDNATFlowEntity.

private FlowEntity buildDNATFlowEntity(BigInteger dpId, InternalToExternalPortMap mapping, long routerId, long associatedVpn) {
    String externalIp = mapping.getExternalIp();
    LOG.info("buildDNATFlowEntity : Bulding DNAT Flow entity for ip {} ", externalIp);
    long segmentId = associatedVpn == NatConstants.INVALID_ID ? routerId : associatedVpn;
    LOG.debug("buildDNATFlowEntity : Segment id {} in build DNAT", segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
    matches.add(MatchEthernetType.IPV4);
    String internalIp = mapping.getInternalIp();
    matches.add(new MatchIpv4Destination(internalIp, "32"));
    List<ActionInfo> actionsInfos = new ArrayList<>();
    // actionsInfos.add(new ActionSetDestinationIp(internalIp, "32"));
    List<InstructionInfo> instructions = new ArrayList<>();
    // instructions.add(new InstructionWriteMetadata(BigInteger.valueOf
    // (routerId), MetaDataUtil.METADATA_MASK_VRFID));
    actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    instructions.add(new InstructionApplyActions(actionsInfos));
    // instructions.add(new InstructionGotoTable(NatConstants.L3_FIB_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.DNAT_TABLE, routerId, internalIp);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.DNAT_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) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 17 with MatchInfo

use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.

the class NaptEventHandler method buildAndGetMatchInfo.

private static List<MatchInfo> buildAndGetMatchInfo(String ip, int port, short tableId, NAPTEntryEvent.Protocol protocol, long segmentId) {
    MatchInfo ipMatchInfo = null;
    MatchInfo portMatchInfo = null;
    MatchInfo protocolMatchInfo = null;
    InetAddress ipAddress = null;
    String ipAddressAsString = null;
    try {
        ipAddress = InetAddress.getByName(ip);
        ipAddressAsString = ipAddress.getHostAddress();
    } catch (UnknownHostException e) {
        LOG.error("buildAndGetMatchInfo : UnknowHostException in buildAndGetMatchInfo." + "Failed  to build NAPT Flow for ip {}", ip, e);
        return null;
    }
    MatchInfo metaDataMatchInfo = null;
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
        ipMatchInfo = new MatchIpv4Source(ipAddressAsString, "32");
        if (protocol == NAPTEntryEvent.Protocol.TCP) {
            protocolMatchInfo = MatchIpProtocol.TCP;
            portMatchInfo = new MatchTcpSourcePort(port);
        } else if (protocol == NAPTEntryEvent.Protocol.UDP) {
            protocolMatchInfo = MatchIpProtocol.UDP;
            portMatchInfo = new MatchUdpSourcePort(port);
        }
        metaDataMatchInfo = new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID);
    } else {
        ipMatchInfo = new MatchIpv4Destination(ipAddressAsString, "32");
        if (protocol == NAPTEntryEvent.Protocol.TCP) {
            protocolMatchInfo = MatchIpProtocol.TCP;
            portMatchInfo = new MatchTcpDestinationPort(port);
        } else if (protocol == NAPTEntryEvent.Protocol.UDP) {
            protocolMatchInfo = MatchIpProtocol.UDP;
            portMatchInfo = new MatchUdpDestinationPort(port);
        }
    // metaDataMatchInfo = new MatchMetadata(BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID);
    }
    ArrayList<MatchInfo> matchInfo = new ArrayList<>();
    matchInfo.add(MatchEthernetType.IPV4);
    matchInfo.add(ipMatchInfo);
    matchInfo.add(protocolMatchInfo);
    matchInfo.add(portMatchInfo);
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
        matchInfo.add(metaDataMatchInfo);
    }
    return matchInfo;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) MatchTcpSourcePort(org.opendaylight.genius.mdsalutil.matches.MatchTcpSourcePort) MatchUdpDestinationPort(org.opendaylight.genius.mdsalutil.matches.MatchUdpDestinationPort) UnknownHostException(java.net.UnknownHostException) MatchTcpDestinationPort(org.opendaylight.genius.mdsalutil.matches.MatchTcpDestinationPort) ArrayList(java.util.ArrayList) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) MatchIpv4Source(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchUdpSourcePort(org.opendaylight.genius.mdsalutil.matches.MatchUdpSourcePort) InetAddress(java.net.InetAddress)

Example 18 with MatchInfo

use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.

the class SNATDefaultRouteProgrammer method buildDefNATFlowEntity.

private FlowEntity buildDefNATFlowEntity(BigInteger dpId, long bgpVpnId, long routerId) {
    InetAddress defaultIP = null;
    try {
        defaultIP = InetAddress.getByName("0.0.0.0");
    } catch (UnknownHostException e) {
        LOG.error("buildDefNATFlowEntity : Failed  to build FIB Table Flow for " + "Default Route to NAT table", e);
        return null;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    // add match for default route "0.0.0.0/0"
    // matches.add(new MatchInfo(MatchFieldType.ipv4_dst, new long[] {
    // NatUtil.getIpAddress(defaultIP.getAddress()), 0 }));
    // add match for vrfid
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(bgpVpnId), MetaDataUtil.METADATA_MASK_VRFID));
    List<InstructionInfo> instructions = new ArrayList<>();
    instructions.add(new InstructionGotoTable(NwConstants.PSNAT_TABLE));
    String flowRef = NatUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, routerId);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_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) UnknownHostException(java.net.UnknownHostException) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 19 with MatchInfo

use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.

the class VpnFloatingIpHandler method makeLFibTableEntry.

private void makeLFibTableEntry(BigInteger dpId, long serviceId, String floatingIpPortMacAddress, short tableId, WriteTransaction writeFlowInvTx) {
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.MPLS_UNICAST);
    matches.add(new MatchMplsLabel(serviceId));
    List<Instruction> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfos = new ArrayList<>();
    actionsInfos.add(new ActionPopMpls());
    actionsInfos.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
    Instruction writeInstruction = new InstructionApplyActions(actionsInfos).buildInstruction(0);
    instructions.add(writeInstruction);
    instructions.add(new InstructionGotoTable(tableId).buildInstruction(1));
    // Install the flow entry in L3_LFIB_TABLE
    String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, serviceId, "");
    Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef, 10, flowRef, 0, 0, NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
    mdsalManager.addFlowToTx(dpId, flowEntity, writeFlowInvTx);
    LOG.debug("makeLFibTableEntry : LFIB Entry for dpID {} : label : {} modified successfully", dpId, serviceId);
}
Also used : InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) MatchMplsLabel(org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel) ActionSetFieldEthernetDestination(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetDestination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ActionPopMpls(org.opendaylight.genius.mdsalutil.actions.ActionPopMpls) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)

Example 20 with MatchInfo

use of org.opendaylight.genius.mdsalutil.MatchInfo in project netvirt by opendaylight.

the class VpnFloatingIpHandler method makeTunnelTableEntry.

private void makeTunnelTableEntry(String vpnName, BigInteger dpnId, long serviceId, List<Instruction> customInstructions, WriteTransaction writeFlowInvTx, ProviderTypes provType) {
    List<MatchInfo> mkMatches = new ArrayList<>();
    LOG.info("makeTunnelTableEntry on DpnId = {} and serviceId = {}", dpnId, serviceId);
    int flowPriority = 5;
    // then handled back to using using flow 25->44(which will be installed as part of SNAT)
    if (NatUtil.isOpenStackVniSemanticsEnforcedForGreAndVxlan(elanService, provType)) {
        mkMatches.add(new MatchTunnelId(NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, serviceId)));
        flowPriority = 6;
    } else {
        mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
    }
    Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE, getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), flowPriority, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
    mdsalManager.addFlowToTx(dpnId, terminatingServiceTableFlowEntity, writeFlowInvTx);
}
Also used : MatchTunnelId(org.opendaylight.genius.mdsalutil.matches.MatchTunnelId) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) ArrayList(java.util.ArrayList) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Aggregations

MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)117 ArrayList (java.util.ArrayList)107 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)63 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)52 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)51 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)50 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)49 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)35 MatchTunnelId (org.opendaylight.genius.mdsalutil.matches.MatchTunnelId)24 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)23 BigInteger (java.math.BigInteger)22 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)18 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)15 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)15 ActionPuntToController (org.opendaylight.genius.mdsalutil.actions.ActionPuntToController)11 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)11 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)10 MatchEthernetDestination (org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination)10 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)10 InstructionWriteMetadata (org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata)9