Fix build faliures due to OFPlugin checktyle fixes
[netvirt.git] / vpnservice / sfc / classifier / impl / src / main / java / org / opendaylight / netvirt / sfc / classifier / service / domain / ClassifierEntry.java
1 /*
2  * Copyright (c) 2017 Ericsson 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
9 package org.opendaylight.netvirt.sfc.classifier.service.domain;
10
11 import com.google.common.base.MoreObjects;
12 import java.util.Objects;
13 import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierEntryRenderer;
14 import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18
19 /**
20  * A generic {@link ClassifierRenderableEntry} implementation that supports all
21  * the different render types.
22  */
23 public final class ClassifierEntry implements ClassifierRenderableEntry {
24
25     private enum EntryType {
26         NODE_ENTRY_TYPE,
27         INGRESS_INTERFACE_ENTRY_TYPE,
28         PATH_ENTRY_TYPE,
29         MATCH_ENTRY_TYPE,
30         EGRESS_INTERFACE_ENTRY_TYPE
31     }
32
33     private final EntryType entryType;
34     private final NodeId node;
35     private final InterfaceKey interfaceKey;
36     private final String connector;
37     private final Matches matches;
38     private final Long nsp;
39     private final Short nsi;
40     private final Short nsl;
41     private final String destinationIp;
42     private final String firstHopIp;
43
44     private ClassifierEntry(EntryType entryType, NodeId node, InterfaceKey interfaceKey, String connector,
45                             Matches matches, Long nsp, Short nsi, Short nsl, String destinationIp,
46                             String firstHopIp) {
47         this.entryType = entryType;
48         this.node = node;
49         this.interfaceKey = interfaceKey;
50         this.connector = connector;
51         this.matches = matches;
52         this.nsp = nsp;
53         this.nsi = nsi;
54         this.nsl = nsl;
55         this.destinationIp = destinationIp;
56         this.firstHopIp = firstHopIp;
57     }
58
59     @Override
60     public int hashCode() {
61         return Objects.hash(
62                 entryType,
63                 node,
64                 interfaceKey,
65                 connector,
66                 matches,
67                 nsp,
68                 nsi,
69                 nsl,
70                 destinationIp,
71                 firstHopIp);
72     }
73
74     @Override
75     public boolean equals(Object obj) {
76         if (this == obj) {
77             return true;
78         }
79         if (obj == null) {
80             return false;
81         }
82         if (!ClassifierEntry.class.equals(obj.getClass())) {
83             return false;
84         }
85         ClassifierEntry other = (ClassifierEntry) obj;
86         return Objects.equals(entryType, other.entryType)
87                 && Objects.equals(node, other.node)
88                 && Objects.equals(interfaceKey, other.interfaceKey)
89                 && Objects.equals(connector, other.connector)
90                 && Objects.equals(matches, other.matches)
91                 && Objects.equals(nsp, other.nsp)
92                 && Objects.equals(nsi, other.nsi)
93                 && Objects.equals(destinationIp, other.destinationIp)
94                 && Objects.equals(nsl, other.nsl)
95                 && Objects.equals(firstHopIp, other.firstHopIp);
96     }
97
98     @Override
99     public String toString() {
100         return MoreObjects.toStringHelper(this)
101                 .add("entryType", entryType)
102                 .add("node", node)
103                 .add("interfaceKey", interfaceKey)
104                 .add("connector", connector)
105                 .add("matches", matches)
106                 .add("nsp", nsp)
107                 .add("nsi", nsi)
108                 .add("nsl", nsl)
109                 .add("destinationIp", destinationIp)
110                 .add("firstHopIp", firstHopIp)
111                 .toString();
112     }
113
114     @Override
115     public void render(ClassifierEntryRenderer classifierEntryRenderer) {
116         switch (entryType) {
117             case NODE_ENTRY_TYPE:
118                 classifierEntryRenderer.renderNode(node);
119                 break;
120             case INGRESS_INTERFACE_ENTRY_TYPE:
121                 classifierEntryRenderer.renderIngress(interfaceKey);
122                 break;
123             case PATH_ENTRY_TYPE:
124                 classifierEntryRenderer.renderPath(node, nsp, nsi, nsl, firstHopIp);
125                 break;
126             case MATCH_ENTRY_TYPE:
127                 classifierEntryRenderer.renderMatch(node, connector, matches, nsp, nsi);
128                 break;
129             case EGRESS_INTERFACE_ENTRY_TYPE:
130                 classifierEntryRenderer.renderEgress(interfaceKey, destinationIp);
131                 break;
132             default:
133         }
134     }
135
136     @Override
137     public void suppress(ClassifierEntryRenderer classifierEntryRenderer) {
138         switch (entryType) {
139             case NODE_ENTRY_TYPE:
140                 classifierEntryRenderer.suppressNode(node);
141                 break;
142             case INGRESS_INTERFACE_ENTRY_TYPE:
143                 classifierEntryRenderer.suppressIngress(interfaceKey);
144                 break;
145             case PATH_ENTRY_TYPE:
146                 classifierEntryRenderer.suppressPath(node, nsp, nsi, nsl, firstHopIp);
147                 break;
148             case MATCH_ENTRY_TYPE:
149                 classifierEntryRenderer.suppressMatch(node, connector, matches, nsp, nsi);
150                 break;
151             case EGRESS_INTERFACE_ENTRY_TYPE:
152                 classifierEntryRenderer.suppressEgress(interfaceKey, destinationIp);
153                 break;
154             default:
155         }
156     }
157
158     /**
159      * Build a {@code ClassifierEntry} supporting an ingress render type.
160      *
161      * @param interfaceKey the ingress interface.
162      * @return the {@code ClassifierEntry}.
163      */
164     public static ClassifierEntry buildIngressEntry(InterfaceKey interfaceKey) {
165         return new ClassifierEntry(
166                 EntryType.INGRESS_INTERFACE_ENTRY_TYPE,
167                 null,
168                 interfaceKey,
169                 null,
170                 null,
171                 null,
172                 null,
173                 null,
174                 null,
175                 null);
176     }
177
178     /**
179      * Build a {@code ClassifierEntry} supporting an node render type.
180      *
181      * @param node the classifier node identifier.
182      * @return the {@code ClassifierEntry}.
183      */
184     public static ClassifierEntry buildNodeEntry(NodeId node) {
185         return new ClassifierEntry(
186                 EntryType.NODE_ENTRY_TYPE,
187                 node,
188                 null,
189                 null,
190                 null,
191                 null,
192                 null,
193                 null,
194                 null,
195                 null);
196     }
197
198     /**
199      * Build a {@code ClassifierEntry} supporting a path render type.
200      *
201      * @param node the classifier node identifier.
202      * @param nsp the path identifier.
203      * @param nsi the path starting index.
204      * @param nsl the path length.
205      * @param firstHopIp the first SFF ip address. Null if the SFF is nodeId.
206      * @return the {@code ClassifierEntry}.
207      */
208     public static ClassifierEntry buildPathEntry(NodeId node, Long nsp, short nsi, short nsl,
209                                                  String firstHopIp) {
210         return new ClassifierEntry(
211                 EntryType.PATH_ENTRY_TYPE,
212                 node,
213                 null,
214                 null,
215                 null,
216                 nsp,
217                 nsi,
218                 nsl,
219                 null,
220                 firstHopIp);
221     }
222
223     /**
224      * Build a {@code ClassifierEntry} supporting an match render type.
225      *
226      * @param node the classifier node identifier.
227      * @param connector the node connector for the ingress interface.
228      * @param matches the ACL matches.
229      * @param nsp the path identifier.
230      * @param nsi the initial path index.
231      * @return the {@code ClassifierEntry}.
232      */
233     public static ClassifierEntry buildMatchEntry(NodeId node, String connector, Matches matches, Long nsp, Short nsi) {
234         return new ClassifierEntry(
235                 EntryType.MATCH_ENTRY_TYPE,
236                 node,
237                 null,
238                 connector,
239                 matches,
240                 nsp,
241                 nsi,
242                 null,
243                 null,
244                 null);
245     }
246
247     /**
248      * Build a {@code ClassifierEntry} supporting a remote egress render type.
249      *
250      * @param interfaceKey the egress interface key.
251      * @param destinationIp the destination IP address associated to the
252      *                      interface. If the interface is a local interface,
253      *                      this should be a node local IP address, otherwise
254      *                      the remote IP address.
255      * @return the {@code ClassifierEntry}.
256      */
257     public static ClassifierEntry buildEgressEntry(InterfaceKey interfaceKey, String destinationIp) {
258         return new ClassifierEntry(
259                 EntryType.EGRESS_INTERFACE_ENTRY_TYPE,
260                 null,
261                 interfaceKey,
262                 null,
263                 null,
264                 null,
265                 null,
266                 null,
267                 destinationIp,
268                 null);
269     }
270 }