4 **xapp-frame** is a simple framework for rapid development of RIC xapps, and supports various services essential for RIC xapps such as RESTful APIs, RMR (RIC Message Routing), database backend services and watching and populating config-map changes in K8S environment.
8 ![Architecture](assets/xappframe-arch.png)
10 ## Features and Components
13 * Health check/probes (readiness and liveliness)
14 * Reading and watching config-map
18 * Encoding and decoding of commonly used RIC ASN.1 messages
22 Make sure that following tools are properly installed and configured
23 * GO (golang) development and runtime tools
24 * MDCLOG (ricplt/com/log)
25 * RMR (ricplt/lib/rmr)
26 * DBAAS (redis-server)
30 #### Below is a simple example xapp. For more information, see the sample code in the xapp/examples folder:
34 import "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
36 type ExampleXapp struct {
39 func (m *ExampleXapp) Consume(rp *xapp.RMRParams) (err error) {
40 xapp.Logger.Debug("Message received - type=%d len=%d", rp.Mtype, rp.PayloadLen)
42 xapp.Sdl.Store("myKey", rp.Payload)
48 xapp.Run(ExampleXapp{})
51 #### Building and running the example xapp
53 git clone https://gerrit.o-ran-sc.org/r/ric-plt/xapp-frame
56 #### To generate an executable binary for our sample xApp application, run the following command:
58 GO111MODULE=on GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o example-xapp examples/example-xapp.go
60 #### To run the generated executable binary locally, run the following command:
62 RMR_SEED_RT=config/uta_rtg.rt ./example-xapp -f config/config-file.yaml
64 Congratulations! You've just built your first **xapp** application.
70 Sets logging level to given "level". Level can be 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG
72 * SetMdc(key string, value string)
74 Sets the application MDC to given string. The MDC will be visible in the logs
76 * Error(pattern string, args ...interface{}).
78 Writes an error log. Other possible function are: Warn, Info and Debug
82 * AddConfigChangeListener(f ConfigChangeCB)
84 Injects an application callback function that is called when config change occurs
86 * GetString(key string) string
88 Returns the value associated with the key as a string. Other possible functions are: GetInt, GetBool and GetStringSlice
92 * RegisterCounterGroup(opts []CounterOpts, subsytem string) (c map[string]Counter)
94 Creates a new 'Counter' vector based on the provided CounterOpts and partitioned by the given label names.
96 * RegisterGaugeGroup(opts []CounterOpts, subsytem string) (c map[string]Gauge)
98 Creates a new 'Gauge' vector based on the provided CounterOpts and partitioned by the given label names.
104 Indicates whether RMR is ready or not
106 * SetReadyCB(cb ReadyCB, params interface{})
108 Injects a callback function that is called when RMR is ready
110 * Allocate() *C.rmr_mbuf_t
112 Allocates and return RMR message buffer
114 * Free(mbuf *C.rmr_mbuf_t)
116 De-allocates a RMR message buffer previously allocated with 'Allocate'
118 * SendMsg(params *RMRParams)
120 Sends RMR message based on the given RMR parameters
122 * SendRts(params *RMRParams)
124 Sends 'rts' RMR message based on the given RMR parameters
128 * InjectRoute(url string, handler http.HandlerFunc, method string) *mux.Route
130 Registers a given URL and corresponding handler, which will be called when incoming request matches with the URL
132 * InjectQueryRoute(url string, h http.HandlerFunc, m string, q ...string) *mux.Route
134 Registers an inquiry URL and corresponding handler, which will be called when incoming request matches with the URL
136 * InjectStatusCb(f StatusCb)
138 Injects a callback function, which is called during K8s aliveness probe
142 * Store(key string, value interface{}) (err error)
144 Store writes the value of a key to SDL. MStore writes multiple key-value pairs atomically
146 * Read(key string) (value map[string]interface{}, err error)
148 Reads the value of a key from SDL. MRead reads multiple keys atomically
151 #### API Usage and Examples
152 * Setting logging level and writing to log
154 xapp.Logger.SetLevel(4)
155 xapp.Logger.Info("Status inquiry ...")
157 * Storing key-value data to SDL
159 xapp.Sdl.Store("myKey", payload)
161 * Sending RMR messages
163 mid := Rmr.GetRicMessageId("RIC_SUB_RESP")
164 xapp.Rmr.Send(mid, 1234, len, payload)
166 * Injecting REST API resources (URL)
168 xapp.Resource.InjectRoute("/ric/v1/health/stat", statisticsHandler, "GET")
169 Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
177 This project is licensed under the Apache License 2.0 - see the [LICENSE.md](LICENSE.md) file for details