Bug 6748: ACL mechanism uses reg5 instead of reg6.
[netvirt.git] / vpnservice / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / AclServiceManagerImpl.java
1 /*
2  * Copyright (c) 2016 Red Hat, 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 package org.opendaylight.netvirt.aclservice;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.netvirt.aclservice.api.AclServiceListener;
15 import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
16 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 @Singleton
22 public class AclServiceManagerImpl implements AclServiceManager {
23
24     private static final Logger LOG = LoggerFactory.getLogger(AclServiceManagerImpl.class);
25
26     private final List<AclServiceListener> aclServiceListeners = new ArrayList<>();
27
28     /**
29      * Initialize the ACL service listener list.
30      */
31     @Inject
32     public AclServiceManagerImpl(final AclServiceImplFactory factory) {
33         addAclServiceListner(factory.createIngressAclServiceImpl());
34         addAclServiceListner(factory.createEgressAclServiceImpl());
35
36         LOG.info("ACL Service Initiated");
37     }
38
39     @Override
40     public void addAclServiceListner(AclServiceListener aclServiceListner) {
41         aclServiceListeners.add(aclServiceListner);
42     }
43
44     @Override
45     public void removeAclServiceListner(AclServiceListener aclServiceListner) {
46         aclServiceListeners.remove(aclServiceListner);
47     }
48
49     @Override
50     public void notify(AclInterface port, AclInterface oldPort, Action action) {
51         for (AclServiceListener aclServiceListener : aclServiceListeners) {
52             boolean result = false;
53             if (action == Action.ADD) {
54                 result = aclServiceListener.applyAcl(port);
55             } else if (action == Action.UPDATE) {
56                 result = aclServiceListener.updateAcl(oldPort, port);
57             } else if (action == Action.REMOVE) {
58                 result = aclServiceListener.removeAcl(port);
59             }
60             if (result) {
61                 LOG.debug("Acl action {} invoking listener {} succeeded", action,
62                     aclServiceListener.getClass().getName());
63             } else {
64                 LOG.warn("Acl action {} invoking listener {} failed", action, aclServiceListener.getClass().getName());
65             }
66         }
67     }
68
69     @Override
70     public void notifyAce(AclInterface port, Action action, Ace ace) {
71         for (AclServiceListener aclServiceListener : aclServiceListeners) {
72             LOG.debug("Ace action {} invoking class {}", action, aclServiceListener.getClass().getName());
73             if (action == Action.ADD) {
74                 aclServiceListener.applyAce(port, ace);
75             } else if (action == Action.REMOVE) {
76                 aclServiceListener.removeAce(port, ace);
77             }
78         }
79     }
80
81 }