Plugin provider functionality
[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 public final class ClassifierEntry implements ClassifierRenderableEntry {
20
21     private enum EntryType {
22         NODE_ENTRY_TYPE,
23         INGRESS_INTERFACE_ENTRY_TYPE,
24         PATH_ENTRY_TYPE,
25         MATCH_ENTRY_TYPE,
26         EGRESS_INTERFACE_ENTRY_TYPE
27     }
28
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;
37
38     private ClassifierEntry(EntryType entryType, NodeId node, InterfaceKey interfaceKey, String connector,
39                             Matches matches, Long nsp, Short nsi, String destinationIp) {
40
41         this.entryType = entryType;
42         this.node = node;
43         this.interfaceKey = interfaceKey;
44         this.connector = connector;
45         this.matches = matches;
46         this.nsp = nsp;
47         this.nsi = nsi;
48         this.destinationIp = destinationIp;
49     }
50
51     @Override
52     public int hashCode() {
53         return Objects.hash(
54                 entryType,
55                 node,
56                 interfaceKey,
57                 connector,
58                 matches,
59                 nsp,
60                 nsi,
61                 destinationIp);
62     }
63
64     @Override
65     public boolean equals(Object obj) {
66         if (this == obj) {
67             return true;
68         }
69         if (Objects.isNull(obj)) {
70             return false;
71         }
72         if (!Objects.equals(obj.getClass(), ClassifierEntry.class)) {
73             return false;
74         }
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);
84     }
85
86     @Override
87     public String toString() {
88         return MoreObjects.toStringHelper(this)
89                 .add("entryType", entryType)
90                 .add("node", node)
91                 .add("interfaceKey", interfaceKey)
92                 .add("connector", connector)
93                 .add("matches", matches)
94                 .add("nsp", nsp)
95                 .add("nsi", nsi)
96                 .add("destinationIp", destinationIp)
97                 .toString();
98     }
99
100     @Override
101     public void render(ClassifierEntryRenderer classifierEntryRenderer) {
102         switch (entryType) {
103             case NODE_ENTRY_TYPE:
104                 classifierEntryRenderer.renderNode(node);
105                 break;
106             case INGRESS_INTERFACE_ENTRY_TYPE:
107                 classifierEntryRenderer.renderIngress(interfaceKey);
108                 break;
109             case PATH_ENTRY_TYPE:
110                 classifierEntryRenderer.renderPath(node, nsp, destinationIp);
111                 break;
112             case MATCH_ENTRY_TYPE:
113                 classifierEntryRenderer.renderMatch(node, connector, matches, nsp, nsi, destinationIp);
114                 break;
115             case EGRESS_INTERFACE_ENTRY_TYPE:
116                 classifierEntryRenderer.renderEgress(interfaceKey);
117                 break;
118             default:
119         }
120     }
121
122     @Override
123     public void suppress(ClassifierEntryRenderer classifierEntryRenderer) {
124         switch (entryType) {
125             case NODE_ENTRY_TYPE:
126                 classifierEntryRenderer.suppressNode(node);
127                 break;
128             case INGRESS_INTERFACE_ENTRY_TYPE:
129                 classifierEntryRenderer.suppressIngress(interfaceKey);
130                 break;
131             case PATH_ENTRY_TYPE:
132                 classifierEntryRenderer.suppressPath(node, nsp, destinationIp);
133                 break;
134             case MATCH_ENTRY_TYPE:
135                 classifierEntryRenderer.suppressMatch(node, connector, matches, nsp, nsi, destinationIp);
136                 break;
137             case EGRESS_INTERFACE_ENTRY_TYPE:
138                 classifierEntryRenderer.suppressEgress(interfaceKey);
139                 break;
140             default:
141         }
142     }
143
144     public static ClassifierEntry buildIngressEntry(InterfaceKey interfaceKey) {
145         return new ClassifierEntry(EntryType.INGRESS_INTERFACE_ENTRY_TYPE, null, interfaceKey, null, null, null,
146                 null, null);
147     }
148
149     public static ClassifierEntry buildNodeEntry(NodeId node) {
150         return new ClassifierEntry(EntryType.NODE_ENTRY_TYPE, node, null, null, null, null,
151                 null, null);
152     }
153
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);
157     }
158
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,
162                 nsi, destinationIp);
163     }
164
165     public static ClassifierEntry buildEgressEntry(InterfaceKey interfaceKey) {
166         return new ClassifierEntry(EntryType.EGRESS_INTERFACE_ENTRY_TYPE, null, interfaceKey, null, null, null,
167                 null, null);
168     }
169 }