blob: a6544c99f5c75823f7a9134a9465abb31a4fb89c [file] [log] [blame]
package org.projectfloodlight.openflow.types;
import org.jboss.netty.buffer.ChannelBuffer;
/**
*
* @author Yotam Harchol (yotam.harchol@bigswitch.com)
*
*/
public class ICMPv4Code implements OFValueType<ICMPv4Code> {
final static int LENGTH = 1;
final static short MAX_CODE = 0xFF;
private final short code;
private static final short NONE_VAL = 0;
public static final ICMPv4Code NONE = new ICMPv4Code(NONE_VAL);
public static final ICMPv4Code NO_MASK = new ICMPv4Code((short)0xFFFF);
public static final ICMPv4Code FULL_MASK = new ICMPv4Code((short)0x0000);
private ICMPv4Code(short code) {
this.code = code;
}
public static ICMPv4Code of(short code) {
if(code == NONE_VAL)
return NONE;
if (code > MAX_CODE || code < 0)
throw new IllegalArgumentException("Illegal ICMPv4 code: " + code);
return new ICMPv4Code(code);
}
@Override
public int getLength() {
return LENGTH;
}
public short getCode() {
return code;
}
public void writeByte(ChannelBuffer c) {
c.writeByte(this.code);
}
public static ICMPv4Code readByte(ChannelBuffer c) {
return ICMPv4Code.of(c.readUnsignedByte());
}
@Override
public ICMPv4Code applyMask(ICMPv4Code mask) {
return ICMPv4Code.of((short)(this.code & mask.code));
}
}