Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 18 | package net.onrc.onos.core.packet; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 19 | |
| 20 | public enum DHCPPacketType { |
| 21 | // From RFC 1533 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 22 | DHCPDISCOVER(1), |
| 23 | DHCPOFFER(2), |
| 24 | DHCPREQUEST(3), |
| 25 | DHCPDECLINE(4), |
| 26 | DHCPACK(5), |
| 27 | DHCPNAK(6), |
| 28 | DHCPRELEASE(7), |
| 29 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 30 | // From RFC2132 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | DHCPINFORM(8), |
| 32 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | // From RFC3203 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | DHCPFORCERENEW(9), |
| 35 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 36 | // From RFC4388 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 37 | DHCPLEASEQUERY(10), |
| 38 | DHCPLEASEUNASSIGNED(11), |
| 39 | DHCPLEASEUNKNOWN(12), |
| 40 | DHCPLEASEACTIVE(13); |
| 41 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 42 | protected int value; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 44 | private DHCPPacketType(int value) { |
| 45 | this.value = value; |
| 46 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 47 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 48 | public int getValue() { |
| 49 | return value; |
| 50 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | |
| 52 | public String toString() { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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"; |
Ray Milkey | 0b122ed | 2014-04-14 10:06:03 -0700 | [diff] [blame] | 80 | default: |
| 81 | return "DHCP_UnknownType(" + value + ")"; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 82 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 83 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 85 | public static DHCPPacketType getType(int value) { |
| 86 | switch (value) { |
| 87 | case 1: |
| 88 | return DHCPDISCOVER; |
| 89 | case 2: |
| 90 | return DHCPOFFER; |
| 91 | case 3: |
| 92 | return DHCPREQUEST; |
| 93 | case 4: |
| 94 | return DHCPDECLINE; |
| 95 | case 5: |
| 96 | return DHCPACK; |
| 97 | case 6: |
| 98 | return DHCPNAK; |
| 99 | case 7: |
| 100 | return DHCPRELEASE; |
| 101 | case 8: |
| 102 | return DHCPINFORM; |
| 103 | case 9: |
| 104 | return DHCPFORCERENEW; |
| 105 | case 10: |
| 106 | return DHCPLEASEQUERY; |
| 107 | case 11: |
| 108 | return DHCPLEASEUNASSIGNED; |
| 109 | case 12: |
| 110 | return DHCPLEASEUNKNOWN; |
| 111 | case 13: |
| 112 | return DHCPLEASEACTIVE; |
Ray Milkey | 0b122ed | 2014-04-14 10:06:03 -0700 | [diff] [blame] | 113 | default: |
| 114 | return null; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 115 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 116 | } |
| 117 | } |