Remove Serializable from instructions, actions, MatchInfo
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetFieldEthernetSource.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.yang.types.rev130715.MacAddress;
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.ethernet.match.fields.EthernetSourceBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
19
20 /**
21  * Set Ethernet source field action.
22  */
23 public class ActionSetFieldEthernetSource extends ActionInfo {
24
25     private final MacAddress source;
26
27     public ActionSetFieldEthernetSource(MacAddress source) {
28         this(0, source);
29     }
30
31     public ActionSetFieldEthernetSource(int actionKey, MacAddress source) {
32         super(actionKey);
33         this.source = source;
34     }
35
36     @Override
37     public Action buildAction() {
38         return buildAction(getActionKey());
39     }
40
41     @Override
42     public Action buildAction(int newActionKey) {
43         return new ActionBuilder()
44             .setAction(new SetFieldCaseBuilder()
45                 .setSetField(new SetFieldBuilder()
46                     .setEthernetMatch(new EthernetMatchBuilder()
47                         .setEthernetSource(new EthernetSourceBuilder().setAddress(source).build())
48                         .build())
49                     .build())
50                 .build())
51             .setKey(new ActionKey(newActionKey))
52             .build();
53     }
54
55     public MacAddress getSource() {
56         return source;
57     }
58
59     @Override
60     public boolean equals(Object other) {
61         if (this == other) {
62             return true;
63         }
64         if (other == null || getClass() != other.getClass()) {
65             return false;
66         }
67         if (!super.equals(other)) {
68             return false;
69         }
70
71         ActionSetFieldEthernetSource that = (ActionSetFieldEthernetSource) other;
72
73         return source != null ? source.equals(that.source) : that.source == null;
74     }
75
76     @Override
77     public int hashCode() {
78         int result = super.hashCode();
79         result = 31 * result + (source != null ? source.hashCode() : 0);
80         return result;
81     }
82
83     @Override
84     public String toString() {
85         return "ActionSetFieldEthernetSource [source=" + source + ", getActionKey()=" + getActionKey() + "]";
86     }
87
88 }