2 * Copyright (c) 2015 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.vpnservice.interfacemgr.servicebindings.flowbased.statehelpers;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
14 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
15 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.services.info.BoundServices;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.math.BigInteger;
25 import java.util.ArrayList;
26 import java.util.List;
28 public class FlowBasedServicesStateUnbindHelper {
29 private static final Logger LOG = LoggerFactory.getLogger(FlowBasedServicesStateUnbindHelper.class);
31 public static List<ListenableFuture<Void>> unbindServicesFromInterface(Interface ifaceState,
32 DataBroker dataBroker) {
33 List<ListenableFuture<Void>> futures = new ArrayList<>();
34 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
36 ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), dataBroker);
37 if (servicesInfo == null) {
41 List<BoundServices> allServices = servicesInfo.getBoundServices();
42 if (allServices == null || allServices.isEmpty()) {
46 BoundServices highestPriorityBoundService = null;
47 short highestPriority = 0xFF;
48 for (BoundServices boundService : allServices) {
49 if (boundService.getServicePriority() < highestPriority) {
50 highestPriorityBoundService = boundService;
51 highestPriority = boundService.getServicePriority();
55 InterfaceKey interfaceKey = new InterfaceKey(ifaceState.getName());
56 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
57 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
59 NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
60 if(nodeConnectorId == null){
63 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
64 FlowBasedServicesUtils.removeIngressFlow(iface, highestPriorityBoundService, dpId, t);
66 for (BoundServices boundService : allServices) {
67 if (!boundService.equals(highestPriorityBoundService)) {
68 FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t);