Search in sources :

Example 11 with TcpMatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder in project openflowplugin by opendaylight.

the class OfToSalTcpSrcCase method process.

@Override
public Optional<MatchBuilder> process(@Nonnull TcpSrcCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
    final MatchBuilder matchBuilder = data.getMatchBuilder();
    final TcpMatchBuilder tcpMatchBuilder = data.getTcpMatchBuilder();
    TcpSrc tcpSrc = source.getTcpSrc();
    if (tcpSrc != null) {
        tcpMatchBuilder.setTcpSourcePort(tcpSrc.getPort());
        matchBuilder.setLayer4Match(tcpMatchBuilder.build());
    }
    return Optional.of(matchBuilder);
}
Also used : TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) TcpSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrc)

Example 12 with TcpMatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder in project openflowplugin by opendaylight.

the class MatchV10ResponseConvertor method convert.

@Override
public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
    MatchBuilder matchBuilder = new MatchBuilder();
    EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
    VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
    Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
    IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
    OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
    BigInteger datapathid = datapathIdConvertorData.getDatapathId();
    if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
        matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, (long) source.getInPort(), ofVersion));
    }
    if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
        EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
        ethSrcBuilder.setAddress(source.getDlSrc());
        ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
        EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
        ethDstBuilder.setAddress(source.getDlDst());
        ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
        ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long) source.getDlType()));
        ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
        VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
        int vlanId = source.getDlVlan() == 0xffff ? 0 : source.getDlVlan();
        vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
        vlanIdBuilder.setVlanIdPresent(vlanId != 0);
        vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
        matchBuilder.setVlanMatch(vlanMatchBuilder.build());
    }
    if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
        vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(source.getDlVlanPcp()));
        matchBuilder.setVlanMatch(vlanMatchBuilder.build());
    }
    if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
        final Ipv4Prefix prefix;
        if (source.getNwSrcMask() != null) {
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
        } else {
            // Openflow Spec : 1.3.2
            // An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
            // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
            // statistics response.
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
        }
        if (!NO_IP.equals(prefix.getValue())) {
            ipv4MatchBuilder.setIpv4Source(prefix);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
        final Ipv4Prefix prefix;
        if (source.getNwDstMask() != null) {
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
        } else {
            // Openflow Spec : 1.3.2
            // An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
            // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
            // statistics response.
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
        }
        if (!NO_IP.equals(prefix.getValue())) {
            ipv4MatchBuilder.setIpv4Destination(prefix);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
        Short nwProto = source.getNwProto();
        ipMatchBuilder.setIpProtocol(nwProto);
        matchBuilder.setIpMatch(ipMatchBuilder.build());
        int proto = nwProto.intValue();
        if (proto == PROTO_TCP) {
            TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
            boolean hasTcp = false;
            if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
                tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
                hasTcp = true;
            }
            if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
                tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                hasTcp = true;
            }
            if (hasTcp) {
                matchBuilder.setLayer4Match(tcpMatchBuilder.build());
            }
        } else if (proto == PROTO_UDP) {
            UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
            boolean hasUdp = false;
            if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
                udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
                hasUdp = true;
            }
            if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
                udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                hasUdp = true;
            }
            if (hasUdp) {
                matchBuilder.setLayer4Match(udpMatchBuilder.build());
            }
        } else if (proto == PROTO_ICMPV4) {
            Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
            boolean hasIcmpv4 = false;
            if (!source.getWildcards().isTPSRC()) {
                Integer type = source.getTpSrc();
                if (type != null) {
                    icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
                    hasIcmpv4 = true;
                }
            }
            if (!source.getWildcards().isTPDST()) {
                Integer code = source.getTpDst();
                if (code != null) {
                    icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
                    hasIcmpv4 = true;
                }
            }
            if (hasIcmpv4) {
                matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
            }
        }
    }
    if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
        Short dscp = ActionUtil.tosToDscp(source.getNwTos());
        ipMatchBuilder.setIpDscp(new Dscp(dscp));
        matchBuilder.setIpMatch(ipMatchBuilder.build());
    }
    return matchBuilder;
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) Collections(java.util.Collections) EthernetTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) EthernetDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder) BigInteger(java.math.BigInteger) EthernetSourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder) BigInteger(java.math.BigInteger) Dscp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp) 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) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)

Example 13 with TcpMatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder in project openflowplugin by opendaylight.

the class TcpSourcePortEntryDeserializer method deserializeEntry.

@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
    processHeader(message);
    final int port = message.readUnsignedShort();
    if (Objects.isNull(builder.getLayer4Match())) {
        builder.setLayer4Match(new TcpMatchBuilder().setTcpSourcePort(new PortNumber(port)).build());
    } else if (TcpMatch.class.isInstance(builder.getLayer4Match()) && Objects.isNull(TcpMatch.class.cast(builder.getLayer4Match()).getTcpSourcePort())) {
        builder.setLayer4Match(new TcpMatchBuilder(TcpMatch.class.cast(builder.getLayer4Match())).setTcpSourcePort(new PortNumber(port)).build());
    } else {
        throwErrorOnMalformed(builder, "layer4Match", "tcpSource");
    }
}
Also used : TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) 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)

Example 14 with TcpMatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder in project openflowplugin by opendaylight.

the class SetTpSrcActionSerializer method buildAction.

@Override
protected SetFieldCase buildAction(Action input) {
    final SetTpSrcAction setTpSrcAction = SetTpSrcActionCase.class.cast(input).getSetTpSrcAction();
    final PortNumber port = setTpSrcAction.getPort();
    final SetFieldBuilder builder = new SetFieldBuilder();
    Optional.ofNullable(IPProtocols.fromProtocolNum(setTpSrcAction.getIpProtocol())).ifPresent(proto -> {
        switch(proto) {
            case ICMP:
                {
                    builder.setIcmpv4Match(new Icmpv4MatchBuilder().setIcmpv4Type((short) (0xFF & port.getValue())).build());
                    break;
                }
            case ICMPV6:
                {
                    builder.setIcmpv6Match(new Icmpv6MatchBuilder().setIcmpv6Type((short) (0xFF & port.getValue())).build());
                    break;
                }
            case TCP:
                {
                    builder.setLayer4Match(new TcpMatchBuilder().setTcpSourcePort(port).build());
                    break;
                }
            case UDP:
                {
                    builder.setLayer4Match(new UdpMatchBuilder().setUdpSourcePort(port).build());
                    break;
                }
            default:
        }
    });
    return new SetFieldCaseBuilder().setSetField(builder.build()).build();
}
Also used : SetFieldCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder) SetTpSrcAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) 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) Icmpv6MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder) SetFieldBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder) SetTpSrcActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase)

Example 15 with TcpMatchBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder in project openflowplugin by opendaylight.

the class TcpDestinationPortEntrySerializerTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    final int tcp = 10;
    final Match sctpMatch = new MatchBuilder().setLayer4Match(new TcpMatchBuilder().setTcpDestinationPort(new PortNumber(tcp)).build()).build();
    assertMatch(sctpMatch, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
}
Also used : 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) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) Test(org.junit.Test)

Aggregations

TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)17 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)12 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)11 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)9 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)8 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)7 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)7 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)6 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)6 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)6 ArpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder)4 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)4 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)4 SctpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder)4 Test (org.junit.Test)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)3 SetFieldCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder)3 SetFieldBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder)3 EthernetTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder)3 BigInteger (java.math.BigInteger)2