Search in sources :

Example 1 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match in project netvirt by opendaylight.

the class ElanNodeListener method addSmacLearnedTableFlow.

private void addSmacLearnedTableFlow(BigInteger dpId) {
    // T50 - match on Reg4 and goto T51
    List<MatchInfoBase> mkMatches = new ArrayList<>();
    mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
    List<InstructionInfo> mkInstructions = new ArrayList<>();
    mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
    String flowRef = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR).append(LEARN_MATCH_REG4_VALUE).toString();
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)), mkMatches, mkInstructions);
    mdsalManager.installFlow(flowEntity);
}
Also used : NxmNxReg4(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) ArrayList(java.util.ArrayList) NxMatchRegister(org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity)

Example 2 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    short tableId = notification.getTableId().getValue();
    LOG.trace("{} onPacketReceived: Packet punted from table {}", LOGGING_PREFIX, tableId);
    byte[] data = notification.getPayload();
    if (notification.getMatch() == null || notification.getMatch().getMetadata() == null) {
        LOG.error("{} onPacketReceived: Received from table {} where the match or metadata are null", LOGGING_PREFIX, tableId);
        return;
    }
    BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
    Ethernet res = new Ethernet();
    if (tableId == NwConstants.L3_SUBNET_ROUTE_TABLE) {
        LOG.trace("{} onPacketReceived: Some packet received as {}", LOGGING_PREFIX, notification);
        try {
            res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.error("{} onPacketReceived: Failed to decode Packet ", LOGGING_PREFIX, e);
            VpnManagerCounters.subnet_route_packet_failed.inc();
            return;
        }
        try {
            Packet pkt = res.getPayload();
            if (pkt instanceof IPv4) {
                IPv4 ipv4 = (IPv4) pkt;
                byte[] srcIp = Ints.toByteArray(ipv4.getSourceAddress());
                byte[] dstIp = Ints.toByteArray(ipv4.getDestinationAddress());
                String dstIpStr = NWUtil.toStringIpAddress(dstIp);
                String srcIpStr = NWUtil.toStringIpAddress(srcIp);
                // It is an ARP request on a configured VPN. So we must
                // attempt to respond.
                long vpnId = MetaDataUtil.getVpnIdFromMetadata(metadata);
                LOG.info("{} onPacketReceived: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and vpnId {}", LOGGING_PREFIX, srcIpStr, dstIpStr, vpnId);
                Optional<VpnIds> vpnIdsOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId));
                if (!vpnIdsOptional.isPresent()) {
                    // Donot trigger subnetroute logic for packets from
                    // unknown VPNs
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: Ignoring IPv4 packet with destination Ip {} and source Ip {}" + " as it came on unknown VPN with ID {}", LOGGING_PREFIX, dstIpStr, srcIpStr, vpnId);
                    return;
                }
                String vpnIdVpnInstanceName = vpnIdsOptional.get().getVpnInstanceName();
                if (VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source IP {} vpnId {} " + "is a valid Neutron port,ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (VpnUtil.getLearntVpnVipToPort(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source Ip {} vpnId {}" + " is an already discovered IPAddress, ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
                if (elanTag == 0L) {
                    VpnManagerCounters.subnet_route_packet_failed.inc();
                    LOG.error("{} onPacketReceived: elanTag value from metadata found to be 0, for IPv4 " + " Packet received with Target IP {} src Ip {} vpnId {}", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (!vpnIdsOptional.get().isExternalVpn()) {
                    handleInternalVpnSubnetRoutePacket(metadata, dstIp, srcIpStr, dstIpStr, ipv4.getDestinationAddress(), vpnIdVpnInstanceName, elanTag);
                    return;
                }
                byte[] srcMac = res.getSourceMACAddress();
                handleBgpVpnSubnetRoute(ipv4, srcMac, dstIp, dstIpStr, srcIpStr, elanTag);
            }
        } catch (UnknownHostException | InterruptedException | ExecutionException ex) {
            // Failed to handle packet
            VpnManagerCounters.subnet_route_packet_failed.inc();
            LOG.error("{} onPacketReceived: Failed to handle subnetroute packet.", LOGGING_PREFIX, ex);
        }
        return;
    }
// All Arp responses learning for invisble IPs is handled by
// ArpNotificationHandler
}
Also used : Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) UnknownHostException(java.net.UnknownHostException) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match in project netvirt by opendaylight.

the class AclMatches method addIpProtocolMatch.

private void addIpProtocolMatch(AceIp aceIp) {
    // Match on IP
    setIpv4EtherType();
    IpMatchBuilder ipMatch = new IpMatchBuilder();
    ipMatch.setIpProtocol(aceIp.getProtocol());
    matchBuilder.setIpMatch(mergeIpMatch(matchBuilder, ipMatch));
    // TODO Ranges are not supported yet
    int srcPort = 0;
    if (aceIp.getSourcePortRange() != null && aceIp.getSourcePortRange().getLowerPort() != null) {
        srcPort = aceIp.getSourcePortRange().getLowerPort().getValue();
    }
    int dstPort = 0;
    if (aceIp.getDestinationPortRange() != null && aceIp.getDestinationPortRange().getLowerPort() != null) {
        dstPort = aceIp.getDestinationPortRange().getLowerPort().getValue();
    }
    // Match on a TCP/UDP src/dst port
    if (aceIp.getProtocol() == IPProtocols.TCP.shortValue()) {
        TcpMatchBuilder tcpMatch = new TcpMatchBuilder();
        if (srcPort != 0) {
            tcpMatch.setTcpSourcePort(new PortNumber(srcPort));
        }
        if (dstPort != 0) {
            tcpMatch.setTcpDestinationPort(new PortNumber(dstPort));
        }
        if (srcPort != 0 || dstPort != 0) {
            matchBuilder.setLayer4Match(tcpMatch.build());
        }
    } else if (aceIp.getProtocol() == IPProtocols.UDP.shortValue()) {
        UdpMatchBuilder udpMatch = new UdpMatchBuilder();
        if (srcPort != 0) {
            udpMatch.setUdpSourcePort(new PortNumber(srcPort));
        }
        if (dstPort != 0) {
            udpMatch.setUdpDestinationPort(new PortNumber(dstPort));
        }
        if (srcPort != 0 || dstPort != 0) {
            matchBuilder.setLayer4Match(udpMatch.build());
        }
    }
}
Also used : IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)

Example 4 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match in project netvirt by opendaylight.

the class OpenFlow13Utils method addMatchTunDstIp.

public static void addMatchTunDstIp(MatchBuilder match, Ipv4Address ipv4Address) {
    NxAugMatchNodesNodeTableFlow am = new NxAugMatchNodesNodeTableFlowBuilder().setNxmNxTunIpv4Dst(new NxmNxTunIpv4DstBuilder().setIpv4Address(ipv4Address).build()).build();
    addExtension(match, NxmNxTunIpv4DstKey.class, am);
}
Also used : NxAugMatchNodesNodeTableFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow) NxAugMatchNodesNodeTableFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder) NxmNxTunIpv4DstBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.ipv4.dst.grouping.NxmNxTunIpv4DstBuilder)

Example 5 with Match

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match in project netvirt by opendaylight.

the class OpenFlow13Utils method addExtension.

private static void addExtension(MatchBuilder match, Class<? extends ExtensionKey> extensionKey, NxAugMatchNodesNodeTableFlow am) {
    GeneralAugMatchNodesNodeTableFlow existingAugmentations = match.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
    List<ExtensionList> extensions = null;
    if (existingAugmentations != null) {
        extensions = existingAugmentations.getExtensionList();
    }
    if (extensions == null) {
        extensions = new ArrayList<>();
    }
    extensions.add(new ExtensionListBuilder().setExtensionKey(extensionKey).setExtension(new ExtensionBuilder().addAugmentation(NxAugMatchNodesNodeTableFlow.class, am).build()).build());
    GeneralAugMatchNodesNodeTableFlow generalAugMatchNodesNode = new GeneralAugMatchNodesNodeTableFlowBuilder().setExtensionList(extensions).build();
    match.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, generalAugMatchNodesNode);
}
Also used : GeneralAugMatchNodesNodeTableFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow) ExtensionListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder) GeneralAugMatchNodesNodeTableFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder) ExtensionList(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList) ExtensionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder)

Aggregations

Test (org.junit.Test)182 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)138 ArrayList (java.util.ArrayList)82 BigInteger (java.math.BigInteger)66 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)62 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)61 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)60 ByteBuf (io.netty.buffer.ByteBuf)59 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)53 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)49 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)48 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match)45 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)44 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)43 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)43 TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)42 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)41 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)40 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)40 Ipv4Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match)39