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 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 5 | public class ICMPv4Type implements OFValueType<ICMPv4Type> { |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 6 | |
| 7 | final static int LENGTH = 1; |
| 8 | |
| 9 | private static final short ICMPV4_TYPE_VAL_ECHO_REPLY = 0; |
| 10 | private static final short ICMPV4_TYPE_VAL_DESTINATION_UNREACHABLE = 3; |
| 11 | private static final short ICMPV4_TYPE_VAL_SOURCE_QUENCH = 4; |
| 12 | private static final short ICMPV4_TYPE_VAL_REDIRECT = 5; |
| 13 | private static final short ICMPV4_TYPE_VAL_ALTERNATE_HOST_ADDRESS = 6; |
| 14 | private static final short ICMPV4_TYPE_VAL_ECHO = 8; |
| 15 | private static final short ICMPV4_TYPE_VAL_ROUTER_ADVERTISEMENT = 9; |
| 16 | private static final short ICMPV4_TYPE_VAL_ROUTER_SOLICITATION = 10; |
| 17 | private static final short ICMPV4_TYPE_VAL_TIME_EXCEEDED = 11; |
| 18 | private static final short ICMPV4_TYPE_VAL_PARAMETER_PROBLEM = 12; |
| 19 | private static final short ICMPV4_TYPE_VAL_TIMESTAMP = 13; |
| 20 | private static final short ICMPV4_TYPE_VAL_TIMESTAMP_REPLY = 14; |
| 21 | private static final short ICMPV4_TYPE_VAL_INFORMATION_REQUEST = 15; |
| 22 | private static final short ICMPV4_TYPE_VAL_INFORMATION_REPLY = 16; |
| 23 | private static final short ICMPV4_TYPE_VAL_ADDRESS_MASK_REQUEST = 17; |
| 24 | private static final short ICMPV4_TYPE_VAL_ADDRESS_MASK_REPLY = 18; |
| 25 | private static final short ICMPV4_TYPE_VAL_TRACEROUTE = 30; |
| 26 | private static final short ICMPV4_TYPE_VAL_DATAGRAM_CONVERSION_ERROR = 31; |
| 27 | private static final short ICMPV4_TYPE_VAL_MOBILE_HOST_REDIRECT = 32; |
| 28 | private static final short ICMPV4_TYPE_VAL_IPV6_WHERE_ARE_YOU = 33; |
| 29 | private static final short ICMPV4_TYPE_VAL_IPV6_I_AM_HERE = 34; |
| 30 | private static final short ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REQUEST = 35; |
| 31 | private static final short ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REPLY = 36; |
| 32 | private static final short ICMPV4_TYPE_VAL_DOMAIN_NAME_REQUEST = 37; |
| 33 | private static final short ICMPV4_TYPE_VAL_DOMAIN_NAME_REPLY = 38; |
| 34 | private static final short ICMPV4_TYPE_VAL_SKIP = 39; |
| 35 | private static final short ICMPV4_TYPE_VAL_PHOTURIS = 40; |
| 36 | private static final short ICMPV4_TYPE_VAL_EXPERIMENTAL_MOBILITY = 41; |
| 37 | |
| 38 | public static final ICMPv4Type ICMPV4_TYPE_ECHO_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_ECHO_REPLY); |
| 39 | public static final ICMPv4Type ICMPV4_TYPE_DESTINATION_UNREACHABLE = new ICMPv4Type(ICMPV4_TYPE_VAL_DESTINATION_UNREACHABLE); |
| 40 | public static final ICMPv4Type ICMPV4_TYPE_SOURCE_QUENCH = new ICMPv4Type(ICMPV4_TYPE_VAL_SOURCE_QUENCH); |
| 41 | public static final ICMPv4Type ICMPV4_TYPE_REDIRECT = new ICMPv4Type(ICMPV4_TYPE_VAL_REDIRECT); |
| 42 | public static final ICMPv4Type ICMPV4_TYPE_ALTERNATE_HOST_ADDRESS = new ICMPv4Type(ICMPV4_TYPE_VAL_ALTERNATE_HOST_ADDRESS); |
| 43 | public static final ICMPv4Type ICMPV4_TYPE_ECHO = new ICMPv4Type(ICMPV4_TYPE_VAL_ECHO); |
| 44 | public static final ICMPv4Type ICMPV4_TYPE_ROUTER_ADVERTISEMENT = new ICMPv4Type(ICMPV4_TYPE_VAL_ROUTER_ADVERTISEMENT); |
| 45 | public static final ICMPv4Type ICMPV4_TYPE_ROUTER_SOLICITATION = new ICMPv4Type(ICMPV4_TYPE_VAL_ROUTER_SOLICITATION); |
| 46 | public static final ICMPv4Type ICMPV4_TYPE_TIME_EXCEEDED = new ICMPv4Type(ICMPV4_TYPE_VAL_TIME_EXCEEDED); |
| 47 | public static final ICMPv4Type ICMPV4_TYPE_PARAMETER_PROBLEM = new ICMPv4Type(ICMPV4_TYPE_VAL_PARAMETER_PROBLEM); |
| 48 | public static final ICMPv4Type ICMPV4_TYPE_TIMESTAMP = new ICMPv4Type(ICMPV4_TYPE_VAL_TIMESTAMP); |
| 49 | public static final ICMPv4Type ICMPV4_TYPE_TIMESTAMP_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_TIMESTAMP_REPLY); |
| 50 | public static final ICMPv4Type ICMPV4_TYPE_INFORMATION_REQUEST = new ICMPv4Type(ICMPV4_TYPE_VAL_INFORMATION_REQUEST); |
| 51 | public static final ICMPv4Type ICMPV4_TYPE_INFORMATION_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_INFORMATION_REPLY); |
| 52 | public static final ICMPv4Type ICMPV4_TYPE_ADDRESS_MASK_REQUEST = new ICMPv4Type(ICMPV4_TYPE_VAL_ADDRESS_MASK_REQUEST); |
| 53 | public static final ICMPv4Type ICMPV4_TYPE_ADDRESS_MASK_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_ADDRESS_MASK_REPLY); |
| 54 | public static final ICMPv4Type ICMPV4_TYPE_TRACEROUTE = new ICMPv4Type(ICMPV4_TYPE_VAL_TRACEROUTE); |
| 55 | public static final ICMPv4Type ICMPV4_TYPE_DATAGRAM_CONVERSION_ERROR = new ICMPv4Type(ICMPV4_TYPE_VAL_DATAGRAM_CONVERSION_ERROR); |
| 56 | public static final ICMPv4Type ICMPV4_TYPE_MOBILE_HOST_REDIRECT = new ICMPv4Type(ICMPV4_TYPE_VAL_MOBILE_HOST_REDIRECT); |
| 57 | public static final ICMPv4Type ICMPV4_TYPE_IPV6_WHERE_ARE_YOU = new ICMPv4Type(ICMPV4_TYPE_VAL_IPV6_WHERE_ARE_YOU); |
| 58 | public static final ICMPv4Type ICMPV4_TYPE_IPV6_I_AM_HERE = new ICMPv4Type(ICMPV4_TYPE_VAL_IPV6_I_AM_HERE); |
| 59 | public static final ICMPv4Type ICMPV4_TYPE_MOBILE_REGISTRATION_REQUEST = new ICMPv4Type(ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REQUEST); |
| 60 | public static final ICMPv4Type ICMPV4_TYPE_MOBILE_REGISTRATION_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REPLY); |
| 61 | public static final ICMPv4Type ICMPV4_TYPE_DOMAIN_NAME_REQUEST = new ICMPv4Type(ICMPV4_TYPE_VAL_DOMAIN_NAME_REQUEST); |
| 62 | public static final ICMPv4Type ICMPV4_TYPE_DOMAIN_NAME_REPLY = new ICMPv4Type(ICMPV4_TYPE_VAL_DOMAIN_NAME_REPLY); |
| 63 | public static final ICMPv4Type ICMPV4_TYPE_SKIP = new ICMPv4Type(ICMPV4_TYPE_VAL_SKIP); |
| 64 | public static final ICMPv4Type ICMPV4_TYPE_PHOTURIS = new ICMPv4Type(ICMPV4_TYPE_VAL_PHOTURIS); |
| 65 | public static final ICMPv4Type ICMPV4_TYPE_EXPERIMENTAL_MOBILITY = new ICMPv4Type(ICMPV4_TYPE_VAL_EXPERIMENTAL_MOBILITY); |
| 66 | |
Yotam Harchol | ff8f85e | 2013-08-21 10:02:23 -0700 | [diff] [blame] | 67 | public static final ICMPv4Type NO_MASK = new ICMPv4Type((short)0xFFFF); |
| 68 | public static final ICMPv4Type FULL_MASK = new ICMPv4Type((short)0x0000); |
Yotam Harchol | c281360 | 2013-08-20 12:14:22 -0700 | [diff] [blame] | 69 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 70 | private final short type; |
| 71 | |
| 72 | private static final int MIN_TYPE = 0; |
| 73 | private static final int MAX_TYPE = 0xFF; |
| 74 | |
| 75 | private ICMPv4Type(short type) { |
| 76 | this.type = type; |
| 77 | } |
| 78 | |
| 79 | public static ICMPv4Type of(short type) { |
| 80 | if (type < MIN_TYPE || type > MAX_TYPE) |
| 81 | throw new IllegalArgumentException("Invalid ICMPv4 type: " + type); |
| 82 | switch (type) { |
| 83 | case ICMPV4_TYPE_VAL_ECHO_REPLY: |
| 84 | return ICMPV4_TYPE_ECHO_REPLY; |
| 85 | case ICMPV4_TYPE_VAL_DESTINATION_UNREACHABLE: |
| 86 | return ICMPV4_TYPE_DESTINATION_UNREACHABLE; |
| 87 | case ICMPV4_TYPE_VAL_SOURCE_QUENCH: |
| 88 | return ICMPV4_TYPE_SOURCE_QUENCH; |
| 89 | case ICMPV4_TYPE_VAL_REDIRECT: |
| 90 | return ICMPV4_TYPE_REDIRECT; |
| 91 | case ICMPV4_TYPE_VAL_ALTERNATE_HOST_ADDRESS: |
| 92 | return ICMPV4_TYPE_ALTERNATE_HOST_ADDRESS; |
| 93 | case ICMPV4_TYPE_VAL_ECHO: |
| 94 | return ICMPV4_TYPE_ECHO; |
| 95 | case ICMPV4_TYPE_VAL_ROUTER_ADVERTISEMENT: |
| 96 | return ICMPV4_TYPE_ROUTER_ADVERTISEMENT; |
| 97 | case ICMPV4_TYPE_VAL_ROUTER_SOLICITATION: |
| 98 | return ICMPV4_TYPE_ROUTER_SOLICITATION; |
| 99 | case ICMPV4_TYPE_VAL_TIME_EXCEEDED: |
| 100 | return ICMPV4_TYPE_TIME_EXCEEDED; |
| 101 | case ICMPV4_TYPE_VAL_PARAMETER_PROBLEM: |
| 102 | return ICMPV4_TYPE_PARAMETER_PROBLEM; |
| 103 | case ICMPV4_TYPE_VAL_TIMESTAMP: |
| 104 | return ICMPV4_TYPE_TIMESTAMP; |
| 105 | case ICMPV4_TYPE_VAL_TIMESTAMP_REPLY: |
| 106 | return ICMPV4_TYPE_TIMESTAMP_REPLY; |
| 107 | case ICMPV4_TYPE_VAL_INFORMATION_REQUEST: |
| 108 | return ICMPV4_TYPE_INFORMATION_REQUEST; |
| 109 | case ICMPV4_TYPE_VAL_INFORMATION_REPLY: |
| 110 | return ICMPV4_TYPE_INFORMATION_REPLY; |
| 111 | case ICMPV4_TYPE_VAL_ADDRESS_MASK_REQUEST: |
| 112 | return ICMPV4_TYPE_ADDRESS_MASK_REQUEST; |
| 113 | case ICMPV4_TYPE_VAL_ADDRESS_MASK_REPLY: |
| 114 | return ICMPV4_TYPE_ADDRESS_MASK_REPLY; |
| 115 | case ICMPV4_TYPE_VAL_TRACEROUTE: |
| 116 | return ICMPV4_TYPE_TRACEROUTE; |
| 117 | case ICMPV4_TYPE_VAL_DATAGRAM_CONVERSION_ERROR: |
| 118 | return ICMPV4_TYPE_DATAGRAM_CONVERSION_ERROR; |
| 119 | case ICMPV4_TYPE_VAL_MOBILE_HOST_REDIRECT: |
| 120 | return ICMPV4_TYPE_MOBILE_HOST_REDIRECT; |
| 121 | case ICMPV4_TYPE_VAL_IPV6_WHERE_ARE_YOU: |
| 122 | return ICMPV4_TYPE_IPV6_WHERE_ARE_YOU; |
| 123 | case ICMPV4_TYPE_VAL_IPV6_I_AM_HERE: |
| 124 | return ICMPV4_TYPE_IPV6_I_AM_HERE; |
| 125 | case ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REQUEST: |
| 126 | return ICMPV4_TYPE_MOBILE_REGISTRATION_REQUEST; |
| 127 | case ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REPLY: |
| 128 | return ICMPV4_TYPE_MOBILE_REGISTRATION_REPLY; |
| 129 | case ICMPV4_TYPE_VAL_DOMAIN_NAME_REQUEST: |
| 130 | return ICMPV4_TYPE_DOMAIN_NAME_REQUEST; |
| 131 | case ICMPV4_TYPE_VAL_DOMAIN_NAME_REPLY: |
| 132 | return ICMPV4_TYPE_DOMAIN_NAME_REPLY; |
| 133 | case ICMPV4_TYPE_VAL_SKIP: |
| 134 | return ICMPV4_TYPE_SKIP; |
| 135 | case ICMPV4_TYPE_VAL_PHOTURIS: |
| 136 | return ICMPV4_TYPE_PHOTURIS; |
| 137 | case ICMPV4_TYPE_VAL_EXPERIMENTAL_MOBILITY: |
| 138 | return ICMPV4_TYPE_EXPERIMENTAL_MOBILITY; |
| 139 | default: |
| 140 | return new ICMPv4Type(type); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public int getLength() { |
| 146 | return LENGTH; |
| 147 | } |
| 148 | |
| 149 | public short getType() { |
| 150 | return type; |
| 151 | } |
| 152 | |
| 153 | public void writeByte(ChannelBuffer c) { |
| 154 | c.writeByte(this.type); |
| 155 | } |
| 156 | |
| 157 | public static ICMPv4Type readByte(ChannelBuffer c) { |
| 158 | return ICMPv4Type.of(c.readUnsignedByte()); |
| 159 | } |
| 160 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 161 | @Override |
| 162 | public ICMPv4Type applyMask(ICMPv4Type mask) { |
| 163 | return ICMPv4Type.of((short)(this.type & mask.type)); |
| 164 | } |
| 165 | |
| 166 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 167 | } |