directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r125108 - in incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp: . io options service
Date Thu, 13 Jan 2005 22:48:16 GMT
Author: erodriguez
Date: Thu Jan 13 14:48:14 2005
New Revision: 125108

URL: http://svn.apache.org/viewcvs?view=rev&rev=125108
Log:
Basic troubleshooting of DHCP processing.
Added:
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
Modified:
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java

Modified: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java?view=diff&rev=125108&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java&r1=125107&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java&r2=125108
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java	(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/DhcpException.java	Thu Jan
13 14:48:14 2005
@@ -20,9 +20,24 @@
 
 public class DhcpException extends Exception
 {
-	public DhcpException(String name)
-	{
-		super(name);
-	}
+    /**
+     * This empty constructor is used if no 
+     * explanation of the DHCP exception is required.
+     */
+    public DhcpException()
+    {
+        super();
+    }
+
+    /**
+     * 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
+     */
+    public DhcpException( String description )
+    {
+        super( description );
+    }
 }
 

Modified: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java?view=diff&rev=125108&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java&r1=125107&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java&r2=125108
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java
(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageDecoder.java
Thu Jan 13 14:48:14 2005
@@ -22,30 +22,42 @@
 import org.apache.dhcp.DhcpException;
 import org.apache.dhcp.messages.DhcpMessage;
 import org.apache.dhcp.messages.DhcpMessageModifier;
+import org.apache.dhcp.messages.MessageType;
+import org.apache.dns.io.ByteBufferCodec;
 
 
 public class DhcpMessageDecoder
 {
 	/**
-	 * Convert a specified byte array into a DhcpMessage.
+	 * Convert a byte buffer into a DhcpMessage.
 	 * 
 	 * @return a DhcpMessage.
 	 * @param buffer ByteBuffer to convert to a DhcpMessage object
 	 */
-	public DhcpMessage decode(ByteBuffer buffer) throws DhcpException
+	public DhcpMessage decode( ByteBuffer buffer ) throws DhcpException
 	{
+		/**
+		 * TODO - need to figure out why the buffer needs to be rewound.
+		 */
+		buffer.rewind();
+		
 		DhcpMessageModifier modifier = new DhcpMessageModifier();
 		
+		modifier.setMessageType( MessageType.DHCPDISCOVER );
+		
 		modifier.setOpCode( buffer.get() );
 		modifier.setHardwareAddressType( buffer.get() );
-		modifier.setHardwareAddressLength( buffer.get() );
+		
+		short hardwareAddressLength = ByteBufferCodec.getUnsignedByte( buffer );
+		
+		modifier.setHardwareAddressLength( (byte)hardwareAddressLength );
 		modifier.setHardwareOptions( buffer.get() );
 		
 		modifier.setTransactionId( buffer.getInt() );
 		modifier.setSeconds( buffer.getShort() );
 		modifier.setFlags( buffer.getShort() );
 		
-		byte[] nextFourBytes = new byte[4];
+		byte[] nextFourBytes = new byte[ 4 ];
 		
 		buffer.get( nextFourBytes );
 		modifier.setActualClientAddress( nextFourBytes );
@@ -59,18 +71,19 @@
 		buffer.get( nextFourBytes );
 		modifier.setRelayAgentAddress( nextFourBytes );
 		
-		byte[] clientHardwareAddress = new byte[16];
+		byte[] clientHardwareAddress = new byte[ 16 ];
+		
 		buffer.get( clientHardwareAddress );
 		modifier.setClientHardwareAddress( clientHardwareAddress );
 		
-		byte[] serverHostname = new byte[64];
+		byte[] serverHostname = new byte[ 64 ];
 		buffer.get( serverHostname );
 		modifier.setServerHostname( serverHostname );
 		
-		byte[] bootFileName = new byte[128];
+		byte[] bootFileName = new byte[ 128 ];
 		buffer.get( bootFileName );
 		modifier.setBootFileName( bootFileName );
-
+		
 		DhcpOptionsDecoder decoder = new DhcpOptionsDecoder();
 		modifier.setOptions( decoder.decode( buffer ) );
 		

Modified: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java?view=diff&rev=125108&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java&r1=125107&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java&r2=125108
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java
(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java
Thu Jan 13 14:48:14 2005
@@ -26,36 +26,33 @@
 public class DhcpMessageEncoder
 {
 	/**
-	 * Converts a DhcpMessage object to a byte array.
+	 * Converts a DhcpMessage object into a byte buffer.
 	 * 
-	 * @return a byte array with information from DhcpMessage object.
+	 * @param byteBuffer ByteBuffer to put DhcpMessage into
+	 * @param message DhcpMessage to encode into ByteBuffer
 	 */
-	public ByteBuffer encode(DhcpMessage message)
+	public void encode( ByteBuffer byteBuffer, DhcpMessage message )
 	{
-		ByteBuffer buffer = ByteBuffer.allocate(1500);
-		
-		buffer.put( (byte)message.getMessageType().getOrdinal() );
-		buffer.put( message.getHardwareAddressType() );
-		buffer.put( message.getHardwareAddressLength() );
-		buffer.put( message.getHardwareOptions() );
-		buffer.putInt( message.getTransactionId() );
-		buffer.putShort( message.getSeconds() );
-		buffer.putShort( message.getFlags() );
-		buffer.put( message.getActualClientAddress() );
-		buffer.put( message.getAssignedClientAddress() );
-		buffer.put( message.getNextServerAddress() );
-		buffer.put( message.getRelayAgentAddress() );
-		buffer.put( message.getClientHardwareAddress() );
-		buffer.put( message.getServerHostname() );
-		buffer.put( message.getBootFileName() );
+		byteBuffer.put( (byte)message.getMessageType().getOrdinal() );
+		byteBuffer.put( message.getHardwareAddressType() );
+		byteBuffer.put( message.getHardwareAddressLength() );
+		byteBuffer.put( message.getHardwareOptions() );
+		byteBuffer.putInt( message.getTransactionId() );
+		byteBuffer.putShort( 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() );
 		
 		OptionsField options = message.getOptions();
 		
 		DhcpOptionsEncoder optionsEncoder = new DhcpOptionsEncoder();
 		
-		optionsEncoder.encode( options, buffer );
-		
-		return buffer;
+		optionsEncoder.encode( options, byteBuffer );
 	}
 }
 

Modified: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java?view=diff&rev=125108&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java&r1=125107&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java&r2=125108
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java
(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/OptionsField.java
Thu Jan 13 14:48:14 2005
@@ -43,7 +43,7 @@
 
 	public DhcpOption[] toArray()
 	{
-		return (DhcpOption[])options.toArray();
+		return (DhcpOption[])options.toArray( new DhcpOption[ options.size() ] );
 	}
 }
 

Added: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java?view=auto&rev=125108
==============================================================================
--- (empty file)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
Thu Jan 13 14:48:14 2005
@@ -0,0 +1,34 @@
+/*
+ *   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.dhcp.service;
+
+import org.apache.dhcp.DhcpService;
+import org.apache.dhcp.messages.DhcpMessage;
+
+
+/**
+ * DHCP Protocol (RFC 2131, RFC 2132)
+ */
+public class DhcpServiceImpl implements DhcpService
+{
+	public DhcpMessage getReplyFor( DhcpMessage request )
+    {
+		return request;
+	}
+}
+

Mime
View raw message