Merge "Fix missing getter and toString in ActionNxResubmit & tests for it"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetFieldMplsLabel.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.ProtocolMatchFieldsBuilder;
17
18 /**
19  * Set MPLS label field action.
20  */
21 public class ActionSetFieldMplsLabel extends ActionInfo {
22     private static final long serialVersionUID = 1L;
23
24     private final long label;
25
26     public ActionSetFieldMplsLabel(long label) {
27         this(0, label);
28     }
29
30     public ActionSetFieldMplsLabel(int actionKey, long label) {
31         super(actionKey);
32         this.label = label;
33     }
34
35     public long getLabel() {
36         return label;
37     }
38
39     @Override
40     public Action buildAction() {
41         return buildAction(getActionKey());
42     }
43
44     @Override
45     public Action buildAction(int newActionKey) {
46         return new ActionBuilder()
47             .setAction(
48                 new SetFieldCaseBuilder()
49                     .setSetField(
50                         new SetFieldBuilder()
51                             .setProtocolMatchFields(
52                                 new ProtocolMatchFieldsBuilder().setMplsLabel(label).build())
53                             .build())
54                     .build())
55             .setKey(new ActionKey(newActionKey))
56             .build();
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         ActionSetFieldMplsLabel that = (ActionSetFieldMplsLabel) other;
72
73         return label == that.label;
74     }
75
76     @Override
77     public int hashCode() {
78         int result = super.hashCode();
79         result = 31 * result + (int) (label ^ label >>> 32);
80         return result;
81     }
82
83     @Override
84     public String toString() {
85         return "ActionSetFieldMplsLabel [label=" + label + ", getActionKey()=" + getActionKey() + "]";
86     }
87
88 }