<?xml version="1.0" encoding="US-ASCII"?>
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="3"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC3031 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3031.xml">
<!ENTITY RFC6790 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6790.xml">
<!ENTITY RFC7274 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7274.xml">
<!ENTITY RFC7665 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7665.xml">
<!ENTITY RFC8174 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8174.xml">
<!ENTITY RFC8300 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8300.xml">
]>

<rfc category="std" docName="draft-farrel-mpls-sfc-05" ipr="trust200902">
  <front>
    <title abbrev="MPLS SFC">An MPLS-Based Forwarding Plane for Service Function Chaining</title>

    <author fullname="Adrian Farrel" initials="A." surname="Farrel">
      <organization>Juniper Networks</organization>
      <address>
        <email>afarrel@juniper.net</email>
      </address>
    </author>

    <author fullname="Stewart Bryant" initials="S." surname="Bryant">
      <organization>Huawei</organization>
      <address>
        <email>stewart.bryant@gmail.com</email>
      </address>
    </author>

    <author fullname="John Drake" initials="J." surname="Drake">
      <organization>Juniper Networks</organization>
      <address>
        <email>jdrake@juniper.net</email>
      </address>
    </author>

    <date month="" year="2018"/>

    <area>Routing Area</area>

    <workgroup>MPLS Working Group</workgroup>

    <keyword>SFC</keyword>
    <keyword>MPLS</keyword>
    <keyword>Service Function Chaining</keyword>
    <keyword>NSH</keyword>
    <keyword>Network Service Header</keyword>
    <keyword>MPLS</keyword>
    <keyword>Multiprotocol Label Switching</keyword>

    <abstract>
      <t>Service Function Chaining (SFC) is the process of directing packets
         through a network so that they can be acted on by an ordered set of
         abstract service functions before being delivered to the intended
         destination.  An architecture for SFC is defined in RFC7665.</t>

      <t>The Network Service Header (NSH) can be inserted into packets to
         steer them along a specific path to realize a Service Function Chain.</t>

      <t>Multiprotocol Label Switching (MPLS) is a widely deployed forwarding
         technology that uses labels placed in a packet in a label stack to
         identify the forwarding actions to be taken at each hop through a
         network.  Actions may include swapping or popping the labels as well,
         as using the labels to determine the next hop for forwarding the packet.
         Labels may also be used to establish the context under which the packet
         is forwarded.</t>

      <t>This document describes how Service Function Chaining can be achieved
         in an MPLS network by means of a logical representation of the NSH in
         an MPLS label stack.  It does not deprecate or replace the NSH, but
         acknowledges that there may be a need for an interim deployment of SFC
         functionality in brownfield networks.</t>
    </abstract>

  </front>

  <middle>
    <section title="Introduction">
      <t>Service Function Chaining (SFC) is the process of directing packets
         through a network so that they can be acted on by an ordered set of
         abstract service functions before being delivered to the intended
         destination.  An architecture for SFC is defined in <xref target="RFC7665" />.</t>

      <t>When applying a particular Service Function Chain to the traffic selected by a
         service classifier, the traffic needs to be steered through an ordered set of
         Service Functions (SFs) in the network.  This ordered set of SFs is termed a
         Service Function Path (SFP), and the traffic is passed between Service Function
         Forwarders (SFFs) that are responsible for delivering the packets to the SFs
         and for forwarding them onward to the next SFF.</t>

      <t>In order to steer the selected traffic between SFFs and to the correct SFs
         the service classifier needs to attach information to each packet.  This
         information indicates the SFP on which the packet is being forwarded and hence
         the SFs to which it must be delivered.  The information also indicates the
         progress the packet has already made along the SFP.</t>

      <t>The Network Service Header (NSH) <xref target="RFC8300" /> has been
         defined to carry the necessary information for Service Function Chaining
         in packets.  The NSH can be inserted into packets and contains various
         information including a Service Path Indicator (SPI), a Service Index (SI),
         and a Time To Live (TTL) counter.</t>

      <t>Multiprotocol Label Switching (MPLS) <xref target="RFC3031" /> is a widely
         deployed forwarding technology that uses labels placed in a packet in a
         label stack to identify the forwarding actions to be taken at each hop
         through a network.  Actions may include swapping or popping the labels as
         well, as using the labels to determine the next hop for forwarding the
         packet.  Labels may also be used to establish the context under which the
         packet is forwarded.    In many cases, MPLS will be used as a tunneling
         technology to carry packets through networks between SFFs.</t>

      <t>This document describes how Service Function Chaining can be achieved
         in an MPLS network by means of a logical representation of the NSH in
         an MPLS label stack.  This approach is applicable to all forms of
         MPLS forwarding (where labels are looked up at each hop, and swapped or
         popped <xref target="RFC3031" />).  It does not deprecate or replace the
         NSH, but acknowledges that there may be a need for an interim deployment
         of SFC functionality in brownfield networks.  The mechanisms described in
         this document are a compromise between the full function that can be
         achieved using the NSH, and the benefits of reusing the existing MPLS
         forwarding paradigms.</t>

      <t>It is assumed that the reader is fully familiar with the terms and concepts
         introduced in <xref target="RFC7665" /> and <xref target="RFC8300" />.</t>

      <t>Note that one of the features of the SFC architecture described in
         <xref target="RFC7665" /> is the "SFC proxy" that exists to include legacy
         SFs that are not able to process NSH-encapsulated packets.  This issue is
         equally applicable to the use of MPLS-encapsulated packets that encode a
         logical representation of an NSH.  It is discussed further in
         <xref target="proxy" />.</t>

    </section>

    <section title="Requirements Language">

      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
         "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
         "OPTIONAL" in this document are to be interpreted as described in BCP 14
         <xref target="RFC2119" /> <xref target="RFC8174" /> when, and only when,
         they appear in all capitals, as shown here.</t>

    </section>

    <section anchor="choice" title="Choice of Data Plane SPI/SI Representation">

      <t>While <xref target="RFC8300" /> defines the NSH that can be used in a number
         of environments, this document provides a mechanism to handle situations in
         which the NSH is not ubiquitously deployed.  In this case it is possible to
         use an alternative data plane representation of the SPI/SI by carrying the
         identical semantics in MPLS labels.</t>

      <t>In order to correctly select the mechanism by which SFC information is encoded
         and carried between SFFs, it may be necessary to configure the capabilities and
         choices either within the whole Service Function Overlay Network, or on a hop by
         hop basis.  It is a requirement that both ends of a tunnel over the underlay
         network (i.e., a pair of SFFs adjacent in the SFC) know that the tunnel is used
         for SFC and know what form of NSH representation is used.  A control plane
         signalling approach to achieve these objectives is provided using BGP in
         <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />.</t>

      <t>Note that the encoding of the SFC information is independent of the choice of
         tunneling technology used between SFFs.  Thus, an MPLS representation of the
         logical NSH (as defined in this document) may be used even if the tunnel between
         a pair of SFFs is not an MPLS tunnel.  Conversely, MPLS tunnels may be used to
         carry other encodings of the logical NSH (specifically, the NSH itself). </t>
    </section>

    <section anchor="basic" title="Basic Unit of Representation">

      <t>When an MPLS label stack is used to carry a logical NSH, a basic unit of representation
         is used.  This unit comprises two MPLS labels as shown below.  The unit may be present
         one or more times in the label stack as explained in subsequent sections.</t>

      <t>In order to convey the same information as is present in the NSH, two MPLS label stack
         entries are used.  One carries a label to provide context within the SFC scope (the SFC
         Context Label), and the other carries a label to show which service function is to be
         actioned (the SF Label).  This two-label unit is shown in <xref target="basicunitfig" />.</t>

        <figure anchor="basicunitfig" title="The Basic Unit of MPLS Label Stack for SFC">
          <artwork>
            <![CDATA[
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           SFC Context Label           | TC  |S|       TTL     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           SF Label                    | TC  |S|       TTL     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            ]]>
          </artwork>
        </figure>

      <t>The fields of these two label stack entries are encoded as follows:
         <list style="hanging">
           <t hangText="Label:">The Label fields contain the values of the SFC Context Label
              and the SF Label encoded as 20 bit integers.  The precise semantics of these
              label fields are dependent on whether the label stack entries are used for MPLS
              label swapping (see <xref target="mplsswap" />) or MPLS label stacking (see
              <xref target="mplsstack" />).</t>
           <t hangText="TC:">The TC bits have no meaning.  They SHOULD be set to zero in both
              label stack entries when a packet is sent and MUST be ignored on receipt.</t>
           <t hangText="S:">The bottom of stack bit has its usual meaning in MPLS.  It MUST be
              clear in the SFC Context label stack entry and MAY be set in the SF label stack entry
              depending on whether the label is the bottom of stack.</t>
           <t hangText="TTL:">The TTL field in the SFC Context label stack entry SHOULD be set to 1.
              The TTL in SF label stack entry (called the SF TTL) is set according to its use
              for MPLS label swapping (see <xref target="mplsswap" />) or MPLS label stacking (see
              <xref target="mplsstack" /> and is used to mitigate packet loops.</t>
         </list></t>

      <t>The sections that follow show how this basic unit of MPLS label stack may be used
         for SFC in the MPLS label swapping case and in the MPLS label stacking. For simplicity,
         these sections do not describe the use of metadata: that is covered separately in
         <xref target="metadata" />.</t>
    </section>

    <section anchor="mplsswap" title="MPLS Label Swapping">

      <t>This section describes how the basic unit of MPLS label stack for SFC introduced in
         <xref target="basic" /> is used when MPLS label swapping is in use.  As can be seen
         from <xref target="swapFig" />, the top of the label stack comprises the labels
         necessary to deliver the packet over the MPLS tunnel between SFFs.  Any MPLS
         encapsulation may be used (i.e., MPLS, MPLS in UDP, MPLS in GRE, and MPLS in VXLAN
         or GPE), thus the tunnel technology does not need to be MPLS, but that is shown here
         for simplicity.</t>

      <t>An entropy label (<xref target="RFC6790" />) may also be present as described in
         <xref target="entropy" /></t>

      <t>Under these labels (or other encapsulation) comes a single instance of the basic unit
         of MPLS label stack for SFC.  In addition to the interpretation of the fields of these
         label stack entries provided in <xref target="basic"/> the following meanings are
         applied:

         <list style="hanging">
           <t hangText="SPI Label:">The Label field of the SFC Context label stack entry contains the
              value of the SPI encoded as a 20 bit integer.  The semantics of the SPI is exactly
              as defined in <xref target="RFC8300"/>.  Note that an SPI as defined by
              <xref target="RFC8300"/> can be encoded in 3 octets (i.e., 24 bits), but
              that the Label field allows for only 20 bits and reserves the values 0 though 15 as
              &apos;special purpose&apos; labels <xref target="RFC7274" />.  Thus, a system using MPLS
              representation of the logical NSH MUST NOT assign SPI values greater than 2^20 - 1
              or less than 16.</t>

           <t hangText="SI Label:">The Label field of the SF label stack entry contains the value
              of the SI exactly as defined in <xref target="RFC8300"/>.  Since the SI
              requires only 8 bits, and to avoid overlap with the &apos;special purpose&apos; label
              range of 0 through 15 <xref target="RFC7274"/>, the SI is carried in the top (most significant) 8
              bits of the Label field with the low order 12 bits set to zero.</t>

           <t hangText="TC:">The TC fields are as described in <xref target="basic" />.</t>

           <t hangText="S:">The S bits are as described in <xref target="basic" />.</t>

           <t hangText="TTL:">The TTL field in the SPI label stack entry SHOULD be set to 1 as
              stated in <xref target="basic" />.  The TTL in SF label stack entry is decremented
              once for each forwarding hop in the SFP, i.e., for each SFF transited, and so mirrors
              the TTL field in the NSH.</t>
         </list></t>

      <figure anchor="swapFig" title="The MPLS SFC Label Stack">
        <artwork>
          <![CDATA[
  ---------------
 ~ Tunnel Labels ~
 +---------------+
 ~   Optional    ~
 ~ Entropy Label ~
 +---------------+ - - -
 |   SPI Label   |
 +---------------+  Basic unit of MPLS label stack for SFC
 |   SI Label    |
 +---------------+ - - -
 |               |
 ~    Payload    ~
 |               |
  ---------------
          ]]>
        </artwork>
      </figure>

      <t>The following processing rules apply to the Label fields:
         <list style="symbols">
            <t>When a Classifier inserts a packet onto an SFP it sets the SPI Label to indicate the
               identity of the SFP, and sets the SI Label to indicate the first SF in the path.</t>
            <t>When a component of the SFC system processes a packet it uses the SPI Label to
               identify the SFP and the SI Label to determine to which SFF or instance of an SF (an SFI)
               to deliver the packet.  Under normal circumstances (with the exception of branching
               and reclassification - see <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />)
               the SPI Label value is preserved on all packets.  The SI Label value is modified
               by SFFs and through reclassification to indicate the next hop along the SFP.</t>
         </list></t>

      <t>The following processing rules apply to the TTL field of the SF label stack entry, and are
         derived from section 2.2 of <xref target="RFC8300"/>:
         <list style="symbols">
            <t>When a Classifier places a packet onto an SFP it MUST set the TTL to a value between
               1 and 255.  It SHOULD set this according to the expected length of the SFP (i.e., the
               number of SFs on the SFP), but it MAY set it to a larger value according to local
               configuration.  The maximum TTL value supported in an NSH is 63, and so the practical
               limit here may also be 63.</t>
            <t>When an SFF receives a packet from any component of the SFC system (Classifier, SFI, or
               another SFF) it MUST discard any packets with TTL set to zero.  It SHOULD log such
               occurrences, but MUST apply rate limiting to any such logs.</t>
            <t>An SFF MUST decrement the TTL by one each time it performs a forwarding lookup.</t>
            <t>If an SFF decrements the TTL to zero it MUST NOT send the packet, and MUST discard the
               packet.  It SHOULD log such occurrences, but MUST apply rate limiting to any such logs.</t>
            <t>SFIs MUST ignore the TTL, but MUST mirror it back to the SFF unmodified along with the SI
               (which may have been changed by local reclassification).</t>
            <t>If a Classifier along the SFP makes any change to the intended path of the packet including
               for looping, jumping, or branching (see <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />
               it MUST NOT change the SI TTL of the packet.  In particular, each component of the SFC
               system MUST NOT increase the SI TTL value otherwise loops may go undetected.</t>
         </list></t>

    </section>

    <section anchor="mplsstack" title="MPLS Label Stacking">

      <t>This section describes how the basic unit of MPLS label stack for SFC introduced in
         <xref target="basic" /> is used when MPLS label stacking is used to carry information about
         the SFP and SFs to be executed.  As can be seen in <xref target="stackFig" />, the top of the
         label stack comprises the labels necessary to deliver the packet over the MPLS tunnel between
         SFFs.  Any MPLS encapsulation may be used.</t>

      <t>An entropy label (<xref target="RFC6790" />) may also be present as described in
         <xref target="entropy" /></t>

      <t>Under these labels comes one of more instances of the basic unit of MPLS label stack for SFC.
         In addition to the interpretation of the fields of these label stack entries provided in
         <xref target="basic"/> the following meanings are applied:

         <list style="hanging">
           <t hangText="SFC Context Label:">The Label field of the SFC Context label stack entry
              contains a label that delivers SFC context.  This label may be used to indicate the
              SPI encoded as a 20 bit integer using the semantics of the SPI is exactly as defined
              in <xref target="RFC8300"/> and noting that in this case a system using MPLS
              representation of the logical NSH MUST NOT assign SPI values greater than 2^20 - 1 or
              less than 16.  This label may also be used to convey other SFC context-speific semantics
              such as indicating how to interpret the SF Label or how to forward the packet to the
              node that offers the SF.</t>

           <t hangText="SF Label:">The Label field of the SF label stack entry contains a value
              that identifies the next SFI to be actioned for the packet.  This label may be
              scoped globally or within the context of the preceding SFC Context Label and
              comes from the range 16 ... 2^20 - 1.</t>

           <t hangText="TC:">The TC fields are as described in <xref target="basic" />.</t>

           <t hangText="S:">The S bits are as described in <xref target="basic" />.</t>

           <t hangText="TTL:">The TTL fields in the SFC Context label stack entry SF label stack
              entry SHOULD be set to 1 as stated in <xref target="basic" />, but MAY be set to larger
              values if the label indicated a forwarding operation towards the node that hosts the
              SF.</t>
         </list></t>

      <figure anchor="stackFig" title="The MPLS SFC Label Stack for Label Stacking">
        <artwork>
          <![CDATA[
  -------------------
 ~   Tunnel Labels   ~
 +-------------------+
 ~     Optional      ~
 ~   Entropy Label   ~
 +-------------------+ - - -
 | SFC Context Label |
 +-------------------+  Basic unit of MPLS label stack for SFC
 |     SF Label      |
 +-------------------+ - - -
 | SFC Context Label |
 +-------------------+  Basic unit of MPLS label stack for SFC
 |     SF Label      |
 +-------------------+ - - -
 ~                   ~
 +-------------------+ - - -
 | SFC Context Label |
 +-------------------+  Basic unit of MPLS label stack for SFC
 |     SF Label      |
 +-------------------+ - - -
 |                   |
 ~    Payload        ~
 |                   |
  -------------------
          ]]>
        </artwork>
      </figure>

      <t>The following processing rules apply to the Label fields:
         <list style="symbols">
            <t>When a Classifier inserts a packet onto an SFP it adds a stack comprising one or
               more instances of the basic unit of MPLS label stack for SFC.  Taken together, this
               stack defines the SFs to be actioned and so defines the SFP that the packet will
               traverse.</t>
            <t>When a component of the SFC system processes a packet it uses the top basic unit of
               label stack for SFC to determine to which SFI to next deliver the packet.  When an
               SFF receives a packet it examines the top basic unit of MPLS label stack for SFC to
               determine where to send the packet next.  If the next recipient is a local SFI, the
               SFC strips the basic unit of MPLS label stack for SFC before forwarding the packet.</t>
         </list></t>

    </section>

    <section anchor="mixedmode" title="Mixed Mode Forwarding">

      <t>The previous sections describe homogeneous networks where SFC forwarding is either all label
         swapping or all label popping (stacking).  But it is also possible that different parts of the network
         utilize swapping or popping.  It is also worth noting that a Classifier may be content to use an SFP
         as installed in the network by a control plane or management plane and so would use label swapping, but
         that there may be a point in the SFP where a choice of SFIs can be made (perhaps for load balancing)
         and where, in this instance, the Classifier wishes to exert control over that choice by use of a
         specific entry on the label stack.
         </t>

      <t>When an SFF receives a packet containing an MPLS label stack, it checks whether it is processing
         an {SFP, SI} label pair for label swapping or a {context label, SFI index} label pair for label stacking.
         It then selects the appropriate SFI to which to send the packet.  When it receives the packet back
         from the SFI, it has four cases to consider.
         <list style="symbols">
            <t>If the current hop requires an {SFP, SI} and the next hop requires an {SFP, SI}, it sets the
               SI label to the SI value of the current hop, selects an instance of the SF to be executed at the
               next hop, and tunnels the packet to the SFF for that SFI.</t>
            <t>If the current hop requires an {SFP, SI} and the next hop requires a {context label, SFI label},
               it pops the {SFP, SI} from the top of the MPLS label stack and tunnels the packet to the SFF
               indicated by the context label.</t>
            <t>If the current hop requires a {context label, SFI label}, it pops the {context label, SFI label}
               from the top of the MPLS label stack.
               <list style="symbols">
                  <t>If the new top of the MPLS label stack contains an {SFP, SI} label pair, it selects an
                     SFI to use at the next hop, and tunnels the packet to SFF for that SFI.</t>
                  <t>If the top of the MPLS label stack contains a {context label, SFI label}, it tunnels the
                     packet to the SFF indicated by the context label.</t>
               </list></t>
         </list></t>

    </section>

    <section anchor="proxy" title="A Note on Service Function Capabilities and SFC Proxies">
      <t>The concept of an "SFC Proxy" is introduced in <xref target="RFC7665"/>.  An SFC Proxy is logically
         located between an SFF and an SFI that is not "SFC-aware".  Such SFIs are not capable of handling the
         SFC encapsulation (whether that be NSH or MPLS) and need the encapsulation stripped from the packets
         they are to process.  In many cases, legacy SFIs that were once deployed as "bumps in the wire" fit
         into this category until they have been upgraded to be SFC-aware.</t>

      <t>The job of an SFC Proxy is to remove and then reimpose SFC encapsulation so that the SFF is able to
         process as though it was communication with an SFC-aware SFI, and so that the SFI is unaware of the
         SFC encapsulation.  In this regard, the job of an SFC Proxy is no different when NSH encapsulation is
         used and when MPLS encapsulation is used as described in this document, although (of course) it is
         different encapsulation bytes that must be removed and reimposed.</t>

      <t>It should be noted that the SFC Proxy is a logical function.  It could be implemented as a separate
         physical component on the path from the SFF to SFI, but it could be coresident with the SFF or it
         could be a component of the SFI.  This is purely an implementation choice.</t>

      <t>Note also that the delivery of metadata (see <xref target="metadata"/>) requires specific processing
         if an SFC Proxy is in use.  This is also no different when NSH or the MPLS encoding defined in this
         document is in use, and how it is handled will depend on how (or if) each non-SFC-aware SFI can receive
         metadata.</t>
    </section>

    <section anchor="controlplane" title="Control Plane Considerations">

      <t>In order that a packet may be forwarded along an SFP several functional
         elements must be executed.
         <list style="symbols">
           <t>Discovery/advertisement of SFIs.</t>
           <t>Computation of SFP.</t>
           <t>Programming of Classifiers.</t>
           <t>Advertisement of forwarding instructions.</t>
         </list></t>

      <t>Various approaches may be taken.  These include a fully centralized model
         where SFFs report to a central controller the SFIs that they support, the
         central controller computes the SFP and programs the Classifiers, and (if
         the label swapping approach is taken) the central controller installs
         forwarding state in the SFFs that lie on the SFP.</t>

      <t>Alternatively, a dynamic control plane may be used such as that described
         in <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />.  In this case
         the SFFs use the control plane to advertise the SFIs that they support, a
         central controller computes the SFP and programs the Classifiers, and (if
         the label swapping approach is taken) the central controller uses the control
         plane to advertise the SFPs so that SFFs that lie on the SFP can install the
         necessary forwarding state.</t>

    </section>

    <section anchor="entropy" title="Use of the Entropy Label">

       <t>Entropy is used in ECMP situations to ensure that packets from the same
          flow travel down the same path, thus avoiding jitter or re-ordering issues
          within a flow.</t>

       <t>Entropy is often determined by hashing on specific fields in a packet header
          such as the "five-tuple" in the IP and transport headers.  However, when an
          MPLS label stack is present, the depth of the stack could be too large for
          some processors to correctly determine the entropy hash.  This problem is
          addressed by the inclusion of an Entropy Label as described in
          <xref target="RFC6790" />.</t>

       <t>When entropy is desired for packets as they are carried in MPLS tunnels over
          the underlay network, it is RECOMMENDED that an Entropy Label is included in
          the label stack immediately after the tunnel labels and before the SFC labels
          as shown in <xref target="swapFig" /> and <xref target="stackFig" />.</t>

       <t>If an Entropy Label is present in an MPLS payload, it is RECOMMENDED that the
          initial Classifier use that value in an Entropy Label inserted in the label
          stack when the packet is forwarded (on the first tunnel) to the first SFF.  In
          this case it is not necessary to remove the Entropy Label from the payload.</t>
    </section>

    <section anchor="metadata" title="Metadata">

       <t>Metadata is defined in <xref target="RFC7665" /> as providing "the ability to
          exchange context information between classifiers and SFs, and among SFs."
          <xref target="RFC8300" /> defines how this context information can be
          directly encoded in fields that form part of the NSH encapsulation.</t>

       <t>The next two sections describe how metadata is associated with user data
          packets, and how metadata may be exchanged between SFC nodes in the network,
          when using an MPLS encoding of the logical representation of the NSH.</t>

       <t>It should be noted that the MPLS encoding is slightly less functional than the
          direct use of the NSH.  Both methods support metadata that is "per-SFP" or
          "per-packet-flow" (see <xref target="I-D.farrel-sfc-convent"/> for definitions
          of these terms), but "per-packet" metadata (where the metadata must be carried
          on each packet because it differs from one packet to the next even on the same
          flow or SFP) is only supported using the NSH and not using the mechanisms
          defined in this document.</t>

       <section anchor="IndMetadata" title="Indicating Metadata in User Data Packets">

         <t>Metadata is achieved in the MPLS realization of the logical NSH by the use of
            an SFC Metadata Label which uses the Extended Special Purpose Label construct
            <xref target="RFC7274" />.  Thus, three label stack entries are present as
            shown in <xref target="metabasicFig" />:
            <list style="symbols">
              <t>The Extension Label (value 15)</t>
              <t>An extended special purpose label called the Metadata Label Indicator (MLI)
                 (value TBD1 by IANA)</t>
              <t>The Metadata Label (ML).</t>
            </list></t>

          <figure anchor="metabasicFig" title="The MPLS SFC Metadata Label">
            <artwork>
              <![CDATA[
    ----------------
   | Extension = 15 |
   +----------------+
   |      MLI       |
   +----------------+
   | Metadata Label |
    ---------------
              ]]>
            </artwork>
          </figure>

         <t>The Metadata Label value is an index into a table of metadata that is programmed
            into the network using in-band or out-of-band mechanisms.  Out-of-band mechanisms
            potentially include management plane and control plane solutions (such as
            <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />), but are out of scope for
            this document.  The in-band mechanism is described in  <xref target="inband" /></t>

         <t>The SFC Metadata Label (as a set of three labels as indicated in
            <xref target="metabasicFig" />) may be present zero, one, or more times in an
            MPLS SFC packet.  For MPLS label swapping, the SFC Metadata Labels are placed
            immediately after the basic unit of MPLS label stack for SFC as shown in
            <xref target="swapmetaFig" />.  For MPLS label stacking, the SFC Metadata Labels
            can be present zero, one, or more times and are placed at the bottom of the label
            stack as shown in <xref target="stackmetaFig" />.</t>

          <figure anchor="swapmetaFig" title="The MPLS SFC Label Stack for Label Swapping with Metadata Label">
            <artwork>
              <![CDATA[
    ----------------
   ~ Tunnel Labels  ~
   +----------------+
   ~   Optional     ~
   ~ Entropy Label  ~
   +----------------+
   |   SPI Label    |
   +----------------+
   |   SI Label     |
   +----------------+
   | Extension = 15 |
   +----------------+
   |     MLI        |
   +----------------+
   | Metadata Label |
   +----------------+
   ~     Other      ~
   |    Metadata    |
   ~  Label Triples ~
   +----------------+
   |                |
   ~    Payload     ~
   |                |
    ----------------
              ]]>
            </artwork>
          </figure>

          <figure anchor="stackmetaFig" title="The MPLS SFC Label Stack for Label Stacking with Metadata Label">
            <artwork>
              <![CDATA[
  -------------------
 ~   Tunnel Labels   ~
 +-------------------+
 ~     Optional      ~
 ~   Entropy Label   ~
 +-------------------+
 | SFC Context Label |
 +-------------------+
 |     SF Label      |
 +-------------------+
 ~                   ~
 +-------------------+
 | SFC Context Label |
 +-------------------+
 |     SF Label      |
 +-------------------+
 |   Extension = 15  |
 +-------------------+
 |        MLI        |
 +-------------------+
 |  Metadata Label   |
 +-------------------+
 ~       Other       ~
 |      Metadata     |
 ~   Label Triples   ~
 +-------------------+
 |                   |
 ~    Payload        ~
 |                   |
  -------------------
              ]]>
            </artwork>
          </figure>

       </section>

       <section anchor="inband" title="Inband Programming of Metadata">

         <t>A mechanism for sending metadata associated with an SFP without a payload packet
            is described in <xref target="I-D.farrel-sfc-convent" />.  The same approach can
            be used in an MPLS network where the NSH is logically represented by an MPLS label
            stack.</t>

         <t>The packet header is formed exactly as previously described in this document so
            that the packet will follow the SFP through the SFC network.  However, instead of
            payload data, metadata is included after the bottom of the MPLS label stack.  An
            Extended Special Purpose Label is used to indicate that the metadata is present.
            Thus, three label stack entries are present:
            <list style="symbols">
              <t>The Extension Label (value 15)</t>
              <t>An extended special purpose label called the Metadata Present Indicator (MPI)
                 (value TBD2 by IANA)</t>
              <t>The Metadata Label (ML) that is associated with this metadata on this SFP
                 and can be used to indicate the use of the metadata as described in
                 <xref target="metadata" />.</t>
            </list></t>

         <t>The SFC Metadata Present Label, if present, is placed immediately after the last
            basic unit of MPLS label stack for SFC.  The resultant label stacks are shown in
            <xref target="swapmetapresFig" /> for the MPLS label swapping case and
            <xref target="stackmetapresFig" /> for the MPLS label stacking case.</t>

        <figure anchor="swapmetapresFig" title="The MPLS SFC Label Stack for Label Swapping Carrying Metadata">
          <artwork>
            <![CDATA[
    ---------------
   ~ Tunnel Labels ~
   +---------------+
   ~   Optional    ~
   ~ Entropy Label ~
   +---------------+
   |   SPI Label   |
   +---------------+
   |   SI Label    |
   +---------------+
   | Extension = 15|
   +---------------+
   |     MPI       |
   +---------------+
   | Metadata Label|
   +---------------+
   |               |
   ~    Metadata   ~
   |               |
    ---------------
            ]]>
          </artwork>
        </figure>

        <figure anchor="stackmetapresFig" title="The MPLS SFC Label Stack for Label Stacking Carrying Metadata">
          <artwork>
            <![CDATA[
  -------------------
 ~   Tunnel Labels   ~
 +-------------------+
 ~     Optional      ~
 ~   Entropy Label   ~
 +-------------------+
 | SFC Context Label |
 +-------------------+
 |     SF Label      |
 +-------------------+
 | SFC Context Label |
 +-------------------+
 |     SF Label      |
 +-------------------+
 ~                   ~
 +-------------------+
 | SFC Context Label |
 +-------------------+
 |     SF Label      |
 +-------------------+
 |   Extension = 15  |
 +-------------------+
 |        MPI        |
 +-------------------+
 |  Metadata Label   |
 +-------------------+
 |                   |
 ~    Metadata       ~
 |                   |
  -------------------
            ]]>
          </artwork>
        </figure>

         <t>In both cases the metadata is formatted as a TLV as shown in <xref target="metaTLV" />.</t>

        <figure anchor="metaTLV" title="The Metadata TLV">
          <artwork>
            <![CDATA[
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Length              |        Metadata Type          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~                         Metadata                              ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
            ]]>
          </artwork>
        </figure>

         <t>The fields of this TLV are interpreted as follows:
           <list style="hanging">
             <t hangText="Length:">The length of the metadata carried in the Metadata
               field in octets not including any padding.</t>
             <t hangText="Metadata Type:">The type of the metadata present.  Values
               for this field are taken from the "MD Types" registry maintained by
               IANA and defined in <xref target="RFC8300" />.</t>
             <t hangText="Metadata:">The actual metadata formatted as described in
               whatever document defines the metadata.  This field is end-padded
               with zero to three octets of zeroes to take it up to a four octet
               boundary.</t>
           </list></t>

       </section>

    </section>

    <section anchor="examples" title="Worked Examples">

       <t>Consider the simplistic MPLS SFC overlay network shown in <xref target="mplsswapeg" />.
          A packet is classified for an SFP that will see it pass through two Service
          Functions, SFa and SFb, that are accessed through Service Function Forwarders
          SFFa and SFFb respectively.  The packet is ultimately delivered to destination, D.</t>

       <t>Let us assume that the SFP is computed and assigned the SPI of 239.  The forwarding
          details of the SFP are distributed (perhaps using the mechanisms of
          <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />) so that the SFFs are programmed
          with the necessary forwarding instructions.</t>

       <t>The packet progresses as follows:
          <list style="letters">
            <t>The Classifier assigns the packet to the SFP and imposes two label stack entries
               comprising a single basic unit of MPLS SFC representation:
               <list style="symbols">
                 <t>The higher label stack entry contains a label carrying the SPI value of 239.</t>
                 <t>The lower label stack entry contains a label carrying the SI value of 255.</t>
               </list>
               Further labels may be imposed to tunnel the packet from the Classifier to SFFa.</t>
            <t>When the packet arrives at SFFa it strips any labels associated with the tunnel that
               runs from the Classifier to SFFa.  SFFa examines the top labels and matches the SPI/SI
               to identify that the packet should be forwarded to SFa.  The packet is forwarded to SFa
               unmodified.</t>
            <t>SFa performs its designated function and returns the packet to SFFa.</t>
            <t>SFFa modifies the SI in the lower label stack entry (to 254) and uses the SPI/SI to
               look up the forwarding instructions.  It sends the packet with two label stack entries:
               <list style="symbols">
                 <t>The higher label stack entry contains a label carrying the SPI value of 239.</t>
                 <t>The lower label stack entry contains a label carrying the SI value of 254.</t>
               </list>
               Further labels may be imposed to tunnel the packet from the SFFa to SFFb.</t>
            <t>When the packet arrives at SFFb it strips any labels associated with the tunnel from SFFa.
               SFFb examines the top labels and matches the SPI/SI to identify that the packet should be
               forwarded to SFb.  The packet is forwarded to SFb unmodified.</t>
            <t>SFb performs its designated function and returns the packet to SFFb.</t>
            <t>SFFb modifies the SI in the lower label stack entry (to 253) and uses the SPI/SI to
               lookup up the forwarding instructions.  It determines that it is the last SFF in the SFP
               so it strips the two SFC label stack entries and forwards the payload toward D using the
               payload protocol.</t>
          </list></t>

        <figure anchor="mplsswapeg" title="Service Function Chaining in an MPLS Network">
          <artwork>
            <![CDATA[
     +---------------------------------------------------+
     |                   MPLS SFC Network                |
     |                                                   |
     |            +---------+       +---------+          |
     |            |   SFa   |       |   SFb   |          |
     |            +----+----+       +----+----+          |
     |               ^ | |             ^ | |             |
     |            (b)| | |(c)       (e)| | |(f)          |
     |       (a)     | | V     (d)     | | V    (g)      |
+----------+ ---> +----+----+ ----> +----+----+ ---> +-------+
|Classifier+------+  SFFa   +-------+  SFFb   +------+   D   |
+----------+      +---------+       +---------+      +-------+
     |                                                   |
     +---------------------------------------------------+
            ]]>
          </artwork>
        </figure>

       <t>Alternatively, consider the MPLS SFC overlay network shown in <xref target="mplsstackeg" />.
          A packet is classified for an SFP that will see it pass through two Service
          Functions, SFx and SFy, that are accessed through Service Function Forwarders
          SFFx and SFFy respectively.  The packet is ultimately delivered to destination, D.</t>

       <t>Let us assume that the SFP is computed and assigned the SPI of 239.  However, the forwarding
          state for the SFP is not distributed and installed in the network.  Instead it will be attached
          to the individual packets using  the MPLS label stack.</t>

       <t>The packet progresses as follows:
          <list style="numbers">
            <t>The Classifier assigns the packet to the SFP and imposes two basic units of MPLS SFC
               representation to describe the full SFP:
               <list style="symbols">
                 <t>The top basic unit comprises two label stack entries as follows:
                    <list style="symbols">
                      <t>The higher label stack entry contains a label carrying the SFC context.</t>
                      <t>The lower label stack entry contains a label carrying the SF indicator for SFx.</t>
                    </list></t>
                 <t>The lower basic unit comprises two label stack entries as follows:
                    <list style="symbols">
                      <t>The higher label stack entry contains a label carrying the SFC context.</t>
                      <t>The lower label stack entry contains a label carrying the SF indicator for SFy.</t>
                    </list></t>
               </list>
               Further labels may be imposed to tunnel the packet from the Classifier to SFFx.</t>
            <t>When the packet arrives at SFFx it strips any labels associated with the tunnel from the
               Classifier.  SFFx examines the top labels and matches the context/SF values to identify that the
               packet should be forwarded to SFx.  The packet is forwarded to SFx unmodified.</t>
            <t>SFx performs its designated function and returns the packet to SFFx.</t>
            <t>SFFx strips the top basic unit of MPLS SFC representation revealing the next basic unit.  It
               then uses the revealed context/SF values to determine how to route the packet to the next SFF,
               SFFy.  It sends the packet with just one basic unit of MPLS SFC representation comprising two
               label stack entries:
               <list style="symbols">
                 <t>The higher label stack entry contains a label carrying the SFC context.</t>
                 <t>The lower label stack entry contains a label carrying the SF indicator for SFy.</t>
               </list>
               Further labels may be imposed to tunnel the packet from the SFFx to SFFy.</t>
            <t>When the packet arrives at SFFy it strips any labels associated with the tunnel from SFFx.
               SFFy examines the top labels and matches the context/SF values to identify that the
               packet should be forwarded to SFy.  The packet is forwarded to SFy unmodified.</t>
            <t>SFy performs its designated function and returns the packet to SFFy.</t>
            <t>SFFy strips the top basic unit of MPLS SFC representation revealing the payload packet. It
               forwards the payload toward D using the payload protocol.</t>
          </list></t>

        <figure anchor="mplsstackeg" title="Service Function Chaining Using MPLS Label Stacking">
          <artwork>
            <![CDATA[
     +---------------------------------------------------+
     |                   MPLS SFC Network                |
     |                                                   |
     |            +---------+       +---------+          |
     |            |   SFx   |       |   SFy   |          |
     |            +----+----+       +----+----+          |
     |               ^ | |             ^ | |             |
     |            (2)| | |(3)       (5)| | |(6)          |
     |       (1)     | | V     (4)     | | V    (7)      |
+----------+ ---> +----+----+ ----> +----+----+ ---> +-------+
|Classifier+------+  SFFx   +-------+  SFFy   +------+   D   |
+----------+      +---------+       +---------+      +-------+
     |                                                   |
     +---------------------------------------------------+
            ]]>
          </artwork>
        </figure>

    </section>

    <section anchor="Security" title="Security Considerations">
      <t>Discussion of the security properties of SFC networks can be found in <xref target="RFC7665" />.
         Further security discussion for the NSH and its use is present in <xref target="RFC8300" />.</t>

      <t>It is fundamental to the SFC design that the classifier is a trusted resource which determines
         the processing that the packet will be subject to, including for example the firewall.  It is also
         fundamental to the MPLS design that packets are routed through the network using the path specified
         by the node imposing the labels, and that labels are swapped or popped correctly.  Where an SF is
         not encapsulation aware the encapsulation may be stripped by an SFC proxy such that packet may exist
         as a native packet (perhaps IP) on the path between SFC proxy and SF, however this is an intrinsic
         part of the SFC design which needs to define how a packet is protected in that environment.</t>


      <t>Additionally, where a tunnel is used to link two non-MPLS domains, the tunnel design needs to
         specify how the tunnel is secured.</t>

      <t>Thus the security vulnerabilities are addressed (or should be addressed) in all the underlying
         technologies used by this design, which itself does not introduce any new security vulnerabilities.</t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t>This document requests IANA to make allocations from the "Extended Special-Purpose MPLS Label Values"
         subregistry of the "Special-Purpose Multiprotocol Label Switching (MPLS) Label Values" registry as follows:</t>

      <figure>
        <artwork>
          <![CDATA[
   Value  | Description                       |
   -------+-----------------------------------+--------------
   TBD1   | Metadata Label Indicator (MLI)    | [This.I-D]
   TBD2   | Metadata Present Indicator (MPI)  | [This.I-D]
          ]]>
        </artwork>
      </figure>

    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>This document derives ideas and text from <xref target="I-D.ietf-bess-nsh-bgp-control-plane" />.</t>
      <t>The authors are grateful to all those who contributed to the discussions that led to this
         work: Loa Andersson, Andrew G. Malis, Alexander Vainshtein, Joel M. Halpern, Tony Przygienda,
         Stuart Mackie, Keyur Patel, and Jim Guichard.  Loa Andersson provided helpful review comments.</t>
      <t>Thanks to Loa Andersson, Lizhong Jin, Matthew Bocci, and Mach Chen for reviews of this text.</t>
    </section>

  </middle>

  <back>

    <references title="Normative References">
      &RFC2119;
      &RFC7274;
      &RFC8174;
      &RFC8300;
      <?rfc include="reference.I-D.farrel-sfc-convent"?>
    </references>

    <references title="Informative References">
      &RFC3031;
      &RFC6790;
      &RFC7665;
      <?rfc include="reference.I-D.ietf-bess-nsh-bgp-control-plane"?>
    </references>

  </back>
</rfc>
