2 * Copyright (c) 2013 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.controller.sal.match.extensible;
11 import java.io.Serializable;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
19 * Represents the generic matching field object
22 @XmlAccessorType(XmlAccessType.NONE)
24 public abstract class MatchField<T> implements Cloneable, Serializable {
25 private static final long serialVersionUID = 1L;
29 @SuppressWarnings("unused")
30 private MatchField() {
33 public MatchField(String type) {
37 @XmlElement(name = "type")
38 public String getType() {
43 * Returns the value set for this match field
47 public abstract T getValue();
49 @XmlElement(name = "value")
50 protected abstract String getValueString();
53 * Returns the mask value set for this field match A null mask means this is
58 public abstract T getMask();
60 @XmlElement(name = "mask")
61 protected abstract String getMaskString();
64 * Returns whether the field match configuration is valid or not
66 * @return true if valid, false otherwise
68 public abstract boolean isValid();
70 public abstract boolean hasReverse();
73 * Returns the reverse match field. For example for a MatchField matching on
74 * source ip 1.1.1.1 it will return a MatchField matching on destination IP
75 * 1.1.1.1. For not reversable MatchField, a copy of this MatchField will be
78 * @return the correspondent reverse MatchField object or a copy of this
79 * object if the field is not reversable
81 public abstract MatchField<T> getReverse();
84 * Returns whether the match field is congruent with IPv6 frames
86 * @return true if congruent with IPv6 frames
88 public abstract boolean isV6();
91 public abstract MatchField<T> clone();
94 public int hashCode() {
97 result = prime * result + ((type == null) ? 0 : type.hashCode());
102 public boolean equals(Object obj) {
109 if (!(obj instanceof MatchField)) {
112 MatchField<?> other = (MatchField<?>) obj;
114 if (other.type != null) {
117 } else if (!type.equals(other.type)) {
124 public String toString() {
125 return (getMask() == null) ? String.format("%s(%s)", getType(), getValueString()) :
126 String.format("%s(%s,%s)", getType(), getValueString(), getMaskString());