Fix ActionNxConntrack.NxNat problems with xtendbeans (with a test)
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetUdpDestinationPort.java
1 /*
2  * Copyright © 2016 Red Hat, Inc. and others.
3  *
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
7  */
8 package org.opendaylight.genius.mdsalutil.actions;
9
10 import org.opendaylight.genius.mdsalutil.ActionInfo;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
18
19 /**
20  * Set UDP destination port action.
21  */
22 public class ActionSetUdpDestinationPort extends ActionInfo {
23
24     private final int port;
25
26     public ActionSetUdpDestinationPort(int port) {
27         this(0, port);
28     }
29
30     public ActionSetUdpDestinationPort(int actionKey, int port) {
31         super(actionKey);
32         this.port = port;
33     }
34
35     @Override
36     public Action buildAction() {
37         return buildAction(getActionKey());
38     }
39
40     @Override
41     public Action buildAction(int newActionKey) {
42         return new ActionBuilder()
43             .setAction(new SetFieldCaseBuilder()
44                 .setSetField(new SetFieldBuilder()
45                     .setLayer4Match(new UdpMatchBuilder()
46                         .setUdpDestinationPort(new PortNumber(port)).build())
47                     .build())
48                 .build())
49             .setKey(new ActionKey(newActionKey))
50             .build();
51     }
52
53     public int getPort() {
54         return port;
55     }
56
57     @Override
58     public boolean equals(Object other) {
59         if (this == other) {
60             return true;
61         }
62         if (other == null || getClass() != other.getClass()) {
63             return false;
64         }
65         if (!super.equals(other)) {
66             return false;
67         }
68
69         ActionSetUdpDestinationPort that = (ActionSetUdpDestinationPort) other;
70
71         return port == that.port;
72     }
73
74     @Override
75     public int hashCode() {
76         int result = super.hashCode();
77         result = 31 * result + port;
78         return result;
79     }
80
81     @Override
82     public String toString() {
83         return "ActionSetUdpDestinationPort [port=" + port + ", getActionKey()=" + getActionKey() + "]";
84     }
85
86 }