directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r126028 - in incubator/directory/dhcp/trunk: core/src/java/org/apache/dhcp/io core/src/java/org/apache/dhcp/options/vendor core/src/java/org/apache/dhcp/service protocol/src/java/org/apache/dhcp/protocol
Date Sat, 22 Jan 2005 10:13:31 GMT
Author: erodriguez
Date: Sat Jan 22 02:13:29 2005
New Revision: 126028

URL: http://svn.apache.org/viewcvs?view=rev&rev=126028
Log:
Stub DHCP service implementation and encoding troubleshooting.
Modified:
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java
   incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
   incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java

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=126028&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java&r1=126027&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/io/DhcpMessageEncoder.java&r2=126028
==============================================================================
--- 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
Sat Jan 22 02:13:29 2005
@@ -33,7 +33,7 @@
 	 */
 	public void encode( ByteBuffer byteBuffer, DhcpMessage message )
 	{
-		byteBuffer.put( (byte)message.getMessageType().getOrdinal() );
+		byteBuffer.put( message.getOpCode() );
 		byteBuffer.put( message.getHardwareAddressType() );
 		byteBuffer.put( message.getHardwareAddressLength() );
 		byteBuffer.put( message.getHardwareOptions() );

Modified: incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java?view=diff&rev=126028&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java&r1=126027&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java&r2=126028
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java
(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/options/vendor/EndOption.java
Sat Jan 22 02:13:29 2005
@@ -34,6 +34,11 @@
 		super( 255, 1 );
 	}
 	
+	public void writeTo( ByteBuffer out )
+	{
+		out.put( (byte)0xFF );
+	}
+	
 	protected void valueToByteBuffer( ByteBuffer out )
 	{
 		/**

Modified: 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=diff&rev=126028&p1=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java&r1=126027&p2=incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java&r2=126028
==============================================================================
--- incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
(original)
+++ incubator/directory/dhcp/trunk/core/src/java/org/apache/dhcp/service/DhcpServiceImpl.java
Sat Jan 22 02:13:29 2005
@@ -19,7 +19,8 @@
 
 import org.apache.dhcp.DhcpService;
 import org.apache.dhcp.messages.DhcpMessage;
-
+import org.apache.dhcp.messages.DhcpMessageModifier;
+import org.apache.dhcp.messages.MessageType;
 
 /**
  * DHCP Protocol (RFC 2131, RFC 2132)
@@ -28,7 +29,34 @@
 {
 	public DhcpMessage getReplyFor( DhcpMessage request )
     {
-		return request;
+		DhcpMessageModifier modifier = new DhcpMessageModifier();
+		
+		modifier.setMessageType( MessageType.DHCPOFFER );
+		modifier.setOpCode( (byte)0x02 );
+		modifier.setHardwareAddressType( (byte)0x00 );
+		modifier.setHardwareAddressLength( (byte)0xFF );
+		modifier.setHardwareOptions( (byte)0x00 );
+		modifier.setTransactionId( request.getTransactionId() );
+		modifier.setSeconds( (short)0 );
+		modifier.setFlags( (short)0 );
+		
+		byte[] actual = { (byte)0, (byte)0, (byte)0, (byte)0 };
+		modifier.setActualClientAddress( actual );
+		
+		byte[] assigned = { (byte)192, (byte)168, (byte)0, (byte)20 };
+		modifier.setAssignedClientAddress( assigned );
+		
+		byte[] unused = { (byte)0, (byte)0, (byte)0, (byte)0 };
+		modifier.setNextServerAddress( unused );
+		modifier.setRelayAgentAddress( unused );
+		
+		modifier.setClientHardwareAddress( request.getClientHardwareAddress() );
+		modifier.setServerHostname( request.getServerHostname() );
+		modifier.setBootFileName( request.getBootFileName() );
+		
+		DhcpMessage reply = modifier.getDhcpMessage();
+		
+		return reply;
 	}
 }
 

Modified: incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java?view=diff&rev=126028&p1=incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java&r1=126027&p2=incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java&r2=126028
==============================================================================
--- incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
(original)
+++ incubator/directory/dhcp/trunk/protocol/src/java/org/apache/dhcp/protocol/DhcpProtocolHandler.java
Sat Jan 22 02:13:29 2005
@@ -17,17 +17,22 @@
 
 package org.apache.dhcp.protocol;
 
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
 import org.apache.dhcp.DhcpService;
 import org.apache.dhcp.messages.DhcpMessage;
 import org.apache.dhcp.service.DhcpServiceImpl;
 import org.apache.mina.common.IdleStatus;
+import org.apache.mina.io.datagram.DatagramConnector;
 import org.apache.mina.protocol.ProtocolHandler;
 import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.protocol.io.IoProtocolConnector;
 
 
 public class DhcpProtocolHandler implements ProtocolHandler
 {
-
     public void sessionOpened( ProtocolSession session )
     {
         System.out.println( session.getRemoteAddress() + " OPENED" );
@@ -55,10 +60,26 @@
     {
         System.out.println( session.getRemoteAddress() + " RCVD: " + message );
         
-        DhcpService dhcpService = new DhcpServiceImpl();
-        DhcpMessage reply = dhcpService.getReplyFor( (DhcpMessage)message );
+        DhcpMessage request = (DhcpMessage)message;
         
-        session.write( reply );
+        if ( request.getOpCode() == 1 )
+        {
+            DhcpService dhcpService = new DhcpServiceImpl();
+            DhcpMessage reply = dhcpService.getReplyFor( request );
+            
+            try
+			{
+            	int PORT = 68;
+                IoProtocolConnector connector = new IoProtocolConnector( new DatagramConnector()
);
+                InetAddress broadcast = InetAddress.getByName( null );
+                ProtocolSession replySession = connector.connect( new InetSocketAddress(
broadcast, PORT ), new DhcpProtocolProvider() );
+                replySession.write( reply );
+			}
+            catch (IOException ioe)
+			{
+            	ioe.printStackTrace();
+			}
+        }
     }
 
     public void messageSent( ProtocolSession session, Object message )

Mime
View raw message