Remove Serializable from instructions, actions, MatchInfo
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetSourceIpv6.java
1 /*
2  * Copyright © 2017 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.Ipv6Prefix;
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._3.match.Ipv6MatchBuilder;
18
19 /**
20  * Set source IPv6 action.
21  */
22 public class ActionSetSourceIpv6 extends ActionInfo {
23
24     private final Ipv6Prefix source;
25
26     public ActionSetSourceIpv6(String sourceIp) {
27         this(0, sourceIp, null);
28     }
29
30     public ActionSetSourceIpv6(int actionKey, String sourceIp) {
31         this(actionKey, sourceIp, null);
32     }
33
34     public ActionSetSourceIpv6(String sourceIp, String sourceMask) {
35         this(0, sourceIp, sourceMask);
36     }
37
38     public ActionSetSourceIpv6(int actionKey, String sourceIp, String sourceMask) {
39         this(actionKey, new Ipv6Prefix(sourceIp + "/" + (sourceMask != null ? sourceMask : "128")));
40     }
41
42     public ActionSetSourceIpv6(Ipv6Prefix source) {
43         this(0, source);
44     }
45
46     public ActionSetSourceIpv6(int actionKey, Ipv6Prefix source) {
47         super(actionKey);
48         this.source = source;
49     }
50
51     @Override
52     public Action buildAction() {
53         return buildAction(getActionKey());
54     }
55
56     @Override
57     public Action buildAction(int newActionKey) {
58         return new ActionBuilder()
59             .setAction(new SetFieldCaseBuilder()
60                 .setSetField(new SetFieldBuilder()
61                     .setLayer3Match(new Ipv6MatchBuilder()
62                         .setIpv6Source(new Ipv6Prefix(source)).build())
63                     .build())
64                 .build())
65             .setKey(new ActionKey(newActionKey))
66             .build();
67     }
68
69     public Ipv6Prefix getSource() {
70         return source;
71     }
72
73     @Override
74     public boolean equals(Object other) {
75         if (this == other) {
76             return true;
77         }
78         if (other == null || getClass() != other.getClass()) {
79             return false;
80         }
81         if (!super.equals(other)) {
82             return false;
83         }
84
85         ActionSetSourceIpv6 that = (ActionSetSourceIpv6) other;
86
87         return source != null ? source.equals(that.source) : that.source == null;
88     }
89
90     @Override
91     public int hashCode() {
92         int result = super.hashCode();
93         result = 31 * result + (source != null ? source.hashCode() : 0);
94         return result;
95     }
96
97     @Override
98     public String toString() {
99         return "ActionSetSourceIpv6 [source=" + source + ", getActionKey()=" + getActionKey() + "]";
100     }
101
102 }