All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.sfc.provider.api.SfcServiceFunctionRoundRobinSchedulerAPI Maven / Gradle / Ivy

There is a newer version: 0.10.4
Show newest version
/*
 * Copyright (c) 2015, 2017 Intel Ltd. and others. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

package org.opendaylight.sfc.provider.api;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SfName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SftTypeName;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.ServiceFunctionType;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.service.function.type.SftServiceFunctionName;
import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.RoundRobin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class implements a round robin SF scheduling mode.
 *
 * 

* * @author Johnson Li ([email protected]) * @version 0.1 * @since 2015-03-04 */ public final class SfcServiceFunctionRoundRobinSchedulerAPI extends SfcServiceFunctionSchedulerAPI { private static final Logger LOG = LoggerFactory.getLogger(SfcServiceFunctionRoundRobinSchedulerAPI.class); private static Map MAP_COUNT_ROUND_ROBIN = new HashMap<>(); protected SfcServiceFunctionRoundRobinSchedulerAPI() { super.setSfcServiceFunctionSchedulerType(RoundRobin.class); } private SfName getServiceFunctionByType(ServiceFunctionType serviceFunctionType) { List sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName(); int countRoundRobin = 0; if (!MAP_COUNT_ROUND_ROBIN.isEmpty()) { for (Entry entry : MAP_COUNT_ROUND_ROBIN.entrySet()) { SftTypeName sfType = entry.getKey(); if (sfType.equals(serviceFunctionType.getType())) { countRoundRobin = entry.getValue(); LOG.debug("countRoundRobin: {}", countRoundRobin); break; } } } SftServiceFunctionName sftServiceFunctionName = sftServiceFunctionNameList.get(countRoundRobin); countRoundRobin = (countRoundRobin + 1) % sftServiceFunctionNameList.size(); MAP_COUNT_ROUND_ROBIN.put(serviceFunctionType.getType(), countRoundRobin); return new SfName(sftServiceFunctionName.getName()); } @Override public List scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex, ServiceFunctionPath sfp) { List sfNameList = new ArrayList<>(); List sfcServiceFunctionList = new ArrayList<>(); sfcServiceFunctionList.addAll(chain.getSfcServiceFunction()); short index = 0; Map sfpMapping = getSFPHopSfMapping(sfp); /* * For each ServiceFunction type in the list of ServiceFunctions we * select a specific service function from the list of service functions * by type. */ for (SfcServiceFunction sfcServiceFunction : sfcServiceFunctionList) { LOG.info("ServiceFunction name: {}", sfcServiceFunction.getName()); SfName hopSf = sfpMapping.get(index++); if (hopSf != null) { sfNameList.add(hopSf); continue; } /* * We iterate thorough the list of service function types and for * each one we try to get get a suitable Service Function. WE need * to perform lots of checking to make sure we do not hit NULL * Pointer exceptions */ ServiceFunctionType serviceFunctionType; serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionType(sfcServiceFunction.getType()); if (serviceFunctionType != null) { List sftServiceFunctionNameList = serviceFunctionType .getSftServiceFunctionName(); if (!sftServiceFunctionNameList.isEmpty()) { SfName sfName = getServiceFunctionByType(serviceFunctionType); sfNameList.add(sfName); } else { LOG.error("Could not create path because there are no configured SFs of type: {}", sfcServiceFunction.getType()); return null; } } else { LOG.error("Could not create path because there are no configured SFs of type: {}", sfcServiceFunction.getType()); return null; } } return sfNameList; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy