
    h1                     F   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZ dd	d
Zddd
Zi Z G d de
          Z G d de
          Z G d de
          Z G d de
          Z  eeed            eee d           dS )aG  
STAMP (Simple Two-Way Active Measurement Protocol) - RFC 8762.

References:
    * `Simple Two-Way Active Measurement Protocol [RFC 8762]
      <https://www.rfc-editor.org/rfc/rfc8762.html>`_
    * `Simple Two-Way Active Measurement Protocol Optional Extensions [RFC 8972]
      <https://www.rfc-editor.org/rfc/rfc8972.html>`_
    )config)Packet_metaclass)UDP)TimeStampField)Packetbind_layers)BitEnumFieldBitFieldByteEnumField	ByteField
FlagsFieldIntFieldMultipleTypeFieldNBytesFieldPacketFieldPacketListField
ShortFieldStrLenFieldUTCTimeFieldz/No External Synchronization for the Time Sourcez2Clock Synchronized to UTC using an External Source)r      zNTP 64-bit Timestamp Formatz PTPv2 Truncated Timestamp Formatc                       e Zd ZdZdZ eddde           eddde           eddd           e	d	d          gZ
d
 ZdS )ErrorEstimatead  
    The Error Estimate specifies the estimate of the error and
    synchronization. The format of the Error Estimate field
    (defined in Section 4.1.2 of `RFC 4656
    <https://www.rfc-editor.org/rfc/rfc4656.html>`_) is reported below::

        0                   1
        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |S|Z|   Scale   |   Multiplier  |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    ``S`` is interpreted as follows:

        +-------+-------------------------------------------------------+
        | Value | Description                                           |
        +-------+-------------------------------------------------------+
        |   0   | there is no notion of external synchronization for    |
        |       | the time source                                       |
        +-------+-------------------------------------------------------+
        |   1   | the party generating the timestamp has a clock that   |
        |       | is synchronized to UTC using an external source       |
        +-------+-------------------------------------------------------+

    ``Z`` is interpreted as follows (defined in Section 2.3 of `RFC 8186
    <https://www.rfc-editor.org/rfc/rfc8186.html>`_):

        +-------+---------------------------------------+
        | Value | Description                           |
        +-------+---------------------------------------+
        |   0   | NTP 64-bit format of a timestamp      |
        +-------+---------------------------------------+
        |   1   | PTPv2 truncated format of a timestamp |
        +-------+---------------------------------------+

    ``Scale`` and ``Multiplier`` are linked by the following relationship::

        ErrorEstimate = Multiplier*2^(-32)*2^Scale (in seconds)


    References:
        * `A One-way Active Measurement Protocol (OWAMP) [RFC 4656]
          <https://www.rfc-editor.org/rfc/rfc4656.html>`_
        * `Support of the IEEE 1588 Timestamp Format in a Two-Way Active
          Measurement Protocol (TWAMP) [RFC 8186]
          <https://www.rfc-editor.org/rfc/rfc8186.html>`_
    zError EstimateSr   r   Zscale   
multiplierc                 $    t           j        j        S N)r   confpadding_layer)selfpayloads     W/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/contrib/stamp.pyguess_payload_classz!ErrorEstimate.guess_payload_classq   s    
 {((    N)__name__
__module____qualname____doc__namer	   _sync_types_timestamp_typesr
   r   fields_descr%    r&   r$   r   r   8   s        . .` DS!Q,,S!Q 011!Q	,""	K) ) ) ) )r&   r   c                       e Zd ZdZdZ edddd           edde           ed	d           e	d
dd           gZ
d Zi Zed             Zedd            ZdS )STAMPTestTLVa  
    The STAMP Test TLV defined in Section 4 of [RFC 8972] provides a flexible
    extension mechanism for optional informational elements.

    The TLV Format in a STAMP Test packet is reported below::

         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
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |STAMP TLV Flags|     Type      |           Length              |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ~                            Value                              ~
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


    +-------+---------+-------------------------------------------------+
    | Field           | Description                                     |
    +-----------------+-------------------------------------------------+
    | STAMP TLV Flags | 8-bit field; for the details about the STAMP    |
    |                 | TLV Flags Format, see RFC 8972                  |
    +-----------------+-------------------------------------------------+
    | Type            | characterizes the interpretation of the Value   |
    |                 | field                                           |
    +-----------------+-------------------------------------------------+
    | Length          | the length of the Value field in octets         |
    +-----------------+-------------------------------------------------+
    | Value           | interpreted according to the value of the Type  |
    |                 | field                                           |
    +-----------------+-------------------------------------------------+


    References:
        * `Simple Two-Way Active Measurement Protocol Optional Extensions
          [RFC 8972] <https://www.rfc-editor.org/rfc/rfc8972.html>`_
    zSTAMP Test Packet - Generic TLVflagsr      UMIRRRRRtypeNlenvalue c                     | j         S r   )r6   pkts    r$   <lambda>zSTAMPTestTLV.<lambda>   s     r&   )length_fromc                 
    d|fS )Nr&   r/   )r"   ps     r$   extract_paddingzSTAMPTestTLV.extract_padding   s    Avr&   c                 .    | | j         | j        j        <   d S r   )registered_stamp_tlvr5   default)clss    r$   register_variantzSTAMPTestTLV.register_variant   s    58 !1222r&   c                 n    |r2t          |dd                   }| j                            ||           S | S )Nr      )ordrB   get)rD   r;   argskargstmp_types        r$   dispatch_hookzSTAMPTestTLV.dispatch_hook   s;     	?3qs8}}H+//#>>>
r&   r   )r'   r(   r)   r*   r+   r   r   _stamp_tlvsr   r   r.   r@   rB   classmethodrE   rM   r/   r&   r$   r1   r1   y   s        " "H -D
7Aq*--fdK00
5!GR-@-@AAA	K   9 9 [9    [  r&   r1   c            
           e Zd ZdZdZ edd           e edd          d fg eddd                     e	d	 e
            e
           ed
d           eddd           edg e          gZdS )%STAMPSessionSenderTestUnauthenticateda*  
    Extended STAMP Session-Sender Test Packet in Unauthenticated Mode.

    The format (defined in Section 3 of `RFC 8972
    <https://www.rfc-editor.org/rfc/rfc8972.html>`_) is shown below::

         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
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                        Sequence Number                        |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                          Timestamp                            |
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |         Error Estimate        |             SSID              |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                                                               |
        |                                                               |
        |                         MBZ (28 octets)                       |
        |                                                               |
        |                                                               |
        |                                                               |
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ~                            TLVs                               ~
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    References:
        * `Simple Two-Way Active Measurement Protocol Optional Extensions
          [RFC 8972] <https://www.rfc-editor.org/rfc/rfc8972.html>`_
    zSTAMP Session-Sender Testseqr   tsc                 "    | j         j        dk    S Nr   err_estimater   r:   s    r$   r<   z.STAMPSessionSenderTestUnauthenticated.<lambda>       s/1Q6 r&   QfmtrW   ssidr   mbz   tlv_objectsN)r'   r(   r)   r*   r+   r   r   r   r   r   r   r   r   r   r1   r.   r/   r&   r$   rQ   rQ      s         > 'Da((668 Lqc***	
 	
 	NMMOO]CC
61E1b!!r<88KKKr&   rQ   c                      e Zd ZdZdZ edd           e edd          d fg eddd                     e	d	 e
            e
           ed
d           e edd          d fg eddd                     edd           e edd          d fg eddd                     e	d e
            e
           edd           edd           eddd           edg e          gZdS )(STAMPSessionReflectorTestUnauthenticatedaU  
    Extended STAMP Session-Reflector Test Packet in Unauthenticated Mode.

    The format (defined in Section 3 of `RFC 8972
    <https://www.rfc-editor.org/rfc/rfc8972.html>`_) is shown below::

         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
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                        Sequence Number                        |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                          Timestamp                            |
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |         Error Estimate        |           SSID                |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                          Receive Timestamp                    |
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                 Session-Sender Sequence Number                |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                  Session-Sender Timestamp                     |
        |                                                               |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        | Session-Sender Error Estimate |           MBZ                 |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |Ses-Sender TTL |                   MBZ                         |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ~                            TLVs                               ~
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    References:
        * `Simple Two-Way Active Measurement Protocol Optional Extensions
          [RFC 8972] <https://www.rfc-editor.org/rfc/rfc8972.html>`_
    zSTAMP Session-Reflector TestrR   r   rS   c                 "    | j         j        dk    S rU   rV   r:   s    r$   r<   z1STAMPSessionReflectorTestUnauthenticated.<lambda>  rX   r&   rY   rZ   rW   r\   r   ts_rxc                 "    | j         j        dk    S rU   rV   r:   s    r$   r<   z1STAMPSessionReflectorTestUnauthenticated.<lambda>  rX   r&   
seq_sender	ts_senderc                 "    | j         j        dk    S rU   )err_estimate_senderr   r:   s    r$   r<   z1STAMPSessionReflectorTestUnauthenticated.<lambda>#  s    s68A= r&   rh   mbz1
ttl_sender   mbz2   r_   N)r'   r(   r)   r*   r+   r   r   r   r   r   r   r   r   r   r   r1   r.   r/   r&   r$   ra   ra      s       " "F *Da((668 Lqc***	
 	
 	NMMOO]CC
61++668 L!---	
 	
 	q!!Q//==? LaS111	
 	
 	)==??MJJ
61	,$$FAq!!r<88=KKKr&   ra   i^  )dport)sportN)!r*   scapyr   scapy.base_classesr   scapy.layers.inetr   scapy.layers.ntpr   scapy.packetr   r   scapy.fieldsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r,   r-   rN   r   r1   rQ   ra   r/   r&   r$   <module>rv      s#          / / / / / / ! ! ! ! ! ! + + + + + + , , , , , , , ,                             $ 9;  %)  

>) >) >) >) >)F >) >) >)B; ; ; ; ;6 ; ; ;|. . . . .F . . .bD D D D Dv D D DN C6c B B B B C9 E E E E E Er&   