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.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierDefinitionId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ClassifierName;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ParameterName;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.IsRequired;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.Parameter.Type;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definition.ParameterBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinition;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.definitions.ClassifierDefinitionBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
30 import com.google.common.collect.ImmutableList;
33 * Match on the ether type of the traffic
35 public class EtherTypeClassifier extends Classifier {
38 * Ethertype parameter name
40 public static final String ETHERTYPE_PARAM = "ethertype";
44 public static final Long ARP_VALUE = Long.valueOf(0x0806);
46 * IPv4 ethertype value
48 public static final Long IPv4_VALUE = Long.valueOf(0x0800);
50 * IPv6 ethertype value
52 public static final Long IPv6_VALUE = Long.valueOf(0x86DD);
54 protected static final ClassifierDefinitionId ID = new ClassifierDefinitionId(
55 "6a48ab45-a462-429d-b18c-3a575b2c8bef");
57 * Ethertype classifier-definition
59 public static final ClassifierDefinition DEFINITION = new ClassifierDefinitionBuilder().setId(ID)
60 .setName(new ClassifierName("ether_type"))
61 .setDescription(new Description("Match on the ether type of the traffic"))
63 ImmutableList.of(new ParameterBuilder().setName(new ParameterName(ETHERTYPE_PARAM))
64 .setDescription(new Description("The ethertype to match against"))
65 .setIsRequired(IsRequired.Required)
70 protected EtherTypeClassifier(Classifier parent) {
75 public ClassifierDefinitionId getId() {
80 public ClassifierDefinition getClassDef() {
85 protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
86 if (params.get(ETHERTYPE_PARAM) == null) {
87 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
88 + "}+ Parameter ethertype not present.");
90 if (params.get(ETHERTYPE_PARAM).getIntValue() == null) {
91 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
92 + "}+ Value of ethertype parameter is not present.");
97 protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
98 Long type = params.get(ETHERTYPE_PARAM).getIntValue();
99 for (MatchBuilder match : matches) {
100 EthernetMatchBuilder em;
101 if (match.getEthernetMatch() != null) {
102 equalOrNotSetValidation(match.getEthernetMatch().getEthernetType(), type);
105 em = new EthernetMatchBuilder();
107 em.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(type)).build());
108 match.setEthernetMatch(em.build());
113 private void equalOrNotSetValidation(EthernetType ethTypeInMatch, long paramValue) {
114 if (ethTypeInMatch != null) {
115 if (paramValue != ethTypeInMatch.getType().getValue().longValue()) {
116 throw new IllegalArgumentException("Classification conflict at " + this.getClassDef().getName()
117 + ": Trying to override ether-type value: " + ethTypeInMatch.getType().getValue()
118 + " by value " + paramValue);
124 protected void checkPrereqs(List<MatchBuilder> matches) {
125 // So far EthType has no prereqs.