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