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