7547c843cfec56d8f3a8d906f37d66de039e8134
[genius.git] / interfacemanager / interfacemanager-impl / src / main / java / org / opendaylight / genius / interfacemanager / servicebindings / flowbased / config / helpers / AbstractFlowBasedServicesConfigBindHelper.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.genius.interfacemanager.servicebindings.flowbased.config.helpers;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.config.factory.FlowBasedServicesConfigAddable;
13 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.L2vlan;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.Tunnel;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.bound.services.state.list.BoundServicesState;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * AbstractFlowBasedServicesConfigBindHelper to enable flow based ingress/egress service binding for interfaces.
23  */
24 public abstract class AbstractFlowBasedServicesConfigBindHelper implements FlowBasedServicesConfigAddable {
25
26     private static final Logger LOG = LoggerFactory.getLogger(AbstractFlowBasedServicesConfigBindHelper.class);
27
28     @Override
29     public final void bindService(List<ListenableFuture<Void>> futures, String interfaceName,
30                                   BoundServices boundServiceNew, List<BoundServices> allServices,
31                                   BoundServicesState interfaceBoundServicesState) {
32
33         if (allServices.isEmpty()) {
34             LOG.error("empty bound service list during bind service {}, for: {}", boundServiceNew, interfaceName);
35             return;
36         }
37
38         if (FlowBasedServicesUtils.isInterfaceTypeBasedServiceBinding(interfaceName)) {
39             bindServiceOnInterfaceType(futures,boundServiceNew, allServices);
40         } else {
41             if (L2vlan.class.equals(interfaceBoundServicesState.getInterfaceType())
42                 || Tunnel.class.equals(interfaceBoundServicesState.getInterfaceType())) {
43                 bindServiceOnInterface(futures, boundServiceNew, allServices, interfaceBoundServicesState);
44             }
45         }
46     }
47
48     protected abstract void bindServiceOnInterface(List<ListenableFuture<Void>> futures, BoundServices boundServiceNew,
49                                                    List<BoundServices> allServices,
50                                                    BoundServicesState interfaceBoundServicesState);
51
52     protected abstract void bindServiceOnInterfaceType(List<ListenableFuture<Void>> futures,
53                                                        BoundServices boundServiceNew, List<BoundServices> allServices);
54 }
55
56