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;
19 public final class ClassifierEntry implements ClassifierRenderableEntry {
21 private enum EntryType {
23 INGRESS_INTERFACE_ENTRY_TYPE,
26 EGRESS_INTERFACE_ENTRY_TYPE
29 private final EntryType entryType;
30 private final NodeId node;
31 private final InterfaceKey interfaceKey;
32 private final String connector;
33 private final Matches matches;
34 private final Long nsp;
35 private final Short nsi;
36 private final String destinationIp;
38 private ClassifierEntry(EntryType entryType, NodeId node, InterfaceKey interfaceKey, String connector,
39 Matches matches, Long nsp, Short nsi, String destinationIp) {
41 this.entryType = entryType;
43 this.interfaceKey = interfaceKey;
44 this.connector = connector;
45 this.matches = matches;
48 this.destinationIp = destinationIp;
52 public int hashCode() {
65 public boolean equals(Object obj) {
69 if (Objects.isNull(obj)) {
72 if (!Objects.equals(obj.getClass(), ClassifierEntry.class)) {
75 ClassifierEntry other = (ClassifierEntry) obj;
76 return Objects.equals(entryType, other.entryType)
77 && Objects.equals(node, other.node)
78 && Objects.equals(interfaceKey, other.interfaceKey)
79 && Objects.equals(connector, other.connector)
80 && Objects.equals(matches, other.matches)
81 && Objects.equals(nsp, other.nsp)
82 && Objects.equals(nsi, other.nsi)
83 && Objects.equals(destinationIp, other.destinationIp);
87 public String toString() {
88 return MoreObjects.toStringHelper(this)
89 .add("entryType", entryType)
91 .add("interfaceKey", interfaceKey)
92 .add("connector", connector)
93 .add("matches", matches)
96 .add("destinationIp", destinationIp)
101 public void render(ClassifierEntryRenderer classifierEntryRenderer) {
103 case NODE_ENTRY_TYPE:
104 classifierEntryRenderer.renderNode(node);
106 case INGRESS_INTERFACE_ENTRY_TYPE:
107 classifierEntryRenderer.renderIngress(interfaceKey);
109 case PATH_ENTRY_TYPE:
110 classifierEntryRenderer.renderPath(node, nsp, destinationIp);
112 case MATCH_ENTRY_TYPE:
113 classifierEntryRenderer.renderMatch(node, connector, matches, nsp, nsi, destinationIp);
115 case EGRESS_INTERFACE_ENTRY_TYPE:
116 classifierEntryRenderer.renderEgress(interfaceKey);
123 public void suppress(ClassifierEntryRenderer classifierEntryRenderer) {
125 case NODE_ENTRY_TYPE:
126 classifierEntryRenderer.suppressNode(node);
128 case INGRESS_INTERFACE_ENTRY_TYPE:
129 classifierEntryRenderer.suppressIngress(interfaceKey);
131 case PATH_ENTRY_TYPE:
132 classifierEntryRenderer.suppressPath(node, nsp, destinationIp);
134 case MATCH_ENTRY_TYPE:
135 classifierEntryRenderer.suppressMatch(node, connector, matches, nsp, nsi, destinationIp);
137 case EGRESS_INTERFACE_ENTRY_TYPE:
138 classifierEntryRenderer.suppressEgress(interfaceKey);
144 public static ClassifierEntry buildIngressEntry(InterfaceKey interfaceKey) {
145 return new ClassifierEntry(EntryType.INGRESS_INTERFACE_ENTRY_TYPE, null, interfaceKey, null, null, null,
149 public static ClassifierEntry buildNodeEntry(NodeId node) {
150 return new ClassifierEntry(EntryType.NODE_ENTRY_TYPE, node, null, null, null, null,
154 public static ClassifierEntry buildPathEntry(NodeId node, Long nsp, String destinationIp) {
155 return new ClassifierEntry(EntryType.PATH_ENTRY_TYPE, node, null, null, null, nsp,
156 null, destinationIp);
159 public static ClassifierEntry buildMatchEntry(NodeId node, String connector, Matches matches, Long nsp, Short nsi,
160 String destinationIp) {
161 return new ClassifierEntry(EntryType.MATCH_ENTRY_TYPE, node, null, connector, matches, nsp,
165 public static ClassifierEntry buildEgressEntry(InterfaceKey interfaceKey) {
166 return new ClassifierEntry(EntryType.EGRESS_INTERFACE_ENTRY_TYPE, null, interfaceKey, null, null, null,