You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/03/18 07:13:18 UTC

svn commit: r638228 [17/20] - in /directory/sandbox/akarasulu/bigbang/apacheds: ./ apacheds-xbean-spring/src/site/ benchmarks/src/site/ bootstrap-extract/src/site/ bootstrap-partition/src/site/ bootstrap-plugin/src/main/java/org/apache/directory/server...

Modified: directory/sandbox/akarasulu/bigbang/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/mitosis/src/test/java/org/apache/directory/mitosis/store/derby/DerbyReplicationStoreTest.java Mon Mar 17 23:12:41 2008
@@ -38,8 +38,9 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerAttribute;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
 import org.apache.directory.shared.ldap.schema.OidNormalizer;
@@ -191,24 +192,40 @@
         oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
         oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
         oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
-        
+
+        AttributeTypeRegistry atRegistry = service.getRegistries().getAttributeTypeRegistry();
+
         CSN csn = csnFactory.newInstance( REPLICA_ID );
         CompositeOperation op1 = new CompositeOperation( csn );
         LdapDN ouA =  new LdapDN( "ou=a" ).normalize( oids );
-        op1.add( new AddEntryOperation( csn, ouA, new DefaultServerEntry( service.getRegistries(), ouA ) ) );
-        op1.add( new AddAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
-        op1.add( new ReplaceAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
-        op1.add( new DeleteAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
+        op1.add( new AddEntryOperation( csn, ouA, 
+            new DefaultServerEntry( service.getRegistries(), ouA ) ) );
+        
+        op1.add( new AddAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
+        
+        op1.add( new ReplaceAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
+        
+        op1.add( new DeleteAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
 
         store.putLog( op1 );
         testGetLogs( csn, op1 );
 
         csn = csnFactory.newInstance( OTHER_REPLICA_ID );
         CompositeOperation op2 = new CompositeOperation( csn );
-        op2.add( new AddEntryOperation( csn, ouA, new DefaultServerEntry( service.getRegistries(), ouA ) ) );
-        op2.add( new AddAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
-        op2.add( new ReplaceAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
-        op2.add( new DeleteAttributeOperation( csn, ouA, new AttributeImpl( "id", "valie" ) ) );
+        op2.add( new AddEntryOperation( csn, ouA, 
+            new DefaultServerEntry( service.getRegistries(), ouA ) ) );
+        
+        op2.add( new AddAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
+        
+        op2.add( new ReplaceAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
+        
+        op2.add( new DeleteAttributeOperation( csn, ouA, 
+            new DefaultServerAttribute( "ou", atRegistry.lookup( "ou" ), "valie" ) ) );
 
         store.putLog( op2 );
         testGetLogs( csn, op2 );

Modified: directory/sandbox/akarasulu/bigbang/apacheds/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/pom.xml?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/pom.xml (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/pom.xml Mon Mar 17 23:12:41 2008
@@ -22,7 +22,7 @@
   <parent>
     <groupId>org.apache.directory.project</groupId>
     <artifactId>project</artifactId>
-    <version>9-SNAPSHOT</version>
+    <version>10-SNAPSHOT</version>
   </parent>
 
   <groupId>org.apache.directory.server</groupId>
@@ -39,19 +39,19 @@
       <dependency>
         <groupId>org.apache.directory.shared</groupId>
         <artifactId>shared-asn1-codec</artifactId>
-        <version>0.9.8-SNAPSHOT</version>
+        <version>0.9.9-SNAPSHOT</version>
       </dependency>
 
       <dependency>
         <groupId>org.apache.directory.shared</groupId>
         <artifactId>shared-ldap</artifactId>
-        <version>0.9.8-SNAPSHOT</version>
+        <version>0.9.9-SNAPSHOT</version>
       </dependency>
 
       <dependency>
         <groupId>org.apache.directory.shared</groupId>
         <artifactId>shared-ldap-constants</artifactId>
-        <version>0.9.8-SNAPSHOT</version>
+        <version>0.9.9-SNAPSHOT</version>
       </dependency>
 
       <dependency>
@@ -63,13 +63,13 @@
       <dependency>
         <groupId>org.apache.mina</groupId>
         <artifactId>mina-core</artifactId>
-        <version>1.1.4-SNAPSHOT</version>
+        <version>1.1.6</version>
       </dependency>
 
       <dependency>
         <groupId>org.apache.mina</groupId>
         <artifactId>mina-filter-ssl</artifactId>
-        <version>1.1.4-SNAPSHOT</version>
+        <version>1.1.6</version>
       </dependency>
 
       <dependency>

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/DhcpException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/DhcpException.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/DhcpException.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/DhcpException.java Mon Mar 17 23:12:41 2008
@@ -50,4 +50,18 @@
     {
         super( description );
     }
+
+
+    /**
+     * This constructor is used if a description of the event that caused the
+     * exception is required.
+     * 
+     * @param description
+     *            this is a description of the exception
+     * @param e
+     */
+    public DhcpException(String description, Exception e)
+    {
+        super( description, e );
+    }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageDecoder.java Mon Mar 17 23:12:41 2008
@@ -6,27 +6,34 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ * 
  */
 
 package org.apache.directory.server.dhcp.io;
 
 
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import org.apache.directory.server.dhcp.DhcpException;
 import org.apache.directory.server.dhcp.messages.DhcpMessage;
-import org.apache.directory.server.dhcp.messages.DhcpMessageModifier;
-import org.apache.directory.server.dhcp.messages.MessageType;
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.options.dhcp.DhcpMessageType;
+import org.apache.directory.server.dhcp.options.dhcp.UnrecognizedOption;
 
 
 /**
@@ -35,6 +42,7 @@
  */
 public class DhcpMessageDecoder
 {
+
     /**
      * Convert a byte buffer into a DhcpMessage.
      * 
@@ -44,57 +52,149 @@
      */
     public DhcpMessage decode( ByteBuffer buffer ) throws DhcpException
     {
-        /**
-         * TODO - need to figure out why the buffer needs to be rewound.
-         */
-        buffer.rewind();
+        byte op = buffer.get();
 
-        DhcpMessageModifier modifier = new DhcpMessageModifier();
+        short htype = ( short ) ( buffer.get() & 0xff );
+        short hlen = ( short ) ( buffer.get() & 0xff );
+        short hops = ( short ) ( buffer.get() & 0xff );
+        int xid = buffer.getInt();
+        int secs = buffer.getShort() & 0xffff;
+        short flags = buffer.getShort();
 
-        modifier.setMessageType( MessageType.DHCPDISCOVER );
+        InetAddress ciaddr = decodeAddress( buffer );
+        InetAddress yiaddr = decodeAddress( buffer );
+        InetAddress siaddr = decodeAddress( buffer );
+        InetAddress giaddr = decodeAddress( buffer );
 
-        modifier.setOpCode( buffer.get() );
-        modifier.setHardwareAddressType( buffer.get() );
+        byte[] chaddr = decodeBytes( buffer, 16 );
 
-        short hardwareAddressLength = ( short ) ( buffer.get() & 0xff );
+        String sname = decodeString( buffer, 64 );
+        String file = decodeString( buffer, 128 );
 
-        modifier.setHardwareAddressLength( ( byte ) hardwareAddressLength );
-        modifier.setHardwareOptions( buffer.get() );
+        OptionsField options = decodeOptions( buffer );
 
-        modifier.setTransactionId( buffer.getInt() );
-        modifier.setSeconds( buffer.getShort() );
-        modifier.setFlags( buffer.getShort() );
+        // message type option: may be null if option isn't set (BOOTP)
+        DhcpMessageType mto = ( DhcpMessageType ) options.get( DhcpMessageType.class );
 
-        byte[] nextFourBytes = new byte[4];
+        return new DhcpMessage( null != mto ? mto.getType() : null, op, new HardwareAddress( htype, hlen, chaddr ),
+            hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, sname, file, options );
+    }
 
-        buffer.get( nextFourBytes );
-        modifier.setActualClientAddress( nextFourBytes );
 
-        buffer.get( nextFourBytes );
-        modifier.setAssignedClientAddress( nextFourBytes );
+    /**
+     * @param buffer
+     * @param len
+     * @return
+     */
+    private static byte[] decodeBytes( ByteBuffer buffer, int len )
+    {
+        byte[] bytes = new byte[len];
+        buffer.get( bytes );
+        return bytes;
+    }
 
-        buffer.get( nextFourBytes );
-        modifier.setNextServerAddress( nextFourBytes );
 
-        buffer.get( nextFourBytes );
-        modifier.setRelayAgentAddress( nextFourBytes );
+    /**
+     * @param buffer
+     * @return
+     */
+    private static String decodeString( ByteBuffer buffer, int len )
+    {
+        byte[] bytes = new byte[len];
+        buffer.get( bytes );
 
-        byte[] clientHardwareAddress = new byte[16];
+        // find zero-terminator
+        int slen = 0;
+        while ( bytes[slen] != 0 )
+            slen++;
+
+        try
+        {
+            return new String( bytes, 0, slen, "ASCII" );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            throw new RuntimeException( "No ASCII encoding", e );
+        }
+    }
 
-        buffer.get( clientHardwareAddress );
-        modifier.setClientHardwareAddress( clientHardwareAddress );
 
-        byte[] serverHostname = new byte[64];
-        buffer.get( serverHostname );
-        modifier.setServerHostname( serverHostname );
+    /**
+     * Read a 4-byte inet address from the buffer.
+     * 
+     * @param buffer
+     * @return
+     * @throws UnknownHostException
+     */
+    private static InetAddress decodeAddress( ByteBuffer buffer )
+    {
+        byte[] addr = new byte[4];
+        buffer.get( addr );
+        try
+        {
+            return InetAddress.getByAddress( addr );
+        }
+        catch ( UnknownHostException e )
+        {
+            // should not happen
+            return null;
+        }
+    }
 
-        byte[] bootFileName = new byte[128];
-        buffer.get( bootFileName );
-        modifier.setBootFileName( bootFileName );
+    private static final byte[] VENDOR_MAGIC_COOKIE =
+        { ( byte ) 99, ( byte ) 130, ( byte ) 83, ( byte ) 99 };
 
-        DhcpOptionsDecoder decoder = new DhcpOptionsDecoder();
-        modifier.setOptions( decoder.decode( buffer ) );
 
-        return modifier.getDhcpMessage();
+    public OptionsField decodeOptions( ByteBuffer message ) throws DhcpException
+    {
+        byte[] magicCookie = new byte[4];
+        message.get( magicCookie );
+
+        if ( !Arrays.equals( VENDOR_MAGIC_COOKIE, magicCookie ) )
+        {
+            throw new DhcpException( "Parse exception." );
+        }
+
+        byte code;
+        byte length;
+        byte value[];
+
+        OptionsField options = new OptionsField();
+
+        while ( true )
+        {
+            code = message.get();
+            if ( code == 0 ) // pad option
+                continue;
+
+            if ( code == -1 ) // end option
+                break;
+
+            length = message.get();
+            value = new byte[length];
+            message.get( value );
+
+            options.add( getOptionInstance( code, value ) );
+        }
+
+        return options;
+    }
+
+
+    private DhcpOption getOptionInstance( int tag, byte[] value ) throws DhcpException
+    {
+        try
+        {
+            Class c = DhcpOption.getClassByTag( tag );
+
+            DhcpOption o = null != c ? ( DhcpOption ) c.newInstance() : new UnrecognizedOption( ( byte ) tag );
+            o.setData( value );
+
+            return o;
+        }
+        catch ( Exception e )
+        {
+            throw new DhcpException( "Can't set option value: " + e.toString() );
+        }
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageEncoder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageEncoder.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageEncoder.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/io/DhcpMessageEncoder.java Mon Mar 17 23:12:41 2008
@@ -6,25 +6,31 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ * 
  */
 
 package org.apache.directory.server.dhcp.io;
 
 
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
 import java.nio.ByteBuffer;
+import java.util.Iterator;
 
 import org.apache.directory.server.dhcp.messages.DhcpMessage;
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+import org.apache.directory.server.dhcp.options.DhcpOption;
 import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.options.dhcp.DhcpMessageType;
 
 
 /**
@@ -41,25 +47,125 @@
      */
     public void encode( ByteBuffer byteBuffer, DhcpMessage message )
     {
-        byteBuffer.put( message.getOpCode() );
-        byteBuffer.put( message.getHardwareAddressType() );
-        byteBuffer.put( message.getHardwareAddressLength() );
-        byteBuffer.put( message.getHardwareOptions() );
+        byteBuffer.put( message.getOp() );
+
+        HardwareAddress hardwareAddress = message.getHardwareAddress();
+
+        byteBuffer.put( ( byte ) ( null != hardwareAddress ? hardwareAddress.getType() : 0 ) );
+        byteBuffer.put( ( byte ) ( null != hardwareAddress ? hardwareAddress.getLength() : 0 ) );
+        byteBuffer.put( ( byte ) message.getHopCount() );
         byteBuffer.putInt( message.getTransactionId() );
-        byteBuffer.putShort( message.getSeconds() );
+        byteBuffer.putShort( ( short ) message.getSeconds() );
         byteBuffer.putShort( message.getFlags() );
-        byteBuffer.put( message.getActualClientAddress() );
-        byteBuffer.put( message.getAssignedClientAddress() );
-        byteBuffer.put( message.getNextServerAddress() );
-        byteBuffer.put( message.getRelayAgentAddress() );
-        byteBuffer.put( message.getClientHardwareAddress() );
-        byteBuffer.put( message.getServerHostname() );
-        byteBuffer.put( message.getBootFileName() );
+
+        writeAddress( byteBuffer, message.getCurrentClientAddress() );
+        writeAddress( byteBuffer, message.getAssignedClientAddress() );
+        writeAddress( byteBuffer, message.getNextServerAddress() );
+        writeAddress( byteBuffer, message.getRelayAgentAddress() );
+
+        writeBytes( byteBuffer, ( null != hardwareAddress ? hardwareAddress.getAddress() : new byte[]
+            {} ), 16 );
+
+        writeString( byteBuffer, message.getServerHostname(), 64 );
+        writeString( byteBuffer, message.getBootFileName(), 128 );
 
         OptionsField options = message.getOptions();
 
-        DhcpOptionsEncoder optionsEncoder = new DhcpOptionsEncoder();
+        // update message type option (if set)
+        if ( null != message.getMessageType() )
+            options.add( new DhcpMessageType( message.getMessageType() ) );
+
+        encodeOptions( options, byteBuffer );
+    }
+
+
+    /**
+     * Write a zero-terminated string to a field of len bytes.
+     * 
+     * @param byteBuffer
+     * @param serverHostname
+     * @param i
+     */
+    private void writeString( ByteBuffer byteBuffer, String string, int len )
+    {
+        if ( null == string )
+            string = "";
+
+        try
+        {
+            byte sbytes[] = string.getBytes( "ASCII" );
+
+            // writeBytes will automatically zero-pad and thus terminate the
+            // string.
+            writeBytes( byteBuffer, sbytes, len );
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            // should not happen
+            throw new RuntimeException( "No ASCII encoding", e );
+        }
+    }
+
+
+    /**
+     * Write an InetAddress to the byte buffer.
+     * 
+     * @param byteBuffer
+     * @param currentClientAddress
+     */
+    private void writeAddress( ByteBuffer byteBuffer, InetAddress currentClientAddress )
+    {
+        if ( null == currentClientAddress )
+        {
+            byte emptyAddress[] =
+                { 0, 0, 0, 0 };
+            byteBuffer.put( emptyAddress );
+        }
+        else
+        {
+            byte[] addressBytes = currentClientAddress.getAddress();
+            byteBuffer.put( addressBytes );
+        }
+    }
+
+
+    /**
+     * Write an array of bytes to the buffer. Write exactly len bytes,
+     * truncating if more than len, padding if less than len bytes are
+     * available.
+     * 
+     * @param byteBuffer
+     * @param currentClientAddress
+     */
+    private void writeBytes( ByteBuffer byteBuffer, byte bytes[], int len )
+    {
+        if ( null == bytes )
+            bytes = new byte[]
+                {};
+
+        byteBuffer.put( bytes, 0, Math.min(len, bytes.length) );
+
+        // pad as necessary
+        int remain = len - bytes.length;
+        while ( remain-- > 0 )
+            byteBuffer.put( ( byte ) 0 );
+    }
+
+    private static final byte[] VENDOR_MAGIC_COOKIE =
+        { ( byte ) 99, ( byte ) 130, ( byte ) 83, ( byte ) 99 };
+
+
+    public void encodeOptions( OptionsField options, ByteBuffer message )
+    {
+        message.put( VENDOR_MAGIC_COOKIE );
+
+        for ( Iterator i = options.iterator(); i.hasNext(); )
+        {
+            DhcpOption option = ( DhcpOption ) i.next();
+            option.writeTo( message );
+        }
 
-        optionsEncoder.encode( options, byteBuffer );
+        // add end option
+        message.put( ( byte ) 0xff );
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/DhcpMessage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/DhcpMessage.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/DhcpMessage.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/DhcpMessage.java Mon Mar 17 23:12:41 2008
@@ -6,276 +6,295 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ * 
  */
 
 package org.apache.directory.server.dhcp.messages;
 
+import java.net.InetAddress;
 
 import org.apache.directory.server.dhcp.options.OptionsField;
 
-
 /**
+ * A DHCP (RFC 2131) message. Field descriptions contain the oroginal RFC field
+ * names in brackets.
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class DhcpMessage
-{
-    private MessageType messageType;
-
-    private byte opCode;
-    private byte hardwareAddressType;
-    private byte hardwareAddressLength;
-    private byte hardwareOptions;
-    private int transactionId;
-    private short seconds;
-    private short flags;
-    private byte actualClientAddress[] = new byte[4];
-    private byte assignedClientAddress[] = new byte[4];
-    private byte nextServerAddress[] = new byte[4];
-    private byte relayAgentAddress[] = new byte[4];
-    private byte clientHardwareAddress[] = new byte[16];
-    private byte serverHostname[] = new byte[64];
-    private byte bootFileName[] = new byte[128];
-
-    private OptionsField options = new OptionsField();
-
-
-    /**
-     * Creates a new instance of DhcpMessage.
-     *
-     * @param messageType
-     * @param opCode
-     * @param hardwareAddressType
-     * @param hardwareAddressLength
-     * @param hardwareOptions
-     * @param transactionId
-     * @param seconds
-     * @param flags
-     * @param actualClientAddress
-     * @param assignedClientAddress
-     * @param nextServerAddress
-     * @param relayAgentAddress
-     * @param clientHardwareAddress
-     * @param serverHostname
-     * @param bootFileName
-     * @param options
-     */
-    public DhcpMessage( MessageType messageType, byte opCode, byte hardwareAddressType, byte hardwareAddressLength,
-        byte hardwareOptions, int transactionId, short seconds, short flags, byte[] actualClientAddress,
-        byte[] assignedClientAddress, byte[] nextServerAddress, byte[] relayAgentAddress, byte[] clientHardwareAddress,
-        byte[] serverHostname, byte[] bootFileName, OptionsField options )
-    {
-        this.messageType = messageType;
-        this.opCode = opCode;
-        this.hardwareAddressType = hardwareAddressType;
-        this.hardwareAddressLength = hardwareAddressLength;
-        this.hardwareOptions = hardwareOptions;
-        this.transactionId = transactionId;
-        this.seconds = seconds;
-        this.flags = flags;
-        this.actualClientAddress = actualClientAddress;
-        this.assignedClientAddress = assignedClientAddress;
-        this.nextServerAddress = nextServerAddress;
-        this.relayAgentAddress = relayAgentAddress;
-        this.clientHardwareAddress = clientHardwareAddress;
-        this.serverHostname = serverHostname;
-        this.bootFileName = bootFileName;
-        this.options = options;
-    }
-
-
-    /**
-     * Message type.
-     * 
-     * @return The {@link MessageType}.
-     */
-    public MessageType getMessageType()
-    {
-        return messageType;
-    }
-
-
-    /**
-     * Message op code / message type.
-     * 1 = BOOTREQUEST, 2 = BOOTREPLY
-     * 
-     * @return The message op code (type).
-     */
-    public byte getOpCode()
-    {
-        return opCode;
-    }
-
-
-    /**
-     * Hardware address type, see ARP section in
-     * "Assigned Numbers" RFC; e.g., '1' = 10mb ethernet.
-     * 
-     * @return The hardware address type.
-     */
-    public byte getHardwareAddressType()
-    {
-        return hardwareAddressType;
-    }
-
-
-    /**
-     * Hardware address length (e.g.  '6' for 10mb ethernet).
-     * 
-     * @return The hardware address length.
-     */
-    public byte getHardwareAddressLength()
-    {
-        return hardwareAddressLength;
-    }
-
-
-    /**
-     * Client sets to zero, optionally used by relay agents
-     * when booting via a relay agent.
-     * 
-     * @return The hardware options.
-     */
-    public byte getHardwareOptions()
-    {
-        return hardwareOptions;
-    }
-
-
-    /**
-     * Transaction ID, a random number chosen by the client,
-     * used by the client and server to associate messages
-     * and responses between a client and a server.
-     * 
-     * @return The transaction ID.
-     */
-    public int getTransactionId()
-    {
-        return transactionId;
-    }
-
-
-    /**
-     * Filled in by client, seconds elapsed since client
-     * began address acquisition or renewal process.
-     * 
-     * @return The seconds.
-     */
-    public short getSeconds()
-    {
-        return seconds;
-    }
-
-
-    /**
-     * Flags.
-     * 
-     * @return The flags.
-     */
-    public short getFlags()
-    {
-        return flags;
-    }
-
-
-    /**
-     * Client IP address; only filled in if client is in BOUND,
-     * RENEW or REBINDING state and can respond to ARP requests.
-     * 
-     * @return The actual client addresses.
-     */
-    public byte[] getActualClientAddress()
-    {
-        return actualClientAddress;
-    }
-
-
-    /**
-     * Get 'your' (client) IP address.
-     * 
-     * @return The assigned client addresses.
-     */
-    public byte[] getAssignedClientAddress()
-    {
-        return assignedClientAddress;
-    }
-
-
-    /**
-     * IP address of next server to use in bootstrap;
-     * returned in DHCPOFFER, DHCPACK by server.
-     * 
-     * @return The next server address.
-     */
-    public byte[] getNextServerAddress()
-    {
-        return nextServerAddress;
-    }
-
-
-    /**
-     * Relay agent IP address, used in booting via a relay agent.
-     * 
-     * @return The relay agent address.
-     */
-    public byte[] getRelayAgentAddress()
-    {
-        return relayAgentAddress;
-    }
-
-
-    /**
-     * Client hardware address.
-     * 
-     * @return The client hardware address.
-     */
-    public byte[] getClientHardwareAddress()
-    {
-        return clientHardwareAddress;
-    }
-
-
-    /**
-     * Optional server host name, null terminated string.
-     * 
-     * @return The server hostname.
-     */
-    public byte[] getServerHostname()
-    {
-        return serverHostname;
-    }
-
-
-    /**
-     * Boot file name, null terminated string; "generic" name or null
-     * in DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
-     * 
-     * @return The boot file name.
-     */
-    public byte[] getBootFileName()
-    {
-        return bootFileName;
-    }
-
-
-    /**
-     * Optional parameters field.  See the options
-     * documents for a list of defined options.
-     * 
-     * @return The options.
-     */
-    public OptionsField getOptions()
-    {
-        return options;
-    }
+public class DhcpMessage {
+	/**
+	 * Flag value: request broadcast answer.
+	 * 
+	 * @see #flags;
+	 */
+	public static final int FLAG_BROADCAST = 0x01;
+
+	/**
+	 * [yiaddr] 'your' (client) IP address.
+	 */
+	private InetAddress assignedClientAddress;
+
+	/**
+	 * [file] Boot file name, null terminated string; "generic" name or null in
+	 * DHCPDISCOVER, fully qualified directory-path name in DHCPOFFER.
+	 */
+	private String bootFileName;
+
+	/**
+	 * [ciaddr] Current client IP address; only filled in if client is in BOUND,
+	 * RENEW or REBINDING state and can respond to ARP requests.
+	 */
+	private InetAddress currentClientAddress;
+
+	/**
+	 * [flags] Flags. (LSB is broadcast flag)
+	 */
+	private short flags;
+
+	/**
+	 * [hops] Client sets to zero, optionally used by relay agents when booting
+	 * via a relay agent.
+	 */
+	private short hopCount;
+
+	/**
+	 * [op] Message op code. 1 = BOOTREQUEST, 2 = BOOTREPLY, ...
+	 */
+	private byte op;
+
+	/**
+	 * Operation constant: boot request (client to server).
+	 * 
+	 * @see #op
+	 */
+	public static final byte OP_BOOTREQUEST = 1;
+
+	/**
+	 * Operation constant: boot reply (server to client).
+	 * 
+	 * @see #op
+	 */
+	public static final byte OP_BOOTREPLY = 2;
+
+	/**
+	 * [siaddr] IP address of next server to use in bootstrap; returned in
+	 * DHCPOFFER, DHCPACK by server.
+	 */
+	private InetAddress nextServerAddress;
+
+	/**
+	 * [options] Optional parameters field. See the options documents for a list
+	 * of defined options.
+	 */
+	private OptionsField options = new OptionsField();
+
+	/**
+	 * [giaddr] Relay agent IP address, used in booting via a relay agent.
+	 */
+	private InetAddress relayAgentAddress;
+
+	/**
+	 * [secs] Filled in by client, seconds elapsed since client began address
+	 * acquisition or renewal process.
+	 */
+	private int seconds;
+
+	/**
+	 * [sname] Optional server host name, null terminated string.
+	 */
+	private String serverHostname;
+
+	/**
+	 * [xid] Transaction ID, a random number chosen by the client, used by the
+	 * client and server to associate messages and responses between a client and
+	 * a server.
+	 */
+	private int transactionId;
+
+	/**
+	 * The DHCP message type option.
+	 */
+	private MessageType messageType;
+
+	private HardwareAddress hardwareAddress;
+
+	/**
+	 * Create a default dhcp message.
+	 */
+	public DhcpMessage() {
+
+	}
+
+	/**
+	 * Create a DHCP message based on the supplied values.
+	 * 
+	 * @param messageType
+	 * @param op
+	 * @param hardwareAddressType
+	 * @param hardwareAddressLength
+	 * @param hops
+	 * @param transactionId
+	 * @param seconds
+	 * @param flags
+	 * @param currentClientAddress
+	 * @param assignedClientAddress
+	 * @param nextServerAddress
+	 * @param relayAgentAddress
+	 * @param clientHardwareAddress
+	 * @param serverHostname
+	 * @param bootFileName
+	 * @param options
+	 */
+	public DhcpMessage(MessageType messageType, byte op,
+			HardwareAddress hardwareAddress, short hops, int transactionId,
+			int seconds, short flags, InetAddress currentClientAddress,
+			InetAddress assignedClientAddress, InetAddress nextServerAddress,
+			InetAddress relayAgentAddress, String serverHostname,
+			String bootFileName, OptionsField options) {
+		this.messageType = messageType;
+		this.op = op;
+		this.hardwareAddress = hardwareAddress;
+		this.hopCount = hops;
+		this.transactionId = transactionId;
+		this.seconds = seconds;
+		this.flags = flags;
+		this.currentClientAddress = currentClientAddress;
+		this.assignedClientAddress = assignedClientAddress;
+		this.nextServerAddress = nextServerAddress;
+		this.relayAgentAddress = relayAgentAddress;
+		this.serverHostname = serverHostname;
+		this.bootFileName = bootFileName;
+		this.options = options;
+	}
+
+	public InetAddress getAssignedClientAddress() {
+		return assignedClientAddress;
+	}
+
+	public String getBootFileName() {
+		return bootFileName;
+	}
+
+	public InetAddress getCurrentClientAddress() {
+		return currentClientAddress;
+	}
+
+	public short getFlags() {
+		return flags;
+	}
+
+	public short getHopCount() {
+		return hopCount;
+	}
+
+	public MessageType getMessageType() {
+		return messageType;
+	}
+
+	public InetAddress getNextServerAddress() {
+		return nextServerAddress;
+	}
+
+	public OptionsField getOptions() {
+		return options;
+	}
+
+	public InetAddress getRelayAgentAddress() {
+		return relayAgentAddress;
+	}
+
+	public int getSeconds() {
+		return seconds;
+	}
+
+	public String getServerHostname() {
+		return serverHostname;
+	}
+
+	public int getTransactionId() {
+		return transactionId;
+	}
+
+	public void setAssignedClientAddress(InetAddress assignedClientAddress) {
+		this.assignedClientAddress = assignedClientAddress;
+	}
+
+	public void setBootFileName(String bootFileName) {
+		this.bootFileName = bootFileName;
+	}
+
+	public void setCurrentClientAddress(InetAddress currentClientAddress) {
+		this.currentClientAddress = currentClientAddress;
+	}
+
+	public void setFlags(short flags) {
+		this.flags = flags;
+	}
+
+	public void setHopCount(short hopCount) {
+		this.hopCount = hopCount;
+	}
+
+	public void setMessageType(MessageType messageType) {
+		this.messageType = messageType;
+	}
+
+	public void setNextServerAddress(InetAddress nextServerAddress) {
+		this.nextServerAddress = nextServerAddress;
+	}
+
+	public void setOptions(OptionsField options) {
+		this.options = options;
+	}
+
+	public void setRelayAgentAddress(InetAddress relayAgentAddress) {
+		this.relayAgentAddress = relayAgentAddress;
+	}
+
+	public void setSeconds(int seconds) {
+		this.seconds = seconds;
+	}
+
+	public void setServerHostname(String serverHostname) {
+		this.serverHostname = serverHostname;
+	}
+
+	public void setTransactionId(int transactionId) {
+		this.transactionId = transactionId;
+	}
+
+	public byte getOp() {
+		return op;
+	}
+
+	public void setOp(byte op) {
+		this.op = op;
+	}
+
+	public HardwareAddress getHardwareAddress() {
+		return hardwareAddress;
+	}
+
+	public void setHardwareAddress(HardwareAddress hardwareAddress) {
+		this.hardwareAddress = hardwareAddress;
+	}
+
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		sb.append(messageType).append(": hwAddress=").append(hardwareAddress)
+				.append(", tx=").append(transactionId).append(", options=").append(
+						options);
+
+		return sb.toString();
+	}
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/MessageType.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/MessageType.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/MessageType.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/MessageType.java Mon Mar 17 23:12:41 2008
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ * 
  */
 
 package org.apache.directory.server.dhcp.messages;
@@ -32,117 +32,95 @@
  */
 public final class MessageType implements Comparable
 {
-    /**
-     * Constant for the "Null" message type.
-     */
-    public static final MessageType NULL = new MessageType( 0, "Null" );
+    // FIXME: does this class make a lot of sense in absence of real (1.5)
+    // enums?
+    // The DOCPDISCOVER et. al. constants can't be used conveniently in
+    // switches,
+    // therefore the byte constants fpr the opcodes are duplicated here.
+    public static final byte CODE_DHCPINFORM = 8;
 
-    /**
-     * Constant for the "DHCP Discover" message type.
-     */
-    public static final MessageType DHCPDISCOVER = new MessageType( 1, "DHCP Discover" );
+    public static final byte CODE_DHCPRELEASE = 7;
 
-    /**
-     * Constant for the "DHCP Offer" message type.
-     */
-    public static final MessageType DHCPOFFER = new MessageType( 2, "DHCP Offer" );
+    public static final byte CODE_DHCPNAK = 6;
 
-    /**
-     * Constant for the "DHCP Request" message type.
-     */
-    public static final MessageType DHCPREQUEST = new MessageType( 3, "DHCP Request" );
+    public static final byte CODE_DHCPACK = 5;
 
-    /**
-     * Constant for the "DHCP Decline" message type.
-     */
-    public static final MessageType DHCPDECLINE = new MessageType( 4, "DHCP Decline" );
+    public static final byte CODE_DHCPDECLINE = 4;
 
-    /**
-     * Constant for the "DHCP Acknowledge" message type.
-     */
-    public static final MessageType DHCPACK = new MessageType( 5, "DHCP Acknowledge" );
+    public static final byte CODE_DHCPREQUEST = 3;
 
-    /**
-     * Constant for the "DHCP Not Acknowledge" message type.
-     */
-    public static final MessageType DHCPNAK = new MessageType( 6, "DHCP Not Acknowledge" );
+    public static final byte CODE_DHCPOFFER = 2;
 
-    /**
-     * Constant for the "DHCP Release" message type.
-     */
-    public static final MessageType DHCPRELEASE = new MessageType( 7, "DHCP Release" );
+    public static final byte CODE_DHCPDISCOVER = 1;
 
     /**
-     * Constant for the "DHCP Inform" message type.
+     * Enumeration elements are constructed once upon class loading. Order of
+     * appearance here determines the order of compareTo.
      */
-    public static final MessageType DHCPINFORM = new MessageType( 8, "DHCP Inform" );
+    public static final MessageType DHCPDISCOVER = new MessageType( CODE_DHCPDISCOVER, "DHCP Discover" );
 
-    /**
-     * Array for building a List of VALUES.
-     */
-    private static final MessageType[] values =
-        { NULL, DHCPDISCOVER, DHCPOFFER, DHCPREQUEST, DHCPDECLINE, DHCPACK, DHCPNAK, DHCPRELEASE, DHCPINFORM };
+    public static final MessageType DHCPOFFER = new MessageType( CODE_DHCPOFFER, "DHCP Offer" );
 
-    /**
-     * A list of all the message type constants.
-     */
-    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
+    public static final MessageType DHCPREQUEST = new MessageType( CODE_DHCPREQUEST, "DHCP Request" );
 
-    /**
-     * The name of the message type.
-     */
-    private final String name;
+    public static final MessageType DHCPDECLINE = new MessageType( CODE_DHCPDECLINE, "DHCP Decline" );
 
-    /**
-     * The value/code for the message type.
-     */
-    private final int ordinal;
+    public static final MessageType DHCPACK = new MessageType( CODE_DHCPACK, "DHCP Acknowledge" );
 
+    public static final MessageType DHCPNAK = new MessageType( CODE_DHCPNAK, "DHCP Not Acknowledge" );
 
-    /**
-     * Private constructor prevents construction outside of this class.
-     */
-    private MessageType( int ordinal, String name )
+    public static final MessageType DHCPRELEASE = new MessageType( CODE_DHCPRELEASE, "DHCP Release" );
+
+    public static final MessageType DHCPINFORM = new MessageType( CODE_DHCPINFORM, "DHCP Inform" );
+
+
+    public String toString()
     {
-        this.ordinal = ordinal;
-        this.name = name;
+        return name;
     }
 
 
-    /**
-     * Returns the message type when specified by its ordinal.
-     *
-     * @param type
-     * @return The message type.
-     */
-    public static MessageType getTypeByOrdinal( int type )
+    public int compareTo( Object that )
+    {
+        return ordinal - ( ( MessageType ) that ).ordinal;
+    }
+
+
+    public static MessageType getTypeByCode( byte type )
     {
         for ( int ii = 0; ii < values.length; ii++ )
             if ( values[ii].ordinal == type )
                 return values[ii];
-        return NULL;
+        return new MessageType( type, "Unrecognized" );
     }
 
 
-    /**
-     * Returns the number associated with this message type.
-     *
-     * @return The message type ordinal.
-     */
-    public int getOrdinal()
+    public byte getCode()
     {
         return ordinal;
     }
 
+    // / PRIVATE /////
+    private final String name;
 
-    public int compareTo( Object that )
-    {
-        return ordinal - ( ( MessageType ) that ).ordinal;
-    }
+    private final byte ordinal;
 
 
-    public String toString()
+    /**
+     * Private constructor prevents construction outside of this class.
+     */
+    private MessageType(byte ordinal, String name)
     {
-        return name;
+        this.ordinal = ordinal;
+        this.name = name;
     }
+
+    /**
+     * These two lines are all that's necessary to export a List of VALUES.
+     */
+    private static final MessageType[] values =
+        { DHCPDISCOVER, DHCPOFFER, DHCPREQUEST, DHCPDECLINE, DHCPACK, DHCPNAK, DHCPRELEASE, DHCPINFORM };
+
+    // VALUES needs to be located here, otherwise illegal forward reference
+    public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values ) );
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressListOption.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressListOption.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressListOption.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressListOption.java Mon Mar 17 23:12:41 2008
@@ -6,56 +6,33 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 
 package org.apache.directory.server.dhcp.options;
 
 
-import java.nio.ByteBuffer;
-
-
 /**
  * The Dynamic Host Configuration Protocol (DHCP) provides a framework
  * for passing configuration information to hosts on a TCP/IP network.  
  * Configuration parameters and other control information are carried in
  * tagged data items that are stored in the 'options' field of the DHCP
  * message.  The data items themselves are also called "options."
- * 
+ *
  * This abstract base class is for options that carry lists of IP addresses.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public abstract class AddressListOption extends DhcpOption
 {
-    private byte[] value;
-
-
-    /**
-     * Creates a new instance of AddressListOption.
-     *
-     * @param tag
-     * @param value
-     */
-    public AddressListOption( int tag, byte[] value )
-    {
-        super( tag, value.length );
-        this.value = value;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
-    {
-        out.put( value );
-    }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressOption.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressOption.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressOption.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/AddressOption.java Mon Mar 17 23:12:41 2008
@@ -6,22 +6,23 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 
 package org.apache.directory.server.dhcp.options;
 
 
-import java.nio.ByteBuffer;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 
 /**
@@ -30,34 +31,50 @@
  * Configuration parameters and other control information are carried in
  * tagged data items that are stored in the 'options' field of the DHCP
  * message.  The data items themselves are also called "options."
- * 
+ *
  * This abstract base class is for options that carry a single IP address.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public abstract class AddressOption extends DhcpOption
 {
-    private static final int length = 4;
+    private InetAddress address;
 
-    private byte[] value;
+
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getData()
+     */
+    public byte[] getData()
+    {
+        return address.getAddress();
+    }
 
 
-    /**
-     * Creates a new instance of AddressOption.
-     *
-     * @param tag
-     * @param value
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#setData(byte[])
      */
-    public AddressOption( int tag, byte[] value )
+    public void setData( byte[] data )
+    {
+        try
+        {
+            address = InetAddress.getByAddress( data );
+        }
+        catch ( UnknownHostException e )
+        {
+            throw new IllegalArgumentException( "illegal address", e );
+        }
+    }
+
+
+    public InetAddress getAddress()
     {
-        super( tag, length );
-        this.value = value;
+        return address;
     }
 
 
-    protected void valueToByteBuffer( ByteBuffer out )
+    public void setAddress( InetAddress address )
     {
-        out.put( value );
+        this.address = address;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/DhcpOption.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/DhcpOption.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/DhcpOption.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/DhcpOption.java Mon Mar 17 23:12:41 2008
@@ -1,27 +1,99 @@
 /*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
  */
 
 package org.apache.directory.server.dhcp.options;
 
 
 import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.server.dhcp.options.dhcp.BootfileName;
+import org.apache.directory.server.dhcp.options.dhcp.ClientIdentifier;
+import org.apache.directory.server.dhcp.options.dhcp.DhcpMessageType;
+import org.apache.directory.server.dhcp.options.dhcp.IpAddressLeaseTime;
+import org.apache.directory.server.dhcp.options.dhcp.MaximumDhcpMessageSize;
+import org.apache.directory.server.dhcp.options.dhcp.OptionOverload;
+import org.apache.directory.server.dhcp.options.dhcp.ParameterRequestList;
+import org.apache.directory.server.dhcp.options.dhcp.RebindingTimeValue;
+import org.apache.directory.server.dhcp.options.dhcp.RenewalTimeValue;
+import org.apache.directory.server.dhcp.options.dhcp.RequestedIpAddress;
+import org.apache.directory.server.dhcp.options.dhcp.ServerIdentifier;
+import org.apache.directory.server.dhcp.options.dhcp.TftpServerName;
+import org.apache.directory.server.dhcp.options.dhcp.UnrecognizedOption;
+import org.apache.directory.server.dhcp.options.dhcp.VendorClassIdentifier;
+import org.apache.directory.server.dhcp.options.misc.DefaultFingerServers;
+import org.apache.directory.server.dhcp.options.misc.DefaultIrcServers;
+import org.apache.directory.server.dhcp.options.misc.DefaultWwwServers;
+import org.apache.directory.server.dhcp.options.misc.MobileIpHomeAgents;
+import org.apache.directory.server.dhcp.options.misc.NbddServers;
+import org.apache.directory.server.dhcp.options.misc.NetbiosNameServers;
+import org.apache.directory.server.dhcp.options.misc.NetbiosNodeType;
+import org.apache.directory.server.dhcp.options.misc.NetbiosScope;
+import org.apache.directory.server.dhcp.options.misc.NisDomain;
+import org.apache.directory.server.dhcp.options.misc.NisPlusDomain;
+import org.apache.directory.server.dhcp.options.misc.NisPlusServers;
+import org.apache.directory.server.dhcp.options.misc.NisServers;
+import org.apache.directory.server.dhcp.options.misc.NntpServers;
+import org.apache.directory.server.dhcp.options.misc.NtpServers;
+import org.apache.directory.server.dhcp.options.misc.Pop3Servers;
+import org.apache.directory.server.dhcp.options.misc.SmtpServers;
+import org.apache.directory.server.dhcp.options.misc.StdaServers;
+import org.apache.directory.server.dhcp.options.misc.StreetTalkServers;
+import org.apache.directory.server.dhcp.options.misc.VendorSpecificInformation;
+import org.apache.directory.server.dhcp.options.misc.XWindowDisplayManagers;
+import org.apache.directory.server.dhcp.options.misc.XWindowFontServers;
+import org.apache.directory.server.dhcp.options.perhost.DefaultIpTimeToLive;
+import org.apache.directory.server.dhcp.options.perhost.IpForwarding;
+import org.apache.directory.server.dhcp.options.perhost.MaximumDatagramSize;
+import org.apache.directory.server.dhcp.options.perhost.NonLocalSourceRouting;
+import org.apache.directory.server.dhcp.options.perhost.PathMtuAgingTimeout;
+import org.apache.directory.server.dhcp.options.perhost.PathMtuPlateauTable;
+import org.apache.directory.server.dhcp.options.perhost.PolicyFilter;
+import org.apache.directory.server.dhcp.options.perinterface.AllSubnetsAreLocal;
+import org.apache.directory.server.dhcp.options.perinterface.BroadcastAddress;
+import org.apache.directory.server.dhcp.options.perinterface.InterfaceMtu;
+import org.apache.directory.server.dhcp.options.perinterface.MaskSupplier;
+import org.apache.directory.server.dhcp.options.perinterface.PerformMaskDiscovery;
+import org.apache.directory.server.dhcp.options.perinterface.PerformRouterDiscovery;
+import org.apache.directory.server.dhcp.options.perinterface.RouterSolicitationAddress;
+import org.apache.directory.server.dhcp.options.perinterface.StaticRoute;
+import org.apache.directory.server.dhcp.options.tcp.TcpDefaultTimeToLive;
+import org.apache.directory.server.dhcp.options.tcp.TcpKeepaliveGarbage;
+import org.apache.directory.server.dhcp.options.tcp.TcpKeepaliveInterval;
+import org.apache.directory.server.dhcp.options.vendor.BootFileSize;
+import org.apache.directory.server.dhcp.options.vendor.CookieServers;
+import org.apache.directory.server.dhcp.options.vendor.DomainName;
+import org.apache.directory.server.dhcp.options.vendor.DomainNameServers;
+import org.apache.directory.server.dhcp.options.vendor.ExtensionsPath;
+import org.apache.directory.server.dhcp.options.vendor.HostName;
+import org.apache.directory.server.dhcp.options.vendor.ImpressServers;
+import org.apache.directory.server.dhcp.options.vendor.LogServers;
+import org.apache.directory.server.dhcp.options.vendor.LprServers;
+import org.apache.directory.server.dhcp.options.vendor.MeritDumpFile;
+import org.apache.directory.server.dhcp.options.vendor.NameServers;
+import org.apache.directory.server.dhcp.options.vendor.ResourceLocationServers;
+import org.apache.directory.server.dhcp.options.vendor.RootPath;
+import org.apache.directory.server.dhcp.options.vendor.Routers;
+import org.apache.directory.server.dhcp.options.vendor.SubnetMask;
+import org.apache.directory.server.dhcp.options.vendor.SwapServer;
+import org.apache.directory.server.dhcp.options.vendor.TimeOffset;
+import org.apache.directory.server.dhcp.options.vendor.TimeServers;
 
 
 /**
@@ -36,36 +108,134 @@
  */
 public abstract class DhcpOption
 {
-    private int tag;
-    private int length;
+    /**
+     * An array of concrete implementations of DhcpOption.
+     */
+    private static Class OPTION_CLASSES[] =
+        { BootfileName.class, ClientIdentifier.class, DhcpMessageType.class, IpAddressLeaseTime.class,
+            MaximumDhcpMessageSize.class, org.apache.directory.server.dhcp.options.dhcp.Message.class,
+            OptionOverload.class, ParameterRequestList.class, RebindingTimeValue.class, RenewalTimeValue.class,
+            RequestedIpAddress.class, ServerIdentifier.class, TftpServerName.class, VendorClassIdentifier.class,
+            ClientIdentifier.class, DhcpMessageType.class, IpAddressLeaseTime.class, MaximumDhcpMessageSize.class,
+            OptionOverload.class, ParameterRequestList.class, RebindingTimeValue.class, RenewalTimeValue.class,
+            RequestedIpAddress.class, ServerIdentifier.class, TftpServerName.class, UnrecognizedOption.class,
+            VendorClassIdentifier.class, DefaultFingerServers.class, DefaultIrcServers.class, DefaultWwwServers.class,
+            MobileIpHomeAgents.class, NbddServers.class, NetbiosNameServers.class, NetbiosNodeType.class,
+            NetbiosScope.class, NisDomain.class, NisPlusDomain.class, NisPlusServers.class, NisServers.class,
+            NntpServers.class, NtpServers.class, Pop3Servers.class, SmtpServers.class, StdaServers.class,
+            StreetTalkServers.class, VendorSpecificInformation.class, XWindowDisplayManagers.class,
+            XWindowFontServers.class, DefaultIpTimeToLive.class, IpForwarding.class, MaximumDatagramSize.class,
+            NonLocalSourceRouting.class, PathMtuAgingTimeout.class, PathMtuPlateauTable.class, PolicyFilter.class,
+            AllSubnetsAreLocal.class, BroadcastAddress.class, InterfaceMtu.class, MaskSupplier.class,
+            PerformMaskDiscovery.class, PerformRouterDiscovery.class, RouterSolicitationAddress.class,
+            StaticRoute.class, TcpDefaultTimeToLive.class, TcpKeepaliveGarbage.class, TcpKeepaliveInterval.class,
+            BootFileSize.class, CookieServers.class, DomainName.class, DomainNameServers.class, ExtensionsPath.class,
+            HostName.class, ImpressServers.class, LogServers.class, LprServers.class, MeritDumpFile.class,
+            NameServers.class, ResourceLocationServers.class, RootPath.class, Routers.class, SubnetMask.class,
+            SwapServer.class, TimeOffset.class, TimeServers.class, };
 
+    /**
+     * A map of concrete implementations of DhcpOption indexed by tag code.
+     */
+    private static Map OPTION_CLASS_BY_CODE;
 
     /**
-     * Creates a new instance of DhcpOption.
-     *
-     * @param tag
-     * @param length
+     * A map of tag codes indexed by OptionClass subclass.
      */
-    public DhcpOption( int tag, int length )
+    private static Map CODE_BY_CLASS;
+
+    static
     {
-        this.tag = tag;
-        this.length = length;
+        try
+        {
+            // initialize the tag-to-class and class-to-tag map
+            Map classByCode = new HashMap();
+            Map codeByClass = new HashMap();
+            for ( int i = 0; i < OPTION_CLASSES.length; i++ )
+            {
+                Class c = OPTION_CLASSES[i];
+
+                if ( !DhcpOption.class.isAssignableFrom( c ) )
+                    throw new RuntimeException( "Class " + c + " is not a descendant of DhcpOption" );
+
+                DhcpOption o = ( DhcpOption ) c.newInstance();
+
+                Integer tagInt = new Integer( o.getTag() );
+                classByCode.put( tagInt, c );
+                codeByClass.put( c, tagInt );
+            }
+
+            OPTION_CLASS_BY_CODE = Collections.unmodifiableMap( classByCode );
+            CODE_BY_CLASS = Collections.unmodifiableMap( codeByClass );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( "Can't initialize option field classes", e );
+        }
     }
 
 
-    abstract protected void valueToByteBuffer( ByteBuffer out );
+    public static Class getClassByTag( int tag )
+    {
+        return ( Class ) OPTION_CLASS_BY_CODE.get( new Integer( tag ) );
+    }
 
 
+    public static int getTagByClass( Class c )
+    {
+        return ( ( Integer ) CODE_BY_CLASS.get( c ) ).intValue();
+    }
+
     /**
-     * Writes this {@link DhcpOption} to the provided {@link ByteBuffer}.
-     *
-     * @param out
+     * The default data array used for simple (unparsed) options.
      */
-    public void writeTo( ByteBuffer out )
+    private byte[] data;
+
+
+    /**
+     * Get the option's code tag.
+     * 
+     * @return
+     */
+    public abstract byte getTag();
+
+
+    /**
+     * Set the data (wire format) from a byte array. The default implementation
+     * just records the data as a byte array. Subclasses may parse the data into
+     * something more meaningful.
+     * 
+     * @param data
+     */
+    public void setData( byte data[] )
+    {
+        this.data = data;
+    }
+
+
+    /**
+     * Get the data (wire format) into a byte array. Subclasses must provide an
+     * implementation which serializes the parsed data back into a byte array if
+     * they override {@link #setData(byte[])}.
+     * 
+     * @return
+     */
+    public byte[] getData()
     {
-        out.put( ( byte ) tag );
-        out.put( ( byte ) length );
+        return data;
+    }
+
+
+    public final void writeTo( ByteBuffer out )
+    {
+        out.put( getTag() );
+
+        // FIXME: handle continuation, i.e. options longer than 128 bytes?
+        byte data[] = getData();
+        if ( data.length > 255 )
+            throw new IllegalArgumentException( "Max data length: 128 bytes." );
 
-        valueToByteBuffer( out );
+        out.put( ( byte ) data.length );
+        out.put( data );
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/OptionsField.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/OptionsField.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/OptionsField.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/OptionsField.java Mon Mar 17 23:12:41 2008
@@ -6,23 +6,24 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 
 package org.apache.directory.server.dhcp.options;
 
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 
 /**
@@ -37,38 +38,105 @@
  */
 public class OptionsField
 {
-    private Set<DhcpOption> options = new HashSet<DhcpOption>();
+    /**
+     * A map of option code (Integer)->DhcpOption. FIXME: use IntHashtable from
+     * commons collections
+     */
+    private Map options = new HashMap();
+
+
+    public void add( DhcpOption option )
+    {
+        options.put( new Integer( option.getTag() ), option );
+    }
+
+
+    public boolean isEmpty()
+    {
+        return options.isEmpty();
+    }
+
+
+    public Iterator iterator()
+    {
+        return options.values().iterator();
+    }
 
 
     /**
-     * Adds the provided {@link DhcpOption} to this {@link OptionsField}.
-     *
-     * @param option
+     * Return the (first) DHCP option matching a given option class or
+     * <code>null</code> of the option isn't set.
+     * 
+     * @param class1
      */
-    public void add( DhcpOption option )
+    public DhcpOption get( Class optionClass )
     {
-        options.add( option );
+        Integer key = new Integer( DhcpOption.getTagByClass( optionClass ) );
+        return ( DhcpOption ) options.get( key );
     }
 
 
     /**
-     * Returns whether this {@link OptionsField} is empty.
-     *
-     * @return true if this {@link OptionsField} is empty.
+     * Return the (first) DHCP option matching a given tag or <code>null</code>
+     * of the option isn't set.
+     * 
+     * @param class1
      */
-    public boolean isEmpty()
+    public DhcpOption get( int tag )
     {
-        return options.isEmpty();
+        Integer key = new Integer( tag );
+        return ( DhcpOption ) options.get( key );
+    }
+
+
+    /**
+     * Merge the options from the given options field into my options. Existing
+     * options are replaced by the ones from the supplied options field.
+     * 
+     * @param options2
+     */
+    public void merge( OptionsField options )
+    {
+        if ( null == options )
+            return;
+
+        for ( Iterator i = options.iterator(); i.hasNext(); )
+        {
+            DhcpOption option = ( DhcpOption ) i.next();
+            this.options.put( new Integer( option.getTag() ), option );
+        }
+    }
+
+
+    /**
+     * Remove instances of the given option class.
+     * 
+     * @param class1
+     */
+    public void remove( Class c )
+    {
+        Integer key = new Integer( DhcpOption.getTagByClass( c ) );
+        options.remove( key );
+    }
+
+
+    /**
+     * Remove options matching the given tag
+     * 
+     * @param class1
+     */
+    public void remove( int tag )
+    {
+        Integer key = new Integer( tag );
+        options.remove( key );
     }
 
 
     /**
-     * Returns this {@link OptionsField} as an array of {@link DhcpOption}s.
-     *
-     * @return The array of {@link DhcpOption}s.
+     * @see Map#clear()
      */
-    public DhcpOption[] toArray()
+    public void clear()
     {
-        return options.toArray( new DhcpOption[options.size()] );
+        options.clear();
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/BootfileName.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/BootfileName.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/BootfileName.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/BootfileName.java Mon Mar 17 23:12:41 2008
@@ -6,54 +6,40 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.StringOption;
 
 
 /**
  * This option is used to identify a bootfile when the 'file' field in
  * the DHCP header has been used for DHCP options.
- * 
+*
  * The code for this option is 67, and its minimum length is 1.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class BootfileName extends DhcpOption
+public class BootfileName extends StringOption
 {
-    private byte[] bootFileName;
-
-
-    /**
-     * Creates a new instance of BootfileName.
-     *
-     * @param bootFileName
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public BootfileName( byte[] bootFileName )
-    {
-        super( 67, 1 );
-        this.bootFileName = bootFileName;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( bootFileName );
+        return 67;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ClientIdentifier.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ClientIdentifier.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ClientIdentifier.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ClientIdentifier.java Mon Mar 17 23:12:41 2008
@@ -21,8 +21,6 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
 import org.apache.directory.server.dhcp.options.DhcpOption;
 
 
@@ -55,23 +53,11 @@
  */
 public class ClientIdentifier extends DhcpOption
 {
-    private byte[] clientIdentifier;
-
-
-    /**
-     * Creates a new instance of ClientIdentifier.
-     *
-     * @param clientIdentifier
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public ClientIdentifier( byte[] clientIdentifier )
-    {
-        super( 61, 2 );
-        this.clientIdentifier = clientIdentifier;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( clientIdentifier );
+        return 61;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/DhcpMessageType.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/DhcpMessageType.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/DhcpMessageType.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/DhcpMessageType.java Mon Mar 17 23:12:41 2008
@@ -21,8 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
+import org.apache.directory.server.dhcp.messages.MessageType;
 import org.apache.directory.server.dhcp.options.DhcpOption;
 
 
@@ -47,23 +46,44 @@
  */
 public class DhcpMessageType extends DhcpOption
 {
-    private byte[] messageType;
+    private MessageType type;
+
+
+    public DhcpMessageType()
+    {
+    }
+
+
+    public DhcpMessageType(MessageType type)
+    {
+        this.type = type;
+    }
 
 
-    /**
-     * Creates a new instance of DhcpMessageType.
-     *
-     * @param messageType
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public DhcpMessageType( byte[] messageType )
+    public byte getTag()
+    {
+        return 53;
+    }
+
+
+    public void setData( byte[] messageType )
+    {
+        type = MessageType.getTypeByCode( messageType[0] );
+    }
+
+
+    public byte[] getData()
     {
-        super( 53, 1 );
-        this.messageType = messageType;
+        return new byte[]
+            { type.getCode() };
     }
 
 
-    protected void valueToByteBuffer( ByteBuffer out )
+    public MessageType getType()
     {
-        out.put( messageType );
+        return type;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/IpAddressLeaseTime.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/IpAddressLeaseTime.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/IpAddressLeaseTime.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/IpAddressLeaseTime.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.IntOption;
 
 
 /**
@@ -40,25 +38,24 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class IpAddressLeaseTime extends DhcpOption
+public class IpAddressLeaseTime extends IntOption
 {
-    private byte[] ipAddressLeaseTime;
+    public IpAddressLeaseTime()
+    {
+    }
 
 
-    /**
-     * Creates a new instance of IpAddressLeaseTime.
-     *
-     * @param ipAddressLeaseTime
-     */
-    public IpAddressLeaseTime( byte[] ipAddressLeaseTime )
+    public IpAddressLeaseTime(long leaseTime)
     {
-        super( 51, 4 );
-        this.ipAddressLeaseTime = ipAddressLeaseTime;
+        setIntValue( leaseTime );
     }
 
 
-    protected void valueToByteBuffer( ByteBuffer out )
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
+     */
+    public byte getTag()
     {
-        out.put( ipAddressLeaseTime );
+        return 51;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/MaximumDhcpMessageSize.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/MaximumDhcpMessageSize.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/MaximumDhcpMessageSize.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/MaximumDhcpMessageSize.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.ShortOption;
 
 
 /**
@@ -39,25 +37,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class MaximumDhcpMessageSize extends DhcpOption
+public class MaximumDhcpMessageSize extends ShortOption
 {
-    private byte[] maximumDhcpMessageSize;
-
-
-    /**
-     * Creates a new instance of MaximumDhcpMessageSize.
-     *
-     * @param maximumDhcpMessageSize
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public MaximumDhcpMessageSize( byte[] maximumDhcpMessageSize )
-    {
-        super( 57, 2 );
-        this.maximumDhcpMessageSize = maximumDhcpMessageSize;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( maximumDhcpMessageSize );
+        return 57;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/Message.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/Message.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/Message.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/Message.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.StringOption;
 
 
 /**
@@ -39,25 +37,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class Message extends DhcpOption
+public class Message extends StringOption
 {
-    private byte[] message;
-
-
-    /**
-     * Creates a new instance of Message.
-     *
-     * @param message
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public Message( byte[] message )
-    {
-        super( 56, 1 );
-        this.message = message;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( message );
+        return 56;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/OptionOverload.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/OptionOverload.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/OptionOverload.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/OptionOverload.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.ByteOption;
 
 
 /**
@@ -48,25 +46,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class OptionOverload extends DhcpOption
+public class OptionOverload extends ByteOption
 {
-    private byte[] optionOverload;
-
-
-    /**
-     * Creates a new instance of OptionOverload.
-     *
-     * @param optionOverload
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public OptionOverload( byte[] optionOverload )
-    {
-        super( 52, 1 );
-        this.optionOverload = optionOverload;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( optionOverload );
+        return 52;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ParameterRequestList.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ParameterRequestList.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ParameterRequestList.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ParameterRequestList.java Mon Mar 17 23:12:41 2008
@@ -21,8 +21,6 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
 import org.apache.directory.server.dhcp.options.DhcpOption;
 
 
@@ -44,23 +42,11 @@
  */
 public class ParameterRequestList extends DhcpOption
 {
-    private byte[] parameterRequestList;
-
-
-    /**
-     * Creates a new instance of ParameterRequestList.
-     *
-     * @param parameterRequestList
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public ParameterRequestList( byte[] parameterRequestList )
-    {
-        super( 55, 1 );
-        this.parameterRequestList = parameterRequestList;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.put( parameterRequestList );
+        return 55;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RebindingTimeValue.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RebindingTimeValue.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RebindingTimeValue.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RebindingTimeValue.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.IntOption;
 
 
 /**
@@ -38,25 +36,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class RebindingTimeValue extends DhcpOption
+public class RebindingTimeValue extends IntOption
 {
-    private int rebindingTimeValue;
-
-
-    /**
-     * Creates a new instance of RebindingTimeValue.
-     *
-     * @param rebindingTimeValue
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public RebindingTimeValue( int rebindingTimeValue )
-    {
-        super( 59, 4 );
-        this.rebindingTimeValue = rebindingTimeValue;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.putInt( rebindingTimeValue );
+        return 59;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RenewalTimeValue.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RenewalTimeValue.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RenewalTimeValue.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RenewalTimeValue.java Mon Mar 17 23:12:41 2008
@@ -21,9 +21,7 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
-import java.nio.ByteBuffer;
-
-import org.apache.directory.server.dhcp.options.DhcpOption;
+import org.apache.directory.server.dhcp.options.IntOption;
 
 
 /**
@@ -38,25 +36,13 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class RenewalTimeValue extends DhcpOption
+public class RenewalTimeValue extends IntOption
 {
-    private int renewalTimeValue;
-
-
-    /**
-     * Creates a new instance of RenewalTimeValue.
-     *
-     * @param renewalTimeValue
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public RenewalTimeValue( int renewalTimeValue )
-    {
-        super( 58, 4 );
-        this.renewalTimeValue = renewalTimeValue;
-    }
-
-
-    protected void valueToByteBuffer( ByteBuffer out )
+    public byte getTag()
     {
-        out.putInt( renewalTimeValue );
+        return 58;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RequestedIpAddress.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RequestedIpAddress.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RequestedIpAddress.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/RequestedIpAddress.java Mon Mar 17 23:12:41 2008
@@ -35,13 +35,11 @@
  */
 public class RequestedIpAddress extends AddressOption
 {
-    /**
-     * Creates a new instance of RequestedIpAddress.
-     *
-     * @param requestedIpAddress
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public RequestedIpAddress( byte[] requestedIpAddress )
+    public byte getTag()
     {
-        super( 50, requestedIpAddress );
+        return 50;
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ServerIdentifier.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ServerIdentifier.java?rev=638228&r1=638227&r2=638228&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ServerIdentifier.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/dhcp/ServerIdentifier.java Mon Mar 17 23:12:41 2008
@@ -21,6 +21,8 @@
 package org.apache.directory.server.dhcp.options.dhcp;
 
 
+import java.net.InetAddress;
+
 import org.apache.directory.server.dhcp.options.AddressOption;
 
 
@@ -43,13 +45,22 @@
  */
 public class ServerIdentifier extends AddressOption
 {
-    /**
-     * Creates a new instance of ServerIdentifier.
-     *
-     * @param serverIdentifier
+    public ServerIdentifier()
+    {
+    }
+
+
+    public ServerIdentifier(InetAddress localHost)
+    {
+        setAddress( localHost );
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.options.DhcpOption#getTag()
      */
-    public ServerIdentifier( byte[] serverIdentifier )
+    public byte getTag()
     {
-        super( 54, serverIdentifier );
+        return 54;
     }
 }