Merge "Add filtering capability to config.ini in order to reference logging bridge...
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / match / extensible / MatchField.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.sal.match.extensible;
10
11 import java.io.Serializable;
12
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;
17
18 /**
19  * Represents the generic matching field object
20  */
21 @XmlRootElement
22 @XmlAccessorType(XmlAccessType.NONE)
23 public abstract class MatchField<T> implements Cloneable, Serializable {
24     private static final long serialVersionUID = 1L;
25     private String type;
26
27     // To satisfy JAXB
28     @SuppressWarnings("unused")
29     private MatchField() {
30     }
31
32     public MatchField(String type) {
33         this.type = type;
34     }
35
36     @XmlElement(name = "type")
37     public String getType() {
38         return type;
39     }
40
41     /**
42      * Returns the value set for this match field
43      *
44      * @return
45      */
46     public abstract T getValue();
47
48     @XmlElement(name = "value")
49     protected abstract String getValueString();
50
51     /**
52      * Returns the mask value set for this field match A null mask means this is
53      * a full match
54      *
55      * @return
56      */
57     public abstract T getMask();
58
59     @XmlElement(name = "mask")
60     protected abstract String getMaskString();
61
62     /**
63      * Returns whether the field match configuration is valid or not
64      *
65      * @return true if valid, false otherwise
66      */
67     public abstract boolean isValid();
68
69     public abstract boolean hasReverse();
70
71     /**
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
75      * returned
76      *
77      * @return the correspondent reverse MatchField object or a copy of this
78      *         object if the field is not reversable
79      */
80     public abstract MatchField<T> getReverse();
81
82     /**
83      * Returns whether the match field is congruent with IPv6 frames
84      *
85      * @return true if congruent with IPv6 frames
86      */
87     public abstract boolean isV6();
88
89     @Override
90     public abstract MatchField<T> clone();
91
92     @Override
93     public int hashCode() {
94         final int prime = 31;
95         int result = 1;
96         result = prime * result + ((type == null) ? 0 : type.hashCode());
97         return result;
98     }
99
100     @Override
101     public boolean equals(Object obj) {
102         if (this == obj) {
103             return true;
104         }
105         if (obj == null) {
106             return false;
107         }
108         if (!(obj instanceof MatchField)) {
109             return false;
110         }
111         MatchField<?> other = (MatchField<?>) obj;
112         if (type == null) {
113             if (other.type != null) {
114                 return false;
115             }
116         } else if (!type.equals(other.type)) {
117             return false;
118         }
119         return true;
120     }
121
122     @Override
123     public String toString() {
124         return (getMask() == null) ? String.format("%s(%s)", getType(), getValueString()) :
125             String.format("%s(%s,%s)", getType(), getValueString(), getMaskString());
126     }
127
128 }