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.sf.classifiers.IpProtoClassifierDefinition;
15 import org.opendaylight.groupbasedpolicy.sf.classifiers.EtherTypeClassifierDefinition;
16 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
24 * Match on the IP protocol of IP traffic
26 public class IpProtoClassifier extends Classifier {
28 protected IpProtoClassifier(Classifier parent) {
33 public ClassifierDefinitionId getId() {
34 return IpProtoClassifierDefinition.ID;
38 public ClassifierDefinition getClassDef() {
39 return IpProtoClassifierDefinition.DEFINITION;
43 protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
44 if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) {
45 throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM
48 if (params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue() == null) {
49 throw new IllegalArgumentException("Value of " + IpProtoClassifierDefinition.PROTO_PARAM
50 + " parameter is not present.");
55 protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
56 Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue();
57 for (MatchBuilder match : matches) {
59 if (match.getIpMatch() != null) {
60 equalOrNotSetValidation(match.getIpMatch().getIpProtocol(), proto);
63 imb = new IpMatchBuilder();
65 imb.setIpProtocol(proto.shortValue());
66 match.setIpMatch(imb.build());
71 private void equalOrNotSetValidation(Short protoInMatch, long paramValue) {
72 if (protoInMatch != null) {
73 if (paramValue != protoInMatch.longValue()) {
74 throw new IllegalArgumentException("Classification conflict detected at " + IpProtoClassifierDefinition.PROTO_PARAM
75 + " parameter for values " + protoInMatch.shortValue() + " and " + paramValue
76 + ". It is not allowed "
77 + "to assign different values to the same parameter among all the classifiers within one rule.");
83 protected void checkPrereqs(List<MatchBuilder> matches) {
84 for (MatchBuilder match : matches) {
85 Long readEthType = null;
87 readEthType = match.getEthernetMatch().getEthernetType().getType().getValue();
88 } catch (NullPointerException e) {
89 throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
92 if (!FlowUtils.IPv4.equals(readEthType) && !FlowUtils.IPv6.equals(readEthType)) {
93 throw new IllegalArgumentException("Parameter " + EtherTypeClassifierDefinition.ETHERTYPE_PARAM
94 + " must have value " + FlowUtils.IPv4 + " or " + FlowUtils.IPv6 + ".");
100 * Return the IpProtocol value. May return null.
101 * @param params the parameters of classifier-instance inserted by user
102 * @return the IpProtocol value
104 public static Long getIpProtoValue(Map<String, ParameterValue> params) {
105 if (params == null) {
108 if (params.get(IpProtoClassifierDefinition.PROTO_PARAM) == null) {
111 Long proto = params.get(IpProtoClassifierDefinition.PROTO_PARAM).getIntValue();