<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="3"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="no"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc rfcedstyle="yes" ?>


<rfc number="7164" category="std" submissionType="IETF" consensus="yes"
  ipr="trust200902" updates="3550">

  <front>
    <title abbrev="RTP and Leap Seconds">RTP and Leap Seconds</title>

    <author fullname="Kevin Gross" initials="K." surname="Gross">
      <organization>AVA Networks</organization>

      <address>
        <postal>
          <street/>
          <city>Boulder</city>
          <region>CO</region>
          <country>US</country>
        </postal>

        <email>kevin.gross@avanw.com</email>
      </address>
    </author>

    <author fullname="Ray van Brandenburg" initials="R."
            surname="van Brandenburg">
      <organization>TNO</organization>

      <address>
        <postal>
          <street>Brassersplein 2</street>
          <city>Delft</city>
          <code>2612CT</code>
          <country>the Netherlands</country>
        </postal>

        <phone>+31-88-866-7000</phone>

        <email>ray.vanbrandenburg@tno.nl</email>
      </address>
    </author>

    <date month="March" year="2014"/>

    <area>Real-time Applications and Infrastructure</area>

    <workgroup>AVTCore</workgroup>

    <keyword>Leap second</keyword>

    <keyword>RTP</keyword>

    <keyword>Real-time Transport Protocol</keyword>

    <keyword>NTP</keyword>

    <keyword>Network Time Protocol</keyword>

    <keyword>UTC</keyword>

    <keyword>Universal Coordinated Time</keyword>
	
	<keyword>TAI</keyword>
	
	<keyword>International Atomic Time</keyword>
	
	<keyword>Unix time</keyword>

    <abstract>
      <t>This document discusses issues that arise when RTP sessions span
      Coordinated Universal Time (UTC) leap seconds. It updates RFC 3550 by
describing how RTP senders and receivers should behave in the presence of leap seconds.</t>
    </abstract>
  </front>

  <middle>
    <section anchor="intro" title="Introduction">
      <t>In some media networking applications, RTP streams are referenced to a
wall-clock time 
      (absolute date and time). This is accomplished through use of
      the NTP timestamp field in the sender report (SR) to create a
      mapping between RTP timestamps and the wall clock. When a wall-clock
      reference is used, the playout time for RTP packets is referenced to the
      wall clock. Smooth and continuous media playout requires a smooth and
      continuous time base. The time base used by the wall clock may include leap
      seconds that are not rendered smoothly.</t>

      <t>This document updates <xref target="RFC3550">RFC 3550</xref> by
providing recommendations for smoothly rendering 
      streamed media referenced to common wall clocks that do not have smooth
      or continuous behavior in the presence of leap seconds.</t>
    </section>

    <section title="Terminology">
      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
      "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
      document are to be interpreted as described in <xref target="RFC2119">RFC 2119</xref>
      and indicate requirement levels for compliant implementations.</t>
    </section>

    <section anchor="background" title="Leap Seconds">
      <t>The world's scientific time standard is International Atomic Time
(TAI), which is based on vibrations of cesium atoms in an atomic clock. 
The world's civil time is based on the rotation of the Earth. In 1972, the civil time
standard, Coordinated Universal Time (UTC), was redefined in terms of TAI and
the concept of leap seconds was introduced to allow UTC to remain synchronized
with the rotation of the Earth.</t> 
      
      <t>Leap seconds are scheduled
      by the International Earth Rotation and Reference Systems Service. Leap seconds may be scheduled at the last day of any month but are preferentially scheduled for 
      December and June and secondarily March and September <xref
target="TF.460-6"/>. Because Earth's rotation is unpredictable, leap seconds
are typically not scheduled more than six months in advance.</t>
      
      <t>Leap seconds do not respect local time and always occur at the end of
the UTC day. Leap seconds can be scheduled to either add or remove
      a second from the day. A leap second that adds an extra second is known
as a positive leap second. A leap second that skips a second is known as a
negative leap second.</t>

	  <t>Since their introduction in 1972, all leap seconds 
have been scheduled in June or December, and they have all been positive.</t> 

      <t>NOTE: The ITU is studying a proposal that could eventually eliminate
      leap seconds from UTC. As of January 2012, this proposal is expected to
      be decided no earlier than 2015 <xref target="ITU-RWP7A"/>.</t>

      <section anchor="UTC" title="UTC Behavior during a Positive Leap Second">
        <t>UTC clocks feature a 61st second at the end of the day when a positive leap
        second is scheduled. The leap second is designated "23h 59m 60s".</t>
      </section>

      <section anchor="NTP" title="NTP Behavior during a Positive Leap Second">
        <t>Under NTP <xref target="RFC5905"/>, a leap second is inserted at the
        beginning of the last second of the day. This results in the clock
        freezing or slowing for one second immediately prior to the last
        second of the affected day. This results in the last second of the day
        having a real-time duration of two seconds. Timestamp accuracy is compromised during this period because the clock's rate is not well defined.</t>
      </section>

      <section anchor="POSIX" title="POSIX Behavior during a Positive Leap Second">
        <t>The POSIX (Portable Operating System Interface) standard <xref
target="IEEE.1003.1"/> requires that leap seconds be omitted from reported
time. All days are defined as having 86,400 seconds, but the timebase is defined
to be UTC, a leap-second-bearing reference. Implementors of POSIX systems are
offered considerable latitude by the standard as to how to map POSIX time to
UTC.</t> 
				
				<t>In many systems, leap seconds are
accommodated by repeating the last second of the day. A
        timestamp within the last second of the day is therefore ambiguous in
        that it can refer to a moment in time in either of the last two seconds of a day
        containing a leap second.</t>
				
				<t>Other systems use the same technique used by NTP, freezing or slowing for one second immediately prior to the last
        second of the affected day.</t>
				
				<t>In some cases, leap seconds are accommodated by warping time <xref target="I-D.kuhn-leapsecond"/> <xref target="Google"/>; that is, the length of the second in the vicinity of a leap second is slightly altered.</t>
      </section>
	  
	  <section title="Example of Leap-Second Behaviors">
		<t><xref target='Leap-second-behavior'/> illustrates the
positive leap second that occurred June 30, 2012 when the offset between TAI
and UTC changed from 34 to 35 seconds. The first column shows RTP timestamps
for an 8 kHz audio stream. The second column shows the TAI reference. The following
columns show behavior for the leap-second-bearing wall clocks described
above. Time values are shown at half-second intervals.</t> 
		
		<texttable anchor='Leap-second-behavior' title="Positive Leap-Second Behavior">
			
			<ttcol align='center'>RTP</ttcol>
			<ttcol align='center'>TAI</ttcol>
			<ttcol align='center'>UTC</ttcol>
			<ttcol align='center'>POSIX</ttcol>
			<ttcol align='center'>NTP</ttcol>
			<c>8000</c>
			<c>00:00:32.500</c>
			<c>23:59:58.500</c>
			<c>23:59:58.500</c>
			<c>23:59:58.500</c>
			<c>12000</c>
			<c>00:00:33.000</c>
			<c>23:59:59.000</c>
			<c>23:59:59.000</c>
			<c>23:59:59.000</c>
			<c>16000</c>
			<c>00:00:33.500</c>
			<c>23:59:59.500</c>
			<c>23:59:59.500</c>
			<c>23:59:59.500</c>
			<c>20000</c>
			<c>00:00:34.000</c>
			<c>23:59:60.000</c>
			<c>23:59:59.000</c>
			<c>00:00:00.000</c>
			<c>24000</c>
			<c>00:00:34.500</c>
			<c>23:59:60.500</c>
			<c>23:59:59.500</c>
			<c>00:00:00.000</c>
			<c>28000</c>
			<c>00:00:35.000</c>
			<c>00:00:00.000</c>
			<c>00:00:00.000</c>
			<c>00:00:00.000</c>
			<c>32000</c>
			<c>00:00:35.500</c>
			<c>00:00:00.500</c>
			<c>00:00:00.500</c>
			<c>00:00:00.500</c>
		</texttable>
    
    <t>NOTE: Some NTP implementations do not entirely freeze the clock while
the leap second is inserted. Successive calls to retrieve system time return
infinitesimally larger (e.g., 1 microsecond or 1 nanosecond larger) time
values. This behavior is designed to satisfy assumptions applications may make
that time increases monotonically. This behavior occurs in the
least-significant bits of the time value and so is not typically visible in the
human-readable format shown in the table.</t> 
		
		<t>NOTE: POSIX implementations vary. The implementation shown
here repeats the last second of the affected day. Other implementations mirror
NTP behavior or alter the length of a second in the vicinity of the leap
second.</t> 
    
	  </section>
    </section>
    
    <section title="Receiver Behavior during a Leap Second" anchor="behavior">
      <t>Timestamps generated during a leap second may be ambiguous or
interpreted differently by a sender and receiver or interpreted differently by
different receivers.</t> 
      
      <t>Without prior knowledge
      of the leap-second schedule, NTP servers and clients may become offset by
      exactly one second with respect to their UTC reference. This potential
      discrepancy begins when a leap second occurs and ends when all
      participants receive a time update from a server or peer. Depending on
      the system implementation, the offset can last anywhere from a few
      seconds to a few days. A long-lived discrepancy can be particularly
      disruptive to operation of NTP-referenced RTP streams.</t>
      
      <t>These discrepancies, depending on direction, may cause receivers to think they are receiving RTP packets after they should be played or to attempt to buffer received data an additional second before playing it. Either situation can cause an interruption in playback. Some receivers may automatically recognize an unexpected offset and resynchronize to the stream to accommodate it. Once the offset is resolved, such receivers may need to resynchronize again.</t>
    </section>

    <section title="Recommendations">
      <t>Senders and receivers that are not referenced to a wall clock are not
      affected by issues associated with leap seconds, and no special
      accommodation is required.</t>

      <t>RTP implementation using a wall-clock reference is simplified by using
      a clock with a timescale that does not include leap seconds. IEEE
      1588 <xref target="IEEE1588-2008"/>, GPS <xref target="IS-GPS-200F"/>, and
      other systems that use a TAI <xref target="TAI"/>
      reference do not include leap seconds. NTP time, operating system
      clocks, and other systems using a UTC reference include
      leap seconds.</t>
			
			<t>Note that some TAI-based systems such as IEEE 1588
and GPS, in addition to the TAI reference clock, deliver TAI to UTC mapping
information. By combining the delivered TAI reference clock and the mapping
information, some receivers of these systems are able to synthesize a
leap-second-bearing UTC reference clock. For the purposes of this document, it is
important to recognize that it is the timescale used, not the delivery
mechanism that determines whether a reference clock is leap-second
bearing.</t> 

			<texttable anchor='recommendations_summary' title="Recommendations Summary">
				<ttcol>Reference clock type</ttcol>
				<ttcol>Examples</ttcol>
				<ttcol>Accommodation</ttcol>
				<c>None</c>
				<c>Self clocking</c>
				<c>None needed</c>
				<c>Non-leap-second-bearing</c>
				<c>IEEE 1588, GPS, TAI</c>
				<c>None needed</c>
				<c>Leap-second-bearing</c>
				<c>NTP</c>
				<c>Recommended</c>
			</texttable>
			
      <t>All participants generating or consuming timestamps associated with a leap-second-bearing reference MUST
      recognize leap seconds and SHOULD have a working communications channel to
      receive notifications of leap-second scheduling. 
A working communication
channel includes a protocol means of notifying clocks of an impending leap
second such as the Leap Indicator in the NTP header <xref target="RFC5905"/>
and also a means for top-tier clocks to receive leap-second schedule
information published by the International Earth Rotation and Reference Systems
Service <xref target="BulletinC"/>.</t> 

			<t>Such a communications channel may not be available
on all networks. For security or
other reasons, leap-second schedules may be configured manually for some
networks or clocks. When a device does not reliably receive leap-second
scheduling information, failures as described in <xref target="behavior"/> may
occur.</t> 

      <t>Because of the timestamp ambiguity that positive leap seconds can introduce and the
      inconsistent manner in which different systems accommodate positive leap seconds,
      generating or using NTP timestamps during the entire last second of a
      day on which a positive leap second has been scheduled SHOULD be avoided. Note
      that the period to be avoided has a real-time duration of two
      seconds. In the <xref target='Leap-second-behavior'/> example, the region to be avoided is indicated by RTP timestamps 12000 through 28000</t>
      
      <t>Negative leap seconds do not introduce timestamp ambiguity or other
complications. No special treatment is needed to avoid ambiguity with respect
to RTP timestamps in the presence of a negative leap second.</t> 
			
			<t>POSIX clocks that use a warping technique to
accommodate leap seconds (e.g., <xref target="Google"/> <xref
target="I-D.kuhn-leapsecond"/>) are not a good choice for an interoperable
timestamp reference and SHOULD not be used to timestamp RTP streams.

</t>  

      <section anchor="reports"
               title="Sender Reports">
				<t>In order to avoid generating or using NTP timestamps during positive leap seconds, RTP senders and receivers need to avoid sending or using sender reports to synchronize their clocks in the vicinity of a leap second and instead rely on their internal clocks to maintain synchronization until the leap second has passed.</t>
				
        <t>RTP Senders using a leap-second-bearing reference for timestamps SHOULD NOT
        generate sender reports containing an originating NTP timestamp in the
        vicinity of a positive leap second. To maintain a consistent RTCP schedule and avoid the risk of unintentional timeouts, such senders MAY send receiver reports in place of sender reports in the vicinity of the leap second.</t>
        
        <t>For the purpose of suspending sender reports in the vicinity of a
leap second, senders MAY assume that a positive leap second occurs at the end
of the last day of every month.</t> 
        
        <t>Receivers consuming leap-second-bearing timestamps SHOULD ignore timestamps in any
        sender reports generated in the vicinity of a positive leap second.</t>

        <t>For the purpose of ignoring sender reports in the vicinity of a leap
second, receivers MAY assume that a positive leap second occurs at the end of
the last day of every month.</t> 
      </section>

      <section anchor="playout" title="RTP Packet Playout">
        <t>Receivers consuming leap-second-bearing timestamps SHOULD take
        both positive and negative leap seconds in the reference into account
to determine the playout time based on RTP timestamps for data in RTP packets.</t>
      </section>
    </section>

    <section anchor="security" title="Security Considerations">
      <t>RTP streams using a wall-clock reference as discussed here present an
additional attack vector compared to self-clocking streams. Manipulation of the
wall clock at either the sender or receiver can potentially disrupt streaming.</t>
      
      <t>For an RTP stream operating to a leap-second-bearing reference to
operate reliably across a leap second, the sender and receiver must both be aware of
the leap second. It is possible to disrupt a stream by blocking or delaying
leap second notification to one of the participants. Streaming can be similarly
affected if one of the participants can be tricked into believing a leap second
has been scheduled where there is not one. These vulnerabilities are present in
<xref target="RFC3550">RFC 3550</xref> and these new recommendations neither
heighten nor diminish them. Integrity of the leap-second schedule is the
responsibility of the operating system and time distribution mechanism, both of
which are outside the scope of <xref target="RFC3550">RFC 3550</xref> and these
recommendations.</t> 
    </section>
	
    <section title="Acknowledgements">
      <t>The authors would like to thank Steve Allen for his valuable comments
      that helped to improve this document.</t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.3550"?>

      <?rfc include="reference.RFC.2119"?>

    </references>
    
    <references title="Informative References">

			<reference anchor="IEEE.1003.1" target="http://standards.ieee.org/findstds/standard/1003.1-2008.html">
				<front>
					<title>Portable Operating System Interface (POSIX)</title> 
					<author>
						<organization>IEEE</organization>
					</author>
					<date month="December" year="2008"/>
				</front>
				<seriesInfo name="IEEE Standard" value="1003.1-2008"/>
			</reference>
			
			<reference anchor="Google" target="http://googleblog.blogspot.com/2011/09/time-technology-and-leaping-seconds.html">
				<front>
					<title>Time, technology and leaping seconds</title>
					<author fullname="">
						<organization>Google, Inc.</organization>
					</author>
					<date day="15" month="September" year="2011"/>
				</front>
			</reference>
			
<!-- rfc include="reference.I-D.kuhn-leapsecond" -->
			
<reference anchor='I-D.kuhn-leapsecond'>
<front>
<title>Coordinated Universal Time with Smoothed Leap Seconds (UTC-SLS)</title>

<author initials='M' surname='Kuhn' fullname='Markus  Kuhn'>
    <organization />
</author>

<date month='January' day='18' year='2006' />

<abstract><t>Coordinated Universal Time (UTC) is the international standard timescale used in many Internet protocols. UTC features occasional single-second adjustments, known as "leap seconds". These happen at the end of announced UTC days, in the form of either an extra second 23:59:60 or a missing second 23:59:59. Both events need special consideration in UTC-synchronized systems that represent time as a scalar value. This specification defines UTC-SLS, a minor variation of UTC that lacks leap seconds. Instead, UTC-SLS performs an equivalent "smooth" adjustment, during which the rate of the clock temporarily changes by 0.1% for 1000 seconds. UTC-SLS is a drop-in replacement for UTC. UTC-SLS can be generated from the same information as UTC. It can be used with any specification that refers to UTC but lacks provisions for leap seconds. UTC-SLS provides a robust and interoperable way for networked UTC- synchronized clocks to handle leap seconds. By providing UTC-SLS instead of UTC to applications, operating systems can free most application and protocol designers from any need to even know about UTC leap seconds.</t></abstract>

</front>

<seriesInfo name='Work in' value='Progress' />
<format type='TXT'
        target='http://www.ietf.org/internet-drafts/draft-kuhn-leapsecond-00.txt' />
</reference>


      <reference anchor="TF.460-6" target="http://www.itu.int/rec/R-REC-TF.460/">
        <front>
          <title>Standard-frequency and time-signal emissions</title>

          <author fullname="">
            <organization>ITU</organization>
          </author>

          <date day="28" month="February" year="2002"/>
        </front>
				<seriesInfo name="ITU-R" value="TF.460-6"/>
      </reference>
	  
      <reference anchor="ITU-RWP7A" target="http://www.itu.int/pub/R-QUE-SG07.236-2001">
        <front>
          <title>QUESTION ITU-R 236/7</title>
          <author fullname="">
            <organization>ITU</organization>
          </author>
          <date day="3" month="February" year="2012"/>
        </front>
      </reference>

      <?rfc include="reference.RFC.5905"?>

      <reference anchor="IEEE1588-2008" target="http://standards.ieee.org/findstds/standard/1588-2008.html">
        <front>
          <title>IEEE Standard for a Precision Clock Synchronization Protocol
          for Networked Measurement and Control Systems</title>

          <author>
            <organization>IEEE</organization>
          </author>

          <date day="24" month="July" year="2008"/>
        </front>
				<seriesInfo name="IEEE" value="Standard 1588-2008"/>
      </reference>

      <reference anchor="IS-GPS-200F" target="http://www.navcen.uscg.gov/pdf/IS-GPS-200F.pdf">
        <front>
          <title>Systems Engineering &amp; Integration Interface Specification</title>

          <author>
            <organization>Global Positioning Systems Directorate</organization>
          </author>

          <date day="21" month="September" year="2011"/>
        </front>
      </reference>

      <reference anchor="TAI" target="http://www.bipm.org/en/scientific/tai/tai.html">
        <front>
          <title>International Atomic Time</title>

          <author>
            <organization>Bureau International des Poids et Mesures</organization>
          </author>
<date month="" year="" />

        </front>
<seriesInfo name="Navstar GPS Space Segment/Navigation User Segment Interfaces" value="IS-GPS-200"/>

      </reference>
	  
      <reference anchor="BulletinC" target="http://datacenter.iers.org/web/guest/eop/-/somos/5Rgv/product/16">
        <front>
          <title>Bulletin C - Product metadata</title>

          <author>
            <organization>IERS Earth Orientation Centre</organization>
          </author>
<date month="" year="" />
        </front>

      </reference>
	  
    </references>
  </back>
</rfc>
