001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    
021    package org.apache.directory.server.ntp.service;
022    
023    
024    import org.apache.directory.server.ntp.NtpService;
025    import org.apache.directory.server.ntp.messages.LeapIndicatorType;
026    import org.apache.directory.server.ntp.messages.ModeType;
027    import org.apache.directory.server.ntp.messages.NtpMessage;
028    import org.apache.directory.server.ntp.messages.NtpMessageModifier;
029    import org.apache.directory.server.ntp.messages.NtpTimeStamp;
030    import org.apache.directory.server.ntp.messages.ReferenceIdentifier;
031    import org.apache.directory.server.ntp.messages.StratumType;
032    
033    
034    /**
035     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036     * @version $Rev: 501532 $, $Date: 2007-01-30 20:58:55 +0100 (Tue, 30 Jan 2007) $
037     */
038    public class NtpServiceImpl implements NtpService
039    {
040        public NtpMessage getReplyFor( NtpMessage request )
041        {
042            NtpMessageModifier modifier = new NtpMessageModifier();
043    
044            modifier.setLeapIndicator( LeapIndicatorType.NO_WARNING );
045            modifier.setVersionNumber( 4 );
046            modifier.setMode( ModeType.SERVER );
047            modifier.setStratum( StratumType.PRIMARY_REFERENCE );
048            modifier.setPollInterval( ( byte ) 0x04 );
049            modifier.setPrecision( ( byte ) 0xFA );
050            modifier.setRootDelay( 0 );
051            modifier.setRootDispersion( 0 );
052            modifier.setReferenceIdentifier( ReferenceIdentifier.LOCL );
053    
054            NtpTimeStamp now = new NtpTimeStamp();
055    
056            modifier.setReferenceTimestamp( now );
057            modifier.setOriginateTimestamp( request.getTransmitTimestamp() );
058            modifier.setReceiveTimestamp( request.getReceiveTimestamp() );
059            modifier.setTransmitTimestamp( now );
060    
061            return modifier.getNtpMessage();
062        }
063    }