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 | public class ICMPv4Type implements OFValueType { |
| 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 | |
| 67 | private final short type; |
| 68 | |
| 69 | private static final int MIN_TYPE = 0; |
| 70 | private static final int MAX_TYPE = 0xFF; |
| 71 | |
| 72 | private ICMPv4Type(short type) { |
| 73 | this.type = type; |
| 74 | } |
| 75 | |
| 76 | public static ICMPv4Type of(short type) { |
| 77 | if (type < MIN_TYPE || type > MAX_TYPE) |
| 78 | throw new IllegalArgumentException("Invalid ICMPv4 type: " + type); |
| 79 | switch (type) { |
| 80 | case ICMPV4_TYPE_VAL_ECHO_REPLY: |
| 81 | return ICMPV4_TYPE_ECHO_REPLY; |
| 82 | case ICMPV4_TYPE_VAL_DESTINATION_UNREACHABLE: |
| 83 | return ICMPV4_TYPE_DESTINATION_UNREACHABLE; |
| 84 | case ICMPV4_TYPE_VAL_SOURCE_QUENCH: |
| 85 | return ICMPV4_TYPE_SOURCE_QUENCH; |
| 86 | case ICMPV4_TYPE_VAL_REDIRECT: |
| 87 | return ICMPV4_TYPE_REDIRECT; |
| 88 | case ICMPV4_TYPE_VAL_ALTERNATE_HOST_ADDRESS: |
| 89 | return ICMPV4_TYPE_ALTERNATE_HOST_ADDRESS; |
| 90 | case ICMPV4_TYPE_VAL_ECHO: |
| 91 | return ICMPV4_TYPE_ECHO; |
| 92 | case ICMPV4_TYPE_VAL_ROUTER_ADVERTISEMENT: |
| 93 | return ICMPV4_TYPE_ROUTER_ADVERTISEMENT; |
| 94 | case ICMPV4_TYPE_VAL_ROUTER_SOLICITATION: |
| 95 | return ICMPV4_TYPE_ROUTER_SOLICITATION; |
| 96 | case ICMPV4_TYPE_VAL_TIME_EXCEEDED: |
| 97 | return ICMPV4_TYPE_TIME_EXCEEDED; |
| 98 | case ICMPV4_TYPE_VAL_PARAMETER_PROBLEM: |
| 99 | return ICMPV4_TYPE_PARAMETER_PROBLEM; |
| 100 | case ICMPV4_TYPE_VAL_TIMESTAMP: |
| 101 | return ICMPV4_TYPE_TIMESTAMP; |
| 102 | case ICMPV4_TYPE_VAL_TIMESTAMP_REPLY: |
| 103 | return ICMPV4_TYPE_TIMESTAMP_REPLY; |
| 104 | case ICMPV4_TYPE_VAL_INFORMATION_REQUEST: |
| 105 | return ICMPV4_TYPE_INFORMATION_REQUEST; |
| 106 | case ICMPV4_TYPE_VAL_INFORMATION_REPLY: |
| 107 | return ICMPV4_TYPE_INFORMATION_REPLY; |
| 108 | case ICMPV4_TYPE_VAL_ADDRESS_MASK_REQUEST: |
| 109 | return ICMPV4_TYPE_ADDRESS_MASK_REQUEST; |
| 110 | case ICMPV4_TYPE_VAL_ADDRESS_MASK_REPLY: |
| 111 | return ICMPV4_TYPE_ADDRESS_MASK_REPLY; |
| 112 | case ICMPV4_TYPE_VAL_TRACEROUTE: |
| 113 | return ICMPV4_TYPE_TRACEROUTE; |
| 114 | case ICMPV4_TYPE_VAL_DATAGRAM_CONVERSION_ERROR: |
| 115 | return ICMPV4_TYPE_DATAGRAM_CONVERSION_ERROR; |
| 116 | case ICMPV4_TYPE_VAL_MOBILE_HOST_REDIRECT: |
| 117 | return ICMPV4_TYPE_MOBILE_HOST_REDIRECT; |
| 118 | case ICMPV4_TYPE_VAL_IPV6_WHERE_ARE_YOU: |
| 119 | return ICMPV4_TYPE_IPV6_WHERE_ARE_YOU; |
| 120 | case ICMPV4_TYPE_VAL_IPV6_I_AM_HERE: |
| 121 | return ICMPV4_TYPE_IPV6_I_AM_HERE; |
| 122 | case ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REQUEST: |
| 123 | return ICMPV4_TYPE_MOBILE_REGISTRATION_REQUEST; |
| 124 | case ICMPV4_TYPE_VAL_MOBILE_REGISTRATION_REPLY: |
| 125 | return ICMPV4_TYPE_MOBILE_REGISTRATION_REPLY; |
| 126 | case ICMPV4_TYPE_VAL_DOMAIN_NAME_REQUEST: |
| 127 | return ICMPV4_TYPE_DOMAIN_NAME_REQUEST; |
| 128 | case ICMPV4_TYPE_VAL_DOMAIN_NAME_REPLY: |
| 129 | return ICMPV4_TYPE_DOMAIN_NAME_REPLY; |
| 130 | case ICMPV4_TYPE_VAL_SKIP: |
| 131 | return ICMPV4_TYPE_SKIP; |
| 132 | case ICMPV4_TYPE_VAL_PHOTURIS: |
| 133 | return ICMPV4_TYPE_PHOTURIS; |
| 134 | case ICMPV4_TYPE_VAL_EXPERIMENTAL_MOBILITY: |
| 135 | return ICMPV4_TYPE_EXPERIMENTAL_MOBILITY; |
| 136 | default: |
| 137 | return new ICMPv4Type(type); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public int getLength() { |
| 143 | return LENGTH; |
| 144 | } |
| 145 | |
| 146 | public short getType() { |
| 147 | return type; |
| 148 | } |
| 149 | |
| 150 | public void writeByte(ChannelBuffer c) { |
| 151 | c.writeByte(this.type); |
| 152 | } |
| 153 | |
| 154 | public static ICMPv4Type readByte(ChannelBuffer c) { |
| 155 | return ICMPv4Type.of(c.readUnsignedByte()); |
| 156 | } |
| 157 | |
| 158 | } |