2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
11 import java.util.List;
14 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.ParameterBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.IsRequired;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.Type;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
28 import com.google.common.collect.ImmutableList;
31 * Match on the IP protocol of IP traffic
33 public class IpProtoClassifier extends Classifier {
35 public static final Long TCP = Long.valueOf(6);
36 public static final Long UDP = Long.valueOf(17);
37 public static final Long SCTP = Long.valueOf(132);
38 public static final String PROTO = "proto";
39 public static final ClassifierDefinitionId ID = new ClassifierDefinitionId("79c6fdb2-1e1a-4832-af57-c65baf5c2335");
40 protected static final ClassifierDefinition DEF = new ClassifierDefinitionBuilder().setId(ID)
41 .setParent(EtherTypeClassifier.ID)
42 .setName(new ClassifierName("ip_proto"))
43 .setDescription(new Description("Match on the IP protocol of IP traffic"))
45 ImmutableList.of(new ParameterBuilder().setName(new ParameterName(PROTO))
46 .setDescription(new Description("The IP protocol to match against"))
47 .setIsRequired(IsRequired.Required)
52 protected IpProtoClassifier(Classifier parent) {
57 public ClassifierDefinitionId getId() {
62 public ClassifierDefinition getClassDef() {
67 protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
68 if (params.get(PROTO) == null) {
69 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
70 + "}+ Parameter proto not present.");
72 if (params.get(PROTO).getIntValue() == null) {
73 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
74 + "}+ Value of proto parameter is not present.");
79 protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
80 Long proto = params.get(PROTO).getIntValue();
81 for (MatchBuilder match : matches) {
83 if (match.getIpMatch() != null) {
84 equalOrNotSetValidation(match.getIpMatch().getIpProtocol(), proto);
87 imb = new IpMatchBuilder();
89 imb.setIpProtocol(proto.shortValue());
90 match.setIpMatch(imb.build());
95 private void equalOrNotSetValidation(Short protoInMatch, long paramValue) {
96 if (protoInMatch != null) {
97 if (paramValue != protoInMatch.longValue()) {
98 throw new IllegalArgumentException("Classification conflict at " + this.getClassDef().getName()
99 + ": Trying to override proto value: " + protoInMatch.shortValue() + " by value " + paramValue);
105 protected void checkPrereqs(List<MatchBuilder> matches) {
106 for (MatchBuilder match : matches) {
107 Long readEthType = null;
109 readEthType = match.getEthernetMatch().getEthernetType().getType().getValue();
110 } catch (NullPointerException e) {
111 throw new IllegalArgumentException("Ether-type match is missing.");
113 if (!FlowUtils.IPv4.equals(readEthType) && !FlowUtils.IPv6.equals(readEthType)) {
114 throw new IllegalArgumentException("Ether-type value should be " + FlowUtils.IPv4 + " or "
115 + FlowUtils.IPv6 + ".");
123 public static Long getIpProtoValue(Map<String, ParameterValue> params) {
124 if (params == null) {
127 if (params.get(PROTO) == null) {
130 Long proto = params.get(PROTO).getIntValue();