Search in sources :

Example 1 with SetTpSrcAction

use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction in project openflowplugin by opendaylight.

the class SalToOfSetTpSrcActionCase method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetTpSrcActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    IPProtocols protocol = null;
    if (data.getIpProtocol() != null) {
        protocol = IPProtocols.fromProtocolNum(data.getIpProtocol());
    }
    SetTpSrcAction settpsrcaction = source.getSetTpSrcAction();
    MatchEntryBuilder matchBuilder = new MatchEntryBuilder();
    matchBuilder.setOxmClass(OpenflowBasicClass.class);
    matchBuilder.setHasMask(false);
    int port = settpsrcaction.getPort().getValue();
    int type = 0xff & port;
    if (protocol != null) {
        switch(protocol) {
            case ICMP:
                matchBuilder.setOxmMatchField(Icmpv4Type.class);
                Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder();
                Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder();
                icmpv4TypeBuilder.setIcmpv4Type((short) type);
                icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build());
                matchBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build());
                break;
            case ICMPV6:
                matchBuilder.setOxmMatchField(Icmpv6Type.class);
                Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder();
                Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder();
                icmpv6TypeBuilder.setIcmpv6Type((short) type);
                icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build());
                matchBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build());
                break;
            case TCP:
                matchBuilder.setOxmMatchField(TcpSrc.class);
                TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder();
                TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder();
                tcpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port));
                tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build());
                matchBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build());
                break;
            case UDP:
                matchBuilder.setOxmMatchField(UdpSrc.class);
                UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder();
                UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder();
                udpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port));
                udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build());
                matchBuilder.setMatchEntryValue(udpSrcCaseBuilder.build());
                break;
            default:
                LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol);
                break;
        }
    } else {
        LOG.warn("Null protocol with combination of SetSourcePort");
    }
    List<MatchEntry> entries = new ArrayList<>();
    entries.add(matchBuilder.build());
    SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
    setFieldBuilder.setMatchEntry(entries);
    SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
    setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
    return Optional.of(new ActionBuilder().setActionChoice(setFieldCaseBuilder.build()).build());
}
Also used : SetFieldCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder) MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) SetFieldActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) ArrayList(java.util.ArrayList) Icmpv6TypeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCaseBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) Icmpv6TypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6TypeBuilder) UdpSrcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrcBuilder) IPProtocols(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols) SetFieldActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder) UdpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCaseBuilder) TcpSrcBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder) SetTpSrcAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction) Icmpv4TypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4TypeBuilder) Icmpv4TypeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCaseBuilder) TcpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with SetTpSrcAction

use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction 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 3 with SetTpSrcAction

use of org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction in project openflowplugin by opendaylight.

the class SalToOfSetTpSrcActionV10Case method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetTpSrcActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    SetTpSrcAction settpsrcaction = source.getSetTpSrcAction();
    SetTpSrcCaseBuilder setTpSrcCaseBuilder = new SetTpSrcCaseBuilder();
    SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
    setTpSrcActionBuilder.setPort(new PortNumber(settpsrcaction.getPort().getValue().longValue()));
    setTpSrcCaseBuilder.setSetTpSrcAction(setTpSrcActionBuilder.build());
    return Optional.of(new ActionBuilder().setActionChoice(setTpSrcCaseBuilder.build()).build());
}
Also used : SetTpSrcAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder) SetTpSrcCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Nonnull(javax.annotation.Nonnull)

Aggregations

SetTpSrcAction (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction)3 Nonnull (javax.annotation.Nonnull)2 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder)2 ArrayList (java.util.ArrayList)1 IPProtocols (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 SetFieldCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder)1 SetTpSrcActionCase (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase)1 SetFieldBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder)1 Icmpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder)1 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)1 TcpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder)1 UdpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder)1 SetFieldCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder)1 SetTpSrcCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder)1 SetFieldActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder)1 SetTpSrcActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder)1 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)1 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)1 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)1