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
021package org.apache.directory.server.dhcp.options.dhcp;
022
023
024import org.apache.directory.server.dhcp.messages.MessageType;
025import 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 */
046public class DhcpMessageType extends DhcpOption
047{
048    private MessageType type;
049
050
051    public DhcpMessageType()
052    {
053    }
054
055
056    public DhcpMessageType( MessageType type )
057    {
058        this.type = type;
059    }
060
061
062    /*
063     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
064     */
065    public byte getTag()
066    {
067        return 53;
068    }
069
070
071    @Override
072    public void setData( byte[] messageType )
073    {
074        type = MessageType.getTypeByCode( messageType[0] );
075    }
076
077
078    @Override
079    public byte[] getData()
080    {
081        return new byte[]
082            { type.getCode() };
083    }
084
085
086    public MessageType getType()
087    {
088        return type;
089    }
090}