コンテンツにスキップ

Topics で読み物として読む

この HLD は実装詳細を含みます。機能の概念・設定・運用を読み物として読みたい場合は Topics 14 章: Platform / Port / Optics を参照。

裏取りステータス: code-verified

sonic-platform-common/sonic_platform_base/sonic_xcvr/ 配下に api/ mem_maps/ codes/ fields/ cdb/ utils/ および xcvr_api_factory.py xcvr_eeprom.py sfp_optoe_base.py を確認。api/public/cmis.py c_cmis.py sff8472.py 等が実装され、xcvr_api_factory.py:51 class XcvrApiFactoryid_mapping で identifier → API クラスを切り替える。sonic-platform-daemons/sonic-xcvrd/xcvrd/sfp.get_xcvr_api() を全面使用。

SFP リファクタ(XcvrApi / XcvrEeprom / spec 自動判別)

なぜ作り直したか

SONiC の SFP 関連 platform API は PI(Platform Independent)と PD(Platform Dependent)が混在しており、vendor が SfpBase 派生で両方を実装する必要があった1sonic_sfp は旧 platform API モデルの遺物で新要件を満たさず、各 vendor が同じ PI ロジックを重複実装する状態だった。

本リファクタは xcvr 仕様(SFF-8436 / SFF-8472 / CMIS 等)を中心に PI ロジックを sonic-platform-common に集約し、vendor は真に PD な部分だけ実装すれば済むよう infrastructure を作り直す。

どんなクラス階層にしたか

classDiagram
    class SfpBase
    class SfpOptoeBase
    SfpBase <|-- SfpOptoeBase
    class XcvrApi {
        +get_temperature()
        +get_model()
        +get_serial()
        +get_transceiver_info()
    }
    class Sff8436Api
    class CmisApi
    class Sff8472Api
    XcvrApi <|-- Sff8436Api
    XcvrApi <|-- CmisApi
    XcvrApi <|-- Sff8472Api
    XcvrApi --> XcvrEeprom : 経由で read/write
    XcvrEeprom --> XcvrMemMap
    XcvrMemMap --> XcvrField
    XcvrApi ..> XcvrCodes : 定数解決
    XcvrApiFactory ..> XcvrApi : new
Component 役割
XcvrApi xcvr EEPROM 操作の PI 共通 interfaceget_temperature / get_transceiver_info 等を spec 別 subclass で実装
XcvrEeprom EEPROM read/write 抽象。Sfp 実装が DB read/write callable を渡す
XcvrMemMap spec ごとの field 配置offset / size / decode 方式
XcvrField 1 field の表現。Numeric / String / Bit / Code 等の subclass で decode() を持つ
XcvrCodes spec 内の固定 enum/code テーブル(SFF-8024 Identifier、CMIS Module State 等)
XcvrApiFactory EEPROM 先頭バイト(identifier)から spec を判定し XcvrApi を生成1

どう spec を選ぶか(identifier-based)

旧設計は port 番号 で parser を選ぶ実装があり、誤った memory map で読むことがあった1。新設計は:

  1. EEPROM 0x00 を読み、SFF-8024 Table 4-1 の identifier 値を取得
  2. id_mapping.pyidentifier → XcvrApi class map を参照
  3. 該当 spec の XcvrApiXcvrApiFactory がインスタンス化

vendor 固有 identifier も同様に拡張可。1 port = 1 xcvr が前提。

Vendor 拡張のディレクトリ

api/public/<spec>.py            # public spec 用 XcvrApi 実装
api/<vendorA>/custom_qsfp.py    # vendor 固有派生
mem_maps/public/<spec>.py
mem_maps/<vendorA>/model_qsfp.py
codes/public/sff8024.py
codes/public/cmis.py

vendor は api/ 下に自社 subclass を追加し、必要なら mem_maps/ で field 配置を上書きするだけで済む1

既存 SfpBase との関係

  • 既存 PI ロジックは新 PI 階層(XcvrApi 系)に移譲
  • SfpBase は xcvrd 向け top-level interface のまま、XcvrApi を内部に保持
  • SfpOptoeBase が CMIS / SFF 系を扱う多くの platform 向け共通 PD ヘルパーを提供1
class XcvrApi(object):
    def __init__(self, xcvr_eeprom): ...
    def get_temperature(self): raise NotImplementedError
    def get_transceiver_info(self): raise NotImplementedError

class Sff8436Api(XcvrApi):
    def get_temperature(self):
        return self.xcvr_eeprom.read(TEMPERATURE_FIELD)
📋 検証エビデンス: sonic-net/SONiC/doc/sfp-refactor/sfp-refactor.md#L150-L154 (sha: 49bab5b5ff0e924f1ea52b3d9db0dfa4191a7c06)

出典:

sonic-net/SONiC/doc/sfp-refactor/sfp-refactor.md#L150-L154 (sha: 49bab5b5ff0e924f1ea52b3d9db0dfa4191a7c06)

抜粋:

The correct specification abstraction needs to be selected at runtime to interpret a xcvr's memory map correctly.
This should be done by reading the first byte in the xcvr's EEPROM ...
This approach is in contrast to what's currently done with selecting parsers based on the xcvr's port number.

判断根拠: identifier-based spec 判定への切替の根拠。

In Scope / Out of Scope

Scope 内容
In SFP / QSFP / OSFP-QSFP-DD(SFF-8472 / SFF-8436 / CMIS)の基本サポート、新 spec 追加の拡張枠、vendor 拡張枠、identifier-based 自動切替
Out SFP-DD 等の他 form factor、sfpshow / xcvrd 自身の本格リファクタ、vendor 別実装本体、sonic_y_cable 統合、Coherent 400G ZR

制限事項

  • 1 port 1 xcvr 前提
  • xcvrd / sfpshow 自体の刷新は別 HLD 待ち
  • 既存 vendor は SfpBase を直接派生しており、移行期は新旧 API が並走

干渉する機能

  • xcvrd: XcvrApi 経由で transceiver 情報を取得する想定
  • media_settings.json: 同じ xcvrd 配下、xcvr 識別との関係
  • CMIS / C-CMIS for ZR: 別 HLD(cmis-and-c-cmis-support-for-zr)が CMIS 側を扱う
  • gearbox / external PHY: XcvrApi ではなく PAI 配下、別系統

関連 Topics

引用元

関連 Topics


  1. sonic-net/SONiC doc/sfp-refactor/sfp-refactor.md @ 49bab5b5ff0e924f1ea52b3d9db0dfa4191a7c06