2 * Copyright (c) 2017 Ericsson Inc. and others. All rights reserved.
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
9 package org.opendaylight.netvirt.sfc.classifier.service.domain;
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;
20 * A generic {@link ClassifierRenderableEntry} implementation that supports all
21 * the different render types.
23 public final class ClassifierEntry implements ClassifierRenderableEntry {
25 private enum EntryType {
27 INGRESS_INTERFACE_ENTRY_TYPE,
30 EGRESS_INTERFACE_ENTRY_TYPE
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;
44 private ClassifierEntry(EntryType entryType, NodeId node, InterfaceKey interfaceKey, String connector,
45 Matches matches, Long nsp, Short nsi, Short nsl, String destinationIp,
47 this.entryType = entryType;
49 this.interfaceKey = interfaceKey;
50 this.connector = connector;
51 this.matches = matches;
55 this.destinationIp = destinationIp;
56 this.firstHopIp = firstHopIp;
60 public int hashCode() {
75 public boolean equals(Object obj) {
82 if (!ClassifierEntry.class.equals(obj.getClass())) {
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);
99 public String toString() {
100 return MoreObjects.toStringHelper(this)
101 .add("entryType", entryType)
103 .add("interfaceKey", interfaceKey)
104 .add("connector", connector)
105 .add("matches", matches)
109 .add("destinationIp", destinationIp)
110 .add("firstHopIp", firstHopIp)
115 public void render(ClassifierEntryRenderer classifierEntryRenderer) {
117 case NODE_ENTRY_TYPE:
118 classifierEntryRenderer.renderNode(node);
120 case INGRESS_INTERFACE_ENTRY_TYPE:
121 classifierEntryRenderer.renderIngress(interfaceKey);
123 case PATH_ENTRY_TYPE:
124 classifierEntryRenderer.renderPath(node, nsp, nsi, nsl, firstHopIp);
126 case MATCH_ENTRY_TYPE:
127 classifierEntryRenderer.renderMatch(node, connector, matches, nsp, nsi);
129 case EGRESS_INTERFACE_ENTRY_TYPE:
130 classifierEntryRenderer.renderEgress(interfaceKey, destinationIp);
137 public void suppress(ClassifierEntryRenderer classifierEntryRenderer) {
139 case NODE_ENTRY_TYPE:
140 classifierEntryRenderer.suppressNode(node);
142 case INGRESS_INTERFACE_ENTRY_TYPE:
143 classifierEntryRenderer.suppressIngress(interfaceKey);
145 case PATH_ENTRY_TYPE:
146 classifierEntryRenderer.suppressPath(node, nsp, nsi, nsl, firstHopIp);
148 case MATCH_ENTRY_TYPE:
149 classifierEntryRenderer.suppressMatch(node, connector, matches, nsp, nsi);
151 case EGRESS_INTERFACE_ENTRY_TYPE:
152 classifierEntryRenderer.suppressEgress(interfaceKey, destinationIp);
159 * Build a {@code ClassifierEntry} supporting an ingress render type.
161 * @param interfaceKey the ingress interface.
162 * @return the {@code ClassifierEntry}.
164 public static ClassifierEntry buildIngressEntry(InterfaceKey interfaceKey) {
165 return new ClassifierEntry(
166 EntryType.INGRESS_INTERFACE_ENTRY_TYPE,
179 * Build a {@code ClassifierEntry} supporting an node render type.
181 * @param node the classifier node identifier.
182 * @return the {@code ClassifierEntry}.
184 public static ClassifierEntry buildNodeEntry(NodeId node) {
185 return new ClassifierEntry(
186 EntryType.NODE_ENTRY_TYPE,
199 * Build a {@code ClassifierEntry} supporting a path render type.
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}.
208 public static ClassifierEntry buildPathEntry(NodeId node, Long nsp, short nsi, short nsl,
210 return new ClassifierEntry(
211 EntryType.PATH_ENTRY_TYPE,
224 * Build a {@code ClassifierEntry} supporting an match render type.
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}.
233 public static ClassifierEntry buildMatchEntry(NodeId node, String connector, Matches matches, Long nsp, Short nsi) {
234 return new ClassifierEntry(
235 EntryType.MATCH_ENTRY_TYPE,
248 * Build a {@code ClassifierEntry} supporting a remote egress render type.
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}.
257 public static ClassifierEntry buildEgressEntry(InterfaceKey interfaceKey, String destinationIp) {
258 return new ClassifierEntry(
259 EntryType.EGRESS_INTERFACE_ENTRY_TYPE,