/** * Reads a SFG from the datastore * * <p> * * @param serviceFunctionType function type * @return ServiceFunctionGroup object or null if not found */ protected static ServiceFunctionGroup getServiceFunctionGroupByType( Class<? extends ServiceFunctionTypeIdentity> serviceFunctionType) { printTraceStart(LOG); ServiceFunctionGroup sfg = null; InstanceIdentifier<ServiceFunctionGroups> sfgIID; sfgIID = InstanceIdentifier.builder(ServiceFunctionGroups.class).build(); ServiceFunctionGroups sfgs = SfcDataStoreAPI.readTransactionAPI(sfgIID, LogicalDatastoreType.CONFIGURATION); if (sfgs != null) { for (ServiceFunctionGroup element : sfgs.getServiceFunctionGroup()) { if (element.getType().equals(serviceFunctionType)) { sfg = element; LOG.debug("found group " + sfg + " that matches type " + serviceFunctionType); break; } } } if (sfg == null) { LOG.debug("didn't found group " + sfg + " that matches type " + serviceFunctionType); } printTraceStop(LOG); return sfg; }
private void buildGroup(ServiceFunctionGroup sfg, boolean isAdd) { try { List<SfcServiceFunction> sfs = sfg.getSfcServiceFunction(); SfName sfName = new SfName(sfs.get(0).getName()); ServiceFunction sf = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); // assuming all SF's have the same SFF // should use the ovs id SffName sffName = sf.getSfDataPlaneLocator().get(0).getServiceFunctionForwarder(); String sffNodeId = null; sffNodeId = getSffOpenFlowNodeName(sffName); if (sffNodeId == null) { LOG.warn("failed to find switch configuration: sffName: {}- \naborting", sffName); return; } ServiceFunctionGroupAlgorithm algorithm = SfcProviderServiceFunctionGroupAlgAPI.readServiceFunctionGroupAlg(sfg.getAlgorithm()); List<GroupBucketInfo> bucketsInfo = new ArrayList<GroupBucketInfo>(); ServiceFunctionForwarder sff = SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sffName); int index = 0; for (SfcServiceFunction sfcServiceFunction : sfg.getSfcServiceFunction()) { sfName = new SfName(sfcServiceFunction.getName()); sf = SfcProviderServiceFunctionAPI.readServiceFunction(sfName); ServiceFunctionDictionary sffSfDict = sfcL2ProviderUtils.getSffSfDictionary(sff, sfName); String outPort = sfcL2ProviderUtils.getDictPortInfoPort(sff, sffSfDict); bucketsInfo.add(buildBucket(sf, outPort, index)); index++; } this.sfcL2FlowProgrammer.configureGroup( sffName.getValue(), sffNodeId, sfg.getName(), sfg.getGroupId(), algorithm.getAlgorithmType().getIntValue(), bucketsInfo, isAdd); } catch (Exception e) { LOG.warn("Failed generating group " + sfg, e); } }
public static List<String> getSfgNameList(ServiceFunctionChain serviceFunctionChain) { List<String> ret = new ArrayList<>(); List<SfcServiceFunction> sfcServiceFunction = serviceFunctionChain.getSfcServiceFunction(); LOG.debug( "searching groups for chain {} which has the elements {}", serviceFunctionChain.getName(), serviceFunctionChain.getSfcServiceFunction()); if (sfcServiceFunction != null) { for (SfcServiceFunction sf : sfcServiceFunction) { ServiceFunctionGroup sfg = SfcProviderServiceFunctionGroupAPI.getServiceFunctionGroupByType(sf.getType()); LOG.debug("look for service function group of type {} and found {}", sf.getType(), sfg); if (sfg != null) { ret.add(sfg.getName()); } else { return null; } } } return ret; }
/** * Puts a SFG in the datastore * * <p> * * @param sfg the ServiceFunctionGroup to put * @return boolean success or failure */ public static boolean putServiceFunctionGroup(ServiceFunctionGroup sfg) { boolean ret; printTraceStart(LOG); InstanceIdentifier<ServiceFunctionGroup> sfgEntryIID = InstanceIdentifier.builder(ServiceFunctionGroups.class) .child(ServiceFunctionGroup.class, sfg.getKey()) .build(); ret = SfcDataStoreAPI.writePutTransactionAPI( sfgEntryIID, sfg, LogicalDatastoreType.CONFIGURATION); printTraceStop(LOG); return ret; }