NETVIRT-1586
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetIpv6NdTarget.java
1 /*
2  * Copyright (c) 2019 Alten Calsoft Labs India Pvt Ltd. 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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
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 IPv6 ND TarAbstractClusteredAsyncDataTreeChangeListenerget action.
21  */
22 public class ActionSetIpv6NdTarget extends ActionInfo {
23
24     private final Ipv6Address ndTarget;
25
26
27     public ActionSetIpv6NdTarget(Ipv6Address ndTarget) {
28         this(0, ndTarget);
29     }
30
31     public ActionSetIpv6NdTarget(int actionKey, Ipv6Address ndTarget) {
32         super(actionKey);
33         this.ndTarget = ndTarget;
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                                 .setLayer3Match(new Ipv6MatchBuilder()
47                                         .setIpv6NdTarget(new Ipv6Address(ndTarget)).build())
48                                 .build())
49                         .build())
50                 .withKey(new ActionKey(newActionKey))
51                 .build();
52     }
53
54     public Ipv6Address getNdTarget() {
55         return ndTarget;
56     }
57
58     @Override
59     public boolean equals(Object other) {
60         if (this == other) {
61             return true;
62         }
63         if (other == null || getClass() != other.getClass()) {
64             return false;
65         }
66         if (!super.equals(other)) {
67             return false;
68         }
69
70         ActionSetIpv6NdTarget that = (ActionSetIpv6NdTarget) other;
71
72         return ndTarget != null ? ndTarget.equals(that.ndTarget) : that.ndTarget == null;
73     }
74
75     @Override
76     public int hashCode() {
77         int result = super.hashCode();
78         result = 31 * result + (ndTarget != null ? ndTarget.hashCode() : 0);
79         return result;
80     }
81
82     @Override
83     public String toString() {
84         return "ActionSetIpv6NdTarget [source=" + ndTarget + ", getActionKey()=" + getActionKey() + "]";
85     }
86
87 }