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