Skip to main content
Glama

PTP MCP Server

by aneeshkp
ptp_model.cpython-311.pyc21.4 kB
� ��|h�U��j�dZddlZddlZddlmZmZmZmZmZddl m Z m Z ddl m Z ddl mZeje��ZGd�de��ZGd �d e��ZGd �d e��Ze Gd �d����Ze Gd�d����Ze Gd�d����ZGd�d��ZdS)zG PTP Model - Contextual model layer for PTP understanding and analysis �N)�Dict�List�Optional�Any�Tuple)�datetime� timedelta)� dataclass)�Enumc�"�eZdZdZdZdZdZdZdS)� ClockTypezPTP Clock Types�OC�BC�TC�GMN)�__name__� __module__� __qualname__�__doc__�ORDINARY_CLOCK�BOUNDARY_CLOCK�TRANSPARENT_CLOCK� GRANDMASTER���5/home/aputtur/Ai Projects/ptp-mcp-server/ptp_model.pyr r s)���������N��N����K�K�Krr c�"�eZdZdZdZdZdZdZdS)�BMCARolez(BMCA (Best Master Clock Algorithm) Roles�master�slave�passive�unknownN)rrrr�MASTER�SLAVE�PASSIVE�UNKNOWNrrrrrs(������2�2� �F� �E��G��G�G�Grrc�&�eZdZdZdZdZdZdZdZdS)� SyncStatuszPTP Synchronization Status�locked�unlocked�holdover�freerunr"N) rrrr�LOCKED�UNLOCKED�HOLDOVER�FREERUNr&rrrr(r(s-������$�$� �F��H��H��G��G�G�Grr(c���eZdZUdZeed<eed<eed<eed<eed<eed<eed<eed <d Ze eed <e j Z e ed <e j Ze ed <d Ze eed<d S)�PTPClockzPTP Clock representation�clock_id� clock_type�domain� priority1� priority2� clock_class�clock_accuracy�offset_scaled_log_varianceN� port_identity� sync_status� bmca_role� last_seen)rrrr�str�__annotations__r �intr;rr(r&r<rr=r>rrrrr2r2%s��������"�"��M�M�M����� �K�K�K��N�N�N��N�N�N��������� #�#�#�#�#'�M�8�C�=�'�'�'�(�0�K��0�0�0�"�*�I�x�*�*�*�$(�I�x��!�(�(�(�(�(rr2c��eZdZUdZeed<eed<eed<eed<dZe e ed<dZ e e ed<dZ e e ed <dS) � PTPInterfacezPTP Interface representation�name� master_only� port_stater<N�offset� frequency� last_update)rrrrr?r@�boolr(rGrrArHrIrrrrrCrC5s�������&�&� �I�I�I������O�O�O����� �F�H�S�M� � � �#�I�x��}�#�#�#�&*�K��(�#�*�*�*�*�*rrCc���eZdZUdZeed<eed<eeeefed<eeeefed<e ed<e ed<eee fed<e ed <eee fed <eeefed <d S) �PTPConfigurationz PTP Configuration representationrD� namespace�profiles�recommendationsr4r5� prioritiesr8�sync_intervals� thresholdsN) rrrrr?r@rrrr rArrrrLrL@s��������*�*� �I�I�I��N�N�N��4��S��>�"�"�"�"��$�s�C�x�.�)�)�)�)����� �K�K�K��S�#�X�����������c��N�"�"�"��S�#�X������rrLc ��eZdZdZd�Zdeeefdefd�Z de eeefde fd�Z de eeefde fd�Zde eeefdeee ffd �Zde eeefde fd �Zde eeefdeee ffd �Zde eeefdeeeffd �Zd ede edefd�Zd ede edefd�Zd edeeeffd�Zde de fd�Zd ede edeeeffd�Zde ede eeeffd�Zdde ededeeeffd�Zd ede edeeeffd�ZdS)�PTPModelz3Contextual model for PTP understanding and analysisc �<�ttdd����|_idd�dd�dd�dd�dd�dd �d d �d d �d d �d d �d d�dd�dd�dd�dd�dd�dd�idd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�dd �d d!�d!d"�d"d#�d#d$��id$d%�d%d&�d&d'�d'd�dd(�d(d)�d)d*�d*d+�d+d,�d,d-�d-d.�d.d/�d/d0�d0d1�d1d2�d2d3�d3d4��id4d5�d5d6�d6d7�d7d8�d8d9�d9d:�d:d;�d;d<�d<d=�d=d>�d>d?�d?d@�d@dA�dAdB�dBdC�dCdD�dDdE��idEdF�dFdG�dGdH�dHdI�dIdJ�dJdK�dKdL�dLdM�dMdN�dNdO�dOdP�dPdQ�dQdR�dRdS�dSdT�dTdU�dUdV��idVdW�dWdX�dXdY�dYdZ�dZd[�d[d\�d\d]�d]d^�d^d_�d_d`�d`da�dadb�dbdc�dcdd�ddde�dedf�dfdg��idgdh�dhdi�didj�djdk�dkdl�dldm�dmdn�dndo�dodp�dpdq�dqdr�drds�dsdt�dtdu�dudv�dvdw�dwdx��idxdy�dydz�dzd{�d{d|�d|d}�d}d~�d~d�dd��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d���id�d��d�d��d�d��d�d��d�d��d�d“d�dÓd�dēd�dœd�dƓd�dǓd�dȓd�dɓd�dʓd�d˓d�d̓d�d͓�id�dΓd�dϓd�dГd�dѓd�dғd�dӓd�dԓd�dՓd�d֓d�dדd�dؓd�dٓd�dړd�dۓd�dܓd�dݓd�dޓ�id�dߓd�d��d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��d�d�d�d�d�d�d�d�d�d�d�d�� �|_dS)�N��,���� � � � � ������������������ �!�"�#�$�%�&�'�(�)�*�+�-�.�/�0�1�2�3�4�5�6�7�8�9�:�;�<�=�>�?�@�A�B�C�D�E�F�G�H�I�J�K�L�M�N�O�P�Q�R�S�T�U�V�W�X�Y�Z�[�\�]�^�_�`�a�b�c�d�e�f�g�h�i�j�k�l�m�n�o�p�q�r�s�t�u�v�w�x�y�z�{�|�}�~�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������) rDrErFrGrHrIrJrKrLrMrN)�list�range� itu_t_domains�clock_class_fallback)�selfs r�__init__zPTPModel.__init__Qs���!�%��B�-�-�0�0���z% � �q�z% � �q�z% � �q�z% � �r� z% � �� z% � �� z% � ��z% � ��z% � ��z% � ��z% � ��z% � ��z% � ��z% � ��z% � ��z% � ��!z% �" ��#z% �z% �$ ��%z% �& ��'z% �( ��)z% �* ��+z% �, ��-z% �. ��/z% �0 ��1z% �2 ��3z% �4 ��5z% �6 ��7z% �8 ��9z% �: ��;z% �< ��=z% �> ��?z% �@ ��Az% �B ��Cz% �D ��Ez% �z% �z% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �z% �z% �h ��iz% �j ��kz% �l ��mz% �n ��oz% �p ��qz% �r ��sz% �t ��uz% �v ��wz% �x ��yz% �z ��{z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �z% �z% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �h ��iz% �j ��kz% �z% �z% �l ��mz% �n ��oz% �p ��qz% �r ��sz% �t ��uz% �v ��wz% �x ��yz% �z ��{z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �z% �z% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �h ��iz% �j ��kz% �l ��mz% �n ��oz% �z% �z% �p ��qz% �r ��sz% �t ��uz% �v ��wz% �x ��yz% �z ��{z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �z% �z% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �h ��iz% �j ��kz% �l ��mz% �n ��oz% �p ��qz% �r ��sz% �z% �z% �t ��uz% �v ��wz% �x ��yz% �z ��{z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �z% �z% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �h ��iz% �j ��kz% �l ��mz% �n ��oz% �p ��qz% �r ��sz% �t ��uz% �v ��wz% �z% �z% �x ��yz% �z ��{z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �z% �z% �Z ��[z% �\ ��]z% �^ ��_z% �` ��az% �b ��cz% �d ��ez% �f ��gz% �h ��iz% �j ��kz% �l ��mz% �n ��oz% �p ��qz% �r ��sz% �t ��uz% �v ��wz% �x ��yz% �z ��{z% �z% �z% �| ��}z% �~ ��z% �@ ��Az% �B ��Cz% �D ��Ez% �F ��Gz% �H ��Iz% �J ��Kz% �L ��Mz% �N ��Oz% �P ��Qz% �R ��Sz% �T ��Uz% �V ��Wz% �X ��Yz% �Z ��[z% �\ ��]z% �z% �^�����������sz% �z% �z% ��!�!�!r� config_data�returnc ���|�d��std���|dd}|�di���dd��}|�di���dd��}|�d i��}|�d g��}|�d g��}|�|��}|�|��} |�|��} |�|��} |�|��} |�|��} t|||||| | | | | � � � S) z/Create PTPConfiguration from parsed config data�itemsz No PTP configuration items foundr�metadatarDr"rMz openshift-ptp�spec�profile� recommend) rDrMrNrOr4r5rPr8rQrR) �get� ValueError�_determine_clock_type�_extract_domain�_extract_priorities�_extract_clock_class�_extract_sync_intervals�_extract_thresholdsrL)rTrV�itemrDrMr[rNrOr4r5rPr8rQrRs r�create_ptp_configurationz!PTPModel.create_ptp_configurationPsm�����w�'�'� A��?�@�@� @��7�#�A�&���x�x� �B�'�'�+�+�F�I�>�>���H�H�Z��,�,�0�0��o�N�N� ��x�x���#�#���8�8�I�r�*�*���(�(�;��3�3���/�/��9�9� ��%�%�h�/�/���-�-�h�7�7� ��/�/��9�9� ��5�5�h�?�?���-�-�h�7�7� �����+�!��!�#�)�!�  �  �  � rrNc�l�|D]�}|�di��}|�di��}|�dd�����}|dkrtjcS|dkrtjcS|dkrtjcS|dkrtjcS��tjS) z"Determine clock type from profiles� ptp4lConf�clockr4�rrrr)r^�upperr rrrr)rTrNr\� ptp4l_conf� clock_conf�clock_type_strs rr`zPTPModel._determine_clock_type�s���� 0� 0�G� ���[�"�5�5�J�#�����4�4�J�'�^�^�L�"�=�=�C�C�E�E�N���%�%� �/�/�/�/��4�'�'� �2�2�2�2��4�'�'� �,�,�,�,��4�'�'� �/�/�/�/�(��'�'rc��|D]I}|�di��}|�di��}|�d��}|�|cS�JdS)z#Extract domain number from profilesri�global� domainNumberNr�r^)rTrNr\rm� global_confr5s rrazPTPModel._extract_domain�sc��� � �G� ���[�"�5�5�J�$�.�.��2�6�6�K� �_�_�^�4�4�F��!�� � � �"��qrc��i}|D]L}|�di��}|�di��}d|vr |d|d<d|vr |d|d<�M|S)z%Extract priority values from profilesrirqr6r7rs)rTrNrPr\rmrts rrbzPTPModel._extract_priorities�sy��� �� C� C�G� ���[�"�5�5�J�$�.�.��2�6�6�K��k�)�)�*5�k�*B� �;�'��k�)�)�*5�k�*B� �;�'���rc��|D]I}|�di��}|�di��}|�d��}|�|cS�JdS)z!Extract clock class from profilesrirq� clockClassNrHrs)rTrNr\rmrtr8s rrczPTPModel._extract_clock_class�sf��� #� #�G� ���[�"�5�5�J�$�.�.��2�6�6�K�%�/�/�,�7�7�K��&�"�"�"�"�'��src���i}|D][}|�di��}|�di��}d|vr |d|d<d|vr |d|d<d|vr |d|d<�\|S)z$Extract sync intervals from profilesrirq�logSyncInterval�logAnnounceInterval�logMinDelayReqIntervalrs)rTrN� intervalsr\rmrts rrdz PTPModel._extract_sync_intervals�s���� �� \� \�G� ���[�"�5�5�J�$�.�.��2�6�6�K� �K�/�/�/:�;L�/M� �+�,�$� �3�3�3>�?T�3U� �/�0�'�;�6�6�6A�BZ�6[� �2�3���rc�n�i}|D]/}|�di��}|r|�|���0|S)z&Extract clock thresholds from profiles�ptpClockThreshold)r^�update)rTrNrRr\� ptp_thresholds rrezPTPModel._extract_thresholds�sM��� �� 1� 1�G�#�K�K�(;�R�@�@�M�� 1��!�!�-�0�0�0���r�config�logsc��|jtjkr tjS|jtjkr tjStjS)z2Analyze BMCA state based on configuration and logs)r4r rrr#rr$)rTr�r�s r�analyze_bmca_statezPTPModel.analyze_bmca_state�sD�� � � � 5� 5� 5��?� "� � � � 8� 8� 8��>� !��~�rc���|jD]V}|�di��}|�di��}|�dd��dkrtjcS�WtjS)z>Analyze synchronization status based on configuration and logsrirq� free_runningr�)rNr^r(r0r&)rTr�r�r\rmrts r�analyze_sync_statuszPTPModel.analyze_sync_status�ss�� �� *� *�G� ���[�"�5�5�J�$�.�.��2�6�6�K����~�q�1�1�Q�6�6�!�)�)�)�)�7��!�!rc��dggd�}|j|jvr)d|d<|d�d|j�d���|jdks |jd kr$|d �d |j�d ���|j���D]3\}}|d ks|d kr"|d�d|�d|�d����4|S)z"Validate ITU-T G.8275.1 complianceT)� compliant�warnings�errorsFr�r�zDomain z' is not in ITU-T G.8275.1 range (24-43)rXrOr�z Clock class z% is outside recommended range (6-255)rzInvalid z value z (must be 0-255))r5rR�appendr8rPrY)rTr�� validation� priority_name�priority_values r�validate_itu_t_compliancez"PTPModel.validate_itu_t_compliance�s#����� � � � �=�� 2� 2� 2�&+�J�{� #� �x� � '� '�P�&�-�P�P�P� � � � � �� !� !�V�%7�#�%=�%=� �z� "� )� )�X�v�1�X�X�X� � � � .4�->�-D�-D�-F�-F� � � )�M�>���!�!�^�c�%9�%9��8�$�+�+�U�}�U�U�^�U�U�U������r� current_classc�8�|j�||��S)z8Get the fallback clock class according to ITU-T G.8275.1)rSr^)rTr�s r�get_clock_class_fallbackz!PTPModel.get_clock_class_fallbacks���(�,�,�]�M�J�J�Jrc��ddddd�}|S)zAnalyze timing traceabilityr"N)�source�qualityrI�statusr)rTr�r�� traceabilitys r�analyze_timing_traceabilityz$PTPModel.analyze_timing_traceabilitys$�� � ���  � � ��rc� �g}|S)z,Detect synchronization loss events from logsr)rTr��sync_loss_eventss r�detect_sync_losszPTPModel.detect_sync_loss"s����  �r� last_hour� time_rangec��ddddddd�}|S)zGet offset trend analysisN�stabler)�current_offset�trend� min_offset� max_offset�average_offset�samplesr)rTr�r�r�s r�get_offset_trendzPTPModel.get_offset_trend+s)��#����"��  � ��� rc �R�dggg|jj|j|j|jd�d�}|S)zGet current clock hierarchyN)�typer5rPr8)� grandmaster�boundary_clocks�ordinary_clocks�transparent_clocks� current_clock)r4�valuer5rPr8)rTr�r�� hierarchys r�get_clock_hierarchyzPTPModel.get_clock_hierarchy;sH�� �!�!�"$��)�/� �-�$�/�%�1� ��  �  � ��rN)r�)rrrrrUrr?rrLrgrr r`rArarbrcrdrerr�r(r�r�r�r�r�r�r�rrrrTrTNs$������=�=�} �} �} �~. �D��c��N�. �GW�. �. �. �. �`(�d�4��S��>�.B�(�y�(�(�(�(�& ��T�#�s�(�^�(<� �� � � � � �D��c�3�h��,@� �T�#�s�(�^� � � � � �T�$�s�C�x�.�-A� �c� � � � ���T�#�s�(�^�0D���c�SV�h������ �D��c�3�h��,@��T�#�s�(�^������)9���c���x�����$ "�*:� "�$�s�)� "�PZ� "� "� "� "��0@��T�#�s�(�^�����<K�c�K�c�K�K�K�K� �2B� �$�s�)� �X\�]`�be�]e�Xf� � � � � �T�#�Y� �4��S�#�X��3G� � � � ���T�#�Y��C��RV�WZ�\_�W_�R`����� �*:��$�s�)��PT�UX�Z]�U]�P^������rrT)r�json�logging�typingrrrrrrr � dataclassesr �enumr � getLoggerr�loggerr rr(r2rCrLrTrrr�<module>r�s����� � � � �����3�3�3�3�3�3�3�3�3�3�3�3�3�3�(�(�(�(�(�(�(�(�!�!�!�!�!�!������� �� �8� $� $����������������t������������� � )� )� )� )� )� )� )� �� )� �+�+�+�+�+�+�+� ��+� � � � � � � � � �� �|�|�|�|�|�|�|�|�|�|r

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aneeshkp/ptp-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server