module ietf-netconf-time {

   namespace "urn:ietf:params:xml:ns:yang:ietf-netconf-time";

   prefix nct;
   import ietf-netconf { prefix nc; }

   import ietf-yang-types { prefix yang; }

   import ietf-netconf-monitoring { prefix ncm; }

   organization
     "IETF";

   contact
     "Editor: Tal Mizrahi
         <dew@tx.technion.ac.il>
      Editor: Yoram Moses
         <moses@ee.technion.ac.il>";

   description
     "This module defines a capability-based extension to the
      Network Configuration Protocol (NETCONF) that allows
      time-triggered configuration and management operations.
      This extension allows NETCONF clients to invoke configuration
      updates according to scheduled times and allows NETCONF
      servers to attach timestamps to the data they send to NETCONF
      clients.

      Copyright (c) 2016 IETF Trust and the persons identified as
      the authors of the code.  All rights reserved.

      Redistribution and use in source and binary forms, with or
      without modification, is permitted pursuant to, and subject
      to the license terms contained in, the Simplified BSD License
      set forth in Section 4.c of the IETF Trust's Legal Provisions
      Relating to IETF Documents
      (http://trustee.ietf.org/license-info).";

   revision 2016-01-26 {
     description
       "Initial version.";
     reference
       "RFC 7758:
        Time Capability in NETCONF";
   }

   typedef time-interval {
     type string {
       pattern '\d{2}:\d{2}:\d{2}(\.\d+)?';
     }
     description
       "Defines a time interval, up to 24 hours.
        The format is specified as HH:mm:ss.f,
        consisting of two digits for hours,
        two digits for minutes, two digits
        for seconds, and zero or more digits
        representing second fractions.";
   }

   grouping scheduling-tolerance-parameters {
     leaf sched-max-future {
       type time-interval;
       default 00:00:15.0;
       description
         "When the scheduled time is in the future, i.e., greater
          than the present time, this leaf defines the maximal
          difference between the scheduled time
          and the present time that the server is willing to
          accept.  If the difference exceeds this number, the
          server responds with an error.";
     }

     leaf sched-max-past {
       type time-interval;
       default 00:00:15.0;
       description
         "When the scheduled time is in the past, i.e., less
          than the present time, this leaf defines the maximal
          difference between the present time
          and the scheduled time that the server is willing to
          accept.  If the difference exceeds this number, the
          server responds with an error.";
     }

     description
       "Contains the parameters of the scheduling tolerance.";
   }
   // extending the get-config operation
   augment /nc:get-config/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <get-config>.";
   }

   augment /nc:get-config/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <get-config>.";
   }

   augment /nc:get/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <get>.";
   }

   augment /nc:get/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <get>.";
   }

   augment /nc:copy-config/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <copy-config>.";
   }

   augment /nc:copy-config/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <copy-config>.";
   }

   augment /nc:edit-config/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <edit-config>.";
   }

   augment /nc:edit-config/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <edit-config>.";
   }

   augment /nc:delete-config/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
      "Adds the time element to <delete-config>.";
   }

   augment /nc:delete-config/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }
     description
       "Adds the time element to <delete-config>.";
   }

   augment /nc:lock/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <lock>.";
   }
   augment /nc:lock/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <lock>.";
   }

   augment /nc:unlock/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <unlock>.";
   }

   augment /nc:unlock/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <unlock>.";
   }
   augment /nc:commit/nc:input {
     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }

     leaf get-time {
       type empty;
       description
         "Indicates that the rpc-reply should include the
          execution-time.";
     }

     description
       "Adds the time element to <commit>.";
   }

   augment /nc:commit/nc:output {
     leaf execution-time {
       type yang:date-and-time;
       description
         "The time at which the RPC was executed.";
     }

     description
       "Adds the time element to <commit>.";
   }

   augment /ncm:netconf-state {
     container scheduling-tolerance {
       uses scheduling-tolerance-parameters;
       description
         "The scheduling tolerance when the time capability
          is enabled.";
     }
     description
       "The scheduling tolerance of the server.";
   }

   rpc cancel-schedule {
     description
       "Cancels a scheduled message.";
     reference
       "RFC 7758:
        Time Capability in NETCONF";

     input {
       leaf cancelled-message-id {
         type string;
         description
           "The ID of the message to be cancelled.";
       }
       leaf get-time {
         type empty;
         description
           "Indicates that the rpc-reply should include
            the execution-time.";
       }
     }
     output {
       leaf execution-time {
         type yang:date-and-time;
         description
           "The time at which the RPC was executed.";
       }
     }
   }

   notification netconf-scheduled-message {
     leaf schedule-id {
       type string;
       description
         "The ID of the scheduled message.";
     }

     leaf scheduled-time {
       type yang:date-and-time;
       description
         "The time at which the RPC is scheduled to be performed.";
     }
     description
       "Indicates that a scheduled message was received.";
     reference
       "RFC 7758:
        Time Capability in NETCONF";
   }

}
