package org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.statehelpers;
import com.google.common.util.concurrent.ListenableFuture;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
public class FlowBasedServicesStateBindHelper {
public static List<ListenableFuture<Void>> bindServicesOnInterface(Interface ifaceState,
DataBroker dataBroker) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- WriteTransaction t = dataBroker.newWriteOnlyTransaction();
ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), dataBroker);
if (servicesInfo == null) {
return futures;
return futures;
}
- BoundServices highestPriorityBoundService = null;
- short highestPriority = 0xFF;
- for (BoundServices boundService : allServices) {
- if (boundService.getServicePriority() < highestPriority) {
- highestPriorityBoundService = boundService;
- highestPriority = boundService.getServicePriority();
- }
- }
-
InterfaceKey interfaceKey = new InterfaceKey(ifaceState.getName());
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
- NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
- long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
- BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
- List<MatchInfo> matches = null;
if (iface.getType().isAssignableFrom(L2vlan.class)) {
- matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface);
+ return bindServiceOnVlan(allServices, iface, ifaceState.getIfIndex(), dataBroker);
} else if (iface.getType().isAssignableFrom(Tunnel.class)){
- matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface);
+ return bindServiceOnTunnel(allServices, iface, ifaceState.getIfIndex(), dataBroker);
}
+ return futures;
+ }
+ private static List<ListenableFuture<Void>> bindServiceOnTunnel(
+ List<BoundServices> allServices,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface,
+ Integer ifIndex, DataBroker dataBroker) {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
+ long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
+ BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
+ List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface);
+ BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices);
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
if (matches != null) {
FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, highestPriorityBoundService,
- t, matches, ifaceState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
+ t, matches, ifIndex, NwConstants.VLAN_INTERFACE_INGRESS_TABLE);
}
for (BoundServices boundService : allServices) {
if (!boundService.equals(highestPriorityBoundService)) {
- FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, t, ifaceState.getIfIndex());
+ FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, t, ifIndex, boundService.getServicePriority(), (short) (boundService.getServicePriority()+1));
}
}
futures.add(t.submit());
return futures;
}
+
+ private static List<ListenableFuture<Void>> bindServiceOnVlan(
+ List<BoundServices> allServices,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface,
+ Integer ifIndex, DataBroker dataBroker) {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker);
+ BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
+ WriteTransaction t = dataBroker.newWriteOnlyTransaction();
+ Collections.sort(allServices, new Comparator<BoundServices>() {
+ @Override
+ public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) {
+ return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority());
+ }
+ });
+ BoundServices highestPriority = allServices.remove(0);
+ short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() : highestPriority.getServicePriority() + 1);
+ FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, highestPriority, iface, t, ifIndex, IfmConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex);
+ BoundServices prev = null;
+ for (BoundServices boundService : allServices) {
+ if (prev!=null) {
+ FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, iface, t, ifIndex, prev.getServicePriority(), boundService.getServicePriority());
+ }
+ prev = boundService;
+ }
+ if (prev!=null) {
+ FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, iface, t, ifIndex, prev.getServicePriority(), (short) (prev.getServicePriority()+1));
+ }
+ futures.add(t.submit());
+ return futures;
+
+ }
+
}
\ No newline at end of file