blob: eb43d34f66b279896e96c68c2263d90aa0ee8fe9 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * 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 Krishnaswamy345ee992012-12-13 20:29:48 -080017
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070018package net.onrc.onos.core.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20public enum DHCPPacketType {
21 // From RFC 1533
Ray Milkey269ffb92014-04-03 14:43:30 -070022 DHCPDISCOVER(1),
23 DHCPOFFER(2),
24 DHCPREQUEST(3),
25 DHCPDECLINE(4),
26 DHCPACK(5),
27 DHCPNAK(6),
28 DHCPRELEASE(7),
29
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080030 // From RFC2132
Ray Milkey269ffb92014-04-03 14:43:30 -070031 DHCPINFORM(8),
32
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033 // From RFC3203
Ray Milkey269ffb92014-04-03 14:43:30 -070034 DHCPFORCERENEW(9),
35
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036 // From RFC4388
Ray Milkey269ffb92014-04-03 14:43:30 -070037 DHCPLEASEQUERY(10),
38 DHCPLEASEUNASSIGNED(11),
39 DHCPLEASEUNKNOWN(12),
40 DHCPLEASEACTIVE(13);
41
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080042 protected int value;
Ray Milkey269ffb92014-04-03 14:43:30 -070043
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080044 private DHCPPacketType(int value) {
45 this.value = value;
46 }
Ray Milkey269ffb92014-04-03 14:43:30 -070047
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080048 public int getValue() {
49 return value;
50 }
Ray Milkey269ffb92014-04-03 14:43:30 -070051
52 public String toString() {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080053 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 Milkey0b122ed2014-04-14 10:06:03 -070080 default:
81 return "DHCP_UnknownType(" + value + ")";
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080082 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080083 }
Ray Milkey269ffb92014-04-03 14:43:30 -070084
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080085 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 Milkey0b122ed2014-04-14 10:06:03 -0700113 default:
114 return null;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800115 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800116 }
117}