blob: 724170e7550c85d90b0c6789b6da0410c8231385 [file] [log] [blame]
Yotam Harchold7b84202013-07-26 16:08:10 -07001package org.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4
5/**
6 *
7 * @author Yotam Harchol (yotam.harchol@bigswitch.com)
8 *
9 */
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070010public class ICMPv4Code implements OFValueType<ICMPv4Code> {
Yotam Harchold7b84202013-07-26 16:08:10 -070011
12 final static int LENGTH = 1;
13 final static short MAX_CODE = 0xFF;
14
15 private final short code;
Yotam Harcholc2813602013-08-20 12:14:22 -070016
Yotam Harcholff8f85e2013-08-21 10:02:23 -070017 public static final ICMPv4Code NO_MASK = new ICMPv4Code((short)0xFFFF);
18 public static final ICMPv4Code FULL_MASK = new ICMPv4Code((short)0x0000);
Yotam Harchold7b84202013-07-26 16:08:10 -070019
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
Yotam Harchol5c9d6f42013-08-01 11:09:20 -070047 @Override
48 public ICMPv4Code applyMask(ICMPv4Code mask) {
49 return ICMPv4Code.of((short)(this.code & mask.code));
50 }
51
52
Yotam Harchold7b84202013-07-26 16:08:10 -070053}