Search in sources :

Example 6 with MatchMetadata

use of org.opendaylight.genius.mdsalutil.matches.MatchMetadata in project netvirt by opendaylight.

the class ExternalRoutersListener method buildNaptPfibFlowEntity.

public FlowEntity buildNaptPfibFlowEntity(BigInteger dpId, long segmentId) {
    LOG.debug("buildNaptPfibFlowEntity : called for dpId {}, segmentId {}", dpId, segmentId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(segmentId), MetaDataUtil.METADATA_MASK_VRFID));
    ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
    ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
    listActionInfo.add(new ActionNxLoadInPort(BigInteger.ZERO));
    listActionInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    instructionInfo.add(new InstructionApplyActions(listActionInfo));
    String flowRef = getFlowRefTs(dpId, NwConstants.NAPT_PFIB_TABLE, segmentId);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.NAPT_PFIB_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_SNAT_TABLE, matches, instructionInfo);
    LOG.debug("buildNaptPfibFlowEntity : Returning NaptPFib Flow Entity {}", flowEntity);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) 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 7 with MatchMetadata

use of org.opendaylight.genius.mdsalutil.matches.MatchMetadata in project netvirt by opendaylight.

the class ExternalRoutersListener method buildNaptPfibFlowEntityWithUpdatedVpnId.

public FlowEntity buildNaptPfibFlowEntityWithUpdatedVpnId(BigInteger dpId, long segmentId, long changedVpnId) {
    LOG.debug("buildNaptPfibFlowEntityWithUpdatedVpnId : called for dpId {}, " + "segmentId {}, BGP VPN ID {}", dpId, segmentId, changedVpnId);
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(MatchEthernetType.IPV4);
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(changedVpnId), MetaDataUtil.METADATA_MASK_VRFID));
    ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
    ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
    listActionInfo.add(new ActionNxLoadInPort(BigInteger.ZERO));
    listActionInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
    instructionInfo.add(new InstructionApplyActions(listActionInfo));
    String flowRef = getFlowRefTs(dpId, NwConstants.NAPT_PFIB_TABLE, segmentId);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.NAPT_PFIB_TABLE, flowRef, NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, 0, 0, NwConstants.COOKIE_SNAT_TABLE, matches, instructionInfo);
    LOG.debug("buildNaptPfibFlowEntityWithUpdatedVpnId : Returning NaptPFib Flow Entity {}", flowEntity);
    return flowEntity;
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) 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 8 with MatchMetadata

use of org.opendaylight.genius.mdsalutil.matches.MatchMetadata in project netvirt by opendaylight.

the class NatUtil method buildDefaultNATFlowEntityForExternalSubnet.

static FlowEntity buildDefaultNATFlowEntityForExternalSubnet(BigInteger dpId, long 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), MetaDataUtil.METADATA_MASK_VRFID));
    List<InstructionInfo> instructions = new ArrayList<>();
    List<ActionInfo> actionsInfo = new ArrayList<>();
    long groupId = createGroupId(NatUtil.getGroupIdKey(subnetId), idManager);
    actionsInfo.add(new ActionGroup(groupId));
    String flowRef = getFlowRef(dpId, NwConstants.L3_FIB_TABLE, defaultIP, vpnId);
    instructions.add(new InstructionApplyActions(actionsInfo));
    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) ArrayList(java.util.ArrayList) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) 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)

Example 9 with MatchMetadata

use of org.opendaylight.genius.mdsalutil.matches.MatchMetadata 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 10 with MatchMetadata

use of org.opendaylight.genius.mdsalutil.matches.MatchMetadata 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)

Aggregations

MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)67 ArrayList (java.util.ArrayList)61 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)50 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)40 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)32 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)31 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)23 BigInteger (java.math.BigInteger)15 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)15 ActionNxResubmit (org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit)15 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)13 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)12 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)12 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)11 InetAddress (java.net.InetAddress)7 UnknownHostException (java.net.UnknownHostException)7 ActionNxLoadInPort (org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort)7 MatchEthernetDestination (org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination)7 NxMatchCtState (org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState)7 ActionGroup (org.opendaylight.genius.mdsalutil.actions.ActionGroup)6