2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.protocol.serialization.actions;
11 import java.util.Optional;
12 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class SetTpDstActionSerializer extends AbstractSetFieldActionSerializer {
28 private static final Logger LOG = LoggerFactory.getLogger(SetTpDstActionSerializer.class);
31 protected SetFieldCase buildAction(Action input) {
32 final SetTpDstAction setTpDstAction = SetTpDstActionCase.class.cast(input).getSetTpDstAction();
33 final PortNumber port = setTpDstAction.getPort();
34 final SetFieldBuilder builder = new SetFieldBuilder();
36 Optional.ofNullable(IPProtocols.fromProtocolNum(setTpDstAction.getIpProtocol())).ifPresent(proto -> {
39 builder.setIcmpv4Match(new Icmpv4MatchBuilder()
40 .setIcmpv4Code((short) (0xFF & port.getValue()))
45 builder.setIcmpv6Match(new Icmpv6MatchBuilder()
46 .setIcmpv6Code((short) (0xFF & port.getValue()))
51 builder.setLayer4Match(new TcpMatchBuilder()
52 .setTcpDestinationPort(port)
57 builder.setLayer4Match(new UdpMatchBuilder()
58 .setUdpDestinationPort(port)
67 return new SetFieldCaseBuilder().setSetField(builder.build()).build();