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), logging, performance metrics and database backend services. It also provides configuration interface for reading, watching and populating config-map changes in K8S environment.
Make sure that following tools are properly installed and configured
package main
import "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
type ExampleXapp struct {
}
func (m *ExampleXapp) Consume(rp *xapp.RMRParams) (err error) {
xapp.Logger.Debug("Message received - type=%d len=%d", rp.Mtype, rp.PayloadLen)
xapp.Sdl.Store("myKey", rp.Payload)
xapp.Rmr.Send(r)
return nil
}
func main() {
xapp.Run(ExampleXapp{})
}
git clone https://gerrit.o-ran-sc.org/r/ric-plt/xapp-frame cd xapp-frame
GO111MODULE=on GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o example-xapp examples/example-xapp.go
RMR_SEED_RT=examples/config/uta_rtg.rt ./example_xapp -f examples/config/config-file.json
Congratulations! You've just built your first xapp application.
Sets logging level to given "level". Level can be 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG
Sets the application MDC to given string. The MDC will be visible in the logs
Writes an error log. Other possible function are: Warn, Info and Debug
Injects an application callback function that is called when config change occurs
Returns the value associated with the key as a string. Other possible functions are: GetInt, GetBool and GetStringSlice
Creates a new 'Counter' vector based on the provided CounterOpts and partitioned by the given label names.
Creates a new 'Gauge' vector based on the provided CounterOpts and partitioned by the given label names.
Indicates whether RMR is ready or not
Injects a callback function that is called when RMR is ready
Allocates and return RMR message buffer
De-allocates a RMR message buffer previously allocated with 'Allocate'
Sends RMR message based on the given RMR parameters
Sends 'rts' RMR message based on the given RMR parameters
Registers a given URL and corresponding handler, which will be called when incoming request matches with the URL
Registers an inquiry URL and corresponding handler, which will be called when incoming request matches with the URL
Injects a callback function, which is called during K8s aliveness probe
Store writes the value of a key to SDL. MStore writes multiple key-value pairs atomically
Reads the value of a key from SDL. MRead reads multiple keys atomically
Setting logging level and writing to log
xapp.Logger.SetLevel(4) xapp.Logger.Info("Status inquiry ...")
Storing key-value data to SDL
xapp.Sdl.Store("myKey", payload)
Sending RMR messages
mid := Rmr.GetRicMessageId("RIC_SUB_RESP") xapp.Rmr.Send(mid, 1234, len, payload)
Injecting REST API resources (URL)
xapp.Resource.InjectRoute("/ric/v1/health/stat", statisticsHandler, "GET") Resource.InjectQueryRoute("/ric/v1/user", handler, "GET", "foo", "bar", "id", "mykey")
Metrics: registering couple of counters
metrics := []xapp.CounterOpts{ {Name: "RICIndicationsRx", Help: "The total number of RIC inidcation events received"}, {Name: "RICExampleMessageRx", Help: "The total number of RIC example messages received"}, } xapp.Metric.RegisterCounterGroup(metrics, "MyXApp") // Use curl-command to get metrics curl http://localhost:8080/ric/v1/metrics
Unit tests of xApp-framework can be run as following:
make test
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details