aboutsummaryrefslogtreecommitdiffstats
path: root/common/chapters/control_if.adoc
blob: dd6938a9ebea5382255b1108f76b66697ab80fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
[[common-control-if]]
== Osmocom Control Interface

The VTY interface as described in <<vty>> is aimed at human interaction
with the respective Osmocom program.

Other programs *should not* use the VTY interface to interact with the
Osmocom software, as parsing the textual representation is cumbersome,
inefficient, and will break every time the formatting is changed by the
Osmocom developers.

Instead, the 'Control Interface' was introduced as a programmatic
interface that can be used to interact with the respective program.

=== Control Interface Protocol

The control interface protocol is a mixture of binary framing with text
based payload.

The protocol for the control interface is wrapped inside the IPA
multiplex header with the stream identifier set to IPAC_PROTO_OSMO (0xEE).

.IPA header for control protocol
[packetdiag]
----
{
	colwidth = 24
	node_height = 24

	0-15: 	Length (network byte order)
	16-23:	Stream ID (0xEE)
}
----

Inside the IPA header is a single byte of extension header with protocol
ID 0x00 which indicates the control interface.

.IPA extension header for control protocol
[packetdiag]
----
{
	colwidth = 8
	node_height = 24

	0-7: 	Protocol (0x00)
}
----

After the concatenation of the two above headers, the plain-text payload
message starts.  The format of that plain text is illustrated for each
operation in the respective message sequence chart in the chapters
below.

The fields specified below follow the following meaning:

<id>::
	A numeric identifier, uniquely identifying this particular
	operation.  `0` is not allowed.  It will be echoed back in any
	response to a particular request.
<var>::
	The name of the variable / field affected by the GET / SET /
	TRAP operation.  Which variables/fields are available is
	dependent on the specific application under control.
<val>::
	The value of the variable / field
<reason>::
	A text formatted, human-readable reason why the operation
	resulted in an error.

==== GET operation

The GET operation is performed by an external application to get a
certain value from inside the Osmocom application.

.Control Interface GET operation (successful outcome)
[mscgen]
----
msc {
	cli [label="Client"], ctrl [label="Control Interface"];

	cli => ctrl	[label="GET <id> <var>"];
	cli <= ctrl	[label="GET_REPLY <id> <var> <val>"];
}
----

.Control Interface GET operation (unsuccessful outcome)
[mscgen]
----
msc {
	cli [label="Client"], ctrl [label="Control Interface"];

	cli => ctrl	[label="GET <id> <var>"];
	cli <= ctrl	[label="ERROR <id> <reason>"];
}
----

==== SET operation

The SET operation is performed by an external application to set a value
inside the Osmocom application.

.Control Interface SET operation (successful outcome)
[mscgen]
----
msc {
	cli [label="Client"], ctrl [label="Control Interface"];

	cli => ctrl	[label="SET <id> <var> <val>"];
	cli <= ctrl	[label="SET_REPLY <id> <var> <val>"];
}
----

.Control Interface SET operation (unsuccessful outcome)
[mscgen]
----
msc {
	cli [label="Client"], ctrl [label="Control Interface"];

	cli => ctrl	[label="SET <id> <var> <val>"];
	cli <= ctrl	[label="ERROR <id> <reason>"];
}
----

==== TRAP operation

The program can at any time issue a trap.  The term is used in the
spirit of SNMP.

.Control Interface TRAP operation
[mscgen]
----
msc {
	cli [label="Client"], ctrl [label="Control Interface"];

	cli <= ctrl	[label="TRAP <var> <val>"];
}
----

[[ctrl_common_vars]]
=== Common variables

There are several variables which are common to all the programs using control
interface. They are described in the following table.

.Variables available over control interface
[options="header",width="100%",cols="20%,10%,50%,20%"]
|===
|Name|Access|Value|Comment
|counter.*|RO||Get counter value.
|rate_ctr.*|RO||Get list of rate counter groups.
|rate_ctr.IN.GN.GI.name|RO||Get value for interval IN of rate counter name which belong to group named GN with index GI.
|===

Those read-only variables allow to get value of arbitrary
counter using its name.

For example "+rate_ctr.per_hour.bsc.0.handover:timeout+" is the number of handover timeouts per hour.

Of course for that to work the program
in question have to register corresponding counter names and groups using
libosmocore functions.

In the example above, "+bsc+" is the rate counter group name and "+0+" is its index. It is possible to
obtain all the rate counters in a given group by requesting "+rate_ctr.per_sec.bsc.*+" variable.

The list of available groups can be obtained by requesting "+rate_ctr.*+" variable.

The rate counter group name have to be prefixed with interval
specification which can be any of "*per_sec*", "*per_min*", "*per_hour*", "*per_day*"
or "*abs*" for absolute value.

The old-style counters available via "+counter.*+" variables are superceeded by "+rate_ctr.abs+"
so its use is discouraged.
There might still be some applications not yet converted to rate_ctr.

=== Control Interface python examples

In the `osmo-python-tests` repository, there is an example python script
called `osmopy/osmo_ctrl.py` which implements the Osmocom
control interface protocol.

You can use this tool either stand-alone to perform control interface
operations against an Osmocom program, or you can use it as a reference
for developing your own python software talking to the control
interface.

Another implementation is in `osmopy/rate_ctr2csv.py` which will retrieve performance counters
for a given Osmocom program and output it in csv format. This can be used to periodically (using systemd timer
for example) retrieve data to build KPI and evaluate how it changes over time.

Internally it uses "+rate_ctr.*+" variable described in <<ctrl_common_var>> to get the list of counter groups
and than request all the counters in each group. Applications interested in individual metrics can request it
directly using `rate_ctr2csv.py` as an example.

==== Getting rate counters

.Example: Use `rate_ctr2csv.py` to get rate counters from OsmoBSC
----
$ ./osmopy/rate_ctr2csv.py --header
Connecting to localhost:4249...
Getting rate counter groups info...
"group","counter","absolute","second","minute","hour","day"
"e1inp.0","hdlc:abort","0","0","0","0","0"
"e1inp.0","hdlc:bad_fcs","0","0","0","0","0"
"e1inp.0","hdlc:overrun","0","0","0","0","0"
"e1inp.0","alarm","0","0","0","0","0"
"e1inp.0","removed","0","0","0","0","0"
"bsc.0","chreq:total","0","0","0","0","0"
"bsc.0","chreq:no_channel","0","0","0","0","0"
...
"msc.0","call:active","0","0","0","0","0"
"msc.0","call:complete","0","0","0","0","0"
"msc.0","call:incomplete","0","0","0","0","0"
Completed: 44 counters from 3 groups received.
----

==== Setting a value

.Example: Use `osmo_ctrl.py` to set the short network name of OsmoBSC
----
$ ./osmo_ctrl.py -d localhost -s short-name 32C3
Got message: SET_REPLY 1 short-name 32C3
----

==== Getting a value

.Example: Use `osmo_ctrl.py` to get the mnc of OsmoBSC
----
$ ./osmo_ctrl.py -d localhost -g mnc
Got message: GET_REPLY 1 mnc 262
----

==== Listening for traps

You can use `osmo_ctrl.py` to listen for traps the following way:

.Example: Using `osmo_ctrl.py` to listen for traps:
----
$ ./osmo_ctrl.py -d localhost -m
<1>
----
<1> the command will not return and wait for any TRAP messages to arrive