<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">
<?rfc toc="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc subcompact="yes"?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="std" ipr="trust200902" docName="draft-ietf-6tisch-msf-13" obsoletes="" updates="" consensus="true" submissionType="IETF" xml:lang="en" tocInclude="true" version="3">
    <!-- xml2rfc v2v3 conversion 2.35.0 -->
    <front>
        <title>
            6TiSCH Minimal Scheduling Function (MSF)
        </title>
        <seriesInfo name="Internet-Draft" value="draft-ietf-6tisch-msf-13"/>
        <author initials="T" surname="Chang" fullname="Tengfei Chang" role="editor">
            <organization>Inria</organization>
            <address>
                <postal>
                    <street>2 rue Simone Iff</street>
                    <city>Paris</city>
                    <code>75012</code>
                    <country>France</country>
                </postal>
                <email>tengfei.chang@inria.fr</email>
            </address>
        </author>
        <author initials="M." surname="Vucinic" fullname="Malisa Vucinic">
            <organization>Inria</organization>
            <address>
                <postal>
                    <street>2 rue Simone Iff</street>
                    <city>Paris</city>
                    <code>75012</code>
                    <country>France</country>
                </postal>
                <email>malisa.vucinic@inria.fr</email>
            </address>
        </author>
        <author initials="X" surname="Vilajosana" fullname="Xavier Vilajosana">
            <organization>Universitat Oberta de Catalunya</organization>
            <address>
                <postal>
                    <street>156 Rambla Poblenou</street>
                    <city>Barcelona</city>
                    <region>Catalonia</region>
                    <code>08018</code>
                    <country>Spain</country>
                </postal>
                <email>xvilajosana@uoc.edu</email>
            </address>
        </author>
        <author initials="S" surname="Duquennoy" fullname="Simon Duquennoy">
            <organization>RISE SICS</organization>
            <address>
                <postal>
                    <street>Isafjordsgatan 22</street>
                    <city>164 29 Kista</city>
                    <country>Sweden</country>
                </postal>
                <email>simon.duquennoy@gmail.com</email>
            </address>
        </author>
        <author initials="D" surname="Dujovne" fullname="Diego Dujovne">
            <organization>Universidad Diego Portales</organization>
            <address>
                <postal>
                    <street>Escuela de Informatica y Telecomunicaciones</street>
                    <street>Av. Ejercito 441</street>
                    <city>Santiago</city>
                    <region>Region Metropolitana</region>
                    <country>Chile</country>
                </postal>
                <phone>+56 (2) 676-8121</phone>
                <email>diego.dujovne@mail.udp.cl</email>
            </address>
        </author>
        <date/>
        <area>Internet Area</area>
        <workgroup>6TiSCH</workgroup>
        <keyword>Draft</keyword>
        <abstract>
            <t>
                This specification defines the 6TiSCH Minimal Scheduling Function (MSF).
                This Scheduling Function describes both
                the behavior of a node when joining the network, and
                how the communication schedule is managed in a distributed fashion.
                MSF is built upon
                the 6TiSCH Operation Sublayer Protocol (6P) and
                the Minimal Security Framework for 6TiSCH.
            </t>
        </abstract>
        <note>
            <name>Requirements Language</name>
            <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="RFC8174" format="default"/>.
            </t>
        </note>
    </front>
    <middle>
        <section anchor="sec_intro" numbered="true" toc="default">
            <name>Introduction</name>
            <t>
                The 6TiSCH Minimal Scheduling Function (MSF), defined in this specification, is a 6TiSCH Scheduling Function (SF).
                The role of an SF is entirely defined in <xref target="RFC8480" format="default"/>.
                This specification complements <xref target="RFC8480" format="default"/> by providing the rules of when to add/delete cells in the communication schedule.
                This specification satisfies all the requirements for an SF listed in Section 4.2 of <xref target="RFC8480" format="default"/>.
            </t>
            <t>
                MSF builds on top of the following specifications:
                the Minimal IPv6 over the TSCH Mode of IEEE 802.15.4e (6TiSCH) Configuration <xref target="RFC8180" format="default"/>,
                the 6TiSCH Operation Sublayer Protocol (6P) <xref target="RFC8480" format="default"/>, and
                the Minimal Security Framework for 6TiSCH <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
            </t>
            <t>
                MSF defines both
                the behavior of a node when joining the network, and
                how the communication schedule is managed in a distributed fashion.
                When a node running MSF boots up, it joins the network by following the 6 steps described in <xref target="sec_boot" format="default"/>.
                The end state of the join process is that the node
                is synchronized to the network,
                has mutually authenticated with the network,
                has identified a routing parent,
                and has scheduled one negotiated Tx cell (defined in <xref target="sec_traffic" format="default"/>) to/from its routing parent.
                After the join process, the node can continuously add/delete/relocate cells, as described in <xref target="sec_add_delete" format="default"/>.
                It does so for 3 reasons:
                to match the link-layer resources to the traffic,
                to handle changing parent and 
                to handle a schedule collision.
            </t>
            <t>
                MSF works closely with the IPv6 Routing Protocol for Low-Power and Lossy Networks (RPL), specifically the routing parent defined in <xref target="RFC6550" format="default"/>.
                This specification only describes how MSF works with the selected routing parent, which is phrased as "selected parent".
                The activity of MSF towards the single routing parent is called a "MSF session". 
                Though the performance of MSF is evaluated only when the "selected parent" represents the node's preferred parent, there should be no restrictions to use multiple MSF sessions, one per parent.
                The distribution of traffic over multiple parents is a routing decision that is out of scope for MSF.
            </t>
            <t>
                MSF is designed to operate in a wide range of application domains.
                It is optimized for applications with regular upstream traffic, from the nodes to the Destination-Oriented Directed Acyclic Graph (DODAG <xref target="RFC6550" format="default"/>) root.
            </t>
            <t>
                This specification follows the recommended structure of an SF specification, given in Appendix A of <xref target="RFC8480" format="default"/>, with the following adaptations:
            </t>
            <ul spacing="compact">
                <li>
                    We have reordered some sections, in particular to have the section on the node behavior at boot (<xref target="sec_boot" format="default"/>) appear early in this specification.
                </li>
                <li>
                    We added sections on
                    the interface to the minimal 6TiSCH configuration (<xref target="sec_minimal" format="default"/>),
                    the use of the SIGNAL command (<xref target="sec_signal" format="default"/>),
                    the MSF constants (<xref target="sec_constants" format="default"/>) and
                    the MSF statistics (<xref target="sec_stats" format="default"/>).
                </li>
            </ul>
        </section>
        <section anchor="sec_minimal" numbered="true" toc="default">
            <name>Interface to the Minimal 6TiSCH Configuration</name>
            <t>
                In a TSCH network, time is sliced up into time slots.
                The time slots are grouped as one or multiple slotframes which repeat over time.
                The TSCH schedule instructs a node what to do at each time slots, such as transmit, receive or sleep <xref target="RFC7554" format="default"/>.
                In case of a slot to transmit or receive, a channel is assigned to the time slot.
                The tuple (slot, channel) is indicated as a cell of TSCH schedule.
                MSF is one of the policies defining how to manage the TSCH schedule.
            </t>
            <t>
                A node implementing MSF SHOULD implement the Minimal 6TiSCH Configuration <xref target="RFC8180" format="default"/>, which defines the "minimal cell", a single shared cell providing minimal connectivity between the nodes in the network.
                The MSF implementation provided in this specification is based on the implementation of the Minimal 6TiSCH Configuration.
                However, an implementor MAY implement MSF based on other specifications as long as the specification defines a way to advertise the EB/DIO among the network.
            </t>
            <t>
                MSF uses the minimal cell for broadcast frames such as Enhanced Beacons (EBs) <xref target="IEEE802154" format="default"/> and broadcast DODAG Information Objects (DIOs) <xref target="RFC6550" format="default"/>.
                Cells scheduled by MSF are meant to be used only for unicast frames.
            </t>
            <t>
                To ensure there is enough bandwidth available on the minimal cell, a node implementing MSF SHOULD enforce some rules for limiting the traffic of broadcast frames. 
                For example, the overall broadcast traffic among the node and its neighbors SHOULD NOT exceed 1/3 of the bandwidth of minimal cell.
                One of the algorithms that fulfills this requirement is the Trickle timer defined in  <xref target="RFC6206" format="default"/> which is applied on DIO messages <xref target="RFC6550" format="default"/>.
                However, any such algorithm of limiting the broadcast traffic to meet those rules is implementation-specific and is out of the scope of MSF.
            </t>
            <t>
                3 slotframes are used in MSF. 
                MSF schedules autonomous cells at Slotframe 1 (<xref target="sec_autonomous_cells" format="default"/>) and 6P negotiated cells at Slotframe 2 (<xref target="sec_add_delete" format="default"/>) ,wh ile Slotframe 0 is used for the bootstrap traffic as defined in the Minimal 6TiSCH Configuration.
                The same slotframe length for Slotframe 0, 1 and 2 is RECOMMENDED.
                Thus it is possible to avoid the scheduling collision between the autonomous cells and 6P negotiated cells (<xref target="sec_autonomous_cells" format="default"/>).
                The default slotframe length (SLOTFRAME_LENGTH) is RECOMMENDED for Slotframe 0, 1 and 2, although any value can be advertised in the EBs.
            </t>
        </section>
        <section anchor="sec_autonomous_cells" numbered="true" toc="default">
            <name>Autonomous Cells</name>
            <t>
                MSF nodes initialize Slotframe 1 with a set of default cells for unicast communication with their neighbors.
                These cells are called 'autonomous cells', because they are maintained autonomously by each node without negotiation through 6P.
                Cells scheduled by 6P transaction are called 'negotiated cells' which are reserved on Slotframe 2.
                How to schedule negotiated cells is detailed in <xref target="sec_add_delete" format="default"/>.
                There are two types of autonomous cells:
            </t>
            <ul spacing="compact">
                <li>
                    Autonomous Rx Cell (AutoRxCell), one cell at a [slotOffset,channelOffset] computed as a hash of the EUI64 of the node itself (detailed next).
                    Its cell options bits are assigned as TX=0, RX=1, SHARED=0.
                </li>
                <li>
                    Autonomous Tx Cell (AutoTxCell), one cell at a [slotOffset,channelOffset] computed as a hash of the layer 2 EUI64 destination address in the unicast frame to be transmitted (detailed in <xref target="sec_join" format="default"/>).
                    Its cell options bits are assigned as TX=1, RX=0, SHARED=1.
                </li>
            </ul>
            <t>
                To compute a [slotOffset,channelOffset] from an EUI64 address, nodes MUST use the hash function SAX <xref target="SAX-DASFAA" format="default"/>.
                The coordinates are computed to distribute the cells across all channel offsets, and all but the first slot offset of Slotframe 1.
                The first time offset is skipped to avoid colliding with the minimal cell in Slotframe 0.
                The slot coordinates derived from a given EUI64 address are computed as follows:
            </t>
            <ul spacing="compact">
                <li>slotOffset(MAC) = 1 + hash(EUI64, length(Slotframe_1) - 1) </li>
                <li>channelOffset(MAC) = hash(EUI64, NUM_CH_OFFSET)</li>
            </ul>
            <t>
                The second input parameter defines the maximum return value of the hash function.
                Other optional parameters defined in SAX determine the performance of SAX hash function.
                Those parameters could be broadcasted in EB frame or pre-configured.
                For interoperability purposes, an example how the hash function is implemented is detailed in <xref target="sec_hash_function" format="default"/>.
            </t>
            <t>
                AutoTxCell is not permanently installed in the schedule but added/deleted on demand when there is a frame to sent.
                Throughout the network lifetime, nodes maintain the autonomous cells as follows:
            </t>
            <ul spacing="compact">
                <li>
                    Add an AutoTxCell to the layer 2 destination address which is indicated in a frame when there is no 6P negotiated Tx cell in schedule for that frame to transmit.
                </li>
                <li>
                    <t>
                        Remove an AutoTxCell when:
                    </t>
                    <ul spacing="compact">
                        <li>there is no frame to transmit on that cell, or</li>
                        <li>there is at least one 6P negotiated Tx cell in the schedule for the frames to transmit.</li>
                    </ul>
                </li>
            </ul>
            <t>
                The AutoRxCell MUST always remain scheduled after synchronization.            
                6P CLEAR MUST NOT erase any autonomous cells.
            </t>
            <t>
                Because of hash collisions, there will be cases that the AutoTxCell and AutoRxCell are scheduled at the same slot offset and/or channel offset.
                In such cases, AutoTxCell always take precedence over AutoRxCell.
                In case of conflicting with a negotiated cell, autonomous cells take precedence over negotiated cell, which is stated in <xref target="IEEE802154" format="default"/>.
                However, when the Slotframe 0, 1 and 2 use the same length value, it is possible for negotiated cell to avoid the collision with AutoRxCell.
            </t>
        </section>
        <section anchor="sec_boot" numbered="true" toc="default">
            <name>Node Behavior at Boot</name>
            <t>
                This section details the behavior the node SHOULD follow from the moment it is switched on, until it has successfully joined the network.
                Alternative behaviors may be involved, for example, when alternative security solutions are used for the network. 
                <xref target="sec_start_state" format="default"/> details the start state;
                <xref target="sec_end_state" format="default"/>   details the end   state.
                The other sections detail the 6 steps of the joining process.
                We use the term "pledge" and "joined node", as defined in <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
            </t>
            <section anchor="sec_start_state" numbered="true" toc="default">
                <name>Start State</name>
                <t>
                    A node implementing MSF SHOULD implement the Constrained Join Protocol (CoJP) for 6TiSCH <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
                    As a corollary, this means that a pledge, before being switched on, may be pre-configured with the Pre-Shared Key (PSK) for joining, as well as any other configuration detailed in (<xref target="I-D.ietf-6tisch-minimal-security" format="default"/>).
                    This is not necessary if the node implements a security solution not based on PSKs, such as (<xref target="I-D.ietf-6tisch-dtsecurity-zerotouch-join" format="default"/>).
                </t>
            </section>
            <section anchor="sec_frequency" numbered="true" toc="default">
                <name>Step 1 - Choosing Frequency</name>
                <t>
                    When switched on, the pledge randomly chooses a frequency among the available frequencies, and starts listening for EBs on that frequency.
                </t>
            </section>
            <section anchor="sec_ebs" numbered="true" toc="default">
                <name>Step 2 - Receiving EBs</name>
                <t>
                    Upon receiving the first EB, the pledge continue listening for additional EBs to learn:
                </t>
                <ol spacing="compact" type="1">
                    <li>the number of neighbors N in its vicinity</li>
                    <li>which neighbor to choose as a Join Proxy (JP) for the joining process</li>
                </ol>
                <t>
                    After having received the first EB, a node MAY keep listening for at most MAX_EB_DELAY seconds until it has received EBs from NUM_NEIGHBOURS_TO_WAIT distinct neighbors.
                    This behavior is defined in <xref target="RFC8180" format="default"/>.
                </t>
                <t>
                    During this step, the pledge only gets synchronized when it received enough EB from the network it wishes to join.
                    How to decide whether an EB originates from a node from the network it wishes to join is implementation-specific, but MAY involve filtering EBs by
                    the PAN ID field it contains,
                    the presence and contents of the IE defined in <xref target="I-D.ietf-6tisch-enrollment-enhanced-beacon" format="default"/>, or
                    the key used to authenticate it.
                </t>
                <t>
                    The decision of which neighbor to use as a JP is implementation-specific, and discussed in <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
                </t>
            </section>
            <section anchor="sec_join" numbered="true" toc="default">
                <name>Step 3 - Setting up Autonomous Cells for the Join Process</name>
                <t>
                    After selected a JP, a node generates a Join Request and installs an AutoTxCell to the JP.
                    The Join Request is then sent by the pledge to its selected JP over the AutoTxCell.
                    The AutoTxCell is removed by the pledge when the Join Request is sent out.
                    The JP receives the Join Request through its AutoRxCell.
                    Then it forwards the Join Request to the join registrar/coordinator (JRC), possibly over multiple hops, over the 6P negotiated Tx cells.
                    Similarly, the JRC sends the Join Response to the JP, possibly over multiple hops, over AutoTxCells or the 6P negotiated Tx cells.
                    When the JP received the Join Response from the JRC, it installs an AutoTxCell to the pledge and sends that Join Response to the pledge over AutoTxCell. 
                    The AutoTxCell is removed by the JP when the Join Response is sent out.
                    The pledge receives the Join Response from its AutoRxCell, thereby learns the keying material used in the network, as well as other configuration settings, and becomes a "joined node".
                </t>
                <t>
                    When 6LoWPAN Neighbor Discovery (<xref target="RFC8505" format="default"/>) (ND) is implemented, the unicast packets used by ND are sent on the AutoTxCell.
                    The specific process how the ND works during the Join process is detailed in <xref target="I-D.ietf-6tisch-architecture" format="default"/>.
                </t>
            </section>
            <section anchor="sec_rank" numbered="true" toc="default">
                <name>Step 4 - Acquiring a RPL Rank</name>
                <t>
                    Per <xref target="RFC6550" format="default"/>, the joined node
                    receives DIOs,
                    computes its own Rank, and
                    selects a routing parent.
                </t>
            </section>
            <section anchor="sec_negotiated_cells" numbered="true" toc="default">
                <name>Step 5 - Setting up first Tx negotiated Cells</name>
                <t>
                    Once it has selected a routing parent, the joined node MUST generate a 6P ADD Request and install an AutoTxCell to that parent.
                    The 6P ADD Request is sent out through the AutoTxCell, containing the following fields:
                </t>
                <ul spacing="compact">
                    <li>CellOptions: set to TX=1,RX=0,SHARED=0</li>
                    <li>NumCells: set to 1</li>
                    <li>CellList: at least 5 cells, chosen according to <xref target="sec_celllist" format="default"/></li>
                </ul>
                <t>
                    The joined node removes the AutoTxCell to the selected parent when the 6P Request is sent out.
                    That parent receives the 6P ADD Request from its AutoRxCell.
                    Then it generates a 6P ADD Response and installs an AutoTxCell to the joined node.
                    When the parent sends out the 6P ADD Response, it MUST remove that AutoTxCell.
                    The joined node receives the 6P ADD Response from its AutoRxCell and completes the 6P transaction.
                    In case the 6P ADD transaction failed, the node MUST issue another 6P ADD Request and repeat until the Tx cell is installed to the parent.
                </t>
            </section>
            <section anchor="sec_eb_dio" numbered="true" toc="default">
                <name>Step 6 - Send EBs and DIOs</name>
                <t>
                    The node starts sending EBs and DIOs on the minimal cell, while following the transmit rules for broadcast frames from <xref target="sec_minimal" format="default"/>.
                </t>
            </section>
            <section anchor="sec_end_state" numbered="true" toc="default">
                <name>End State</name>
                <t>
                    For a new node, the end state of the joining process is:
                </t>
                <ul spacing="compact">
                    <li>it is synchronized to the network</li>
                    <li>it is using the link-layer keying material it learned through the secure joining process</li>
                    <li>it has selected one neighbor as its routing parent</li>
                    <li>it has one AutRxCell</li>
                    <li>it has one negotiated Tx cell to the selected parent</li>
                    <li>it starts to send DIOs, potentially serving as a router for other nodes' traffic</li>
                    <li>it starts to send EBs,  potentially serving as a JP for new pledge</li>
                </ul>
            </section>
        </section>
        <section anchor="sec_add_delete" numbered="true" toc="default">
            <name>Rules for Adding/Deleting Cells</name>
            <t>
                Once a node has joined the 6TiSCH network, it adds/deletes/relocates cells with the selected parent for three reasons:
            </t>
            <ul spacing="compact">
                <li>to match the link-layer resources to the traffic between the node and the selected parent (<xref target="sec_traffic" format="default"/>)</li>
                <li>to handle switching parent or(<xref target="sec_switching_parent" format="default"/>)</li>
                <li>to handle a schedule collision (<xref target="sec_collision" format="default"/>)</li>
            </ul>
            <t>
                Those cells are called 'negotiated cells' as they are scheduled through 6P, negotiated with the node's parent.
                Without specific declaring, all cells mentioned in this section are negotiated cells and they are installed at Slotframe 2.
            </t>
            <section anchor="sec_traffic" numbered="true" toc="default">
                <name>Adapting to Traffic</name>
                <t>
                    A node implementing MSF MUST implement the behavior described in this section.
                </t>
                <t>
                    The goal of MSF is to manage the communication schedule in the 6TiSCH schedule in a distributed manner.
                    For a node, this translates into monitoring the current usage of the cells it has to the selected parent:
                </t>
                <ul spacing="compact">
                    <li>
                        If the node determines that the number of link-layer frames it is attempting to exchange with the selected parent per unit of time is larger than the capacity offered by the TSCH negotiated cells it has scheduled with it, the node issues a 6P ADD command to that parent to add cells to the TSCH schedule.
                    </li>
                    <li>
                        If the traffic is lower than the capacity, the node issues a 6P DELETE command to that parent to delete cells from the TSCH schedule.
                    </li>
                </ul>
                <t>
                    The node MUST maintain two separate pairs of the following counters for the selected parent,
                        one for the negotiated Tx cells to that parent and 
                        one for the negotiated Rx cells to that parent.
                </t>
                <dl newline="false" spacing="compact" indent="4">
                    <dt>NumCellsElapsed :</dt>
                    <dd>
                        Counts the number of negotiated cells that have elapsed since the counter was initialized. 
                        This counter is initialized at 0.
                        When the current cell is declared as a negotiated cell to the selected parent, NumCellsElapsed is incremented by exactly 1, regardless of whether the cell is used to transmit/receive a frame.
                    </dd>
                    <dt>NumCellsUsed:</dt>
                    <dd>
                        <t>
                            Counts the number of negotiated cells that have been used. 
                            This counter is initialized at 0.
                            NumCellsUsed is incremented by exactly 1 when, during a negotiated cell to the selected parent, either of the following happens:
                        </t>
                        <ul spacing="compact">
                            <li>
                                The node sends a frame to the parent.
                                The counter increments regardless of whether a link-layer acknowledgment was received or not.
                            </li>
                            <li>
                                The node receives a valid frame from the parent.
                                The counter increments only when the frame is a valid IEEE802.15.4 frame.
                            </li>
                        </ul>
                    </dd>
                </dl>
                <t>
                    The cell option of cells listed in CellList in 6P Request frame SHOULD be either (Tx=1, Rx=0) only or (Tx=0, Rx=1) only.
                    Both NumCellsElapsed and NumCellsUsed counters can be used to both type of negotiated cells.
                </t>
                <t>
                    As there is no negotiated Rx Cell installed at initial time, the AutoRxCell is taken into account as well for downstream traffic adaptation.
                    In this case:
                </t>
                <ul spacing="compact">
                    <li>
                        NumCellsElapsed is incremented by exactly 1 when the current cell is AutoRxCell.
                    </li>
                    <li>
                        NumCellsUsed is incremented by exactly 1 when the node receives a frame from the selected parent on AutoRxCell.
                    </li>
                </ul>
                <t>
                    Implementors MAY choose to create the same counters for each neighbor, and add them as additional statistics in the neighbor table.
                </t>
                <t>
                    The counters are used as follows:
                </t>
                <ol spacing="compact" type="1">
                    <li>
                        Both NumCellsElapsed and NumCellsUsed are initialized to 0 when the node boots.
                    </li>
                    <li>
                        <t>
                            When the value of NumCellsElapsed reaches MAX_NUM_CELLS:
                        </t>
                        <ul spacing="compact">
                            <li>If NumCellsUsed &gt; LIM_NUMCELLSUSED_HIGH, trigger 6P to add    a single cell to the selected parent</li>
                            <li>If NumCellsUsed &lt; LIM_NUMCELLSUSED_LOW,  trigger 6P to remove a single cell to the selected parent</li>
                            <li>Reset both NumCellsElapsed  and NumCellsUsed to 0 and go to step 2.</li>
                        </ul>
                    </li>
                </ol>
                <t>
                    The value of MAX_NUM_CELLS is chosen according to the traffic type of the network.
                    Generally speaking, the larger the value MAX_NUM_CELLS is, the more accurate the cell usage is calculated.
                    The 6P traffic overhead using a larger value of MAX_NUM_CELLS could be reduced as well.
                    Meanwhile, the latency won't increase much by using a larger value of MAX_NUM_CELLS for periodic traffic type.
                    For burst traffic type, larger value of MAX_NUM_CELLS indeed introduces higher latency.
                    The latency caused by slight changes of traffic load can be absolved by the additional scheduled cells. 
                    In this sense, MSF is a scheduling function trading latency with energy by scheduling more cells than needed.
                    It is recommended to set MAX_NUM_CELLS value at least 4x of the maximum number of used cells in a slot frame in recent history.
                    For example, a 2 packets/slotframe traffic load results an average 4 cells scheduled (2 cells are used), using at least the value of double number of scheduled cells (which is 8) as MAX_NUM_CELLS gives a good resolution on cell usage calculation.
                </t>
                <t>
                    In case that a node booted or disappeared from the network, the cell reserved at the selected parent may be kept in the schedule forever.
                    A clean-up mechanism MUST be provided to resolve this issue.
                    The clean-up mechanism is implementation-specific.
                    The goal is to confirm those negotiated cells are not used anymore by the associated neighbors and remove them from the schedule.
                </t>
            </section>
            <section anchor="sec_switching_parent" numbered="true" toc="default">
                <name>Switching Parent</name>
                <t>
                    A node implementing MSF SHOULD implement the behavior described in this section.
                </t>
                <t>
                    Part of its normal operation, the RPL routing protocol can have a node switch parent.
                    The procedure for switching from the old parent to the new parent is:
                </t>
                <ol spacing="compact" type="1">
                    <li>the node counts the number of negotiated cells it has per slotframe to the old parent</li>
                    <li>the node triggers one or more 6P ADD commands to schedule the same number of negotiated cells with same cell options to the new parent</li>
                    <li>when that successfully completes, the node issues a 6P CLEAR command to its old parent</li>
                </ol>
                <t>
                    For what type of negotiated cell should be installed first, it depends on which traffic has the higher priority, upstream or downstream, which is application-specific and out-of-scope of MSF.
                </t>
            </section>
            <section anchor="sec_collision" numbered="true" toc="default">
                <name>Handling Schedule Collisions</name>
                <t>
                    A node implementing MSF SHOULD implement the behavior described in this section.
                    Other schedule collisions handling algorithm can be an alternative of the algorithm proposed in this section.
                </t>
                <t>
                    Since scheduling is entirely distributed, there is a non-zero probability that two pairs of nearby neighbor nodes schedule a negotiated cell at the same [slotOffset,channelOffset] location in the TSCH schedule.
                    In that case, data exchanged by the two pairs may collide on that cell.
                    We call this case a "schedule collision".
                </t>
                <t>
                    The node MUST maintain the following counters for each negotiated Tx cell to the selected parent:
                </t>
                <dl newline="false" spacing="compact" indent="4">
                    <dt>NumTx:</dt>
                    <dd>
                        Counts the number of transmission attempts on that cell.
                        Each time the node attempts to transmit a frame on that cell, NumTx is incremented by exactly 1.
                    </dd>
                    <dt>NumTxAck:</dt>
                    <dd>
                        Counts the number of successful transmission attempts on that cell.
                        Each time the node receives an acknowledgment for a transmission attempt, NumTxAck is incremented by exactly 1.
                    </dd>
                </dl>
                <t>
                    Since both NumTx and NumTxAck are initialized to 0, we necessarily have NumTxAck &lt;= NumTx.
                    We call Packet Delivery Ratio (PDR) the ratio NumTxAck/NumTx; and represent it as a percentage.
                    A cell with PDR=50% means that half of the frames transmitted are not acknowledged.
                </t>
                <t>
                    Each time the node switches parent (or during the join process when the node selects a parent for the first time), both NumTx and NumTxAck MUST be reset to 0.
                    They increment over time, as the schedule is executed and the node sends frames to that parent.
                    When NumTx reaches MAX_NUMTX, both NumTx and NumTxAck MUST be divided by 2.
                    MAX_NUMTX needs to be a power of two to avoid division error.
                    For example, when MAX_NUMTX is set to 256, from NumTx=255 and NumTxAck=127, the counters become NumTx=128 and NumTxAck=64 if one frame is sent to the parent with an Acknowledgment received.
                    This operation does not change the value of the PDR, but allows the counters to keep incrementing.
                    The value of MAX_NUMTX is implementation-specific.
                </t>
                <t>
                    The key for detecting a schedule collision is that, if a node has several cells to the selected parent, all cells should exhibit the same PDR.
                    A cell which exhibits a PDR significantly lower than the others indicates than there are collisions on that cell.
                </t>
                <t>
                    Every HOUSEKEEPINGCOLLISION_PERIOD, the node executes the following steps:
                </t>
                <ol spacing="compact" type="1">
                    <li>
                        It computes, for each negotiated Tx cell with the parent (not for the autonomous cell), that cell's PDR.
                    </li>
                    <li>
                        Any cell that hasn't yet had NumTx divided by 2 since it was last reset is skipped in steps 3 and 4.
                        This avoids triggering cell relocation when the values of NumTx and NumTxAck are not statistically significant yet.
                    </li>
                    <li>
                        It identifies the cell with the highest PDR.
                    </li>
                    <li>
                        For any other cell, it compares its PDR against that of the cell with the highest PDR.
                        If the difference is larger than RELOCATE_PDRTHRES, it triggers the relocation of that cell using a 6P RELOCATE command.
                    </li>
                </ol>
                <t>
                    The RELOCATION for negotiated Rx cells is not supported by MSF. 
                </t>
            </section>
        </section>
        <section anchor="sec_signal" numbered="true" toc="default">
            <name>6P SIGNAL command</name>
            <t>
                The 6P SIGNAL command is not used by MSF.
            </t>
        </section>
        <section anchor="sec_sfid" numbered="true" toc="default">
            <name>Scheduling Function Identifier</name>
            <t>
                The Scheduling Function Identifier (SFID) of MSF is IANA_6TISCH_SFID_MSF.
                How the value of IANA_6TISCH_SFID_MSF is chosen is described in <xref target="sec_iana" format="default"/>.
            </t>
        </section>
        <section anchor="sec_celllist" numbered="true" toc="default">
            <name>Rules for CellList</name>
            <t>
                MSF uses 2-step 6P Transactions exclusively.
                6P transactions are only initiated by a node towards its parent.
                As a result, the cells to put in the CellList of a 6P ADD command, and in the candidate CellList of a RELOCATE command, are chosen by the node initiating the 6P transaction.
                In both cases, the same rules apply:
            </t>
            <ul spacing="compact">
                <li>The CellList is RECOMMENDED to have 5 or more cells.</li>
                <li>Each cell in the CellList MUST have a different slotOffset value.</li>
                <li>For each cell in the CellList, the node MUST NOT have any scheduled cell on the same slotOffset.</li>
                <li>The slotOffset value of any cell in the CellList MUST NOT be the same as the slotOffset of the minimal cell (slotOffset=0).</li>
                <li>The slotOffset    of a cell in the CellList SHOULD be randomly and uniformly chosen among all the slotOffset values that satisfy the restrictions above.</li>
                <li>The channelOffset of a cell in the CellList SHOULD be randomly and uniformly chosen in [0..numFrequencies], where numFrequencies represents the number of frequencies a node can communicate on.</li>
            </ul>
            <t>
                As a consequence of randomly cell selection, there is a non-zero chance that nodes in the vicinity installed cells with same slotOffset and channelOffset.
                An implementer MAY implement a strategy to monitor the candidate cells before adding them in CellList to avoid collision.
                For example, a node MAY maintain a candidate cell pool for the CellList.
                The candidate cells in the pool are pre-configured as Rx cells to promiscuously listen to detect transmissions on those cells.
                If IEEE802.15.4 transmissions are observed on one cell over multiple iterations of the schedule, that cell is probably used by a TSCH neighbor.
                It is moved out from the pool and a new cell is selected as a candidate cell.
                The cells in CellList are picked from the candidate pool directly when required.
            </t>
        </section>
        <section anchor="sec_timeout" numbered="true" toc="default">
            <name>6P Timeout Value</name>
            <t>
                The timeout value is calculated for the worst case that a 6P response is received, which means the 6P response is sent out successfully at the very latest retransmission.
                And for each retransmission, it backs-off with largest value.
                Hence the 6P timeout value is calculated as ((2^MAXBE)-1)*MAXRETRIES*SLOTFRAME_LENGTH, where:
            </t>
            <ul spacing="compact">
                <li>MAXBE is the maximum backoff exponent used</li>
                <li>MAXRETRIES is the maximum retransmission times</li>
                <li>SLOTFRAME_LENGTH represents the length of slotframe</li>
            </ul>
        </section>
        <section anchor="sec_ordering" numbered="true" toc="default">
            <name>Rule for Ordering Cells</name>
            <t>
                Cells are ordered slotOffset first, channelOffset second.
            </t>
            <t>
                The following sequence is correctly ordered (each element represents the [slottOffset,channelOffset] of a cell in the schedule):
            </t>
            <t>
                [1,3],[1,4],[2,0],[5,3],[6,0],[6,3],[7,9]
            </t>
        </section>
        <section anchor="sec_metadata" numbered="true" toc="default">
            <name>Meaning of the Metadata Field</name>
            <t>
                The Metadata field is not used by MSF.
            </t>
        </section>
        <section anchor="sec_error" numbered="true" toc="default">
            <name>6P Error Handling</name>
            <t>
                Section 6.2.4 of <xref target="RFC8480" format="default"/> lists the 6P Return Codes.
                <xref target="tab_error" format="default"/> lists the same error codes, and the behavior a node implementing MSF SHOULD follow.
            </t>
            <figure anchor="tab_error">
                <name>Recommended behavior for each 6P Error Code.</name>
                <artwork name="" type="" align="left" alt=""><![CDATA[
       +-----------------+----------------------+
       | Code            | RECOMMENDED behavior |
       +-----------------+----------------------+
       | RC_SUCCESS      | nothing              |
       | RC_EOL          | nothing              |
       | RC_ERR          | quarantine           |
       | RC_RESET        | quarantine           |
       | RC_ERR_VERSION  | quarantine           |
       | RC_ERR_SFID     | quarantine           |
       | RC_ERR_SEQNUM   | clear                |
       | RC_ERR_CELLLIST | clear                |
       | RC_ERR_BUSY     | waitretry            |
       | RC_ERR_LOCKED   | waitretry            |
       +-----------------+----------------------+
]]></artwork>
            </figure>
            <t>
                The meaning of each behavior from <xref target="tab_error" format="default"/> is:
            </t>
            <dl newline="false" spacing="compact" indent="4">
                <dt>nothing:</dt>
                <dd>
                    Indicates that this Return Code is not an error.
                    No error handling behavior is triggered.
                </dd>
                <dt>clear:</dt>
                <dd>
                    Abort the 6P Transaction.
                    Issue a 6P CLEAR command to that neighbor (this command may fail at the link layer).
                    Remove all cells scheduled with that neighbor from the local schedule.
                </dd>
                <dt>quarantine:</dt>
                <dd>
                    Same behavior as for "clear".
                    In addition, remove the node from the neighbor and routing tables.
                    Place the node's identifier in a quarantine list for QUARANTINE_DURATION.
                    When in quarantine, drop all frames received from that node.
                </dd>
                <dt>waitretry:</dt>
                <dd>
                    Abort the 6P Transaction.
                    Wait for a duration randomly and uniformly chosen in [WAIT_DURATION_MIN,WAIT_DURATION_MAX].
                    Retry the same transaction.
                </dd>
            </dl>
        </section>
        <section anchor="sec_inconsistency" numbered="true" toc="default">
            <name>Schedule Inconsistency Handling</name>
            <t>
                The behavior when schedule inconsistency is detected is explained in <xref target="tab_error" format="default"/>, for 6P Return Code RC_ERR_SEQNUM.
            </t>
        </section>
        <section anchor="sec_constants" numbered="true" toc="default">
            <name>MSF Constants</name>
            <t>
                <xref target="tab_constants" format="default"/> lists MSF Constants and their RECOMMENDED values.
            </t>
            <figure anchor="tab_constants">
                <name>MSF Constants and their RECOMMENDED values.</name>
                <artwork name="" type="" align="left" alt=""><![CDATA[
        +------------------------------+-------------------+
        | Name                         | RECOMMENDED value |
        +------------------------------+-------------------+
        | SLOTFRAME_LENGTH             |      101 slots    |
        | NUM_CH_OFFSET                |       16          |
        | MAX_NUM_CELLS                |      100          |
        | LIM_NUMCELLSUSED_HIGH        |       75          |
        | LIM_NUMCELLSUSED_LOW         |       25          |
        | MAX_NUMTX                    |      256          |
        | HOUSEKEEPINGCOLLISION_PERIOD |        1 min      |
        | RELOCATE_PDRTHRES            |       50 %        |
        | QUARANTINE_DURATION          |        5 min      |
        | WAIT_DURATION_MIN            |       30 s        |
        | WAIT_DURATION_MAX            |       60 s        |
        +------------------------------+-------------------+
]]></artwork>
            </figure>
        </section>
        <section anchor="sec_stats" numbered="true" toc="default">
            <name>MSF Statistics</name>
            <t>
                <xref target="tab_stats" format="default"/> lists MSF Statistics and their RECOMMENDED width.
            </t>
            <figure anchor="tab_stats">
                <name>MSF Statistics and their RECOMMENDED width.</name>
                <artwork name="" type="" align="left" alt=""><![CDATA[
                +-----------------+-------------------+
                | Name            | RECOMMENDED width |
                +-----------------+-------------------+
                | NumCellsElapsed |      1 byte       |
                | NumCellsUsed    |      1 byte       |
                | NumTx           |      1 byte       |
                | NumTxAck        |      1 byte       |
                +-----------------+-------------------+
]]></artwork>
            </figure>
        </section>
        <section anchor="sec_security" numbered="true" toc="default">
            <name>Security Considerations</name>
            <t>
                MSF defines a series of "rules" for the node to follow.
                It triggers several actions, that are carried out by the protocols defined in the following specifications:
                the Minimal IPv6 over the TSCH Mode of IEEE 802.15.4e (6TiSCH) Configuration <xref target="RFC8180" format="default"/>,
                the 6TiSCH Operation Sublayer Protocol (6P) <xref target="RFC8480" format="default"/>, and
                the Constrained Join Protocol (CoJP) for 6TiSCH <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
                The security considrations of the specifications continue to apply in the MSF scope.
                In particular, MSF does not define a new protocol or packet format.
            </t>
            <t>
                MSF uses autonomous cells for initial bootstrap and the transport of join traffic.
                Autonomous cells are computed as a hash of nodes’ EUI64 addresses.
                This makes the coordinates of autonomous cell an easy target for an attacker, as EUI64 addresses are visible on the wire and are not encrypted by the link-layer security mechanism.
                With the coordinates of autonomous cells available, the attacker can launch a selective jamming attack against any nodes’ AutoRxCell.
                If the attacker targets a node acting as a JP, it can prevent pledges from using that JP to join the network.
                The pledge detects such a situation through the absence of a link-layer acknowledgment for its Join Request.
                As it is expected that each pledge will have more than one JP available to join the network, one available countermeasure for the pledge is to pseudo-randomly select a new JP when the link to the previous JP appears bad.
                Such strategy alleviates the issue of the attacker randomly jamming to disturb the network but does not help in case the attacker is targeting a particular pledge.
                In that case, the attacker can jam the AutoRxCell of the pledge, in order to prevent it from receiving the join response.
                This situation should be detected through the absence of a particular node from the network and handled by the network administrator through out-of-band means.
            </t>
            <t>
                MSF adapts to traffic containing packet from the IP layer. 
                It is possible that the IP packet has a non-zero DSCP (Diffserv Code Point <xref target="RFC2474" format="default"/>) value in its IPv6 header.
                The decision how to hand that packet belongs to the upper layer and is out of scope of MSF.
                As long as the decision is made to hand over to MAC layer to transmit, MSF will take that packet into account when adapting to traffic.
            </t>
            <t>
                Note that non-zero DSCP value may imply that the traffic is originated at unauthenticated pledges, referring to <xref target="I-D.ietf-6tisch-minimal-security" format="default"/>.
                The implementation at IPv6 layer SHOULD rate-limit this join traffic before it is passed to 6top sublayer where MSF can observe it.
                In case there is no rate limit for join traffic, intermediate nodes in the 6TiSCH network may be prone to a resource exhaustion attack, with the attacker injecting unauthenticated traffic from the network edge.
                The assumption is that the rate limiting function is aware of the available bandwidth in the 6top L3 bundle(s) towards a next hop, not directly from MSF, but from an interaction with the 6top sublayer that manages ultimately the bundles under MSF's guidance.
                How this rate-limit is implemented is out of scope of MSF.
            </t>
        </section>
        <section anchor="sec_iana" numbered="true" toc="default">
            <name>IANA Considerations</name>
            <section anchor="sec_iana_sfid" numbered="true" toc="default">
                <name>MSF Scheduling Function Identifiers</name>
                <t>
                    This document adds the following number to the
                    "6P Scheduling Function Identifiers" sub-registry,
                    part of the "IPv6 over the TSCH mode of IEEE 802.15.4e (6TiSCH) parameters" registry,
                    as defined by <xref target="RFC8480" format="default"/>:
                </t>
                <figure anchor="fig_iana_sfid">
                    <name>New SFID in 6P Scheduling Function Identifiers subregistry.</name>
                    <artwork name="" type="" align="left" alt=""><![CDATA[
+----------------------+-----------------------------+-------------+
|  SFID                | Name                        | Reference   |
+----------------------+-----------------------------+-------------+
| IANA_6TISCH_SFID_MSF | Minimal Scheduling Function | RFC_THIS    |
|                      | (MSF)                       |             |
+----------------------+-----------------------------+-------------+
]]></artwork>
                </figure>
                <t>
                    IANA_6TISCH_SFID_MSF is chosen from range 0-127, which is used for IETF Review or IESG Approval.
                </t>
            </section>
        </section>
        <section anchor="sec_contributors" numbered="true" toc="default">
            <name>Contributors</name>
            <ul spacing="compact">
                <li>Beshr Al Nahas (Chalmers University, beshr@chalmers.se)</li>
                <li>Olaf Landsiedel (Chalmers University, olafl@chalmers.se)</li>
                <li>Yasuyuki Tanaka (Inria-Paris, yasuyuki.tanaka@inria.fr)</li>
            </ul>
        </section>
    </middle>
    <back>
        <references>
            <name>References</name>
            <references>
                <name>Normative References</name>
                <!-- RFC 6TiSCH-->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8180.xml"/>
                <!-- Minimal IPv6 over the TSCH Mode of IEEE 802.15.4e (6TiSCH) Configuration -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8480.xml"/>
                <!-- 6TiSCH Operation Sublayer (6top) Protocol (6P) -->
                <!-- RFC others -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6550.xml"/>
                <!-- The Trickle Algorithm -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
                <!-- Definition of the Differentiated Services Field (DS Field) in the IPv4 and IPv6 Headers -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2474.xml"/>
                <!-- Registration Extensions for IPv6 over Low-Power Wireless Personal Area Network (6LoWPAN) Neighbor Discovery -->
                <!-- I-D 6TiSCH -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-6tisch-minimal-security-13.xml"/>
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-6tisch-enrollment-enhanced-beacon-06.xml"/>
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-6tisch-architecture-28.xml"/>
                <!-- I-D others -->
                <!-- external -->
                <reference anchor="IEEE802154" target='http://ieeexplore.ieee.org/document/7460875/'>
                    <front>
                        <title>
                            IEEE Std 802.15.4 Standard for Low-Rate Wireless Personal Area Networks (WPANs)
                        </title>
                        <author>
                            <organization>IEEE standard for Information Technology</organization>
                        </author>
                        <date/>
                    </front>
                    <seriesInfo name='DOI' value='10.1109/IEEE P802.15.4-REVd/D01'/>
                </reference>
                <reference anchor="SAX-DASFAA">
                    <front>
                        <title> Performance in Practice of String Hashing Functions</title>
                        <seriesInfo name="DASFAA" value=""/>
                        <author initials="M.V" surname="Ramakrishna"/>
                        <author initials="J" surname="Zobel"/>
                        <date year="1997"/>
                    </front>
                    <seriesInfo name='DOI' value='10.1142/9789812819536_0023'/>
                </reference>
            </references>
            <references>
                <name>Informative References</name>
                <!-- RFC 6TiSCH-->
                <!-- Using IEEE 802.15.4e Time-Slotted Channel Hopping (TSCH) in the Internet of Things (IoT): Problem Statement -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7554.xml"/>
                <!-- 6tisch Zero-Touch Secure Join protocol -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-6tisch-dtsecurity-zerotouch-join-04.xml"/>
                <!-- RFC others -->
                <!-- RPL: IPv6 Routing Protocol for Low-Power and Lossy Networks -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6206.xml"/>
                <!-- 6LoWPAN Neighbor Discovery -->
                <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8505.xml"/>
                <!-- I-D 6TiSCH -->
                <!-- I-D others -->
                <!-- external -->
            </references>
        </references>
        <section anchor="sec_hash_function" numbered="true" toc="default">
            <name>Example of Implementation of SAX hash function</name>
            <t>
                Considering the interoperability, this section provides an example of implemention SAX hash function <xref target="SAX-DASFAA" format="default"/>.
                The input parameters of the function are:
            </t>
            <ul spacing="compact">
                <li>T, which is the hashing table length</li>
                <li>c, which is the characters of string s, to be hashed</li>
            </ul>
            <t>
                In MSF, the T is replaced by the length of slotframe 1.
                String s is replaced by the mote EUI64 address. The characters of the string c0, c1, ..., c7 are the 8 bytes of EUI64 address.
            </t>
            <t>
                The SAX hash function requires shift operation which is defined as follow:
            </t>
            <ul spacing="compact">
                <li>L_shift(v,b), which refers to left  shift variable v by b bits</li>
                <li>R_shift(v,b), which refers to right shift variable v by b bits</li>
            </ul>
            <t>
                The steps to calculate the hash value of SAX hash function are:
            </t>
            <ol spacing="compact" type="1">
                <li>initialize variable h to h0 and variable i to 0, where h is the intermediate hash value and i is the index of the bytes of EUI64 address</li>
                <li>sum the value of L_shift(h,l_bit), R_shift(h,r_bit) and ci</li>
                <li>calculate the result of exclusive or between the sum value in Step 2 and h</li>
                <li>modulo the result of Step 3 by T</li>
                <li>assign the result of Step 4 to h</li>
                <li>increase i by 1</li>
                <li>repeat Step2 to Step 6 until i reaches to 8 </li>
            </ol>
            <t>
                The value of variable h is the hash value of SAX hash function.
            </t>
            <t>
                The values of h0, l_bit and r_bit in Step 1 and 2 are configured as: 
            </t>
            <ul spacing="compact">
                <li>h0       = 0</li>
                <li>l_bit    = 0</li>
                <li>r_bit    = 1</li>
            </ul>
            <t>
                The appropriate values of l_bit and r_bit could vary depending on the the set of motes' EUI64 address.
                How to find those values is out of the scope of this specification. 
            </t>
        </section>
    </back>
</rfc>
