Merge "Bug 499: Added support for old DOM Broker APIs."
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / match / extensible / DlType.java
1 package org.opendaylight.controller.sal.match.extensible;
2
3 import javax.xml.bind.annotation.XmlAccessType;
4 import javax.xml.bind.annotation.XmlAccessorType;
5 import javax.xml.bind.annotation.XmlElement;
6 import javax.xml.bind.annotation.XmlRootElement;
7
8 import org.opendaylight.controller.sal.utils.EtherTypes;
9 import org.opendaylight.controller.sal.utils.NetUtils;
10
11 @XmlRootElement
12 @XmlAccessorType(XmlAccessType.NONE)
13 public class DlType extends MatchField<Short> {
14     private static final long serialVersionUID = 1L;
15     public static final String TYPE = "DL_TYPE";
16     private short ethertype;
17
18     /**
19      * Creates a Match field for the data layer type
20      *
21      * @param address
22      *            the data layer type
23      */
24     public DlType(short ethertype) {
25         super(TYPE);
26         this.ethertype = ethertype;
27     }
28
29     // To satisfy JAXB
30     private DlType() {
31         super(TYPE);
32     }
33
34     @Override
35     public Short getValue() {
36         return ethertype;
37     }
38
39     @Override
40     @XmlElement(name = "value")
41     protected String getValueString() {
42         return String.format("0X%s", Integer.toHexString(NetUtils.getUnsignedShort(ethertype)));
43     }
44
45     @Override
46     public Short getMask() {
47         return null;
48     }
49
50     @Override
51     protected String getMaskString() {
52         return null;
53     }
54
55     @Override
56     public boolean isValid() {
57         return true;
58     }
59
60     @Override
61     public boolean hasReverse() {
62         return false;
63     }
64
65     @Override
66     public DlType getReverse() {
67         return this.clone();
68     }
69
70     @Override
71     public DlType clone() {
72         return new DlType(ethertype);
73     }
74
75     @Override
76     public boolean isV6() {
77         return this.ethertype == EtherTypes.IPv6.shortValue();
78     }
79
80     @Override
81     public int hashCode() {
82         final int prime = 31;
83         int result = 1;
84         result = prime * result + ethertype;
85         return result;
86     }
87
88     @Override
89     public boolean equals(Object obj) {
90         if (this == obj) {
91             return true;
92         }
93         if (obj == null) {
94             return false;
95         }
96         if (!(obj instanceof DlType)) {
97             return false;
98         }
99         DlType other = (DlType) obj;
100         if (ethertype != other.ethertype) {
101             return false;
102         }
103         return true;
104     }
105 }