2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.netvirt.aclservice.listeners;
10 import javax.annotation.PostConstruct;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
15 import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
16 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
17 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
18 import org.opendaylight.netvirt.aclservice.api.utils.AclInterfaceCacheUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddDpnEvent;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AddInterfaceToDpnOnVpnEvent;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.OdlL3vpnListener;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.RemoveDpnEvent;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.RemoveInterfaceFromDpnOnVpnEvent;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.add._interface.to.dpn.on.vpn.event.AddInterfaceEventData;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.remove._interface.from.dpn.on.vpn.event.RemoveInterfaceEventData;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 public class AclVpnChangeListener implements OdlL3vpnListener {
31 private static final Logger LOG = LoggerFactory.getLogger(AclVpnChangeListener.class);
32 private final AclServiceManager aclServiceManager;
35 public AclVpnChangeListener(AclServiceManager aclServiceManager) {
36 this.aclServiceManager = aclServiceManager;
41 LOG.trace("Initializing singleton..");
46 LOG.trace("Destroying singleton...");
50 public void onAddDpnEvent(AddDpnEvent notification) {
54 public void onRemoveDpnEvent(RemoveDpnEvent notification) {
58 public void onAddInterfaceToDpnOnVpnEvent(AddInterfaceToDpnOnVpnEvent notification) {
59 AddInterfaceEventData data = notification.getAddInterfaceEventData();
60 LOG.trace("Processing vpn interface {} addition", data.getInterfaceName());
61 Long vpnId = data.getVpnId();
62 AclInterface aclInterface = AclInterfaceCacheUtil.getAclInterfaceFromCache(data.getInterfaceName());
63 if (null != aclInterface && aclInterface.isPortSecurityEnabled() && !vpnId.equals(aclInterface.getVpnId())) {
64 aclServiceManager.notify(aclInterface, null, Action.UNBIND);
65 aclInterface.setVpnId(vpnId);
66 aclServiceManager.notify(aclInterface, null, Action.BIND);
71 public void onRemoveInterfaceFromDpnOnVpnEvent(RemoveInterfaceFromDpnOnVpnEvent notification) {
72 RemoveInterfaceEventData data = notification.getRemoveInterfaceEventData();
73 LOG.trace("Processing vpn interface {} deletion", data.getInterfaceName());
74 Long vpnId = data.getVpnId();
75 AclInterface aclInterface = AclInterfaceCacheUtil.getAclInterfaceFromCache(data.getInterfaceName());
76 if (null != aclInterface && aclInterface.isPortSecurityEnabled() && vpnId.equals(aclInterface.getVpnId())) {
77 aclServiceManager.notify(aclInterface, null, Action.UNBIND);
78 aclInterface.setVpnId(null);
79 aclServiceManager.notify(aclInterface, null, Action.BIND);