f5da0e2a97351c90791470f86339fc2004e27847
[netvirt.git] / vpnservice / sfc / classifier / impl / src / main / java / org / opendaylight / netvirt / sfc / classifier / service / domain / impl / OperationalClassifierImpl.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.impl;
10
11 import java.util.Collections;
12 import java.util.Set;
13 import java.util.concurrent.ConcurrentHashMap;
14 import org.opendaylight.netvirt.sfc.classifier.service.domain.ClassifierEntry;
15 import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierEntryRenderer;
16 import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry;
17 import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierState;
18 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;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21
22 public class OperationalClassifierImpl implements ClassifierState {
23
24     private final Set<ClassifierRenderableEntry> entries = ConcurrentHashMap.newKeySet();
25
26     @Override
27     public Set<ClassifierRenderableEntry> getAllEntries() {
28         return Collections.unmodifiableSet(entries);
29     }
30
31     public ClassifierEntryRenderer getRenderer() {
32         return new ClassifierEntryRenderer() {
33
34             @Override
35             public void renderIngress(InterfaceKey interfaceKey) {
36                 entries.add(ClassifierEntry.buildIngressEntry(new InterfaceKey(interfaceKey)));
37             }
38
39             @Override
40             public void renderNode(NodeId nodeId) {
41                 entries.add(ClassifierEntry.buildNodeEntry(nodeId));
42             }
43
44             @Override
45             public void renderPath(NodeId nodeId, Long nsp, short nsi, short nsl, String firstHopIp) {
46                 entries.add(ClassifierEntry.buildPathEntry(nodeId, nsp, nsi, nsl, firstHopIp));
47             }
48
49             @Override
50             public void renderMatch(NodeId nodeId, String connector, Matches matches, Long nsp, Short nsi) {
51                 entries.add(ClassifierEntry.buildMatchEntry(nodeId, connector, matches, nsp, nsi));
52             }
53
54             @Override
55             public void renderEgress(InterfaceKey interfaceKey, String destinationIp) {
56                 entries.add(ClassifierEntry.buildEgressEntry(interfaceKey, destinationIp));
57             }
58
59             @Override
60             public void suppressIngress(InterfaceKey interfaceKey) {
61                 entries.remove(ClassifierEntry.buildIngressEntry(new InterfaceKey(interfaceKey)));
62             }
63
64             @Override
65             public void suppressNode(NodeId nodeId) {
66                 entries.remove(ClassifierEntry.buildNodeEntry(nodeId));
67             }
68
69             @Override
70             public void suppressPath(NodeId nodeId, Long nsp, short nsi, short nsl, String firstHopIp) {
71                 entries.remove(ClassifierEntry.buildPathEntry(nodeId, nsp, nsi, nsl, firstHopIp));
72             }
73
74             @Override
75             public void suppressMatch(NodeId nodeId, String connector, Matches matches, Long nsp, Short nsi) {
76                 entries.remove(ClassifierEntry.buildMatchEntry(nodeId, connector, matches, nsp, nsi));
77             }
78
79             @Override
80             public void suppressEgress(InterfaceKey interfaceKey, String destinationIp) {
81                 entries.remove(ClassifierEntry.buildEgressEntry(interfaceKey, destinationIp));
82             }
83         };
84     }
85
86 }