Move adsal into its own subdirectory.
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / match / extensible / NwTos.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.NetUtils;
9
10 @XmlRootElement
11 @XmlAccessorType(XmlAccessType.NONE)
12 public class NwTos extends MatchField<Byte> {
13     private static final long serialVersionUID = 1L;
14     public static final String TYPE = "NW_TOS";
15     private static final short MAX = 63;
16     private byte tos;
17
18     /**
19      * Creates a Match field for the network TOS
20      *
21      * @param address
22      *            the network TOS
23      */
24     public NwTos(byte tos) {
25         super(TYPE);
26         this.tos = tos;
27     }
28
29     public NwTos(int tos) {
30         super(TYPE);
31         this.tos = (byte) tos;
32     }
33
34     public NwTos(short tos) {
35         super(TYPE);
36         this.tos = (byte) tos;
37     }
38
39     // To satisfy JAXB
40     private NwTos() {
41         super(TYPE);
42     }
43
44     @Override
45     public Byte getValue() {
46         return tos;
47     }
48
49     @Override
50     @XmlElement(name = "value")
51     protected String getValueString() {
52         return String.format("0X%s", Integer.toHexString(NetUtils.getUnsignedByte(tos)));
53     }
54
55     @Override
56     public Byte getMask() {
57         return null;
58     }
59
60     @Override
61     protected String getMaskString() {
62         return null;
63     }
64
65     @Override
66     public boolean isValid() {
67         return tos >= 0 && tos <= MAX;
68     }
69
70     @Override
71     public boolean hasReverse() {
72         return false;
73     }
74
75     @Override
76     public NwTos getReverse() {
77         return this.clone();
78     }
79
80     @Override
81     public NwTos clone() {
82         return new NwTos(tos);
83     }
84
85     @Override
86     public boolean isV6() {
87         return true;
88     }
89
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = 1;
94         result = prime * result + tos;
95         return result;
96     }
97
98     @Override
99     public boolean equals(Object obj) {
100         if (this == obj) {
101             return true;
102         }
103         if (obj == null) {
104             return false;
105         }
106         if (!(obj instanceof NwTos)) {
107             return false;
108         }
109         NwTos other = (NwTos) obj;
110         if (tos != other.tos) {
111             return false;
112         }
113         return true;
114     }
115 }