001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020
021 package org.apache.directory.server.dhcp.options.dhcp;
022
023
024 import org.apache.directory.server.dhcp.messages.MessageType;
025 import org.apache.directory.server.dhcp.options.DhcpOption;
026
027
028 /**
029 * This option is used to convey the type of the DHCP message. The code
030 * for this option is 53, and its length is 1. Legal values for this
031 * option are:
032 *
033 * Value Message Type
034 * ----- ------------
035 * 1 DHCPDISCOVER
036 * 2 DHCPOFFER
037 * 3 DHCPREQUEST
038 * 4 DHCPDECLINE
039 * 5 DHCPACK
040 * 6 DHCPNAK
041 * 7 DHCPRELEASE
042 * 8 DHCPINFORM
043 *
044 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
045 * @version $Rev: 638228 $, $Date: 2008-03-18 08:12:41 +0200 (Tue, 18 Mar 2008) $
046 */
047 public class DhcpMessageType extends DhcpOption
048 {
049 private MessageType type;
050
051
052 public DhcpMessageType()
053 {
054 }
055
056
057 public DhcpMessageType(MessageType type)
058 {
059 this.type = type;
060 }
061
062
063 /*
064 * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
065 */
066 public byte getTag()
067 {
068 return 53;
069 }
070
071
072 public void setData( byte[] messageType )
073 {
074 type = MessageType.getTypeByCode( messageType[0] );
075 }
076
077
078 public byte[] getData()
079 {
080 return new byte[]
081 { type.getCode() };
082 }
083
084
085 public MessageType getType()
086 {
087 return type;
088 }
089 }