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.Parameter.IsRequired;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.Type;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.ParameterBuilder;
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 {
36 * Protocol parameter name
38 public static final String PROTO_PARAM = "proto";
42 public static final Long TCP_VALUE = Long.valueOf(6);
46 public static final Long UDP_VALUE = Long.valueOf(17);
50 public static final Long ICMP_VALUE = Long.valueOf(1);
54 public static final Long SCTP_VALUE = Long.valueOf(132);
56 protected static final ClassifierDefinitionId ID = new ClassifierDefinitionId(
57 "79c6fdb2-1e1a-4832-af57-c65baf5c2335");
59 * Protocol classifier-definition
61 public static final ClassifierDefinition DEFINITION = new ClassifierDefinitionBuilder().setId(ID)
62 .setParent(EtherTypeClassifier.ID)
63 .setName(new ClassifierName("ip_proto"))
64 .setDescription(new Description("Match on the IP protocol of IP traffic"))
66 ImmutableList.of(new ParameterBuilder().setName(new ParameterName(PROTO_PARAM))
67 .setDescription(new Description("The IP protocol to match against"))
68 .setIsRequired(IsRequired.Required)
73 protected IpProtoClassifier(Classifier parent) {
78 public ClassifierDefinitionId getId() {
83 public ClassifierDefinition getClassDef() {
88 protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
89 if (params.get(PROTO_PARAM) == null) {
90 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
91 + "}+ Parameter proto not present.");
93 if (params.get(PROTO_PARAM).getIntValue() == null) {
94 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
95 + "}+ Value of proto parameter is not present.");
100 protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
101 Long proto = params.get(PROTO_PARAM).getIntValue();
102 for (MatchBuilder match : matches) {
104 if (match.getIpMatch() != null) {
105 equalOrNotSetValidation(match.getIpMatch().getIpProtocol(), proto);
108 imb = new IpMatchBuilder();
110 imb.setIpProtocol(proto.shortValue());
111 match.setIpMatch(imb.build());
116 private void equalOrNotSetValidation(Short protoInMatch, long paramValue) {
117 if (protoInMatch != null) {
118 if (paramValue != protoInMatch.longValue()) {
119 throw new IllegalArgumentException("Classification conflict at " + this.getClassDef().getName()
120 + ": Trying to override proto value: " + protoInMatch.shortValue() + " by value " + paramValue);
126 protected void checkPrereqs(List<MatchBuilder> matches) {
127 for (MatchBuilder match : matches) {
128 Long readEthType = null;
130 readEthType = match.getEthernetMatch().getEthernetType().getType().getValue();
131 } catch (NullPointerException e) {
132 throw new IllegalArgumentException("Ether-type match is missing.");
134 if (!FlowUtils.IPv4.equals(readEthType) && !FlowUtils.IPv6.equals(readEthType)) {
135 throw new IllegalArgumentException("Ether-type value should be " + FlowUtils.IPv4 + " or "
136 + FlowUtils.IPv6 + ".");
144 public static Long getIpProtoValue(Map<String, ParameterValue> params) {
145 if (params == null) {
148 if (params.get(PROTO_PARAM) == null) {
151 Long proto = params.get(PROTO_PARAM).getIntValue();