第二章:介绍OpenSIPS
本章将帮你了解OpenSIPS。最重要的事情是澄清相关SIP生态系统:OpenSIPS擅长什么,OpenSIPS能做什么,它不能做什么,OpenSIPS在哪里可以回答你。我们描述OpenSIPS设计。这次理解OpenSIPS的基础,在使用前从外到内去看。
本章,我们涵盖以下主题:
- OpenSIPS是什么
- 如何获取OpenSIPS相关知识
- 什么时候用OpenSIPS,它们不同的使用场景
- OpenSIPS内部设计和结构
理解OpenSIPS
OpenSIPS是一个开源的,遵循GPL,多用途的SIP服务器,含有大量的SIP相关功能,例如SIP Registrar,SIP proxy/router, Instant Messaging server, Presence server, SIP Redirect server, SIP load balancer or SIP dispatcher, SIP Back-to-Back user agent, Call Queuing System, SIP IP gateway, SIP media controller, SIP application server等等
OpenSIPS定义了三大主要能力:
- 性能:能处理较大吞吐量,在一台重型服务器上的单个OpenSIPS实例CPS达到60,000, 1,500,000万呼叫,5,000,000注册用户,1,000,000 TCP连接
- 多功能:提供了SIP协议, SQL或者NoSQL数据库操作,AAA 集成, 路由算法(quality,prefix, load-based routing, dialplans),管理和控制(events和外部命令)等相关功能及特性的160模块。
- 扩展性:提供路由语言,简单强大的脚本语言(shell-like)允许编程方式来控制SIP traffic
OpenSIPS作为SIP服务器主要处理SIP traffic.OpenSIPS没有处理媒体能力(RTP).虽然如此,一些外部扩展允许OpenSIPS可控制RTP traffic,例如控制外部媒体转发(RTPproxy, MediaProxy和RTPEngine)或者外部转码器(Sangoma D1 transcoding cards)。
用两个词就可以很好定义OpenSIPS: SIP 和 Engine:
- OpenSIPS为SIP设计:从该视角,OpenSIPS涵盖了提供了不同的transport协议,例如SIP(UDP, TCP, TLS, SCTP, WebSockets等等),并且实现了RFC兼容的SIP栈来处理SIP包(parsing, building和changing).
- OpenSIPS处理:OpenSIPS拥有强大可扩展引擎来高效、快速,自定义方式处理SIP traffic,可实现任意类型路由逻辑。
OpenSIPS的功能和性能使他可以成为SIP平台核心,无论什么服务类型,无论什么大小,无论什么需求。
OpenSIPS 能力
OpenSIPS原有意构建成Class4 SIP switch, 但由于这些年的发展, OpenSIPS超出了原始目标,开始提供了Class5特性。它不饿能提供完整的Class5特性是因为受限于SIP 信令相关特性(call forwarding, call transfer, call pickup等)。这里的限制由于OpenSIPS不处理媒体,所有不能处理媒体相关特性。你可以查看OpenSIPS能力如下表:
Transport-level capabilities:
UDP / TCP / TLS / SCTP / WebSockets support IPv4 and IPv6 Multihomed with interface exchange IP blacklists
Endpoint-oriented capabilities:
SIP registration NAT traversal (STUN, TURN, SIP pinging) Digest authentication (against SQL, noSQL, AAA, LDAP) Trunking or IP authentication Complex call accounting/CDRs Multidomain support User profiles (groups, attributes, flags)
Class 4 routing:
SIP aliases, DID aliasing Speed dialling Call Processing Language (CPL) interpreter Dialplan (text and regular expression-based) Traffic dispatching (with multiple dispatching algorithms) Prefix-based routing to multiple carriers (with failovers) Load balancing ENUM-based routing Redirect server, redirect UAC Geolocation-based routing OSP integration
Class 5 routing
Generic SIP B2B capabilities Inbound call center with call queuing UAC registration UAC authentication UAC mangling (From, To, Call-ID, CSeq) Call managing (call forward, call hunting, call pickup, redirect) White/Black list for inbound and outbound calls
SIP SIMPLE
SIP Presence BLF, SCA, BLA, MWI XCAP support RLS SIP messaging and SIP chatting SIP to XMPP gatewaying Offline messages storing SMS gateway (AT and SMPP)
Media/RTP-related capabilities
Media relaying (RTPProxy, MediaProxy, RTPEngine) Media transcoding (Sangoma D1 cards) Codec manipulation
SIP security
Fraud detection and prevention Flood detection (at IP level) SIP traffic validation QoS control Parallel calls and calling rate limitation
SIP-related capabilities
Dialog support (monitor, probing, termination) SIP DNS lookup (A, SRV, NAPTR) DNS-based failover SIP compression SIP Identity SIP Session Timer (SST)
OpenSIPS scripting capabilities
Processing benchmarking Script tracing Custom data caching (from script) Execution of external scripts/applications LUA, Perl, and Python scripting support Mathematical operation support SIP traffic capturing (tracing and Homer integration)
OpenSIPS management and integration
Event interface—subscribing and delivering events to external entities Built-in HTTP server Management interface (FIFO, XMLRPC, JSON, Datagram, HTTP) SNMP support Internal statistics
Backend support
SQL—Berkeley, Flat File, HTTP, MySQL, Postgres, Oracle, Perl VDB, Text, and Unix ODBC AAA—Radius and Diameter NoSQL—Cassandra, MongoDB, Redis, CouchBase, and Memcached LDAP REST client
注意:OpenSIPS内部没有媒体处理能力,但是它可以控制外部媒体引擎
OpenSIPS项目概览
OpenSIPS是一个活跃的开源项目,遵循GNU General Public License version2 (GPLv2)。
OpenSIPS通过daemon-like形式运行在类Unix平台——BSD家庭,Linux, Solaris, OSX等等。主要面向是Linux环境。
OpenSIPS使用C语言开发,还使用其他语言构建辅助工具,如Shell, Perl或者Python(用来安装创建DB结构,CLI命令等)。OpenSIPS相当活跃,每6到12月会发送一个主要版本,1到3月发次要版本。基本一些信息在:
- OpenSIPS项目托管在GitHub: https://github.com/OpenSIPS
- 代码在: https://github.com/OpenSIPS/opensips
- 使用issue来提交bug:https://github.com/OpenSIPS/opensips/issues
- OpenSIPS由OpenSIPS Software Foundation(OSF)管理,单依赖众多国际群体。
OSF的目标是提供开源框架,鼓励共享者贡献代码到OpenSIPS。OSF主要专注构建项目镜像,组织OpenSIPS相关事件,管理市场。OSF没参与任何项目开发决定。
社区主要项目开发和进程。探索,代码开发,测试,报告,修正,信息传递。
每月在OpenSIPS IRC channel举行会员,涉及到当前项目状态,制定未来规划。
OpenSIPS使用场景
丰富的模块以及路由脚本功能使得OpenSIPS可以几乎可以适应任何SIP相关场景。
简单到复杂的路由交换,从ingress到egress,OpenSIPS都可以高效处理需求,并且容易扩展。
本章并没有打算列出所有的OpenSIPS使用场景,仅仅展示了一些流行的使用场景。我们从经典的SIP网络作为示例,通常包含了ingress, 一个core和egres.我们将探讨每一部分看看OpenSIPS能为它们做什么。
ingress
SIP网络中,ingress组件坐落在SIP endpoints之间(registering SIP phones, SIP PBX和SIP trunks)和SIP core platform.
由于它的定位,ingress组件需要应对两个主要问题:
- 可伸缩性:ingress SIP 服务器从终端处理大量呼叫
- 安全: SIP服务器直接与endpoints通信,需要处理攻击,floods和其他安全问题
通常,ingress组件也称为Session Border Controller(SBC)。通常理解SBC仅处理安全和NAT穿越,这种SBC属于一般型。一般坐落在网络边缘,处理进出网络流量。以下图示展示了OpenSIPS作为SIP router工作机制:
作为SBC(ingress 组件),OpenSIPS要同时处理以下职责:
- 网络桥接
- NAT穿越
- 协议转换
- Flood检测
- IP过滤
在SIP层上,OpenSIPS作为SBC要处理以下事项:
- SIP认证
- Call aware
- 网络拓扑隐藏
- Traffic过滤
- 媒体处理
- SIP追踪
- Data replication
在路由层上:
- 终端验证
- Traffic shaping
- Dialplan
- Dispatching/Load-balancing
- Custom routing
有很多基于PBX的SIP服务器,例如FreeSwitch, Asterisk和Yate.这些主要是提供rich services给端用户,但是面临伸缩性的问题。例如PBX服务对于处理用户和ative calls有很大限制,通常的解决的方式是部署多个相同服务器,但是为了要管理这些pool/cluster服务器,就必须要有个前段服务器来处理并分布traffic
OpenSIPS能力就非常适合做这项事情。
core
SIP平台的核心组件通常称为应用,telephony,media,或者feature服务器。
有几个服务类型,例如residentail(end user-oriented), 托管PBX,或者enterprise(company-oriented), trunking (traffic exchange),或者origination/termination(inbound或者outbound gateways)
OpenSIPS非常适合构建例如Residentail和Hosted PBX服务器。
提供了如下面向用户特性:
- Endpoints management
- DID management
- Advanced call routing(forwardm filter, DND, and star codec)
- Presence和messging
- Class5 calling