Bug 8398 - communication between two tenant network failed while
[netvirt.git] / vpnservice / aclservice / impl / src / main / java / org / opendaylight / netvirt / aclservice / utils / AclServiceUtilFacade.java
1 /*
2  * Copyright (c) 2017 Hewlett Packard Enterprise, Co. 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.aclservice.utils;
10
11 import com.google.common.base.Optional;
12 import java.math.BigInteger;
13 import java.util.List;
14 import java.util.Map;
15
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
21 import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
22 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
23 import org.opendaylight.netvirt.aclservice.api.utils.IAclServiceUtil;
24 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;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
27
28 @Singleton
29 public class AclServiceUtilFacade implements IAclServiceUtil {
30     private final AclServiceManager aclServiceManager;
31     private final DataBroker broker;
32
33     @Inject
34     public AclServiceUtilFacade(DataBroker broker, AclServiceManager aclServiceManager) {
35         this.broker = broker;
36         this.aclServiceManager = aclServiceManager;
37     }
38
39     @Override
40     public Map<String, List<MatchInfoBase>> programIpFlow(Matches matches) {
41         return AclServiceOFFlowBuilder.programIpFlow(matches);
42     }
43
44     @Override
45     public void updateBoundServicesFlow(String interfaceName, Long vpnId) {
46         Optional<Interface> intfc = AclServiceUtils.getInterface(broker, interfaceName);
47         InterfaceAcl aclInPort = intfc.get().getAugmentation(InterfaceAcl.class);
48         if (aclInPort != null && aclInPort.isPortSecurityEnabled()) {
49             aclServiceManager.bindAclTableForVpn(AclServiceUtils.buildAclInterfaceState(interfaceName, aclInPort),
50                     vpnId);
51         }
52     }
53
54     @Override
55     public void updateRemoteAclFilterTable(String interfaceName, Long vpnId, BigInteger dpnId, int addOrDelete) {
56         Optional<Interface> intfc = AclServiceUtils.getInterface(broker, interfaceName);
57         InterfaceAcl aclInPort = intfc.get().getAugmentation(InterfaceAcl.class);
58         if (aclInPort != null && aclInPort.isPortSecurityEnabled()) {
59             AclInterface aclInterface = AclServiceUtils.buildAclInterfaceState(interfaceName, aclInPort);
60             aclInterface.setDpId(dpnId);
61             aclServiceManager.updateRemoteAclFilterTable(aclInterface, addOrDelete, vpnId);
62         }
63     }
64
65 }