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)
23 public abstract class MatchField<T> implements Cloneable, Serializable {
24 private static final long serialVersionUID = 1L;
28 @SuppressWarnings("unused")
29 private MatchField() {
32 public MatchField(String type) {
36 @XmlElement(name = "type")
37 public String getType() {
42 * Returns the value set for this match field
46 public abstract T getValue();
48 @XmlElement(name = "value")
49 protected abstract String getValueString();
52 * Returns the mask value set for this field match A null mask means this is
57 public abstract T getMask();
59 @XmlElement(name = "mask")
60 protected abstract String getMaskString();
63 * Returns whether the field match configuration is valid or not
65 * @return true if valid, false otherwise
67 public abstract boolean isValid();
69 public abstract boolean hasReverse();
72 * Returns the reverse match field. For example for a MatchField matching on
73 * source ip 1.1.1.1 it will return a MatchField matching on destination IP
74 * 1.1.1.1. For not reversable MatchField, a copy of this MatchField will be
77 * @return the correspondent reverse MatchField object or a copy of this
78 * object if the field is not reversable
80 public abstract MatchField<T> getReverse();
83 * Returns whether the match field is congruent with IPv6 frames
85 * @return true if congruent with IPv6 frames
87 public abstract boolean isV6();
90 public abstract MatchField<T> clone();
93 public int hashCode() {
96 result = prime * result + ((type == null) ? 0 : type.hashCode());
101 public boolean equals(Object obj) {
108 if (!(obj instanceof MatchField)) {
111 MatchField<?> other = (MatchField<?>) obj;
113 if (other.type != null) {
116 } else if (!type.equals(other.type)) {
123 public String toString() {
124 return (getMask() == null) ? String.format("%s(%s)", getType(), getValueString()) :
125 String.format("%s(%s,%s)", getType(), getValueString(), getMaskString());