1c8400909406a21329026438c982b3c3ff3c2c2e
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionNdReserved.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 java.util.Collections;
11 import org.opendaylight.genius.mdsalutil.ActionInfo;
12 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
13 import org.opendaylight.openflowplugin.extension.api.GroupingLooseResolver;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdReservedKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.reserved.grouping.EricOfIcmpv6NdReservedBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetField;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
29 import org.opendaylight.yangtools.yang.binding.Augmentation;
30
31 /**
32  * Set source IPv6 action.
33  */
34 public class ActionNdReserved extends ActionInfo {
35
36     private final long ndReserved;
37
38     public ActionNdReserved(long ndReserved) {
39         this(0, ndReserved);
40     }
41
42     public ActionNdReserved(int actionKey, long ndReserved) {
43         super(actionKey);
44         this.ndReserved = ndReserved;
45     }
46
47     public long getNdReserved() {
48         return ndReserved;
49     }
50
51     @Override
52     public Action buildAction() {
53         return buildAction(getActionKey());
54     }
55
56     @Override
57     public Action buildAction(int newActionKey) {
58         GroupingLooseResolver<GeneralExtensionListGrouping> eqGroup =
59                 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
60         eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
61
62         ExtensionAugment<? extends Augmentation<Extension>> extensionMatch
63                 =  new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
64                 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdReserved(
65                         new EricOfIcmpv6NdReservedBuilder().setIcmpv6NdReserved(ndReserved).build()).build(),
66                 Icmpv6NdReservedKey.class);
67
68         ExtensionListBuilder extListBld = null;
69         ExtensionBuilder extBld = new ExtensionBuilder();
70         extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
71
72         extListBld = new ExtensionListBuilder();
73         extListBld.setExtension(extBld.build());
74         extListBld.setExtensionKey(extensionMatch.getKey());
75
76         GeneralAugMatchNodesNodeTableFlowWriteActionsSetField ndReservedSetField =
77                 new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
78                         .setExtensionList(Collections.singletonList(extListBld.build())).build();
79
80         return new ActionBuilder()
81                 .setAction(new SetFieldCaseBuilder()
82                         .setSetField(new SetFieldBuilder()
83                                 .addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
84                                         ndReservedSetField)
85                                 .build())
86                         .build())
87                 .withKey(new ActionKey(newActionKey))
88                 .build();
89     }
90
91     @Override
92     public boolean equals(Object other) {
93         if (this == other) {
94             return true;
95         }
96         if (other == null || getClass() != other.getClass()) {
97             return false;
98         }
99         if (!super.equals(other)) {
100             return false;
101         }
102
103         ActionNdReserved that = (ActionNdReserved) other;
104
105         return ndReserved == that.ndReserved;
106     }
107
108     @Override
109     public int hashCode() {
110         int result = super.hashCode();
111         result = 31 * result + (int) (ndReserved ^ ndReserved >>> 32);
112         return result;
113     }
114
115     @Override
116     public String toString() {
117         return "ActionNdReserved [source=" + ndReserved + ", getActionKey()=" + getActionKey() + "]";
118     }
119 }