<?xml version="1.0" encoding="US-ASCII"?>
<!-- $Id: draft-abad-i2nsf-sdn-ipsec-flow-protection-03.xml,v 1.5 2017/04/12 02:48:15 sowmini Exp $ -->
<!-- This template is for creating an Internet Draft using xml2rfc,
     which is available here: http://xml.resource.org. -->
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!-- One method to get references from the online citation libraries.
     There has to be one entity for each item to be referenced.
     An alternate method (rfc include) is described in the references. -->

<!ENTITY RFC2119 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2865 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2865.xml">
<!ENTITY RFC2866 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2866.xml">
<!ENTITY RFC3575 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3575.xml">
<!ENTITY RFC3579 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3579.xml">
<!ENTITY RFC4849 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4849.xml">
<!ENTITY RFC5080 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5080.xml">
<!ENTITY RFC5226 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5226.xml">
<!ENTITY RFC7149 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7149.xml">
<!ENTITY RFC4301 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4301.xml">
<!ENTITY RFC6071 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6071.xml">
<!ENTITY RFC2367 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2367.xml">
<!ENTITY RFC3549 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3549.xml">
<!ENTITY RFC3948 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3948.xml">
<!ENTITY RFC7296 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7296.xml">
<!ENTITY RFC7317 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7317.xml">
<!ENTITY I-D.ietf-i2nsf-framework SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-i2nsf-framework.xml">
<!ENTITY I-D.ietf-i2nsf-terminology SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-i2nsf-terminology.xml">
<!ENTITY I-D.ietf-i2nsf-problem-and-use-cases SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.ietf-i2nsf-problem-and-use-cases.xml">
<!ENTITY I-D.sivakumar-yang-nat SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.sivakumar-yang-nat.xml">
]>

<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs), please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use. (Here they are set differently than their defaults in xml2rfc v1.32) -->
<!-- <?rfc strict="yes" ?> -->
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC -->
<?rfc tocdepth="3"?>
<!-- the number of levels of subsections in ToC. default: 3 -->
<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space
     (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<?rfc inline="yes"?>
<?rfc strict="no"?>
<?rfc rfcedstyle="yes"?>

<rfc ipr="trust200902" category="exp" docName="draft-abad-i2nsf-sdn-ipsec-flow-protection-03">
  <!-- category values: std, bcp, info, exp, and historic
     ipr values: full3667, noModification3667, noDerivatives3667
     you can add the attributes updates="NNNN" and obsoletes="NNNN"
     they will automatically be output with "(if approved)" -->

  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the
         full title is longer than 39 characters -->

    <title abbrev="SDN IPsec Flow Protection Services"> Software-Defined Networking (SDN)-based IPsec Flow Protection</title>

    <!-- add 'role="editor"' below for the editors if appropriate -->

    <!-- Another author who claims to be an editor -->

    <author fullname="Rafa Marin-Lopez" initials="R." surname="Marin-Lopez">
      <organization>University of Murcia</organization>
      <address>
        <postal>
          <street>Campus de Espinardo S/N, Faculty of Computer Science</street>
          <!-- Reorder these if your country does things differently -->
          <city>Murcia</city>
          <region></region>
          <code>30100</code>
          <country>Spain</country>
        </postal>
        <phone>+34 868 88 85 01</phone>
        <email>rafa@um.es</email>
        <!-- uri and facsimile elements may also be added -->
      </address>
    </author>
    <author fullname="Gabriel Lopez-Millan" initials="G." surname="Lopez-Millan">
      <organization>University of Murcia</organization>
      <address>
        <postal>
          <street>Campus de Espinardo S/N, Faculty of Computer Science</street>
          <!-- Reorder these if your country does things differently -->
          <city>Murcia</city>
          <region></region>
          <code>30100</code>
          <country>Spain</country>
        </postal>
        <phone>+34 868 88 85 04</phone>
        <email>gabilm@um.es</email>
        <!-- uri and facsimile elements may also be added -->
      </address>
    </author>
    <date month="May" year="2017" />

    <!-- If the month and year are both specified and are the current ones, xml2rfc will fill
         in the current day for you. If only the current year is specified, xml2rfc will fill
     in the current day and month for you. If the year is not the current one, it is
     necessary to specify at least a month (xml2rfc assumes day="1" if not specified for the
     purpose of calculating the expiry date).  With drafts it is normally sufficient to
     specify just the year. -->

    <!-- Meta-data Declarations -->

    <area>General</area>

    <workgroup>I2NSF</workgroup>

    <!-- WG name at the upperleft corner of the doc,
         IETF is fine for individual submissions.
     If this element is not present, the default is "Network Working Group",
         which is used by the RFC Editor as a nod to the history of the IETF. -->

    <keyword>NSF, SDN, IPSec</keyword>

    <!-- Keywords will be incorporated into HTML output
         files in a meta tag but they have no effect on text or nroff
         output. If you submit your draft to the RFC Editor, the
         keywords will be used for the search engine. -->

    <abstract>
        <t>
			This document describes the use case of providing IPsec-based flow protection by means of
            a Software-Defined Network (SDN) controller (aka. Security Controller) and
            establishes the requirements to support this service. It considers two main
            well-known scenarios in IPsec: (i) gateway-to-gateway and (ii) host-to-host.
            This document describes a mechanism based on
            the SDN paradigm to support the distribution and monitoring of IPsec information
            from a SDN controller to one or several flow-based Network Security Function (NSF).
            The NSFs implement IPsec to protect data traffic between network resources with IPsec.
        </t>
            
        <t> The document focuses in the NSF Facing Interface by providing models for Configuration
            and State data model required to allow the Security Controller to configure
            the IPsec databases (SPD, SAD, PAD) and IKE to establish security associations
            with a reduced intervention of the network administrator.
            NOTE: State data model will be developed as part of this work but it is still TBD.
        </t>
    </abstract>
  </front>

  <middle>
  
    <section anchor="intro" title="Introduction">
		<t>
			Software-Defined Networking (SDN) is an architecture that enables
			users to directly program, orchestrate, control and manage network
			resources through software. SDN paradigm relocates the control of network
			resources to a dedicated network element, namely SDN controller.
			The SDN controller manages and configures the distributed network resources 
			and provides an abstracted view of the network
			resources to the SDN applications. The SDN application can customize
			and automate the operations (including management) of the abstracted
			network resources in a programmable manner via this interface
			<xref target="RFC7149" /><xref target="ITU-T.Y.3300" />
			<xref target="ONF-SDN-Architecture" /><xref target="ONF-OpenFlow" />.
		</t>
		
        <t>
			Typically, traditional IPsec VPN concentrators and, in general, entities
            (i.e. hosts or security gateways) supporting IKE/IPsec, must be configured
            directly by the administrator. This makes the IPsec security association (SA)
            management difficult and generates a lack of flexibility, specially if the number
            of security policies and SAs to handle is high. With the growth of SDN-based
            scenarios where network resources are deployed in an autonomous manner, a mechanism
            to manage IPsec SAs according to the SDN architecture becomes more relevant. Thus,
            the SDN-based service described in this document will autonomously deal with
            IPsec SAs management.
        </t>
        <t>
            An example of usage can be the notion of Software Defined WAN (SD-WAN), SDN extension
            providing a software abstraction to create secure network overlays over traditional WAN
            and branch networks. SD-WAN is based on IPsec as underlying security protocol and aims
            to provide flexible, automated, fast deployment and on-demand security network services.
		</t>
        
    
        <t> IPsec architecture <xref target="RFC4301" /> defines a clear separation between
            the processing to provide security services to IP packets and the key management
            procedures to establish the IPsec security associations. In this document, we define a service
            where the key management procedures can be carried by an external entity: the Security Controller.
        </t>

		<t> First, this document exposes the requirements to support the protection of
            data flows using IPsec <xref target="RFC4301" />. We have considered two
            general cases:
            
            <list style="format %d)">
            
            <t> The Network Security Function (NSF) implements the Internet Key Exchange (IKE)
                protocol and the IPsec databases: the Security Policy Database (SPD),
                the Security Association Database (SAD) and the Peer Authorization Database (PAD).
                The Security Controller is in charge of provisioning the NSF with the required information
                to IKE, the SPD and the PAD.
            </t>
            
            <t> The NSF only implements the IPsec databases (no IKE implementation).
                The Security Controller will provide the required parameters to create
                valid entries in the SPD and the SAD into the NSF. Therefore, the NSF
                will have only support for IPsec while automated key management
                functionality is moved to the controller.
            </t>
            
            </list>
        </t>
        
        <t> In both cases, an interface/protocol is required to carry out this provisioning
            between the Security Controller and the NSF. In particular, Case 1 requires the provision
            of SPD and PAD entries and the IKE credential and information related with the IKE negotiation
            (e.g. IKE_SA_INIT); and Case 2 requires the management of SPD and SAD entries. Based on YANG
            models in <xref target="netconf-vpn" /> and <xref target="I-D.tran-ipsecme-yang"/>,
            RFC 4301 <xref target="RFC4301" /> and RFC 7296 <xref target="RFC7296" />
            this document defines the required interfaces with a YANG model for configuration
            data for IKE, PAD, SPD and SAD <xref target="appendix-a" /> . State data is TBD.
        </t>
		
        <t>
            This document considers two typical scenarios to manage autonomously IPsec SAs:
            gateway-to-gateway and host-to-host <xref target="RFC6071" />.
            The analysis of the host-to-gateway (roadwarrior) scenario is TBD.
            In these cases, host or gateways or both may act as NSFs. Finally,
            it also discusses the situation where two NSFs are under the control of
            two different Security Controllers.
        </t>
            
        <t>
            NOTE: This work pays attention to the challenge "Lack of Mechanism for Dynamic
            Key Distribution to NSFs" defined in <xref target="I-D.ietf-i2nsf-problem-and-use-cases"></xref>
            in the particular case of the establishment and management of IPsec SAs. In fact,
            this I-D could be considered as a proper use case for this particular challenge
            in <xref target="I-D.ietf-i2nsf-problem-and-use-cases"></xref>.
        </t>

	
    </section>
	
	<section title="Requirements Language">
		<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>.
			When these words appear in lower case, they have their natural language meaning.
		</t>
	</section>

    <section anchor="notation" title="Terminology">
       
        <t>
			This document uses the terminology described in <xref target="RFC7149" />, <xref target="RFC4301" />,
            <xref target="ITU-T.Y.3300" />, <xref target="ONF-SDN-Architecture" />,
            <xref target="ONF-OpenFlow" />, <xref target="ITU-T.X.1252" />,
			<xref target="ITU-T.X.800" /> and <xref target="I-D.ietf-i2nsf-terminology" />.
            
            In addition, the following terms are defined below:
            
            <list style="symbols">
                <t>
					Software-Defined Networking. A set of techniques enabling to
					directly program, orchestrate, control, and manage network
					resources, which facilitates the design, delivery and operation of
					network services in a dynamic and scalable manner <xref target="ITU-T.Y.3300" />.
                </t>
				
                <t>
					Flow/Data Flow. Set of network packets sharing a set of characteristics,
                    for example IP dst/src values or QoS parameters.
                </t>
				<t>
                    Security Controller.  A Controller is a management Component that contains
                    control plane functions to manage and facilitate information
                    sharing, as well as execute security functions.
                    In the context of this document, it provides IPsec management information.
                </t>
                <t>
                    Network Security Function (NSF). Software that provides a set of
                    security-related services.
                </t>
                
                <t>
                    Flow-based NSF. A NSF that inspects network flows according to a
                    set of policies intended for enforcing security properties.
                    The NSFs considered in this document falls into this classification.
                </t>
				
                <t>
					Flow-based Protection Policy. The set of rules defining the conditions
					under which a data flow MUST be protected with IPsec, and the rules
                    that MUST be applied to the specific flow.
				</t>
                
                <t>
                    Internet Key Exchange (IKE) v2 Protocol to establish IPsec Security Associations (SAs).
                    It requires information about the required authentication method (i.e. preshared keys),
                    DH groups, modes and algorithms for IKE SA negotiation, etc.
                </t>
                
                <t>
                    Security Policy Database (SPD). It includes information about IPsec policies direction
                    (in, out), local and remote addresses, inbound and outboud SAs, etc.
                </t>
                
                <t>
                    Security Associations Database (SAD). It includes information about IPsec SAs, such as SPI,
                    destination addresses, authentication and encryption algorithms and keys to protect IP flow.
                </t>
                
                <t>
                    Peer Authorization Database (PAD). It provides the link between the SPD and a security
                    association management protocol such as IKE or our SDN-based solution.
                </t>

            </list>
        </t>
    </section> <!-- Terminology -->
    
    <section anchor="objectives" title="Objectives">
        <t>
            <list style="symbols">
                
                <t> To describe the architecture for the SDN-based IPsec management, which implements
                    a security service to allow the establishment and management of IPsec security
                    associations from a central point to protect specific data flows.
                </t>
                
                <t>
                    To define the interfaces required to manage and monitor the IPsec Security
                    Associations in the NSF from a Security Controller. YANG models are defined
                    for configuration and state data for IPsec management.
                </t>
            </list>
        </t>
    </section> <!-- Objetives -->
  
  
    <section anchor="cases" title="SDN-based IPsec management description">
      
      <t> As mentioned in <xref target="intro" />, two cases are considered: </t>
  
        <section anchor="case1" title="Case 1: IKE/IPsec in the NSF">
        
        <t> In this case the NSF ships an IKE implementation besides the IPsec support.
            The Security Controller is in charge of managing and applying SPD and PAD
            entries (deriving and delivering IKE Credentials such as a pre-shared key, certificates, etc.),
            and applying other IKE configuration parameters (e.g. IKE_SA_INIT algorithms)
            to the NSF for the IKE negotiation. </t>
        
        <t> With these entries, the IKE implementation can operate to establish the IPsec SAs.
            The application (administrator) establishes the IPsec requirements and information about
            the end points information (through the Client Facing Interface), and the Security Controller
            translates those requirements into SPD and PAD entries that will be installed into the NSF
            (through the NSF Facing Interface). With that information, the NSF can just run IKE
            to establish the required IPsec SA (when the data flow needs protection).
            <xref target="fig:nsf-architecture1" /> shows the different layers and corresponding
            functionality.
        </t>
        
        
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:nsf-architecture1" title="Case 1: IKE/IPsec in the NSF">
            <artwork align="center"><![CDATA[
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                |   IPsec Management/Orchestration Application| Client or
                |                I2NSF Client                 | App Gateway
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                        |    Client Facing Interface
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    Vendor      |             Application Support             |
    Facing <--->+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Security
    Interface   | IKE Credential, PAD and SPD entries Distr.  | Controller
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                        |       NSF Facing Interface
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                |                 I2NSF Agent                 |
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Network
                |   IKE    |      IPsec(SPD,SPD,PAD)          | Security
                +-------------------------------------------- + Function (NSF)
                |         Data Protection and Forwarding      |
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            ]]></artwork>
        </figure>
        
        
        
            <section anchor="requirements1" title="Interface Requirements for Case 1">
            <t>
                SDN-based IPsec flow protection services provide dynamic and flexible
                management of IPsec SAs in flow-based NSF. In order to support this capability
                in case 1, the following interface requirements are to be met:
                
                <list style="symbols">
                    <t> A YANG data model for Configuration data for IKE, SPD and PAD.</t>
                    <t> A YANG data model for State data for IKE, SPD, PAD and SAD (Note
                        that SAD entries are created in runtime by IKE.) </t>
                    <t>
                        In scenarios where multiple controllers are implicated, SDN-based
                        IPsec management services may require a mechanism to discover which
                        Security Controller is managing a specific NSF. Moreover, an east-west
                        interface is required to exchange IPsec-related information.
                    </t>
                </list>
            </t>
            </section> <!-- Interface Requirements for Case 1" -->
        
        </section> <!-- "Case 1: IKE/IPsec in the NSF"" -->

        <section anchor="case2" title="Case 2: IPsec (no IKE) in the NSF">
        <t>
            In this case the NSF does not deploy IKE and, therefore,
            the Security Controller has to perform the management of IPsec SAs
            by populating and monitoring the SPD and the SAD.
        </t>
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:nsf-architecture2" title="Case 2: IPsec (no IKE) in the NSF">
        <artwork align="center"><![CDATA[
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            |   IPsec Management/Orchestration Application| Client or
            |               I2NSF Client                  | App Gateway
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                    |   Client Facing Interface
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Vendor      |             Application Support             |
Facing <--->+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Security
Interface   |         SPD, SAD and PAD Entries Distr.     | Controller
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                    |   NSF Facing Interface
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            |                  I2NSF Agent                | Network
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Security
            |               IPsec (SPD,SAD)               | Function (NSF)
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            |        Data Protection and Forwarding       |
            +---------------------------------------------+
        ]]></artwork>
        </figure>
    
        <t>
            As shown in <xref target="fig:nsf-architecture2" />, applications for flow protection
            run on the top of the Security Controller. When an administrator enforces flow-based
            protection policies through the Client Facing Interface, the Security Controller
            translates those requirements into SPD and SAD entries, which are installed in the NSF.
            PAD entries are not required since there is no IKE in the NSF.
        </t>

            <section anchor="requirements2" title="Interface Requirements for Case 2">
                <t>
                    In order to support case 2, the following requirements are to be met:
                    <list style="symbols">
                        <t> A YANG data model for Configuration data for SPD and SAD.</t>
                        <t> A YANG data model for State data for SPD and SAD.</t>
                        <t>
                            In scenarios where multiple controllers are implicated, SDN-based
                            IPsec management services may require a mechanism to discover which
                            Security Controller is managing a specific NSF. Moreover, an east-west
                            interface is required to exchange IPsec-related information.
                        </t>
                    </list>
                </t>
            </section>
         
        </section> <!-- "Case 2: IPsec (no IKE) in the NSF" -->
    

        <section anchor="comparison" title="Case 1 vs Case 2">
        
         <t>Case 1 MAY be easier to deploy than Case 2 because current gateways typically have
             an IKE/IPsec implementation. Moreover hosts can install easily an IKE implemention.
             As downside, the NSF needs more resources to hold IKE. Moreover, the IKE
             implementation needs to implement an interface so that the I2NSF Agent can interact
             with them.</t>
        
         <t>Alternatively, Case 2 allows lighter NSFs (no IKE implementation), which benefits
             the deployment in constrained NSFs. Moreover, IKE does not need to be performed
             in gateway-to-gateway and host-to-host scenarios under the same Security Controller
             (see <xref target="gw2gw-onecontroller" />). On the contrary, the overload of creation of fresh
             IPsec SA is shifted to the Security Controller since IKE is not in the NSF.
             As a consequence, this may result in a more complex implementation in the controller side. </t>
         
         
         <t>For example, the Security Controller needs to supervise the IPsec SAs states and take care
             of the rekeying process so that, after some period of time (e.g. IPsec SA soft lifetime),
             it has to create a new IPsec SA and remove the old one. Or the Security Controller needs to process
             events coming from the I2NSF when for example an IPsec SA is requested (e.g. acquire
             or expire events). Another example is the NAT traversal support. In general, the SDN
             paradigm assumes the SDN controller has a view of the network it controls. This view is
             built either requesting information to the NSFs under its control or because these NSFs
             inform the SDN controller. Based on this information, the SDN/security controller can guess
             if there is a NAT configured between two hosts, apply the required policies to both NSFs
             besides activating the usage of UDP encapsulation of ESP packets <xref target="RFC3948" />.</t>
        
        
         <t>In those scenarios, the Controller could directly request the NSF for specific data such as
            networking configuration, NAT support, etc. Protocols such as NETCONF or SNMP can be
            used here. For example, RFC 7317 <xref target="RFC7317" /> provides a YANG data model for
            system management or <xref target="I-D.sivakumar-yang-nat"	/> a data model for NAT management.</t>
        
        </section>
    
    </section> <!--SDN-based IPsec management description-->
    
    <section anchor="models" title="YANG configuration data models">
    
    <t> In order to support case 1 and case 2 we have modelled the different parameters
        and values that must be configured to manage IPsec SAs. Specifically, case 1
        requires modelling IKEv2, SPD and PAD while case 2 requires models for the
        SPD and SAD. A single YANG file represents both cases though some part of the models
        are selectively activated depending a feature defined in the YANG file. For example,
        the IKE configuration is not enabled in case 2. </t>
        
    <t> In the following, we summarize, by using a tree representation, the
        different configuration data models (NOTE: State data models are TBD though
        they are expected to be very similar to the model defined here). The complete
        YANG configuration data model is in <xref target="appendix-a" /> </t>
    
  
        <section anchor="spd-model" title="Security Policy Database (SPD) Model">
        
        <t>
            The definition of this model has been extracted from the specification
            in section 4.4.1 and Appendix D in <xref target="RFC4301"/>
        </t>
        <t>
            <figure>
                <artwork>
                    
                    <![CDATA[
              
              +--rw spd
              |  +--rw spd-entry* [rule-number]
              |     +--rw rule-number        uint64
              |     +--rw priority?          uint32
              |     +--rw names* [name]
              |     |  +--rw name-type?   ipsec-spd-name
              |     |  +--rw name         string
              |     +--rw condition
              |     |  +--rw traffic-selector-list* [ts-number]
              |     |     +--rw ts-number              uint32
              |     |     +--rw direction?             ipsec-traffic-direction
              |     |     +--rw local-addresses* [start end]
              |     |     |  +--rw start    inet:ip-address
              |     |     |  +--rw end      inet:ip-address
              |     |     +--rw remote-addresses* [start end]
              |     |     |  +--rw start    inet:ip-address
              |     |     |  +--rw end      inet:ip-address
              |     |     +--rw next-layer-protocol*   ipsec-next-layer-proto
              |     |     +--rw local-ports* [start end]
              |     |     |  +--rw start    inet:port-number
              |     |     |  +--rw end      inet:port-number
              |     |     +--rw remote-ports* [start end]
              |     |     |  +--rw start    inet:port-number
              |     |     |  +--rw end      inet:port-number
              |     |     +--rw selector-priority?     uint32
              |     +--rw processing-info
              |     |  +--rw action          ipsec-spd-operation
              |     |  +--rw ipsec-sa-cfg
              |     |     +--rw pfp-flag?            boolean
              |     |     +--rw extSeqNum?           boolean
              |     |     +--rw seqOverflow?         boolean
              |     |     +--rw statefulfragCheck?   boolean
              |     |     +--rw security-protocol?   ipsec-protocol
              |     |     +--rw mode?                ipsec-mode
              |     |     +--rw ah-algorithms
              |     |     |  +--rw ah-algorithm*   integrity-algorithm-t
              |     |     +--rw esp-algorithms
              |     |     |  +--rw authentication*   integrity-algorithm-t
              |     |     |  +--rw encryption*       encryption-algorithm-t
              |     |     +--rw tunnel
              |     |        +--rw local?          inet:ip-address
              |     |        +--rw remote?         inet:ip-address
              |     |        +--rw bypass-df?      boolean
              |     |        +--rw bypass-dscp?    boolean
              |     |        +--rw dscp-mapping?   yang:hex-string
              |     |        +--rw ecn?            boolean
              |     +--rw spd-lifetime
              |        +--rw time-soft?       uint32
              |        +--rw time-hard?       uint32
              |        +--rw time-use-soft?   uint32
              |        +--rw time-use-hard?   uint32
              |        +--rw byte-soft?       uint32
              |        +--rw byte-hard?       uint32
              |        +--rw packet-soft?     uint32
              |        +--rw packet-hard?     uint32

                    ]]>
                </artwork>
            </figure>
        </t>
        

        </section>

        <section anchor="sad-model" title="Security Association Database (SAD) Model">
            <t>
                The definition of this model has been extracted from the specification in section 4.4.2
                in <xref target="RFC4301"/>
            </t>
            <t>
            <figure>
                <artwork>
                    
                    <![CDATA[
        
        +--rw sad {case2}?
        |  +--rw sad-entry* [spi]
        |     +--rw spi                         ipsec-spi
        |     +--rw seq-number?                 uint64
        |     +--rw seq-number-overflow-flag?   boolean
        |     +--rw anti-replay-window?         uint16
        |     +--rw rule-number?                uint32
        |     +--rw local-addresses* [start end]
        |     |  +--rw start    inet:ip-address
        |     |  +--rw end      inet:ip-address
        |     +--rw remote-addresses* [start end]
        |     |  +--rw start    inet:ip-address
        |     |  +--rw end      inet:ip-address
        |     +--rw next-layer-protocol*        ipsec-next-layer-proto
        |     +--rw local-ports* [start end]
        |     |  +--rw start    inet:port-number
        |     |  +--rw end      inet:port-number
        |     +--rw remote-ports* [start end]
        |     |  +--rw start    inet:port-number
        |     |  +--rw end      inet:port-number
        |     +--rw security-protocol?          ipsec-protocol
        |     +--rw ah-sa
        |     |  +--rw integrity-algorithm?   integrity-algorithm-t
        |     |  +--rw key?                   string
        |     +--rw esp-sa
        |     |  +--rw encryption
        |     |  |  +--rw encryption-algorithm?   encryption-algorithm-t
        |     |  |  +--rw key?                    string
        |     |  |  +--rw iv?                     string
        |     |  +--rw integrity
        |     |  |  +--rw integrity-algorithm?   integrity-algorithm-t
        |     |  |  +--rw key?                   string
        |     |  +--rw combined
        |     |     +--rw combined-algorithm?   combined-algorithm-t
        |     +--rw sa-lifetime
        |     |  +--rw time-soft?       uint32
        |     |  +--rw time-hard?       uint32
        |     |  +--rw time-use-soft?   uint32
        |     |  +--rw time-use-hard?   uint32
        |     |  +--rw byte-soft?       uint32
        |     |  +--rw byte-hard?       uint32
        |     |  +--rw packet-soft?     uint32
        |     |  +--rw packet-hard?     uint32
        |     |  +--rw action?          lifetime-action
        |     +--rw mode?                       ipsec-mode
        |     +--rw statefulfragCheck?          boolean
        |     +--rw dscp?                       yang:hex-string
        |     +--rw tunnel
        |     |  +--rw local?          inet:ip-address
        |     |  +--rw remote?         inet:ip-address
        |     |  +--rw bypass-df?      boolean
        |     |  +--rw bypass-dscp?    boolean
        |     |  +--rw dscp-mapping?   yang:hex-string
        |     |  +--rw ecn?            boolean
        |     +--rw path-mtu?                   uint16
        |     +--rw encap
        |        +--rw espinudp?   boolean
        |        +--rw sport?      inet:port-number
        |        +--rw dport?      inet:port-number
        |        +--rw oaddr?      inet:ip-address
        
                    ]]>
                </artwork>
            </figure>
        </t>
        
        <t>
            <figure>
                <artwork>
                    
                    <![CDATA[
    
    rpcs:
    +---x sadb_register
       +---w input
       |  +---w base-list* [version]
       |     +---w version       string
       |     +---w msg_type?     sadb-msg-type
       |     +---w msg_satype?   sadb-msg-satype
       |     +---w msg_seq?      uint32
       +--ro output
          +--ro base-list* [version]
          |  +--ro version       string
          |  +--ro msg_type?     sadb-msg-type
          |  +--ro msg_satype?   sadb-msg-satype
          |  +--ro msg_seq?      uint32
          +--ro algorithm-supported*
             +--ro authentication
             |  +--ro name?       integrity-algorithm-t
             |  +--ro ivlen?      uint8
             |  +--ro min-bits?   uint16
             |  +--ro max-bits?   uint16
             +--ro encryption
                +--ro name?       encryption-algorithm-t
                +--ro ivlen?      uint8
                +--ro min-bits?   uint16
                +--ro max-bits?   uint16

  notifications:
    +---n spd-expire
    |  +--ro index?   uint64
    +---n sadb_acquire
    |  +--ro state    uint32
    +---n sadb_expire
       +--ro state    uint32
       
  
                    ]]>
                </artwork>
            </figure>
        </t>
        
    
        </section>
  
        <section anchor="pad-model" title="Peer Authorization Database (PAD) Model">
            <t>
                The definition of this model has been extracted from the specification in section 4.4.3
                in <xref target="RFC4301"/> (NOTE: We have observed that many implementations integrate
                PAD configuration as part of the IKE configuration.)
            </t>
       <t>
           <figure>
               <artwork>
                   
                   <![CDATA[
                +--rw pad {case1}?
                   +--rw pad-entries* [pad-entry-id]
                       +--rw pad-entry-id             uint64
                       +--rw (identity)?
                       |  +--:(ipv4-address)
                       |  |  +--rw ipv4-address?            inet:ipv4-address
                       |  +--:(ipv6-address)
                       |  |  +--rw ipv6-address?            inet:ipv6-address
                       |  +--:(fqdn-string)
                       |  |  +--rw fqdn-string?             inet:domain-name
                       |  +--:(rfc822-address-string)
                       |  |  +--rw rfc822-address-string?   string
                       |  +--:(dnX509)
                       |  |  +--rw dnX509?                  string
                       |  +--:(id_key)
                       |     +--rw id_key?                  string
                       +--rw pad-auth-protocol?       auth-protocol-type
                       +--rw auth-method
                       +--rw auth-m?          auth-method-type
                       +--rw pre-shared
                       |  +--rw secret?   string
                       +--rw rsa-signature
                       +--rw key-data?    string
                       +--rw key-file?    string
                       +--rw ca-data*     string
                       +--rw ca-file?     string
                       +--rw cert-data?   string
                       +--rw cert-file?   string
                       +--rw crl-data?    string
                       +--rw crl-file?    string
           ]]>
               </artwork>
        </figure>
       </t>
    
        </section>
  
	
        <section anchor="ike-model" title="Internet Key Exchange (IKE) Model">
        <t>
            The model related to IKEv2 has been extracted from reading IKEv2 standard
            in <xref target="RFC7296"/>, and observing some open source implementations,
            such as Strongswan or Libreswan.
            <!--Rafa: I do not see in case of autostartup what policy should be chose-->
        </t>
        <t>
            <figure>
                <artwork>
                    
                    <![CDATA[
    
    +--rw ikev2 {case1}?
    |  +--rw ike-connection
    |     +--rw ike-conn-entries* [conn-name]
    |        +--rw conn-name          string
    |        +--rw autostartup        boolean
    |        +--rw nat-traversal?     boolean
    |        +--rw version?           enumeration
    |        +--rw phase1-lifetime    uint32
    |        +--rw phase1-authby      auth-method-type
    |        +--rw phase1-authalg*    integrity-algorithm-t
    |        +--rw phase1-encalg*     encryption-algorithm-t
    |        +--rw dh_group           uint32
    |        +--rw local
    |        |  +--rw (my-identifier-type)?
    |        |  |  +--:(ipv4)
    |        |  |  |  +--rw ipv4?            inet:ipv4-address
    |        |  |  +--:(ipv6)
    |        |  |  |  +--rw ipv6?            inet:ipv6-address
    |        |  |  +--:(fqdn)
    |        |  |  |  +--rw fqdn?            inet:domain-name
    |        |  |  +--:(dn)
    |        |  |  |  +--rw dn?              string
    |        |  |  +--:(user_fqdn)
    |        |  |     +--rw user_fqdn?       string
    |        |  +--rw my-identifier    string
    |        +--rw remote
    |        |  +--rw (my-identifier-type)?
    |        |  |  +--:(ipv4)
    |        |  |  |  +--rw ipv4?            inet:ipv4-address
    |        |  |  +--:(ipv6)
    |        |  |  |  +--rw ipv6?            inet:ipv6-address
    |        |  |  +--:(fqdn)
    |        |  |  |  +--rw fqdn?            inet:domain-name
    |        |  |  +--:(dn)
    |        |  |  |  +--rw dn?              string
    |        |  |  +--:(user_fqdn)
    |        |  |     +--rw user_fqdn?       string
    |        |  +--rw my-identifier    string
    |        +--rw local-addrs        inet:ip-address
    |        +--rw remote-addr        inet:ip-address
    |        +--rw pfs_group?         uint32
    |        +--rw phase2-lifetime    uint32
    |        +--rw phase2-authalg*    integrity-algorithm-t
    |        +--rw phase2-encalg*     encryption-algorithm-t
 
 
                    ]]>
                </artwork>
            </figure>
        </t>

        </section>


    </section>

    <section anchor="usecase" title="Use cases examples">
    <t>
        This section explains how different traditional configurations, that is,
        host-to-host and gateway-to-gateway are deployed using our SDN-based IPsec
        management service. In turn, these configurations will be typical
        in modern networks where, for example, virtualization will be key.
    </t>
    
        <section anchor="gw2gw-onecontroller" title="Host-to-Host or Gateway-to-gateway under the same controller">
         
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:g2gsinglecontroller1" title="Gateway-to-Gateway single controller flow for case 1 .">
            <artwork align="center"><![CDATA[
                +----------------------------------------+
                |           Security Controller          |
                |                                        |
             (1)|   +--------------+ (2)+--------------+ |
Flow-based  ------> |Translate into|--->| South. Prot. | |
Security. Pol.  |   |IPsec Policies|    |              | |
                |   +--------------+    +--------------+ |
                |                          |     |       |
                |                          |     |       |
                +--------------------------|-----|-------+
                                           |     |
                                           | (3) |
                 |-------------------------+     +---|
                 V                                   V
     +----------------------+         +----------------------+
     |    NSF1              |<=======>|   NSF2               |
     |IKE/IPsec(SPD/SAD/PAD)|         |IKE/IPsec(SPD/SAD/PAD)|
     +----------------------+  (4)    +----------------------+
            ]]></artwork>
        </figure>
        
        <t>
            <xref target="fig:g2gsinglecontroller1" /> describes the case 1:
        </t>
        <t>
            <list style="numbers">
                <t>
                    The administrator defines general flow-based security policies. The controller looks for the NSFs involved (NSF1 and NSF2).
                </t>
                <!--<t>
                    
                </t>-->
                <t>
                    The controller generates IKE credentials for them and translates the policies into SPD and PAD entries.
                </t>
                <t>
                    The controller inserts the SPD and PAD entries in both NSF1 and NSF2.
                </t>
                <!--<t>
                    Either all packets belonging to the flow that matches the IPsec SPD inserted
                    by the Security Controller trigger the IKE negotiation in NSF1 and NSF2
                    by using the IKE credentials or the Security Controller includes a route
                </t>-->
                <t> The flow is protected with the IPsec SA established with IKEv2.</t>
            </list>
        </t>
        
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:g2gsinglecontroller2" title="Host-to-Host / Gateway-to-Gateway single controller flow for case 2.">
            <artwork align="center"><![CDATA[
                +----------------------------------------+
                |    (1)     Security Controller         |
    Flow-based  |                                        |
    Security -----------|                                |
    Policy      |       V                                |
                |  +---------------+ (2)+-------------+  |
                |  |Translate into |--->| South. Prot.|  |
                |  |IPsec policies |    |             |  |
                |  +---------------+    +-------------+  |
                |                         |     |        |
                |                         |     |        |
                +-------------------------| --- |--------+
                                          |     |
                                          | (3) |
                   |----------------------+     +--|
                   V                               V
          +------------------+       +------------------+
          |    NSF1          |<=====>|   NSF2           |
          |IPsec(SPD/SAD)    |   4)  |IPsec(SPD/SAD)    |
          +------------------+       +------------------+
            ]]></artwork>
        </figure>
        
        <t>
            In case 2, flow-based security policies defined by the administrator are also
            translated into IPsec SPD entries and inserted into the corresponding NSFs.
            Besides, fresh SAD entries will be also genereated by the controller and
            enforced in the NSFs. In this case the execution of IKE is not necessary
            in the controller, and it provides the cryptographic material for the IPsec SAs.
            These keys will be also distributed securely through the southbound interface. Note
            that this is possible because both NSFs are managed by the same controller.
        </t>

        <t>
            <xref target="fig:g2gsinglecontroller2" /> describes the case 2, when a data packet
            needs to be protected in the path between the NSF1 and NSF2:
        </t>
        <t>
            
            <list style="numbers">
                <t>
                    The administrator establishes the flow-based security policies. The controller
                    looks for the involved NSFs.
                </t>
                <!--<t>
                    The controller looks for the involved NSFs.
                </t>-->
                <t>
                    The controller translates the flow-based security policies into IPsec SPD and SAD entries.
                </t>
                <t>
                    The controller inserts the these entries in both NSF1 and NSF2 IPsec databases.
                </t>
                <!--<t>
                    All packets belonging to the flow are protected (e.g.  with ESP or AH, in transport
                    mode for the host-to-host scenario or tunnel mode in the gateway-to-gateway scenario)
                    between NSF1 and NSF2 by using the enforced configuration keys and
                    parameters. No need to run IKE between NSF1 and NSF2.
                </t>-->
                <t> The flow is protected with the IPsec SA established by the Security Controller.</t>
               
                
            </list>
            
        </t>
        
        <t> Both NSFs could be two hosts that exchange traffic and require to establish an
            end-to-end security association to protect their communications (host-to-host)
            or two gateways (gateway-to-gateway)), for example, within an enterprise that needs
            to protect the traffic between, for example, the networks of two branch offices.</t>
        
        <t> Applicability of these configurations appear in current and new networking scenarios.
            For example, SD-WAN technologies are providing dynamic and on-demand VPN connections
            between branch offices or between branches and SaaS cloud services. Beside, IaaS services
            providing virtualization environments are deployments solutions based on IPsec to provide
            secure channels between virtual instances (Host-to-Host) and providing VPN solutions
            for virtualized networks (Gateway-to-Gateway).</t>
            
            
        
        <!-- <t>
                    From the point of view of the SDN architecture the host-to-host scenario is similar to the gateway-to-gateway described above. The main differences are related with security policies applied by each NSF and the kind of IPsec secure protocol being used in the scenarios.
            
            Regarding the security policies, on one hand, a Gateway-to-Gateway scenario has to take into account the internal subnetworks behing the NSFs (the gateways) and the network addressing, for example, if NAT has to be taken into account. On the other hand, the Host-to-Host scenario makes use of IPSec in the endpoints of the communication (NSFs) and NAT is not applied. -->
            
            <!-- Rafa: A NAT can be possible in host-to-host as well -->
            
            <!--Regarding the kind of IPsec secure protocol, a Gateway-to-Gateway scenario requires the use of IPSec tunnel mode and the Host-to-Host scenario requires the use of IPSec transport mode.-->
            
       <!--     New use cases examples for both scenarios appear in the current networking solutions. For example, SD-WAN technologies are providing dynamic and on-demand VPN connections between branch offices or between branches and SaaS cloud services. Beside, IaaS services providing virtualization environments are deployments solutions based on IPsec to provide secure channels between virtual instances (Host-to-Host) and providing VPN solutions for virtualized networks (Gateway-to-Gateway).
        </t> -->
        
        <t>
            In general (for case 1 and case 2), this system presents various advantages:
            <list style="numbers">
                <t>
                    It allows to create a IPsec SA among two NSFs, with only the application
                    of more general flow-based security policies at the application layer.
                    Thus, an administrator/s can manage all security associations in a centralized point
                    with an abstracted view of the network;
                </t>
                <t>
                    All NSFs deployed after the application of the new policies are
                    NOT manually configured, therefore allowing its deployment in an automated manner.
                </t>
            </list>
        </t>
        
        
        </section>
    
    
        <section anchor="gw2gw-multicontroller" title="Host-to-Host or Gateway-to-gateway under different Security controllers">
        
        <t> It is also possible that two NSFs (i.e. NSF1 and NSF2) are under the control of
            two different security controllers. This may happen, for example, when two organizations,
            namely Enterprise A and Enterprise B, have their headquarters interconnected through a WAN
            connection and they both have deployed a SDN-based architecture to provide connectivity
            to all their clients.
        </t>
        <!-- <t>
         Two organizations, Enterprise A and Enterprise B, have its headquarters interconnected through a WAN
         connection. They have deployed a SDN-based architecture to provide connectivity to all its clients.
         </t>
         <t>
         Now, these organizations require certain traffic among its headquarters to be protected with confidentiality
         and integrity, so they have to configure Flow Protection Policies in their corresponding Security Controllers.
         Both administrators define Flow Protection Policies in each Security Controller that will end with the translation into SPD and PAD
         entries and IKE credentials in each NSF so that the specified traffic exchanged among these headquarters will be protected.
         </t> -->
        
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:g2gmulticontroller1" title="Different security controllers in Case 1">
            <artwork align="center"><![CDATA[
                +-------------+                 +-------------+
                |             |                 |             |
      Flow-based|   Security  |<===============>|   Security <--Flow-based
      Sec. Pol.--> Controller |        (3)      |  Controller | Sec. Pol.
            (1) |      A      |                 |      B      |   (2)
                +-------------+                 +-------------+
                     |                                 |
                     | (4)                         (4) |
                     V                                 V
          +----------------------+          +----------------------+
          |    NSF1              |<========>|   NSF2               |
          |IKE/IPsec(SPD/SAD/PAD)|          |IKE/IPsec(SPD/SAD/PAD)|
          +----------------------+  (5)     +----------------------+
            ]]></artwork>
        </figure>
        
        <t>
            <xref target="fig:g2gmulticontroller1" /> describes case 1 when two Security Controllers
            are involved in the process.
        </t>
        
        <t>
            
            <list style="numbers">
                <t>
                    The A's 'administrator establishes general Flow-based Security Policies in Security Controller A.
                </t>
                <t>
                    The B's administrator establishes general Flow-based Security Policies in Security Controller B.
                </t>
                <t>
                    The Security Controller A realizes that protection is required between the NSF1 and NSF2,
                    but the NSF2 is under the control of another Security Controller (Security Controller B),
                    so it starts negotiations with the other controller to agree on the IPsec SPD policies
                    and IKE credentials for their respective NSFs. NOTE: This may require extensions in the
                    East/West interface.
                </t>
                <t>
                    Then, both Security Controllers enforce the IKE credentials and related parameters and the
                    SPD and PAD entries in their respective NSFs.
                </t>
                <!--<t>
                    All packets belonging to the flow that matches the IPsec SPD inserted by the Security
                    Controllers triggers the IKE negotiation between NSF1 and NSF2 by using the enforced
                    configuration keys and parameters.
                </t>-->
                <t> The flow is protected with the IPsec SA established with IKEv2 between both NSFs.</t>
            </list>
            
        </t>
        
        
        <!-- maximum wide of the figure                                   -->
        <figure align="center" anchor="fig:g2gmulticontroller2" title="Different security controllers in case 2">
            <artwork align="center"><![CDATA[
                +--------------+                   +--------------+
                |              |                   |              |
         Flow-based. --->               IKE?       |          <---- Flow-based
         Prot.  |   Security   |<=================>|   Security   | Sec.
         Pol.(1)|  Controller  |        (3)        |  Controller  | Pol. (2)
                |       A      |                   |       B      |
                +--------------+                   +--------------+
                        |                               |
                        | (4)                       (4) |
                        V                               V
                +------------------+      (5)       +------------------+
                |    NSF1          |<==============>|    NSF2          |
                |IPsec(SPD/SAD/PAD)|                |IPsec(SPD/SAD/PAD)|
                +------------------+                +------------------+
            ]]></artwork>
        </figure>
        
        <!--<t>
            On the other hand, case 2, <xref target="fig:g2gmulticontroller2" /> describes
            the data and control plane communications required when a data packet
            is sent from Enterprise A's HQ (HQ A) to destination Enterprise B's HQ (HQ B):
        </t>-->
        
        <t>
            <xref target="fig:g2gmulticontroller1" /> describes case 1 when two Security Controllers
            are involved in the process.
        </t>

        <t>
            <list style="numbers">
                
                
                <t>
                    The A's administrator establishes general Flow Protection Policies in Security Controller A.
                </t>
                <t>
                    The B's administrator establishes general Flow Protection Policies in Security Controller B.
                </t>

                <t>
                    The Security Controller A realizes that the flow between NSF1 and NSF2
                    MUST be protected. Nevertheless, the controller notices that
                    NSF2 is under the control of another Security Controller, so it
                    starts negotiations with the other controller to agree on the IPsec SPD
                    and SAD entries that define the IPsec SAs. NOTE: It would worth evaluating
                    IKE as the protocol for the the East/West interface in this case.
                </t>
                <t>
                    Once the controllers have agreed on key material and the details of the IPsec SA,
                    they both enforce this information into their respective NSFs.
                </t>
                <!--<t>
                    Therefore, all packets belonging to the flow are protected between NSF1 and NSF2
                    by using the enforced configuration keys and
                    parameters.
                </t>-->
                
                <t> The flow is protected with the IPsec SA established by both Security Controllers
                    in their respective NSFs.</t>
            </list>
        </t>
        <!--<t>
            In general (case 1 and case 2), this system presents various advantages to both A and B: (i) it allows to create a security association among two network resources across A and B, from each enterprise's point of view, only the application of specific Flow Protection Policies  at the application layer is needed, so they can manage all
            security associations in a centralized point and with an abstracted view of the network;
            (ii) All new resources deployed after the application of the new policies will not need to be manually configured,
            thus allowing its deployment in an automated manner.
        </t>-->
        </section>
    
    
    </section>
    
    <!-- Gabi: realmente esta seccion no aparece nunca, pero para una version 0.2 se puede dejar-->
    <section anchor="impl" title="Implementation notes">
    
    <t>At the time of writing this document, we have implemented a proof-of-concept using
    NETCONF as southbound protocol, and the YANG model described in <xref target="appendix-a" />.
    The netopeer implementation <xref target="netopeer" /> has been used for both case 1 and case 2
    using host-to-host and gateway-to-gateway configuration. For the case 1, we have used Strongswan
    <xref target="strongswan" /> distribution for the IKE implementation.</t>
    
    <t>Note that the proposed YANG model provides the models for SPD, SAD, PAD and IKE, but, as describe before,
        only part of them are required depending of the case (1 or 2) been applied. The Controller should be able
        to know the kind of case to be applied in the NSF and to select the corresponding models based on the
        YANG features defines for each one </t>
    
    <t>Internally to the NSF, the NETCONF server (that implements the I2NSF Agent) is able to apply the
        required configuration updating the corresponding NETCONF datastores (running, startup, etc.).
        Besides, it can deal with the SPD and SAD configuration at kernel level, through different APIs.
        For example, the IETF RFC 2367 (PF_KEYv2) <xref target="RFC2367" /> provides a generic key
        management API that can be used not only for IPsec but also for other network security
        services to manage the IPsec SAD. Besides, as an extension to this API, the document
        <xref target="I-D.pfkey-spd" /> specifies some PF_KEY extensions to maintain the SPD. This API
        is accessed using sockets.</t>
    
    <t>An alternative key management API based on Netlink socket API <xref target="RFC3549"/>
        is used to configure IPsec on the Linux Operating System.
    </t>
    
    <t>To allow the NETCONF server implementation interacts with the IKE daemon, we have
        used the Versatile IKE Configuration Interface (VICI) in Strongswan. This allows
        changes in the IKE part of the configuration data to be applied in the IKE
        daemon dynamically.</t>
    </section>

    <section anchor="security" title="Security Considerations">
        <t>
            TBD.
            <!--This document shares all the security issues of SDN that are
			specified in the "Security Considerations" section of <xref target="ITU-T.Y.3300" /> and <xref target="I-D.dunbar-i2nsf-problem-statement" />.-->
        </t>
    </section>

    <section anchor="ack" title="Acknowledgements">
        <t>
            Authors want to thank Sowmini Varadhan, David Carrel, Yoav Nir, Tero Kivinen, Paul Wouters, Graham Bartlett,
            Sandeep Kampati, Linda Dunbar, Carlos J. Bernardos, Alejandro Perez-Mendez,
            Alejandro Abad-Carrascosa, Ignacio Martinez and Ruben Ricart
            for their valuable comments.
        </t>
    </section>
    
  </middle>
  
  <back>
      <references title="Normative References">
          &RFC2119;
          &RFC5226;
          &RFC4301;
          &RFC7296;
      </references>
      <references title="Informative References">
          &RFC7149;
          &RFC2367;
          &RFC3549;
          &RFC6071;
          &RFC3948;
          &RFC7317;
          &I-D.ietf-i2nsf-framework;
          &I-D.ietf-i2nsf-terminology;
          &I-D.ietf-i2nsf-problem-and-use-cases;
          &I-D.sivakumar-yang-nat;
          
          <reference anchor="I-D.tran-ipsecme-yang">
              <front>
                  <title>Yang Data Model for Internet Protocol Security (IPsec)</title>
                  <author initials="K" surname="Tran" fullname="Khanh Tran">
                      <organization/>
                  </author>
                  <author initials="H" surname="Wang" fullname="Honglei Wang">
                      <organization/>
                  </author>
                  <author initials="V" surname="Nagaraj" fullname="Vijay Kumar Nagaraj">
                      <organization/>
                  </author>
                  <author initials="X" surname="Chen" fullname="Xia Chen">
                      <organization/>
                  </author>
                  
                  <date month="June" day="15" year="2015"/>
                  <abstract>
                      <t>
                          This document describes a YANG data model for the IPsec(Internet
                          Protocol Security) protocol.  The model covers the IPsec protocol
                          operational state and remote procedural calls.
                      </t>
                  </abstract>
              </front>
              <seriesInfo name="Internet-Draft" value="draft-tran-ipsecme-yang-01"/>
              <format type="TXT" target="https://tools.ietf.org/html/draft-tran-ipsecme-yang-01"/>
          </reference>
          
          <reference anchor="ITU-T.Y.3300">
              <front>
                  <title>Recommendation ITU-T Y.3300</title>
                  <author/>
                  <date month="June" year="2014" />
              </front>
          </reference>
          
          <reference anchor="ONF-SDN-Architecture">
              <front>
                  <title>SDN Architecture</title>
                  <author/>
                  <date month="June" year="2014" />
              </front>
          </reference>
          
          <reference anchor="ONF-OpenFlow">
              <front>
                  <title>OpenFlow Switch Specification (Version 1.4.0)</title>
                  <author>
                      <organization>ONF</organization>
                  </author>
                  <date month="October" year="2013" />
              </front>
          </reference>
          
          <reference anchor="ITU-T.X.1252">
              <front>
                  <title>Baseline Identity Management Terms and Definitions</title>
                  <author/>
                  <date month="April" year="2010" />
              </front>
          </reference>
          
          <reference anchor="ITU-T.X.800">
              <front>
                  <title>Security Architecture for Open Systems Interconnection for  CCITT Applications</title>
                  <author/>
                  <date month="March" year="1991" />
              </front>
          </reference>
          <reference anchor="netconf-vpn">
              <front>
                  <title>Tutorial: NETCONF and YANG</title>
                  <author>
                      <organization>Stefan Wallin</organization>
                  </author>
                  <date month="January" year="2014" />
              </front>
          </reference>
          
          <reference anchor="I-D.jeong-i2nsf-sdn-security-services-05">
              <front>
                  <title>Software-Defined Networking Based Security Services using Interface to
                      Network Security Functions</title>
                  <author initials="J" surname="Jeong" fullname="J Jeong">
                      <organization>Sungkyunkwan University</organization>
                  </author>
                  <author initials="H" surname="Kim" fullname="H Kim">
                      <organization>Sungkyunkwan University</organization>
                  </author>
                  <author initials="J" surname="Park" fullname="P Park">
                      <organization>ETRI</organization>
                  </author>
                  <author initials="T" surname="Ahn" fullname="T Ahn">
                      <organization>Korea Telecom</organization>
                  </author>
                  <author initials="S" surname="Lee" fullname="S Lee">
                      <organization>Korea Telecom</organization>
                  </author>
                  
                  <date month="July" day="5" year="2016"/>
              </front>
              <seriesInfo name="Internet-Draft" value="draft-jeong-i2nsf-sdn-security-services-05"/>
              <format type="TXT" target="https://tools.ietf.org/html/draft-jeong-i2nsf-sdn-security-services-05"/>
          </reference>
          
          <reference anchor="I-D.pfkey-spd">
              <front>
                  <title>PF_KEY Extensions for IPsec Policy Management in KAME Stack</title>
                  <author initials="S" surname="Sakane" fullname="Shoichi Sakane">
                      <organization>KAME Project</organization>
                  </author>
                  <date month="October" day="12" year="2002"/>
              </front>
              <format type="TXT" target="http://www.kame.net/newsletter/20021210/"/>
          </reference>
          
          <reference anchor="netopeer">
              <front>
                  <title>NETCONF toolset Netopeer</title>
                  <author initials="CESNET" surname="CESNET" fullname="CESNET">
                      <organization>CESNET</organization>
                  </author>
                  <date month="November" day="24" year="2016"/>
              </front>
              <format type="TXT" target="https://github.com/CESNET/netopeer"/>
          </reference>
          <reference anchor="strongswan">
              <front>
                  <title>StrongSwan: the OpenSource IPsec-based VPN Solution</title>
                  <author initials="CESNET" surname="CESNET" fullname="CESNET">
                      <organization>CESNET</organization>
                  </author>
                  <date month="April" day="21" year="2017"/>
              </front>
              <format type="TXT" target="https://www.strongswan.org"/>
          </reference>
          
          
          
      </references>

    
    <!-- Gabi: el anexo no va al final del todo? -->
    <section anchor="appendix-a" title="Appendix A: YANG model IPsec Configuration data">
    <t>
        <figure>
            <artwork>
                
                
                <![CDATA[
                    <CODE BEGINS> file "ietf-ipsec.yang"
 module ietf-ipsec {

    namespace "urn:ietf:params:xml:ns:yang:ietf-ipsec";
    
    prefix "eipsec";

    import ietf-inet-types { prefix inet; }
    import ietf-yang-types { prefix yang; }
    
    organization "University of Murcia";
    
    contact
    " Rafael Marin Lopez
    Dept. Information and Communications Engineering (DIIC)
    Faculty of Computer Science-University of Murcia
    30100 Murcia - Spain
    Telf: +34868888501
    e-mail: rafa@um.es
    
    
    Gabriel Lopez Millan
    Dept. Information and Communications Engineering (DIIC)
    Faculty of Computer Science-University of Murcia
    30100 Murcia - Spain
    Tel: +34 868888504
    email: gabilm@um.es
    ";
    
    
    
    description "Data model for IPSec";


    revision "2017-05-02" {
     description
     "Initial revision.";
     reference "";
    }

    feature case1 { description "feature case 1: IKE SPD PAD"; } // IKE/IPSec in the NSFs
    feature case2 { description "feature case 2: SPD SAD"; } // Only IPSec in the NSFs


 	typedef encryption-algorithm-t {
 		
 		type enumeration {
        enum reserved-0 {description "reserved";}
        enum des-iv4 { description "DES IV 4";}
        enum des {  description "DES"; }
        enum 3des {  description "3DES"; }
        enum rc5 {  description "RC5"; }
        enum idea {  description "IDEA"; }
        enum cast {  description "CAST"; }
        enum blowfish {  description "BlowFish"; }
        enum 3idea {  description "3IDEA"; }
        enum des-iv32 {  description "DES-IV32"; }
        enum reserved-10 {  description "reserved-10"; }
        enum null {  description "NULL"; }
        enum aes-cbc {  description "AES-CBC"; }
        enum aes-ctr {  description "AES-CTR"; }
        enum aes-ccm-8 {  description "AES-CCM-8"; }
        enum aes-ccm-12 {  description "AES-CCM-12"; }
        enum aes-ccm-16 {  description "AES-CCM-16"; }
        enum reserved-17 {  description "reserved-17"; }
        enum aes-gcm-8-icv {  description "AES-GCM-8-ICV"; }
        enum aes-gcm-12-icv { description "AES-GCM-12-ICV"; }
        enum aes-gcm-16-icv {  description "AES-GCM-16-ICV"; }
        enum null-auth-aes-gmac {  description "Null-Auth-AES-GMAC"; }
  		enum ieee-p1619-xts-aes {
     			description
       			"encr-ieee-p1619-xts-aes --> Reserved for IEEE P1619 XTS-AES.";
   		}
        enum camellia-cbc {  description "CAMELLIA-CBC"; }
        enum camellia-ctr {  description "CAMELLIA.CTR"; }
        enum camellia-ccm-8-icv {  description "CAMELLIA-CCM-8-ICV"; }
        enum camellia-ccm-12-icv {  description "CAMELLIA-CCM-12-ICV"; }
        enum camellia-ccm-16-icv { description "CAMELLIA-CCM-16-ICV"; }
        enum aes-cbc-128 { description "AES-CBC-128"; }
        enum aes-cbc-192 { description "AES-CBC-192"; }
        enum aes-cbc-256 { description "AES-CBC-256"; }
        enum blowfish-128 { description "BlowFish-128"; }
        enum blowfish-192 { description "BlowFish-192"; }
        enum blowfish-256 { description "BlowFish-256"; }
        enum blowfish-448 { description "BlowFish-448"; }
        enum camellia-128 { description "CAMELLIA-128"; }
        enum camellia-192 { description "CAMELLIA-192"; }
        enum camellia-256 { description "CAMELLIA-256"; }
 		}
        description "Encryption algorithms --> RFC_5996";
 	}
      
 	typedef integrity-algorithm-t {
 		
 		type enumeration {
        enum none { description "NONE"; }
        enum hmac-md5-96 { description "HMAC-MD5-96"; }
        enum hmac-sha1-96 { description "HMAC-SHA1-96"; }
        enum des-mac { description "DES-MAC"; }
        enum kpdk-md5 {description "KPDK-MD5"; }
        enum aes-xcbc-96 { description "AES-XCBC-96"; }
        enum hmac-md5-128 { description "HMAC-MD5-128"; }
        enum hmac-sha1-160 { description "HMAC-SHA1-160"; }
        enum aes-cmac-96 { description "AES-CMAC-96"; }
        enum aes-128-gmac { description "AES-128-GMAC"; }
        enum aes-192-gmac { description "AES-192-GMAC"; }
        enum aes-256-gmac { description "AES-256-GMAC"; }
        enum hmac-sha2-256-128 { description "HMAC-SHA2-256-128"; }
        enum hmac-sha2-384-192 { description "HMAC-SHA2-384-192"; }
        enum hmac-sha2-512-256 { description "HMAC-SHA2-512-256"; }
        enum hmac-sha2-256-96 { description "HMAC-SHA2-256-096"; }
 		}
        description "Integrity Algorithms --> RFC_5996";
 	}

  typedef combined-algorithm-t {
  
    type enumeration {
    enum AES-GCM-16-ICV {  description "AES-GCM-16-ICV"; }
    enum AES-CCM { description "AES-CCM"; }
    }
    description "Combined Algorithms --> RFC 7321";
  }

  typedef auth-protocol-type {
    type enumeration {
      enum IKEv1 { // not supported by model
        description "Authentication protocol based on IKEv1";
      }
      enum IKEv2 {
        description "Authentication protocol based on IKEv2";
      }
      enum KINK { // not supported by model
        description "Authentication protocol based on KINK";
      }
    }
    description "Peer authentication protocols";
  }

  typedef ipsec-mode {
  
    type enumeration {
      enum TRANSPORT { description "Transport mode"; }
      enum TUNNEL { description "Tunnel mode"; }
      enum BEET { description "Bound End-to-End Tunnel (BEET) mode for ESP.";} /*Supported by XFRM*/
      enum RO { description "Route Optimization mode for Mobile IPv6";} /*Supported by XFRM*/
      enum IN_TRIGGER {description "In trigger mode for Mobile IPv6";} /*Supported by XFRM*/
    }
    description "type define of ipsec mode";
  }

  typedef ipsec-protocol {
  
    type enumeration {
      enum ah { description "AH Protocol"; }
      enum esp { description "ESP Protocol"; }
      enum comp { description "IP Compression";} /*Supported by XFRM*/
      enum route2 { description "Routing Header type 2. Mobile IPv6";} /*Supported by XFRM*/
      enum hao {description "Home Agent Option";} /*Supported by XFRM*/
    }
    description "type define of ipsec security protocol";
  }

  typedef ipsec-spi {
  
    type uint32 { range "1..max"; }
    description "SPI";
  }

   typedef lifetime-action {
    type enumeration {
      enum terminate {description "Terminate the IPsec SA";}
      enum replace  {description "Replace the IPsec SA with a new one";}
    }
    description "Action when lifetime expiration";
  }


  typedef ipsec-traffic-direction {
  
    type enumeration {
      enum INBOUND { description "Inbound traffic"; }
      enum OUTBOUND { description "Outbound traffic"; }
      enum FORWARD{ description "Forwarded traffic"; }
    }
    description "IPsec traffic direction";
  }


  typedef ipsec-spd-operation {
  
    type enumeration {
      enum PROTECT { description "PROTECT the traffic with IPsec"; }
      enum BYPASS { description "BYPASS the traffic"; }
      enum DISCARD { description "DISCARD the traffic"; }
    }
    description "The operation when traffic matches IPsec security policy";
  }


  typedef ipsec-next-layer-proto {
  
    type enumeration {
      enum TCP { description "PROTECT the traffic with IPsec"; }
      enum UDP { description "BYPASS the traffic"; }
      enum SCTP { description "PROTECT the traffic with IPsec";} 
      enum DCCP { description "PROTECT the traffic with IPsec";}
      enum ICMP { description "PROTECT the traffic with IPsec";}
      enum IPv6-ICMP { description "PROTECT the traffic with IPsec";}
      enum MH {description "PROTECT the traffic with IPsec";}
      enum GRE {description "PROTECT the traffic with IPsec";}
    }
    description "Next layer proto on top of IP";
  }


  typedef ipsec-spd-name {
  
    type enumeration {
      enum id_rfc_822_addr {
        description "Fully qualified user name string.";
      }    
      enum id_fqdn {
        description "Fully qualified DNS name.";
      }         
      enum id_der_asn1_dn {
        description "X.500 distinguished name.";
      }       
      enum id_key {
        description "IKEv2 Key ID.";
      }
    }
    description "IPsec SPD name type";
  }



   typedef auth-method-type {
      	/* Most implementations also provide XAUTH protocol, others used are: BLISS, P12, NTLM, PIN */

		type enumeration {
   		  enum pre-shared {
  			description "Select pre-shared key message as the authentication method";
   		  }
   		  enum rsa-signature {
  			description "Select rsa digital signature as the authentication method";
  		  }
 		  enum dss-signature {
		  	description "Select dss digital signature as the authentication method";
		  }
 		  enum eap {
		  	description "Select EAP as the authentication method";
 	  	 }
       }
       description "Peer authentication method";
 	}

/*################## PAD grouping ####################*/

  grouping auth-method-grouping {
    description "Peer authentication method data";

    container auth-method {
      description "Peer authentication method container";
         
      leaf auth-m { 
        type auth-method-type;
        description "Type of authentication method (preshared, rsa, etc.)";
      }
     
      container pre-shared {
        when "../auth-m = 'pre-shared'";
        leaf secret { type string; description "Pre-shared secret value";}
        description "Shared secret value";
      }
         
      container rsa-signature {
        when "../auth-m = 'rsa-signature'";
        leaf key-data {
          type string;
          description "RSA private key data - PEM";
        } 

        leaf key-file {
          type string;
          description "RSA private key file name ";
        } 

        leaf-list ca-data {
          type string;
          description "List of trusted CA certs - PEM";
        }
        leaf ca-file {
          type string;
          description "List of trusted CA certs file";
        } 
        leaf cert-data {
          type string;
          description "X.509 certificate data - PEM4";
        } 
        leaf cert-file {
          type string; 
          description "X.509 certificate file";
        } 
        leaf crl-data {
          type string;
          description "X.509 CRL certificate data in base64";
        } 
        leaf crl-file {
          type string;
          description " X.509 CRL certificate file";
        }
        description "RSA signature container";
      }     
    }
  }

  grouping identity-grouping {
    description "Identification type. It is an union identity";
    choice identity {
      description "Choice of identity.";

      leaf ipv4-address {
        type inet:ipv4-address;
        description "Specifies the identity as a single four (4) octet IPv4 address. An example is, 10.10.10.10. ";
      }      
      leaf ipv6-address {
        type inet:ipv6-address;
        description "Specifies the identity as a single sixteen (16) octet IPv6 address. An example is FF01::101, 2001:DB8:0:0:8:800:200C:417A .";
      }
      leaf fqdn-string {
        type inet:domain-name;
        description "Specifies the identity as a Fully-Qualified Domain Name (FQDN) string. An example is: example.com. The string MUST not contain any terminators (e.g., NULL, CR, etc.)."; 
      } 
      leaf rfc822-address-string {
        type string;
        description "Specifies the identity as a fully-qualified RFC822 email address string. An example is, jsmith@example.com. The string MUST not contain any terminators (e.g., NULL, CR, etc.).";
      }
      leaf dnX509 {
        type string;
        description "Specifies the identity as a distinguished name in the X.509 tradition.";
      }
      leaf id_key {
        type string;
        description "Key id";
      } /* From RFC4301 list of id types */
    }
  } /* grouping identity-grouping */

/*################ end PAD grouping ##################*/

/*################## SAD and SPD grouping ####################*/

  grouping ip-addr-range {
  description "IP address range grouping";
    leaf start {
      type inet:ip-address;
      description "Start IP address";
    }
    leaf end {
      type inet:ip-address;
      description "End IP address";
    }
  }
  
  grouping port-range  {
  description "Port range grouping";
    leaf start {
      type inet:port-number;
      description "Start IP address";
    }
    leaf end {
      type inet:port-number;
      description "End IP address";
    }
  }

  grouping tunnel-grouping {
  description "Tunnel mode grouping";
    leaf local{ type inet:ip-address; description "Local tunnel endpoint"; }
    leaf remote{ type inet:ip-address; description "Remote tunnel enpoint"; }
    leaf bypass-df { type boolean; description "bypass DF bit"; }
    leaf bypass-dscp { type boolean; description "bypass DSCP"; }
    leaf dscp-mapping { type yang:hex-string; description "DSCP mapping"; }
    leaf ecn { type boolean; description "Bit ECN"; } /* RFC 4301 ASN1 notation. Annex C*/
  }

  grouping selector-grouping {
  description "Traffic selector grouping";
    list local-addresses {
      key "start end";
      uses ip-addr-range;
      description "List of local addresses";
    }  
    list remote-addresses {
      key "start end";
      uses ip-addr-range;
      description "List of remote addresses";
    }
    leaf-list next-layer-protocol { type ipsec-next-layer-proto; description "List of Next Layer Protocol";}
    list local-ports {
      key "start end";
      uses port-range;
      description "List of local ports";
    }

    list remote-ports {
      key "start end";
      uses port-range;
      description "List of remote ports";
    }
  }

/*################## SAD grouping ####################*/

  grouping ipsec-sa-grouping {
    description "Configure Security Association (SA). Section 4.4.2.1 in RFC 4301";

    leaf spi { type ipsec-spi;  description "Security Parameter Index";}
    leaf seq-number { type uint64; description "Current sequence number of IPsec packet."; }
    leaf seq-number-overflow-flag { type boolean; description "The flag indicating whether overflow of the sequence number counter should prevent transmission of additional packets on the SA, or whether rollover is permitted."; }
    leaf anti-replay-window { type uint16 { range "0 | 32..1024"; } description "Anti replay window"; }
    leaf rule-number {type uint32; description "This value links the SA with the SPD entry";}

    uses selector-grouping;

    leaf security-protocol { type ipsec-protocol; description "Security protocol of IPsec SA: Either AH or ESP."; }
    
    container ah-sa {
      when "../security-protocol = 'ah'";
      description "Configure Authentication Header (AH) for SA";
      leaf integrity-algorithm { type integrity-algorithm-t; description "Configure Authentication Header (AH)."; }
      leaf key { type string; description "AH key value";}
    }

    container esp-sa {
      when "../security-protocol = 'esp'";
      description "Set IPSec Encapsulation Security Payload (ESP)";
      
      container encryption {
        description "Configure encryption for IPSec Encapsulation Secutiry Payload (ESP)";
        leaf encryption-algorithm { type encryption-algorithm-t; description "Configure ESP encryption"; }
        leaf key { type string; description "ESP encryption key value";}
        leaf iv {type string; description "ESP encryption IV value"; }
      }

      container integrity {
        description "Configure authentication for IPSec Encapsulation Secutiry Payload (ESP)";
        leaf integrity-algorithm { type integrity-algorithm-t; description "Configure Authentication Header (AH)."; }
        leaf key { type string; description "ESP integrity key value";}
      }

      container combined {
        description "ESP combined mode algorithms (encryption and integrity)";
        leaf combined-algorithm { type combined-algorithm-t; description "Combined algorithm AEAD";}
      }
    }


    container sa-lifetime { 
      description "This may be expressed as a time or byte count, or a simultaneous use of both with the first lifetime to expire taking precedence";
      leaf time-soft { type uint32; default 0; description "Soft time lifetime";}
      leaf time-hard { type uint32; default 0; description "Hard time lifetime"; }
      leaf time-use-soft { type uint32; default 0; description "Use Soft time lifetime";}
      leaf time-use-hard { type uint32; default 0; description "Use Hard time lifetime";}
      leaf byte-soft { type uint32; default 0;description "Byte soft lifetime"; }
      leaf byte-hard { type uint32; default 0; description "Byte hard lifetime";}
      leaf packet-soft {type uint32; default 0; description "Packet soft lifetime";}
      leaf packet-hard { type uint32; default 0; description "Packet hard lifetime";}
      leaf action {type lifetime-action; description "action lifetime";}
    }

    leaf mode { type ipsec-mode; description "SA Mode"; }
    leaf statefulfragCheck { type boolean; description "TRUE stateful fragment checking, FALSE no stateful fragment checking"; }
    leaf dscp { type yang:hex-string; description "DSCP value"; }


    container tunnel {
      when "../mode = 'TUNNEL'";
      uses tunnel-grouping;
      description "Container for tunnel grouping";
    }

    leaf path-mtu { type uint16; description "Maximum size of an IPsec packet that can be transmitted without fragmentation"; }

    container encap { /* This is defined by XFRM */
      description "Encapsulation container";
      leaf espinudp {type boolean; description "TRUE espinudp; FALSE espindup-nonike";}
      leaf sport {type inet:port-number; description "Encapsulation source port";}
      leaf dport {type inet:port-number; description "Encapsulation destination port"; }
      leaf oaddr {type inet:ip-address; description "Encapsulation Original Address ";}
    }
       
}

/*################## end SAD grouping ##################*/
  


/*################## SPD grouping ####################*/

  grouping ipsec-policy-grouping {
    description "Holds configuration information for an IPSec SPD entry.";
  
    leaf rule-number {
      type uint64;
      description "SPD index. RFC4301 does not mention an index however real implementations provide a policy index/or id to refer a policy. ";
    }   
    leaf priority {type uint32; default 0; description "Policy priority";}
    list names {
      key "name";
      leaf name-type {
        type ipsec-spd-name;
        description "SPD name type.";
      }   
      leaf name {
        type string; description "Policy name";
      }
      description "List of policy names";
    }

        
    container condition {
      description "SPD condition --> RFC4301";
      
      list traffic-selector-list {
    
        key "ts-number";
        
        leaf ts-number { type uint32; description "Traffic selector number"; }
        leaf direction { type ipsec-traffic-direction; description "in/fwd/out"; } 

        uses selector-grouping;
        leaf selector-priority {type uint32; default 0; description "It establishes a priority to the traffic selector";}
        ordered-by user;
        
        description "List of traffic selectors";
      } 
    }

    container processing-info {
      description "SPD processing --> RFC4301";
      leaf action{ type ipsec-spd-operation; mandatory true; description "If the action is bypass or discard processing container ipsec-sa-cfg is empty";} 
  
      container ipsec-sa-cfg {
        when "../action = 'PROTECT'";
        
        leaf pfp-flag { type boolean; description "Each selector has with a pfp flag."; }   
        leaf extSeqNum { type boolean; description "TRUE 64 bit counter, FALSE 32 bit"; }
        leaf seqOverflow { type boolean; description "TRUE rekey, FALSE terminare & audit"; } 
        leaf statefulfragCheck { type boolean; description "TRUE stateful fragment checking, FALSE no stateful fragment checking"; }
        leaf security-protocol { type ipsec-protocol; description "Security protocol of IPsec SA: Either AH or ESP."; }
        leaf mode { type ipsec-mode; description "transport/tunnel"; }
        
        container ah-algorithms {
          when "../security-protocol = 'ah'";
          leaf-list ah-algorithm {
            type integrity-algorithm-t; 
            description "Configure Authentication Header (AH)."; 
          }
          description "AH algoritms ";
        }
        
        container esp-algorithms {
          when "../security-protocol = 'esp'";
          description "Configure Encapsulating Security Payload (ESP).";
          leaf-list authentication { type integrity-algorithm-t; description "Configure ESP authentication"; }
          leaf-list encryption { type encryption-algorithm-t; description "Configure ESP encryption"; }
        }
               
        container tunnel {
          when "../mode = 'TUNNEL'";
          uses tunnel-grouping;
          description "tunnel grouping container";
        }
        description " IPSec SA configuration container";
      }
    }

    container spd-lifetime {
      description "SPD lifetime parameters";
      leaf time-soft { type uint32; default 0; description "Soft time lifetime";}
      leaf time-hard { type uint32; default 0; description "Hard time lifetime";}
      leaf time-use-soft { type uint32; default 0; description "Use soft lifetime";}
      leaf time-use-hard { type uint32; default 0; description "Use hard lifetime";}
      leaf byte-soft { type uint32; default 0; description "Byte soft lifetime";}
      leaf byte-hard { type uint32; default 0; description "Hard soft lifetime";}
      leaf packet-soft {type uint32; default 0; description "Packet soft lifetime";}
      leaf packet-hard { type uint32; default 0; description "Packet hard lifetime";}
    }        
  }/* grouping ipsec-policy-grouping */

/*################ end SPD grouping ##################*/



/*################## IKEv2-grouping ##################*/


	grouping isakmp-proposal {
    description "ISAKMP proposal grouping";
		leaf phase1-lifetime {
			type uint32;
			mandatory true;
			description "lifetime for IKE Phase 1 SAs";
		}
		leaf phase1-authby {
			type auth-method-type;
			mandatory true;
			description "Auth method for IKE Phase 1 SAs";
		}
		leaf-list phase1-authalg {
			type integrity-algorithm-t;
			description "Auth algorigthm for IKE Phase 1 SAs";
		}
		leaf-list phase1-encalg {
			type encryption-algorithm-t;
			description "Auth algorigthm for IKE Phase 1 SAs";
		}
		leaf dh_group {
			type uint32;
			mandatory true;
			description "Group number for Diffie Hellman Exponentiation";
		}
	} /* list isakmp-proposal */


	grouping phase2-info {
    description "IKE Phase 2 Information";
		leaf local-addrs {
			type inet:ip-address;
			mandatory true;
            description "IKEv2 Local address";
		}
		leaf remote-addr {
			type inet:ip-address;
			mandatory true;
            description "IKEv2 Remote address";
		}
		leaf pfs_group {
			type uint32;
			description
			"If non-zero, require perfect forward secrecy
			when requesting new SA. The non-zero value is
			the required group number";
		}
		leaf phase2-lifetime {
			type uint32;
			mandatory true;
			description "lifetime for IKE Phase 2 SAs";
		}
		leaf-list phase2-authalg {
			type integrity-algorithm-t;
			description "Auth algorigthm for IKE Phase 2 SAs";
		}
		leaf-list phase2-encalg {
			type encryption-algorithm-t;
			description "Auth algorithm for IKE Phase 2 SAs";
		}
	}

	grouping local-grouping {
		description "Configure the local peer in an IKE connection";
    		
		container local {
         description "Local container";
  		  choice my-identifier-type {
  			default ipv4;
  			case ipv4 {
  				leaf ipv4 {
  					type inet:ipv4-address;
  					description "IPv4 dotted-decimal address";
  				}
  			}
  			case ipv6 {
  				leaf ipv6 {
  					type inet:ipv6-address;
  					description "numerical IPv6 address";
  				}
  			}
  			case fqdn {
  				leaf fqdn {
  					type inet:domain-name;
  					description "Fully Qualifed Domain name ";
  				}
  			}
  			case dn {
  				leaf dn {
  					type string;
  					description "Domain name";
  				}
  			}
  			case user_fqdn {
  				leaf user_fqdn {
  					type string;
  					description "User FQDN";
  				}
  			}
            description "Local ID type";
  		}
        leaf my-identifier {
            type string;
            mandatory true;
            description "Local id used for authentication";
        }
  	  }
	}

	grouping remote-grouping {
  	description "Configure the remote peer in an IKE connection";
  	  container remote {
        description "Remote container";
  		choice my-identifier-type {
  			default ipv4;
  			case ipv4 {
  				leaf ipv4 {
  					type inet:ipv4-address;
  					description "IPv4 dotted-decimal address";
  				}
  			}
  			case ipv6 {
  				leaf ipv6 {
  					type inet:ipv6-address;
  					description "numerical IPv6 address";
  				}
  			}
  			case fqdn {
  				leaf fqdn {
  					type inet:domain-name;
  					description "Fully Qualifed Domain name ";
  				}
  			}
  			case dn {
  				leaf dn {
  					type string;
  					description "Domain name";
  				}
  			}
  			case user_fqdn {
  				leaf user_fqdn {
  					type string;
  					description "User FQDN";
  				}
  			}
  			description "Local ID type";
  		}
  		leaf my-identifier {
    		type string; 
  			mandatory true; 
  			description "Local id used for authentication";
  		}
      }
	}

/*################## End IKEv2-groupingUMU ##################*/

/*################# Register grouping #################*/

  typedef sadb-msg-type {
  
    type enumeration {
       enum sadb_reserved { description "SADB_RESERVED";}
       enum sadb_getspi { description "SADB_GETSPI";}
       enum sadb_update { description "SADB_UPDATE";}
       enum sadb_add { description "SADB_ADD";}
       enum sadb_delete { description "SADB_DELETE"; }
       enum sadb_get { description "SADB_GET"; }
       enum sadb_acquire { description "SADB_ACQUIRE"; }
       enum sadb_register { description "SADB_REGISTER"; }
       enum sadb_expire { description "SADB_EXPIRE"; }
       enum sadb_flush { description "SADB_FLUSH"; }
       enum sadb_dump { description "SADB_DUMP"; }
       enum sadb_x_promisc { description "SADB_X_PROMISC"; }
       enum sadb_x_pchange { description "SADB_X_PCHANGE"; }
       enum sadb_max{  description "SADB_MAX"; }
    }
    description "PF_KEY base message types";
  }

  typedef sadb-msg-satype {
  
    type enumeration {
       enum sadb_satype_unspec { description "SADB_SATYPE_UNSPEC"; }
       enum sadb_satype_ah { description "SADB_SATYPE_AH"; }
       enum sadb_satype_esp { description "SADB_SATYPE_ESP"; }
       enum sadb_satype_rsvp { description "SADB_SATYPE_RSVP"; }
       enum sadb_satype_ospfv2 { description "SADB_SATYPE_OSPFv2"; }
       enum sadb_satype_ripv2 { description "SADB_SATYPE_RIPv2"; }
       enum sadb_satype_mip { description "SADB_SATYPE_MIP"; }
       enum sadb_satype_max { description "SADB_SATYPE_MAX"; }
    }
    description "PF_KEY Security Association types";
  }

  grouping base-grouping {
    description "Configuration for the  message header format";
    list base-list {
      key "version";
      leaf version { type string; description "Version of PF_KEY (MUST be PF_KEY_V2)"; }
      leaf msg_type { type sadb-msg-type; description "Identifies the type of message"; }
      leaf msg_satype { type sadb-msg-satype; description "Defines the type of Security Association"; }
      leaf msg_seq { type uint32; description "Sequence number of this message."; }
      description "Configuration for a specific message header format";
    }     
  }

  grouping algorithm-grouping {
    description "List of supported authentication and encryptation algorithms";
    list algorithm-supported{
      container authentication {
        description "Authentication algorithm supported";
        leaf name { type integrity-algorithm-t; description "Name of authentication algorithm"; }
        leaf ivlen { type uint8; description "Length of the initialization vector to be used for the algorithm"; }
        leaf min-bits { type uint16; description "The minimun acceptable key length, in bits"; }
        leaf max-bits { type uint16; description "The maximun acceptable key length, in bits"; }
      }
      container encryption {
        description "Encryptation algorithm supported";
        leaf name { type encryption-algorithm-t; description "Name of encryption algorithm"; }
        leaf ivlen { type uint8; description "Length of the initialization vector to be used for the algorithm"; }
        leaf min-bits { type uint16; description "The minimun acceptable key length, in bits"; }
        leaf max-bits { type uint16; description "The maximun acceptable key length, in bits"; }
      }
      description "List for a specific algorithm";
    }
  }

/*################# End Register grouping #################*/


/*################## ipsec ##################*/

	container ietf-ipsec {
    description "Main IPsec container ";
 	
		container ikev2 {
  		if-feature case1;
  		description "Configure the IKEv2";

  		container ike-connection {
    		description "IKE connections configuration";

    		list ike-conn-entries {
    			key "conn-name"; 
    			description "IKE peer connetion information";
    			leaf conn-name  {
						type string; 
						mandatory true; 
						description "Name of IKE connection";
                }
    			leaf autostartup {
    				type boolean;
    				mandatory true;
     	 			description "if True: automatically start tunnel at startup; else we do lazy tunnel setup based on trigger from datapath";
    			}
    			leaf nat-traversal {
    				type boolean;
    				default false;
    				description "Enable/Disable NAT traversal";
    			}
    			leaf version {
                    type enumeration {
                    /* we only support ikev2 in this version */
                       enum ikev2 {value 2; description "IKE version 2";}
                     }
                     description "IKE version";
    			}

    			uses isakmp-proposal;
    			uses local-grouping;
    			uses remote-grouping;
    			uses phase2-info;

    		} /* ike-conn-entries */
  		} /* container ike-connection */
    } /* container ikev2 */

    container ipsec {
      description "Configuration IPsec";

      
      container spd {
        description "Configure the Security Policy Database (SPD)";
        list spd-entry {
          key "rule-number";
          uses ipsec-policy-grouping;
          ordered-by user;
          description "List of SPD entries";
        }
      }

      container sad {
        if-feature case2;
        description "Configure the IPSec Security Association Database (SAD)";
        list sad-entry {
          key "spi"; 
          uses ipsec-sa-grouping;
          description "List of SAD entries";
        }
      }

      container pad {
        if-feature case1;
        description "Configure Peer Authorization Database (PAD)";

        list pad-entries {
          key "pad-entry-id";
          ordered-by user;
          description "Peer Authorization Database (PAD)";

          leaf pad-entry-id {
            type uint64;
            description "SAD index. ";
          } 

          uses identity-grouping;
  
          leaf pad-auth-protocol {
            type auth-protocol-type;
            description "IKEv1, IKEv2, KINK, etc. ";
          } 
          uses auth-method-grouping;
        } 
      } 
    } 


	} /* container ietf-ipsec */ 


/*########## State Data ############*/

// TBD

/*################## RPC and Notifications ##################*/

/* Note: not yet completed */
// Those RPCs are needed by a Security Controller in case 2 */

  rpc sadb_register {
    description "Allows netconf to register its key socket as able to acquire new security associations for the kernel";
    input {
      uses base-grouping;
    }
    output {
      uses base-grouping; 
      uses algorithm-grouping;           
    }
  }

  notification spd-expire {
    description "A SPD entry has expired";
    leaf index {
      type uint64;
      description "SPD index. RFC4301 does not mention an index however real implementations (e.g. XFRM or PFKEY_v2 with KAME extensions provide a policy index to refer a policy. ";
    }
  }

  notification sadb_acquire {
    description "A IPsec SA is required ";
    leaf state {
      type uint32;
      mandatory "true";
      description
        "Request the creation of a SADB entry";
    }
  }

  notification sadb_expire {
    description ".....";
    leaf state {
      type uint32;
      mandatory "true";
      description
        "Notify the expiration of a entry in the SADB";
    }
  }

}  /*module ietf-ipsec*/

                    
                    <CODE ENDS>
                ]]>
            </artwork>
        </figure>
    </t>
     
    </section>



  </back>
</rfc>
