blob: 46ada58c26023ab0b8f4187402f359e390e304c5 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4
5/**
6 *
7 * @author Yotam Harchol (yotam.harchol@bigswitch.com)
8 *
9 */
10public class ICMPv4Code implements OFValueType<ICMPv4Code> {
11
12 final static int LENGTH = 1;
13 final static short MAX_CODE = 0xFF;
14
15 private final short code;
16
17 public static final ICMPv4Code NO_MASK = new ICMPv4Code((short)0xFFFF);
18 public static final ICMPv4Code FULL_MASK = new ICMPv4Code((short)0x0000);
19
20 private ICMPv4Code(short code) {
21 this.code = code;
22 }
23
24 public static ICMPv4Code of(short code) {
25 if (code > MAX_CODE || code < 0)
26 throw new IllegalArgumentException("Illegal ICMPv4 code: " + code);
27 return new ICMPv4Code(code);
28 }
29
30 @Override
31 public int getLength() {
32 return LENGTH;
33 }
34
35 public short getCode() {
36 return code;
37 }
38
39 public void writeByte(ChannelBuffer c) {
40 c.writeByte(this.code);
41 }
42
43 public static ICMPv4Code readByte(ChannelBuffer c) {
44 return ICMPv4Code.of(c.readUnsignedByte());
45 }
46
47 @Override
48 public ICMPv4Code applyMask(ICMPv4Code mask) {
49 return ICMPv4Code.of((short)(this.code & mask.code));
50 }
51
52
53}