import java.util.List;
import java.util.Map;
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.groupbasedpolicy.sf.classifiers.IpProtoClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.sf.classifiers.EtherTypeClassifierDefinition;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.IsRequired;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.Type;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.ParameterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.has.parameters.type.parameter.type.IntBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.capabilities.supported.classifier.definition.SupportedParameterValuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.supported._int.value.fields.SupportedIntValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.supported._int.value.fields.SupportedIntValueBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
-import com.google.common.collect.ImmutableList;
-
/**
* Match on the IP protocol of IP traffic
*/
public class IpProtoClassifier extends Classifier {
- /**
- * Protocol parameter name
- */
- public static final String PROTO_PARAM = "proto";
- /**
- * TCP protocol value
- */
- public static final Long TCP_VALUE = Long.valueOf(6);
- /**
- * UDP protocol value
- */
- public static final Long UDP_VALUE = Long.valueOf(17);
- /**
- * ICMP protocol value
- */
- public static final Long ICMP_VALUE = Long.valueOf(1);
- /**
- * SCTP protocol value
- */
- public static final Long SCTP_VALUE = Long.valueOf(132);
-
- protected static final ClassifierDefinitionId ID = new ClassifierDefinitionId(
- "79c6fdb2-1e1a-4832-af57-c65baf5c2335");
- /**
- * Protocol classifier-definition
- */
- public static final ClassifierDefinition DEFINITION = new ClassifierDefinitionBuilder().setId(ID)
- .setParent(EtherTypeClassifier.ID)
- .setName(new ClassifierName("ip_proto"))
- .setDescription(new Description("Match on the IP protocol of IP traffic"))
- .setParameter(
- ImmutableList.of(new ParameterBuilder().setName(new ParameterName(PROTO_PARAM))
- .setDescription(new Description("The IP protocol to match against"))
- .setIsRequired(IsRequired.Required)
- .setType(Type.Int)
- .build()))
- .build();
-
protected IpProtoClassifier(Classifier parent) {
super(parent);
}
@Override
public ClassifierDefinitionId getId() {
- return ID;
+ return IpProtoClassifierDefinition.ID;
}
@Override
- public ClassifierDefinition getClassDef() {
- return DEFINITION;
+ public ClassifierDefinition getClassifierDefinition() {
+ return IpProtoClassifierDefinition.DEFINITION;
+ }
+
+ @Override
+ public List<SupportedParameterValues> getSupportedParameterValues() {
+
+ List<SupportedIntValue> values = ImmutableList.of(
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.ICMP_VALUE)
+ .build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.SCTP_VALUE)
+ .build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.TCP_VALUE)
+ .build(),
+ new SupportedIntValueBuilder().setValue(IpProtoClassifierDefinition.UDP_VALUE)
+ .build());
+ SupportedParameterValuesBuilder b = new SupportedParameterValuesBuilder();
+ b.setParameterName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM));
+ b.setParameterType(new IntBuilder().setSupportedIntValue(values).build());
+
+ return ImmutableList.of(b.build());
}
@Override
protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
- if (params.get(PROTO_PARAM) == null) {
- throw new IllegalArgumentException("Parameter " + PROTO_PARAM + " not specified.");
+ if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) {
+ throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM
+ + " not specified.");
}
- if (params.get(PROTO_PARAM).getIntValue() == null) {
- throw new IllegalArgumentException("Value of " + PROTO_PARAM + " parameter is not present.");
+ if (params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue() == null) {
+ throw new IllegalArgumentException("Value of " + IpProtoClassifierDefinition.PROTO_PARAM
+ + " parameter is not present.");
}
}
@Override
protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
- Long proto = params.get(PROTO_PARAM).getIntValue();
+ Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue();
for (MatchBuilder match : matches) {
IpMatchBuilder imb;
if (match.getIpMatch() != null) {
private void equalOrNotSetValidation(Short protoInMatch, long paramValue) {
if (protoInMatch != null) {
if (paramValue != protoInMatch.longValue()) {
- throw new IllegalArgumentException("Classification conflict detected at " + PROTO_PARAM
+ throw new IllegalArgumentException("Classification conflict detected at " + IpProtoClassifierDefinition.PROTO_PARAM
+ " parameter for values " + protoInMatch.shortValue() + " and " + paramValue
+ ". It is not allowed "
+ "to assign different values to the same parameter among all the classifiers within one rule.");
try {
readEthType = match.getEthernetMatch().getEthernetType().getType().getValue();
} catch (NullPointerException e) {
- throw new IllegalArgumentException("Parameter " + EtherTypeClassifier.ETHERTYPE_PARAM + " is missing.");
+ throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
+ + " is missing.");
}
if (!FlowUtils.IPv4.equals(readEthType) && !FlowUtils.IPv6.equals(readEthType)) {
- throw new IllegalArgumentException("Parameter " + EtherTypeClassifier.ETHERTYPE_PARAM + " must have value "
- + FlowUtils.IPv4 + " or " + FlowUtils.IPv6 + ".");
+ throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
+ + " must have value " + FlowUtils.IPv4 + " or " + FlowUtils.IPv6 + ".");
}
}
}
if (params == null) {
return null;
}
- if (params.get(PROTO_PARAM) == null) {
+ if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) {
return null;
}
- Long proto = params.get(PROTO_PARAM).getIntValue();
+ Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue();
if (proto != null) {
return proto;
}