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.genius.interfacemanager.servicebindings.flowbased.state.helpers;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.math.BigInteger;
14 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.genius.infra.Datastore.Configuration;
17 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
18 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
19 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
20 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.state.factory.FlowBasedServicesStateAddable;
21 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeBase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * AbstractFlowBasedServicesConfigBindHelper to enable flow based ingress/egress service binding for interfaces.
34 public abstract class AbstractFlowBasedServicesStateBindHelper implements FlowBasedServicesStateAddable {
36 private static final Logger LOG = LoggerFactory.getLogger(AbstractFlowBasedServicesStateBindHelper.class);
38 private final DataBroker dataBroker;
39 private final ManagedNewTransactionRunner txRunner;
43 * @param dataBroker instance of interfaceMgrProvider
45 protected AbstractFlowBasedServicesStateBindHelper(final DataBroker dataBroker) {
46 this.dataBroker = dataBroker;
47 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
50 protected DataBroker getDataBroker() {
54 protected ManagedNewTransactionRunner getTxRunner() {
60 public final void bindServices(List<ListenableFuture<Void>> futures, Interface ifaceState,
61 List<BoundServices> allServices, Class<? extends ServiceModeBase> serviceMode) {
62 futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
63 LOG.debug("binding services on interface {}", ifaceState.getName());
64 ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(tx, ifaceState.getName(),
66 if (servicesInfo == null) {
67 LOG.trace("service info is null for interface {}", ifaceState.getName());
70 if (allServices == null || allServices.isEmpty()) {
71 LOG.trace("bound services is empty for interface {}", ifaceState.getName());
75 if (L2vlan.class.equals(ifaceState.getType()) || Tunnel.class.equals(ifaceState.getType())) {
76 bindServicesOnInterface(tx, allServices, ifaceState);
81 protected abstract void bindServicesOnInterface(TypedReadWriteTransaction<Configuration> tx,
82 List<BoundServices> allServices, Interface ifState);
85 public abstract void bindServicesOnInterfaceType(List<ListenableFuture<Void>> futures, BigInteger dpnId,