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());
}
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();
}
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());
}
Aggregations