星期日, 9月 29, 2019

SNMP MIBs for Voice Gateway

Management Information Base (MIB) 物件的規則、定義與語法是由 IETF 的 SMI 管理資訊結構來指定結構與描述資料物件的方法。

MIB-II (RFC1213) 每一項網管物件(Object),又稱為網路狀態資訊,均有一個唯一的物件識別值(Object Identifier,簡稱OID)
MIB for SNMP:RFC3418
RMON MIBs (Remote Network Monitoring, Statistsics, History, Alarm, Hosts Group)
RFC2465 MIB for IPv6: Textual Conventions and General Group
RFC2466 MIB for IPv6: ICMPv6 Group
RFC2452 IPv6 MIB for TCP
RFC2454 IPv6 MIB for UDP

RFC4780 MIB for SIP

FXS Port 狀態
  • IF-MIB::ifDescr.37 = STRING: Foreign Exchange Station 2/0/0
  • CISCO-VOICE-ANALOG-IF-MIB::cvaIfFXSCfgSignalType.37 = INTEGER: fxsLoopStart(1)
  • IF-MIB::ifAdminStatus.37 = INTEGER: up(1)
  • IF-MIB::ifOperStatus.37 = INTEGER: up(1)
  • CISCO-VOICE-ANALOG-IF-MIB::cvaIfFXSHookStatus.37 = INTEGER: offHook(2)
  • CISCO-VOICE-IF-MIB::cvIfCfgEchoCancelEnable.37 = INTEGER: true(1)
FXS 呼叫狀態
  • IF-MIB::ifDescr.37 = STRING: Foreign Exchange Station 2/0/0
  • CISCO-VOICE-COMMON-DIAL-CONTROL-MIB::cvCommonDcCallActiveCoderTypeRate. 1102966.1 = INTEGER: ietfg729r8000(25)
  • CISCO-VOICE-COMMON-DIAL-CONTROL-MIB::cvCommonDcCallActiveVADEnable. 1102966.1 = INTEGER: true(1)

DIGIUM-MIB
ASTERISK-MIB
https://github.com/librenms/librenms/issues/8015q

AddPac Enterprise MIBs
  • VOIP-GLOBAL–MIB: Manages the Global setting and status.
  • VOICE-IF-MIB: Manages the voice related parameters for both voice analog and ISDN interfaces.
  • VOIP-POTS-PEER-MIB: Manages the POTS dial peer related parameters for POTS.
  • VOIP-VOIP-PEER-MIB: Manages the VOIP dial peer related parameters for VOIP.
  • VOIP-MISC-MIB: Manages the Translation rule Table, Codec Class Table, User Class Table, Alternate Gatekeeper Table, Number Expansion Table.
  • VOIP-STAT-MIB: Shows call statistics of current active calls and call history

星期六, 9月 28, 2019

ubus

ubus (OpenWrt micro bus architecture)

包含 daemon ubusd、函式庫 libubus、和一些額外的 helpers.

ubusd 是 ubus 的心臟,提供界面給其它 daemons 註冊和送訊息,採用 Unix sockets 和 TLV (type-length-value) 訊息。

libubus 簡化使用 ubus 的軟體開發。

每個 daemon 在特定 namespace 註冊一些路徑,每個路徑可提供多個有任意數目引數的 procedure,procedures 可用訊息回應。

http://git.openwrt.org/project/ubus.git

工具指令

指令 ubus 和註冊到 ubus 的服務互動,用來檢查註冊的 namespaces,以及撰寫 shell 指令搞。使用 user-friendly 的 JSON 格式呼叫 procedure 和回應。

用法:ubus [選項] 命令 [參數...]

選項:
-s <socket>:設定要連結的 unix socket,沒指定預設是「/var/run/ubus.sock」
-t <timeout>:設定指令逾時秒數
-S:使用簡化輸出 (指令稿用)
-v:More verbose 輸出
-m <type>:(for monitor): include a specific message type (可多個)
-M <r|t>:(for monitor): only capture received or transmitted traffic

命令:
list [<path>]:列出已註冊的 namespace,-v 的話包含 procedures 和其 argument signatures 也列出。
call <path> <method> [<message>]:呼叫 namespace 的 procedure,可含以 JSON 表示的引數
listen [<path>...]:Listen for events
send <type> [<message>]:送事件通知。
wait_for <object> [<object>...]:等候 multiple objects to appear on ubus
monitor:Monitor ubus traffic

範例
`ubus listen &`:建立一個 listening socket 來觀察新進的事件。
ubus
ubus list
ubus -v list system
ubus call system info

透過 HTTP 存取 ubus

uhttpd 有 ubus plugin -- uhttpd-mod-ubus 讓 ...

在 lua 使用 ubus

Namespaces & Procedures

使用 ubus 常見的專案。

netifd

rpcd

for file, iwinfo, session, uci

Example code snippets

ubusd

ubusd 內部是一個 uloop,監視預設 bind 到「/var/run/ubus.sock」的 fd 所發生的事件,

參考

  1. https://wiki.openwrt.org/doc/techref/ubus
  2. 用ubus實現Inter-Process Communication
  3. ubus_invoke()使用介紹
http://wiki.openwrt.org/doc/techref/netifd

延伸閱讀:http://data.pavlix.net/installfest/2014/openwrt-software.pdf

星期日, 9月 22, 2019

DMIPS

直接看處理器每秒能執行多少百萬個指令 (MIPS, Million Instructions per second) 可衡量處理器的效能,但不同處理器的每個指令,能做多少「工作」並不同。

例如一個處理器內建有除法指令,所以一個指令就能做完一個除法。另一個處理器沒有除法指令,就需要用好幾個指令才能完成一個除法。所以以單位時間執行多少指令評估效能並不公平,效能應該要以單位時間執行多少「工作」來評估較公平。但如何定義標準的「工作」呢?

1984 年 Reinhold P. Weicker 從用 FORTRAN、PL/1、SAL、ALGOL 68、和 Pascal 寫的各種程式收集程式常見的構造特徵 (呼叫、間接指標、數值指定等),統計他們的處理器使用情況,在 Ada 上寫成精心設計的簡單程式 Dhrystone 來模擬,作為「工作」的效能基準。Rick Richardson 轉成 Unix C 版本 (Dhrystone 版本 1.1) 促成普遍使用。Dhrystone 基準不含浮點運算,逐漸成為代表通用 (整數) 處理器的性能指標。Dhrystone score 計算程式每秒跑幾次,除以 1757 是常見的 DMIPS (Dhrystone MIPS) 表示方式。1757 是 VAX 11/780 (名義上 1 MIPS) 的 Dhrystone score。DMIPS 除以 CPU frequency 是 DMIPS/MHz,用來比較處理器跑在不同速率。

Dhrystone 是當時另一個含有浮點運算的效能基準 Whetstone 的雙關語 (pun)。

問題:
  • 1988 年修改成版本 2.1 ...
  • 程式小和資料少。程式小可整個放進現代處理器的指令快取,而沒測到指令 fetch。
  • slight over-representation of string operations
  • 不代表實際程式
  • 可對 Dhrystone 編譯最佳化造成失真。
其它效能基準
  • EEMBC、HINT、Stream、Bytemark、Cachebench (for the memory subsystem)、TTCP (for TCP/IP)。
參考
  1. https://en.wikipedia.org/wiki/Dhrystone
  2. http://www.roylongbottom.org.uk/dhrystone%20results.htm
  3. https://www.nxp.com/docs/en/application-note/AN2354.pdf
  4. MFLOPS (Million Floating-point operations per second):每秒執行多少百萬浮點運算。

OpenWrt

OpenWrt 是一個 Linux 發行版本和開發環境。

特點
  • Linux 發行版本 (distribution)
  • 支援許多硬體
  • 跨平台編譯環境
  • 許多套件支援各種功能
  • 許多使用輕量版軟體提供相當的功能 (所以快?)
  • 套件安裝
  • 不含 non-free 驅動程式,以至於有些硬體無法運作。(dd-wrt、Tomato 則有 non-free 的部份)

  • OpenWrt 一開始是在 2004 年基於 Linksys 無線路由器 WRT54G 的 GPL 原始碼。
  • OpenWrt 開發環境基於大量修改過的 Buildroot。
  • 2016 年分出 LEDE,2018 年併回 OpenWrt。
軟體
  • 原始碼:git clone https://git.openwrt.org/openwrt/openwrt.git
  • 開機:preinit
  • uClibc
  • 系統軟體:procd、ubus、netifd
  • 設定管理:uci
  • busybox
  • shell
  • json
  • 套件管理:opkg
  • wget 由 uclinet-fetch 取代
  • telnetd 由無密碼的 dropbear 取代
  • syslog => ubox's logd and logread
  • https://wiki.openwrt.org/doc/techref/netifd 有個表格跟一般 Linux Distribution 及 Android 等比較系統軟體架構
作業系統架構比較
OpenWrtBuildrootDesktop
C 標準函式庫uClibc?glibc
initprocd?systemd
網路設定netifd?NetworkManager
套件管理opkg?apt, ...
原始碼
  • 下載:http, ftp, git, ...。壓縮檔或目錄
  • 不是壓縮檔的話產生壓縮檔:方便帶著走
  • 解壓縮
  • patch
  • configure
  • compile
  • install
參考
  • https://openwrt.org/
  • dd-wrt、Tomato、Gargoyle
  • OpenWrt 開發框架較複雜而不好修改簡化。Buildroot 關聯性較低、比較沒那麼自動化。

星期日, 9月 15, 2019

AMBA Bus System

ARM 的 Advanced Microcontroller Bus Architecture (AMBA) 是一個 SoC 內各種功能區塊互連的規範,開放且免費的。

1996 AMBA 1
  • Advanced System Bus (ASB):32 位元 synchronous pipelined bus,放置 CPU 和記憶體。
  • Advanced Peripheral Bus (APB):適合低速控制存取,設計簡單,適合其它週邊。APB 透過 bridge 作 buffering 接到 ASB,可減少 ASB 負載。
1999 AMBA 2
  • Advanced High-performance Bus (AHB):single clock-edge protocol,廣泛用在 ARM7、ARM9 和 Cortex-M。
  • Advanced System Bus (ASB)
  • Advanced Peripheral Bus (APB2 or APB)
2003 AMBA 3
  • Advanced eXtensible Interface (AXI3 or AXI v1.0):互連達到更高效能,廣泛用在 Cortex-A9 處理器。
  • Advanced High-performance Bus Lite (AHB-Lite v1.0)
  • Advanced Peripheral Bus (APB3 v1.0)
  • Advanced Trace Bus (ATB v1.0):CoreSight on-chip debug and trace solution 的一部分。
2010 & 2011 AMBA 4
  • AXI Coherency Extensions (ACE):廣泛用在 Cortex-A7 和 Cortex-A15。
  • AXI Coherency Extensions Lite (ACE-Lite)
  • Advanced Extensible Interface 4 (AXI4)
  • Advanced Extensible Interface 4 Lite (AXI4-Lite)
  • Advanced Extensible Interface 4 Stream (AXI4-Stream v1.0)
  • Advanced Trace Bus (ATB v1.1)
  • Advanced Peripheral Bus (APB4 v2.0)
2013 AMBA 5
  • AXI5, AXI5-Lite and ACE5 Protocol Specification
  • Advanced High-performance Bus (AHB5, AHB-Lite)
  • Coherent Hub Interface (CHI):重新設計 high-speed transport layer and features designed 來減少 congestion。
  • Distributed Translation Interface (DTI)
  • Generic Flash Bus (GFB)

AHB (Advanced High-performance Bus)

AHB 在 AMBA 2 首次介紹,後續加大匯流排寬度到 64/128/256/512/1024 bit)。AHB 的 transaction 包含 address phase 和 data phase,不含 wait states 只有兩個 bus-cycles。

AHB-Lite 簡化 AHB 的設計給單一 master 使用。

APB (Advanced Peripheral Bus)

APB 為低速控制存取設計,如週邊的暫存器。APB 類似 AHB 有 address 和 data 階段,但大大減少需要的訊號數目,沒有 bursts 等。APB 透過 bridge 作 buffering 接到 AHB,減少 AHB 負載。

AXI (Advanced eXtensible Interface)

ATB (Advanced Trace Bus)

CHI (Coherent Hub Interface)

DTI (Distributed Translation Interface)

GFB (Generic Flash Bus)

參考

https://en.wikipedia.org/wiki/Advanced_Microcontroller_Bus_Architecture
http://twins.ee.nctu.edu.tw/courses/embedlab_11/lecture/AMBA.pdf

星期六, 9月 07, 2019

處理器記憶體空間

實體記憶體 (Physical Memory) 是處理器的系統定址空間。如果處理器有 24 條位址線,可定指到 16MB 空間。硬體設計時,通常把 RAM 放在底部,快閃記憶體放在頂端,中間的範圍分配給各種週邊。
Flash

週邊

RAM

高階處理器有記憶體管理單元 (Memory Management Unit, MMU),創造出虛擬記憶體空間 (Virtual Memory Space),對應轉換到實體記憶體,讓作業系統可對記憶體空間進行存取控制。

星期五, 9月 06, 2019

CPU alignment restriction

記憶體對齊限制

處理器大多都可以定址到每個  bye,但通常設計成存取以 word 為倍數的邊界上的 word 最有效率。例如 word 是 32-bit,存取位址 4 的倍數為開始的 32-bit 最有效率。

如果直接存取位址不為 4 的倍數開始的 32-bit,結果可能不是你想要的,或產生 alignment fault。結果要對的話需要分兩次存取,再位移合併成需要的 word。

參考
Computer Organization and Design, The hardware/software interface by David A. Patterson and Jonh L. Hennessy
http://opass.logdown.com/posts/743054-about-memory-alignment