Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | |
| 5 | /** |
| 6 | * |
| 7 | * @author Yotam Harchol (yotam.harchol@bigswitch.com) |
| 8 | * |
| 9 | */ |
| 10 | public class ICMPv4Code implements OFValueType { |
| 11 | |
| 12 | final static int LENGTH = 1; |
| 13 | final static short MAX_CODE = 0xFF; |
| 14 | |
| 15 | private final short code; |
| 16 | |
| 17 | private ICMPv4Code(short code) { |
| 18 | this.code = code; |
| 19 | } |
| 20 | |
| 21 | public static ICMPv4Code of(short code) { |
| 22 | if (code > MAX_CODE || code < 0) |
| 23 | throw new IllegalArgumentException("Illegal ICMPv4 code: " + code); |
| 24 | return new ICMPv4Code(code); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public int getLength() { |
| 29 | return LENGTH; |
| 30 | } |
| 31 | |
| 32 | public short getCode() { |
| 33 | return code; |
| 34 | } |
| 35 | |
| 36 | public void writeByte(ChannelBuffer c) { |
| 37 | c.writeByte(this.code); |
| 38 | } |
| 39 | |
| 40 | public static ICMPv4Code readByte(ChannelBuffer c) { |
| 41 | return ICMPv4Code.of(c.readUnsignedByte()); |
| 42 | } |
| 43 | |
| 44 | } |