2 * Copyright (c) 2016, 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 com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Comparator;
12 import java.util.List;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.apache.aries.blueprint.annotation.service.Reference;
16 import org.opendaylight.genius.infra.Datastore.Configuration;
17 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
18 import org.opendaylight.genius.interfacemanager.IfmUtil;
19 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
20 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
21 import org.opendaylight.genius.mdsalutil.NwConstants;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
26 import org.opendaylight.yangtools.yang.common.Uint64;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class FlowBasedEgressServicesStateBindHelper extends AbstractFlowBasedServicesStateBindHelper {
33 private static final Logger LOG = LoggerFactory.getLogger(FlowBasedEgressServicesStateBindHelper.class);
35 private final InterfaceManagerCommonUtils interfaceManagerCommonUtils;
38 public FlowBasedEgressServicesStateBindHelper(@Reference final DataBroker dataBroker,
39 final InterfaceManagerCommonUtils interfaceManagerCommonUtils) {
41 this.interfaceManagerCommonUtils = interfaceManagerCommonUtils;
45 public void bindServicesOnInterface(TypedReadWriteTransaction<Configuration> tx, List<BoundServices> allServices,
47 LOG.info("bind all egress services for interface: {}", ifState.getName());
48 NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(ifState);
49 Uint64 dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId);
50 allServices.sort(Comparator.comparing(BoundServices::getServicePriority));
51 BoundServices highestPriority = allServices.remove(0);
52 short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority().toJava()
53 : highestPriority.getServicePriority().toJava() + 1);
54 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
55 .ietf.interfaces.rev140508.interfaces.Interface iface = interfaceManagerCommonUtils
56 .getInterfaceFromConfigDS(ifState.getName());
57 FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, highestPriority, ifState.getName(), tx,
58 ifState.getIfIndex(), NwConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex, iface);
59 BoundServices prev = null;
60 for (BoundServices boundService : allServices) {
62 FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), tx,
63 ifState.getIfIndex(), prev.getServicePriority().toJava(),
64 boundService.getServicePriority().toJava(), iface);
69 FlowBasedServicesUtils.installEgressDispatcherFlows(dpId, prev, ifState.getName(), tx,
70 ifState.getIfIndex(), prev.getServicePriority().toJava(),
71 (short) (prev.getServicePriority().toJava() + 1), iface);
76 public void bindServicesOnInterfaceType(List<ListenableFuture<Void>> futures, Uint64 dpnId, String ifaceName) {