alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | ******************************************************************************/ |
| 16 | /** |
| 17 | * Copyright 2011, Big Switch Networks, Inc. |
| 18 | * Originally created by David Erickson, Stanford University |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. You may obtain |
| 22 | * a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 29 | * License for the specific language governing permissions and limitations |
| 30 | * under the License. |
| 31 | **/ |
| 32 | |
| 33 | package org.onlab.packet; |
| 34 | |
| 35 | public enum DHCPPacketType { |
| 36 | // From RFC 1533 |
| 37 | DHCPDISCOVER(1), DHCPOFFER(2), DHCPREQUEST(3), DHCPDECLINE(4), DHCPACK(5), DHCPNAK( |
| 38 | 6), DHCPRELEASE(7), |
| 39 | |
| 40 | // From RFC2132 |
| 41 | DHCPINFORM(8), |
| 42 | |
| 43 | // From RFC3203 |
| 44 | DHCPFORCERENEW(9), |
| 45 | |
| 46 | // From RFC4388 |
| 47 | DHCPLEASEQUERY(10), DHCPLEASEUNASSIGNED(11), DHCPLEASEUNKNOWN(12), DHCPLEASEACTIVE( |
| 48 | 13); |
| 49 | |
| 50 | protected int value; |
| 51 | |
| 52 | private DHCPPacketType(final int value) { |
| 53 | this.value = value; |
| 54 | } |
| 55 | |
| 56 | public int getValue() { |
| 57 | return this.value; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String toString() { |
| 62 | switch (this.value) { |
| 63 | case 1: |
| 64 | return "DHCPDISCOVER"; |
| 65 | case 2: |
| 66 | return "DHCPOFFER"; |
| 67 | case 3: |
| 68 | return "DHCPREQUEST"; |
| 69 | case 4: |
| 70 | return "DHCPDECLINE"; |
| 71 | case 5: |
| 72 | return "DHCPACK"; |
| 73 | case 6: |
| 74 | return "DHCPNAK"; |
| 75 | case 7: |
| 76 | return "DHCPRELEASE"; |
| 77 | case 8: |
| 78 | return "DHCPINFORM"; |
| 79 | case 9: |
| 80 | return "DHCPFORCERENEW"; |
| 81 | case 10: |
| 82 | return "DHCPLEASEQUERY"; |
| 83 | case 11: |
| 84 | return "DHCPLEASEUNASSIGNED"; |
| 85 | case 12: |
| 86 | return "DHCPLEASEUNKNOWN"; |
| 87 | case 13: |
| 88 | return "DHCPLEASEACTIVE"; |
| 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | public static DHCPPacketType getType(final int value) { |
| 97 | switch (value) { |
| 98 | case 1: |
| 99 | return DHCPDISCOVER; |
| 100 | case 2: |
| 101 | return DHCPOFFER; |
| 102 | case 3: |
| 103 | return DHCPREQUEST; |
| 104 | case 4: |
| 105 | return DHCPDECLINE; |
| 106 | case 5: |
| 107 | return DHCPACK; |
| 108 | case 6: |
| 109 | return DHCPNAK; |
| 110 | case 7: |
| 111 | return DHCPRELEASE; |
| 112 | case 8: |
| 113 | return DHCPINFORM; |
| 114 | case 9: |
| 115 | return DHCPFORCERENEW; |
| 116 | case 10: |
| 117 | return DHCPLEASEQUERY; |
| 118 | case 11: |
| 119 | return DHCPLEASEUNASSIGNED; |
| 120 | case 12: |
| 121 | return DHCPLEASEUNKNOWN; |
| 122 | case 13: |
| 123 | return DHCPLEASEACTIVE; |
| 124 | default: |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | return null; |
| 129 | } |
| 130 | } |