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