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.ParameterBuilder;
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.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 {
37 public static final ClassifierDefinitionId ID = new ClassifierDefinitionId("6a48ab45-a462-429d-b18c-3a575b2c8bef");
38 public static final String ETHER_TYPE = "ethertype";
39 protected static final ClassifierDefinition DEF = new ClassifierDefinitionBuilder().setId(ID)
40 .setName(new ClassifierName("ether_type"))
41 .setDescription(new Description("Match on the ether type of the traffic"))
43 ImmutableList.of(new ParameterBuilder().setName(new ParameterName(ETHER_TYPE))
44 .setDescription(new Description("The ethertype to match against"))
45 .setIsRequired(IsRequired.Required)
50 protected EtherTypeClassifier(Classifier parent) {
55 public ClassifierDefinitionId getId() {
60 public ClassifierDefinition getClassDef() {
65 protected void checkPresenceOfRequiredParams(Map<String, ParameterValue> params) {
66 if (params.get(ETHER_TYPE) == null) {
67 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
68 + "}+ Parameter ethertype not present.");
70 if (params.get(ETHER_TYPE).getIntValue() == null) {
71 throw new IllegalArgumentException("Classifier: {" + this.getClassDef().getName()
72 + "}+ Value of ethertype parameter is not present.");
77 protected List<MatchBuilder> update(List<MatchBuilder> matches, Map<String, ParameterValue> params) {
78 Long type = params.get(ETHER_TYPE).getIntValue();
79 for (MatchBuilder match : matches) {
80 EthernetMatchBuilder em;
81 if (match.getEthernetMatch() != null) {
82 equalOrNotSetValidation(match.getEthernetMatch().getEthernetType(), type);
85 em = new EthernetMatchBuilder();
87 em.setEthernetType(new EthernetTypeBuilder().setType(new EtherType(type)).build());
88 match.setEthernetMatch(em.build());
93 private void equalOrNotSetValidation(EthernetType ethTypeInMatch, long paramValue) {
94 if (ethTypeInMatch != null) {
95 if (paramValue != ethTypeInMatch.getType().getValue().longValue()) {
96 throw new IllegalArgumentException("Classification conflict at " + this.getClassDef().getName()
97 + ": Trying to override ether-type value: " + ethTypeInMatch.getType().getValue()
98 + " by value " + paramValue);
104 protected void checkPrereqs(List<MatchBuilder> matches) {
105 // So far EthType has no prereqs.