Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 17 | * under the License. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 18 | */ |
| 19 | |
| 20 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 21 | |
| 22 | package org.onlab.packet; |
| 23 | |
| 24 | public enum DHCPPacketType { |
| 25 | // From RFC 1533 |
| 26 | DHCPDISCOVER(1), DHCPOFFER(2), DHCPREQUEST(3), DHCPDECLINE(4), DHCPACK(5), DHCPNAK( |
| 27 | 6), DHCPRELEASE(7), |
| 28 | |
| 29 | // From RFC2132 |
| 30 | DHCPINFORM(8), |
| 31 | |
| 32 | // From RFC3203 |
| 33 | DHCPFORCERENEW(9), |
| 34 | |
| 35 | // From RFC4388 |
| 36 | DHCPLEASEQUERY(10), DHCPLEASEUNASSIGNED(11), DHCPLEASEUNKNOWN(12), DHCPLEASEACTIVE( |
| 37 | 13); |
| 38 | |
| 39 | protected int value; |
| 40 | |
| 41 | private DHCPPacketType(final int value) { |
| 42 | this.value = value; |
| 43 | } |
| 44 | |
| 45 | public int getValue() { |
| 46 | return this.value; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String toString() { |
| 51 | switch (this.value) { |
| 52 | case 1: |
| 53 | return "DHCPDISCOVER"; |
| 54 | case 2: |
| 55 | return "DHCPOFFER"; |
| 56 | case 3: |
| 57 | return "DHCPREQUEST"; |
| 58 | case 4: |
| 59 | return "DHCPDECLINE"; |
| 60 | case 5: |
| 61 | return "DHCPACK"; |
| 62 | case 6: |
| 63 | return "DHCPNAK"; |
| 64 | case 7: |
| 65 | return "DHCPRELEASE"; |
| 66 | case 8: |
| 67 | return "DHCPINFORM"; |
| 68 | case 9: |
| 69 | return "DHCPFORCERENEW"; |
| 70 | case 10: |
| 71 | return "DHCPLEASEQUERY"; |
| 72 | case 11: |
| 73 | return "DHCPLEASEUNASSIGNED"; |
| 74 | case 12: |
| 75 | return "DHCPLEASEUNKNOWN"; |
| 76 | case 13: |
| 77 | return "DHCPLEASEACTIVE"; |
| 78 | default: |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | public static DHCPPacketType getType(final 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; |
| 113 | default: |
| 114 | break; |
| 115 | } |
| 116 | |
| 117 | return null; |
| 118 | } |
| 119 | } |