Tommy Carpenter | 53786ca | 2020-02-28 09:17:46 -0500 | [diff] [blame] | 1 | .. This work is licensed under a Creative Commons Attribution 4.0 International License. |
| 2 | .. SPDX-License-Identifier: CC-BY-4.0 |
| 3 | .. Copyright (C) 2020 AT&T Intellectual Property |
| 4 | |
| 5 | xapp-frame-py Overview |
| 6 | ====================== |
| 7 | |
| 8 | This library is a framework for writing Xapps in python. |
| 9 | There may or may not be many Xapps written in python; however rmr, sdl, and logging libraries all exist for python, and this framework brings them together. |
| 10 | |
Tommy Carpenter | 99a0b48 | 2020-03-03 10:21:24 -0500 | [diff] [blame^] | 11 | There are (at the time of writing) two "kinds" of Xapps one can instantiate with this framework that model "push" (RMR Xapps) and "pull" (General Xapps), as described below. |
Tommy Carpenter | 53786ca | 2020-02-28 09:17:46 -0500 | [diff] [blame] | 12 | |
| 13 | RMR Xapps |
| 14 | --------- |
| 15 | This class of Xapps are purely reactive to rmr; data is always "pushed" to it via rmr. |
| 16 | That is, every time the Xapp receives an rmr message, they do something, then wait for the next message to arrive, end never need to execute functionality at another time (if they do, use the next class). |
| 17 | This is represented by a very simple callback `consume` that is invoked every time an rmr message arrives (note, this is subject to change, with more callbacks for specific messages like `A1_POLICY_REQUEST`). |
| 18 | An analogy of this is AWS Lambda: "execute this code every time an event comes in" (the code to execute can depend on the type of event). |
| 19 | |
Tommy Carpenter | 99a0b48 | 2020-03-03 10:21:24 -0500 | [diff] [blame^] | 20 | General Xapps |
| 21 | ------------- |
Tommy Carpenter | 53786ca | 2020-02-28 09:17:46 -0500 | [diff] [blame] | 22 | In this class of Xapp the user simply provides a function that gets invoked, and typically that function has a `while (something)` in it. |
| 23 | If the function returns, the Xapp will stop. |
| 24 | In this type of Xapp, the Xapp must "pull" it's own data, typically from SDL, rmr (ie query another component for data), or other sources. |
| 25 | The framework is "lighter" in this case then the former; it sets up an SDL connection, an rmr thread, and then calls the client provided function. |
| 26 | This is to be used for Xapps that are not purely event driven. |
| 27 | |
| 28 | RMR Threading in the framework |
| 29 | ------------------------------ |
| 30 | NOTE: this is an implementation detail! |
| 31 | We expose this for transparency but most users will not have to worry about this. |
| 32 | |
| 33 | In both types of Xapp, the framework launches a seperate thread whose only job is to read from rmr and deposit all messages (and their summaries) into a thread safe queue. |
Tommy Carpenter | 99a0b48 | 2020-03-03 10:21:24 -0500 | [diff] [blame^] | 34 | When the client Xapp reads using the framework (this read is done by the framework itself in the RMR Xapp, but by the client in a general Xapp), the read is done from the queue. |
Tommy Carpenter | 53786ca | 2020-02-28 09:17:46 -0500 | [diff] [blame] | 35 | The framework is implemented this way so that a long running client function (e.g., consume) cannot block rmr reads. |
| 36 | This is important because rmr is *not* a persistent message bus, if any rmr client does not read "fast enough", messages can be lost. |
| 37 | So in this framework the client code is not in the same thread as the rmr reads, so that long running client code can never lead to lost messages. |
| 38 | |
| 39 | Examples |
| 40 | -------- |
Tommy Carpenter | 99a0b48 | 2020-03-03 10:21:24 -0500 | [diff] [blame^] | 41 | There are two examples in the `examples` directory; `ping` which is a general Xapp, and `pong` which is an RMR Xapp. |
| 42 | Ping sends a message, pong receives the message and use rts to reply. |
| 43 | Ping then reads it's own mailbox and demonstrates other functionality. |
| 44 | The highlight to note is that `pong` is purely reactive, it only does anything when a message is received. |
| 45 | Ping uses a general that also happens to read it's rmr mailbox inside. |
Tommy Carpenter | 53786ca | 2020-02-28 09:17:46 -0500 | [diff] [blame] | 46 | |
| 47 | Current gaps |
| 48 | ------------ |
| 49 | The following are known gaps or potential enhancements at the time of writing. |
| 50 | :: |
| 51 | |
| 52 | * a logger has to be provided to the xapp |
| 53 | * the ability to specify more callacks per message type? |
| 54 | |