/** * Return the IpProtocol value. May return null. * * @param params the parameters of classifier-instance inserted by user * @return the IpProtocol value */ public static Long getIpProtoValue(Map<String, ParameterValue> params) { if (params == null) { return null; } if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) { return null; } Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue(); if (proto != null) { return proto; } return null; } }
private static boolean isSrcOrDstPortParam(ParameterValue pv) { String pvName = pv.getName().getValue(); return pv.getIntValue() != null && (pvName.equals(L4ClassifierDefinition.SRC_PORT_PARAM) || pvName.equals(L4ClassifierDefinition.DST_PORT_PARAM)); }
private static boolean isRangePortParam(ParameterValue pv) { String pvName = pv.getName().getValue(); return pv.getRangeValue() != null && (pvName.equals(L4ClassifierDefinition.SRC_PORT_RANGE_PARAM) || pvName.equals(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)); }
private static List<ParameterValue> createParams(long etherType, long proto, @Nullable Long srcPort, @Nullable Long dstPort) { List<ParameterValue> params = new ArrayList<>(); if (srcPort != null) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.SRC_PORT_PARAM)) .setIntValue(srcPort) .build()); } if (dstPort != null) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(dstPort) .build()); } params.add(new ParameterValueBuilder().setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(proto) .build()); params.add(new ParameterValueBuilder().setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(etherType) .build()); return params; } }
private void addToPortSet(Map<String, ParameterValue> params, String portParam, String portRangeParam, Set<Long> portSet) { if (params.get(portParam) != null) { portSet.add(params.get(portParam).getIntValue()); } else if (params.get(portRangeParam) != null) { portSet.addAll(createSetFromRange(params.get(portRangeParam).getRangeValue())); } }
private ParameterValue getChainNameParameter(List<ParameterValue> paramValueList) { if (paramValueList == null) return null; for (ParameterValue pv : paramValueList) { if (pv.getName().getValue().equals(ChainActionDefinition.SFC_CHAIN_NAME)) { return pv; } } return null; }
private void validateRange(Map<String, ParameterValue> params, String portRangeParam) { if (params.get(portRangeParam) != null) { validateRangeValue(params.get(portRangeParam).getRangeValue()); } }
private void deleteSfcRsp() { ParameterValue pv = getChainNameParameter(originalInstance.getParameterValue()); if (pv == null) return; rspMap.remove(pv.getStringValue()); }
@Override protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) { if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) { throw new IllegalArgumentException( "Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " not specified."); } if (params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue() == null) { throw new IllegalArgumentException( "Value of " + IpProtoClassifierDefinition.PROTO_PARAM + " parameter is not present."); } }
private static ParameterValue getParamVal(List<ParameterValue> parametersAndValues, String paramName) { for (ParameterValue paramVal : parametersAndValues) { if (paramName.equals(paramVal.getName().getValue())) { return paramVal; } } return null; }
private void changeSfcRsp() { ParameterValue newPv = getChainNameParameter(actionInstance.getParameterValue()); ParameterValue origPv = getChainNameParameter(originalInstance.getParameterValue()); if (!newPv.getStringValue().equals(origPv.getStringValue())) { if (rspMap.containsKey(origPv.getStringValue())) { /* * Flow cleanup will happen as part of the * resolved policy * * TODO: can we guarantee that this * happens after we remove the RSP?). */ rspMap.remove(origPv.getStringValue()); } addSfcRsp(); } }
/** * Return the IpProtocol value. May return null. * * @param params the parameters of classifier-instance inserted by user * @return the IpProtocol value */ public static Long getIpProtoValue(Map<String, ParameterValue> params) { if (params == null) { return null; } if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) { return null; } Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue(); if (proto != null) { return proto; } return null; } }
private ParameterValue getChainNameParameter(List<ParameterValue> pvl) { if (pvl == null) return null; for (ParameterValue pv: actionInstance.getParameterValue()) { if (pv.getName().getValue().equals(SFC_CHAIN_NAME)) { return pv; } } return null; }
private ValidationResult isValidGbpChain(List<ParameterValue> paramValue) { ParameterValue pv = getChainNameParameter(paramValue); if (pv == null) { return new ValidationResultBuilder().failed().setMessage( "Chain parameter {" + paramValue + "} not found!").build(); } SfcName sfcName = new SfcName(pv.getStringValue()); LOG.trace("isValidGbpChain: Invoking RPC for chain {}", pv.getStringValue()); ServiceFunctionChain chain = SfcProviderServiceChainAPI.readServiceFunctionChain(sfcName); if (chain != null){ return new ValidationResultBuilder().success().build(); } else { return new ValidationResultBuilder().failed().setMessage( "Chain named {" + pv.getStringValue() + "} not found in config DS.").build(); } }
@Override protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) { if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) { throw new IllegalArgumentException( "Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " " + MSG_NOT_SPECIFIED); } if (params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue() == null) { throw new IllegalArgumentException( "Value of " + IpProtoClassifierDefinition.PROTO_PARAM + " " + MSG_PARAMETER_IS_NOT_PRESENT); } }
@Override protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) { if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM) == null) { throw new IllegalArgumentException( "Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " " + MSG_NOT_SPECIFIED); } if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM).getIntValue() == null) { throw new IllegalArgumentException( "Value of " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " " + MSG_PARAMETER_IS_NOT_PRESENT); } }
@Override protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) { if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM) == null) { throw new IllegalArgumentException( "Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " not specified."); } if (params.get(EtherTypeClassifierDefinition.ETHERTYPE_PARAM).getIntValue() == null) { throw new IllegalArgumentException( "Value of " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM + " parameter is not present."); } } }
private void validatePortParam(Map<String, ParameterValue> params, String portParam, String portRangeParam) { if (params.get(portParam) != null) { StringBuilder paramLog = new StringBuilder(); if (params.get(portParam).getIntValue() == null) { paramLog.append("Value of ").append(portParam).append(" parameter " + MSG_NOT_SPECIFIED); throw new IllegalArgumentException(paramLog.toString()); } if (params.get(portRangeParam) != null) { paramLog.append("Source port parameters ") .append(portParam) .append(" and ") .append(portRangeParam) .append(" are " + MSG_MUTUALLY_EXCLUSIVE); throw new IllegalArgumentException(paramLog.toString()); } } }
private static boolean addL4InfoToFlowCache(Classifier classifier, FlowCacheDefinitionBuilder fcdBuilder) { List<ParameterValue> parametersAndValues = classifier.getParameterValue(); ParameterValue ipProtoParam = getParamVal(parametersAndValues, IpProtoClassifierDefinition.PROTO_PARAM); ParameterValue dstPortParam = getParamVal(parametersAndValues, L4ClassifierDefinition.DST_PORT_PARAM); ParameterValue srcPortParam = getParamVal(parametersAndValues, L4ClassifierDefinition.SRC_PORT_PARAM); if (ipProtoParam == null || (dstPortParam == null && srcPortParam == null)) { LOG.trace( "Cannot add L4 information to flow cache for Sflow-RT." + "\nipProtoParam:{} dstPortParam:{} srcPortParam:{}", ipProtoParam, dstPortParam, srcPortParam); return false; } if (dstPortParam != null) { if (!addTcpUdpPortKeys(ipProtoParam.getIntValue(), dstPortParam.getIntValue(), true, fcdBuilder)) { return false; } } if (srcPortParam != null) { if (!addTcpUdpPortKeys(ipProtoParam.getIntValue(), srcPortParam.getIntValue(), false, fcdBuilder)) { return false; } } return true; }
private static boolean addIpProtoInfoToFlowCache(Classifier classifier, FlowCacheDefinitionBuilder fcdBuilder) { List<ParameterValue> parametersAndValues = classifier.getParameterValue(); ParameterValue ipProtoParam = getParamVal(parametersAndValues, IpProtoClassifierDefinition.PROTO_PARAM); if (ipProtoParam != null) { fcdBuilder.getKeysBuilder().addValue(FlowCacheCons.Key.IP_PROTOCOL.get()); fcdBuilder.getFilterBuilder() .addValue(FlowCacheCons.Key.IP_PROTOCOL.get() + FlowCacheCons.EQ + ipProtoParam.getIntValue()); return true; } else { LOG.trace("Cannot add ip-proto information to flow cache for Sflow-RT."); return false; } }