opensips - an event-driven sip routing engine - fosdem · 2017-08-21 · liviu chircu - 4th feb...

27
Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Upload: others

Post on 28-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Liviu Chircu- 4th Feb 2017 -

OpenSIPS - an event-drivenSIP routing engine

Page 2: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Outline

● Architecture timeline

● Event subscribe-notify

● Usage scenarios

● OpenSIPS scripts

● Conclusions

2

Page 3: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Architecture timeline

Page 4: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Step 1: “Linear” architecture

OpenSIPS 1.X

4

TimeSIP packet arrivals

Thread 1

Thread 2

CPU bound

I/O bound

Page 5: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Step 2: “Async” architecture

OpenSIPS 2.1, 2.2

5

TimeSIP packet arrivals

Thread 1

CPU bound

I/O bound

Page 6: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Limitation: Processing is still linear!

Advanced SIP scenarios:

● Push Notifications● FreeSWITCH ESL Events (e.g. DTMF)● Call Pick-up

What’s missing:

● Communication & data exchange between different processing contexts

6

Page 7: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Step 3: “Event-driven” architecture

7

TimeSIP packet arrivals

Thread 1

Thread 2

SIP msg A

SIP msg B

wait(event X) resume()

event X

Page 8: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Step 3: “Event-driven” architecture

8

TimeSIP packet arrival

Thread 1

SIP msg A 4xx SIP replywait(event X) resume()

timeout!

Page 9: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Step 3: “Event-driven” architecture

9

TimeSIP packet arrivals

Thread 1

Thread 2

SIP msg A

SIP msg B

trigger(handler, eventX)

eventX

handler

Page 10: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Event subscribe/notify

Page 11: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Event Definition

● Triggered by actions / data processing during runtime● Events hold key/value attributes● OpenSIPS has a list of predefined events

11

Page 12: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Subscribe

● interested OpenSIPS workers subscribe to events● event subscriptions may contain filtering attributes

12

Page 13: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Notify

● Notification == event● Events are generated during runtime● They are dispatched to all relevant subscribers● Events are parametrized (e.g. DTMF digit, REG Contact)

13

Page 14: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Usage scenarios

Page 15: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

15

INVITE bob

1xxPN

REGISTER

INVITE bob

Page 16: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

Current way

1. incoming call for “bob”

2. send PN to “bob”’s mobile device

3. async sleep (N)

4. call(“bob”) if registered(“bob”) else goto 3.

16

Page 17: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

Current way (limitations)

1. performance killer

2. inflexible, cannot handle complex scenarios

● parallel forking (desk + mobile devices)● multiple gateways

17

Page 18: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

In 2.3:

1. incoming call for “bob”

2. subscribe(“REGISTER”, “aor=bob”, “reg_handler”)

3. send PN to “bob”’s mobile device

4. fork calls to existing registrations

...

route [reg_handler] { fork_call(“$event(contact)”); }

18

Page 19: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

DTMF-based fax/voicemail detection

In 2.3:

1. incoming call for “bob”

2. subscribe(“DTMF”, “callid=$ci”, “dtmf_handler”)

3. send call to “bob”

...

route [dtmf_handler] { hangup() if $event(digit) != 2 }

19

Page 20: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

OpenSIPS Script

Page 21: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

subscribe("REGISTER", "aor=bob", "reg_handler");

route(SEND_APN);

if (lookup("location"))

t_relay();

halt();

21

Page 22: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

route [SEND_APN] {

rest_append_hf("Authorization: key=CONSOLE_API_KEY");

rest_append_hf("Content-Type: \"application/json\"");

rest_post("https://android.googleapis.com/gcm/send",

"{ \"data\" : {\"foo\": \"bar\"},

\"registration_ids\":[\"REGISTRATION_ID\"] }"...);

}22

Page 23: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Push Notifications

route [reg_handler] {

route(CHECK_IF_MOBILE, "$event(contact)");

t_relay();

}

23

Page 24: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

Conclusions

Page 25: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

Conclusions

Event-driven approach:

● powerful & easy to use● complex scenarios with simple script● lightning fast!

25

Page 26: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

- FOSDEM ‘17 -Liviu Chircu - OpenSIPS Project

OpenSIPS 2.3 - “integration”

● SIP capturing - Homer/SIPCapture● billing - CGRateS● software PBX - FreeSWITCH● middleware - RabbitMQ

26

Page 27: OpenSIPS - an event-driven SIP routing engine - FOSDEM · 2017-08-21 · Liviu Chircu - 4th Feb 2017 - OpenSIPS - an event-driven SIP routing engine

● Liviu Chircu○ OpenSIPS Project: www.opensips.org○ [email protected]

Take-Away Message

Under development!