libosmo-sigtran 2.2.0 Osmocom SIGTRAN library

ss7_as.h
Go to the documentation of this file.
1#pragma once
2
3#include "config.h"
4
5#include <stdint.h>
6#include <osmocom/core/linuxlist.h>
7#include <osmocom/core/fsm.h>
8#include <osmocom/core/hashtable.h>
9#include <osmocom/core/msgb.h>
10#include <osmocom/core/tdef.h>
11#include <osmocom/netif/stream.h>
12
13#include <osmocom/sigtran/osmo_ss7.h>
14
15#include "ss7_internal.h"
16#include "xua_msg.h"
17
18/***********************************************************************
19 * SS7 Application Server
20 ***********************************************************************/
21
22 struct osmo_ss7_instance;
23 struct osmo_ss7_asp;
24 struct osmo_mtp_transfer_param;
25 struct xua_msg;
26
27 enum osmo_ss7_as_patch_sccp_mode {
28 OSMO_SS7_PATCH_NONE, /* no patching of SCCP */
29 OSMO_SS7_PATCH_BOTH, /* patch both OPC and DPC into SCCP addresses */
30};
31
32 enum ss7_as_ctr {
33 SS7_AS_CTR_RX_MSU_DISCARD,
34 SS7_AS_CTR_RX_MSU_TOTAL,
35 SS7_AS_CTR_RX_MSU_SLS_0,
36 SS7_AS_CTR_RX_MSU_SLS_1,
37 SS7_AS_CTR_RX_MSU_SLS_2,
38 SS7_AS_CTR_RX_MSU_SLS_3,
39 SS7_AS_CTR_RX_MSU_SLS_4,
40 SS7_AS_CTR_RX_MSU_SLS_5,
41 SS7_AS_CTR_RX_MSU_SLS_6,
42 SS7_AS_CTR_RX_MSU_SLS_7,
43 SS7_AS_CTR_RX_MSU_SLS_8,
44 SS7_AS_CTR_RX_MSU_SLS_9,
45 SS7_AS_CTR_RX_MSU_SLS_10,
46 SS7_AS_CTR_RX_MSU_SLS_11,
47 SS7_AS_CTR_RX_MSU_SLS_12,
48 SS7_AS_CTR_RX_MSU_SLS_13,
49 SS7_AS_CTR_RX_MSU_SLS_14,
50 SS7_AS_CTR_RX_MSU_SLS_15,
51 SS7_AS_CTR_TX_MSU_TOTAL,
52 SS7_AS_CTR_TX_MSU_SLS_0,
53 SS7_AS_CTR_TX_MSU_SLS_1,
54 SS7_AS_CTR_TX_MSU_SLS_2,
55 SS7_AS_CTR_TX_MSU_SLS_3,
56 SS7_AS_CTR_TX_MSU_SLS_4,
57 SS7_AS_CTR_TX_MSU_SLS_5,
58 SS7_AS_CTR_TX_MSU_SLS_6,
59 SS7_AS_CTR_TX_MSU_SLS_7,
60 SS7_AS_CTR_TX_MSU_SLS_8,
61 SS7_AS_CTR_TX_MSU_SLS_9,
62 SS7_AS_CTR_TX_MSU_SLS_10,
63 SS7_AS_CTR_TX_MSU_SLS_11,
64 SS7_AS_CTR_TX_MSU_SLS_12,
65 SS7_AS_CTR_TX_MSU_SLS_13,
66 SS7_AS_CTR_TX_MSU_SLS_14,
67 SS7_AS_CTR_TX_MSU_SLS_15,
68#ifdef WITH_TCAP_LOADSHARING
69 SS7_AS_CTR_RX_TCAP_DECODED,
70 SS7_AS_CTR_RX_TCAP_FAILED,
71 SS7_AS_CTR_TCAP_ASP_SELECTED,
72 SS7_AS_CTR_TCAP_ASP_FALLBACK,
73 SS7_AS_CTR_TCAP_ASP_FAILED,
74#endif /* WITH_TCAP_LOADSHARING */
75};
76
77#define NUM_AS_EXT_SLS 128
78 typedef uint8_t as_ext_sls_t; /* range: 0-127, 7 bit */
79 struct osmo_ss7_as_esls_entry {
80 /* ITU Q.704 4.2.1: "normal signallink link" */
81 struct osmo_ss7_asp *normal_asp;
82 /* ITU Q.704 4.2.1: "alternative signallink link" */
83 struct osmo_ss7_asp *alt_asp;
84};
85
86 struct osmo_ss7_as {
88 struct llist_head list;
89 struct osmo_ss7_instance *inst;
90
92 struct osmo_fsm_inst *fi;
93
95 bool rkm_dyn_allocated;
96
98 bool simple_client_allocated;
99
101 struct rate_ctr_group *ctrg;
102
103 /* ASP loadshare: */
104 struct osmo_ss7_as_esls_entry aesls_table[NUM_AS_EXT_SLS];
105
106#ifdef WITH_TCAP_LOADSHARING
107 struct {
108 /* optimisation: true if tid_ranges contains PCs (not only wildcards) */
109 bool contains_pc;
110 /* optimisation: true if tid_ranges contains SSNs (not only wildcards (0)) */
111 bool contains_ssn;
112 DECLARE_HASHTABLE(tid_ranges, 10);
113 /* gargabe collector timer */
114 struct osmo_timer_list gc_timer;
115 /* TODO: the hash tables size might not be optimal */
116 DECLARE_HASHTABLE(trans_track_own, 10);
117 DECLARE_HASHTABLE(trans_track_peer, 10);
118 } tcap;
119#endif /* WITH_TCAP_LOADSHARING */
120
121 struct {
122 char *name;
123 char *description;
124 enum osmo_ss7_asp_protocol proto;
125 struct osmo_ss7_routing_key routing_key;
126 enum osmo_ss7_as_traffic_mode mode;
127 /* traffic mode was configured by VTY / config file */
128 bool mode_set_by_vty;
129 /* traffic mode was configured by RKM (routing key management) or first ASPAC */
130 bool mode_set_by_peer;
131 uint32_t recovery_timeout_msec;
132 uint8_t qos_class;
133 struct {
134 bool opc_enabled;
135 bool dpc_enabled;
136 uint32_t opc;
137 uint32_t dpc;
138 enum osmo_ss7_as_patch_sccp_mode sccp_mode;
139 } pc_override;
140
141 struct osmo_ss7_asp *asps[16];
142 /* used for load-sharing traffic mode (round robin implementation) */
143 uint8_t last_asp_idx_assigned;
144 uint8_t last_asp_idx_sent;
145
146 struct {
147 /* How many bits from ITU SLS field (starting from least-significant-bit)
148 * to skip for routing decisions.
149 * range 0-3, defaults to 0, which means take all 4 bits. */
150 uint8_t sls_shift;
151 /* Whether to generate a extended-SLS with OPC information, see opc_shift below. */
152 bool opc_sls;
153 /* How many bits from ITU OPC field (starting from least-significant-bit)
154 * to skip for routing decisions (always takes 12 bits).
155 * range 0-2, defaults to 0, which means take least significant 12 bits. */
156 uint8_t opc_shift;
157#ifdef WITH_TCAP_LOADSHARING
158 /* Should we do load-sharing based on tcap ids? */
159 struct {
160 bool enabled;
161 unsigned int timeout_s;
162 } tcap;
163#endif /* WITH_TCAP_LOADSHARING */
164 } loadshare;
165 } cfg;
166};
167 struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name,
168 enum osmo_ss7_asp_protocol proto);
169 struct osmo_ss7_asp *ss7_as_select_asp(struct osmo_ss7_as *as, const struct xua_msg *xua);
170
171 unsigned int osmo_ss7_as_count_asp(const struct osmo_ss7_as *as);
172 int ss7_as_add_asp(struct osmo_ss7_as *as, struct osmo_ss7_asp *asp);
173 int ss7_as_del_asp(struct osmo_ss7_as *as, struct osmo_ss7_asp *asp);
174 int ss7_as_get_local_role(const struct osmo_ss7_as *as);
175 void ss7_as_loadshare_binding_table_reset(struct osmo_ss7_as *as);
176
177#define LOGPAS(as, subsys, level, fmt, args ...) \
178 _LOGSS7((as)->inst, subsys, level, "AS(%s) " fmt, (as)->cfg.name, ## args)
osmo_ss7.h
osmo_ss7_asp_protocol
osmo_ss7_asp_protocol
Definition: osmo_ss7.h:157
osmo_ss7_as_traffic_mode
osmo_ss7_as_traffic_mode
Definition: osmo_ss7.h:183
xua_msg.h
osmo_ss7_as_patch_sccp_mode
osmo_ss7_as_patch_sccp_mode
Definition: ss7_as.h:27
OSMO_SS7_PATCH_BOTH
@ OSMO_SS7_PATCH_BOTH
Definition: ss7_as.h:29
OSMO_SS7_PATCH_NONE
@ OSMO_SS7_PATCH_NONE
Definition: ss7_as.h:28
ss7_as_loadshare_binding_table_reset
void ss7_as_loadshare_binding_table_reset(struct osmo_ss7_as *as)
Definition: ss7_as.c:437
as_ext_sls_t
uint8_t as_ext_sls_t
Definition: ss7_as.h:78
ss7_as_get_local_role
int ss7_as_get_local_role(const struct osmo_ss7_as *as)
Definition: ss7_as.c:333
NUM_AS_EXT_SLS
#define NUM_AS_EXT_SLS
Definition: ss7_as.h:77
ss7_as_add_asp
int ss7_as_add_asp(struct osmo_ss7_as *as, struct osmo_ss7_asp *asp)
Add given ASP to given AS.
Definition: ss7_as.c:177
ss7_as_alloc
struct osmo_ss7_as * ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name, enum osmo_ss7_asp_protocol proto)
Allocate an Application Server.
Definition: ss7_as.c:125
ss7_as_select_asp
struct osmo_ss7_asp * ss7_as_select_asp(struct osmo_ss7_as *as, const struct xua_msg *xua)
Select an AS to transmit a message, according to AS configuration and ASP availability.
Definition: ss7_as.c:574
ss7_as_ctr
ss7_as_ctr
Definition: ss7_as.h:32
SS7_AS_CTR_TX_MSU_SLS_8
@ SS7_AS_CTR_TX_MSU_SLS_8
Definition: ss7_as.h:60
SS7_AS_CTR_TX_MSU_SLS_15
@ SS7_AS_CTR_TX_MSU_SLS_15
Definition: ss7_as.h:67
SS7_AS_CTR_RX_MSU_SLS_10
@ SS7_AS_CTR_RX_MSU_SLS_10
Definition: ss7_as.h:45
SS7_AS_CTR_RX_MSU_TOTAL
@ SS7_AS_CTR_RX_MSU_TOTAL
Definition: ss7_as.h:34
SS7_AS_CTR_TX_MSU_SLS_14
@ SS7_AS_CTR_TX_MSU_SLS_14
Definition: ss7_as.h:66
SS7_AS_CTR_TX_MSU_SLS_7
@ SS7_AS_CTR_TX_MSU_SLS_7
Definition: ss7_as.h:59
SS7_AS_CTR_RX_MSU_SLS_15
@ SS7_AS_CTR_RX_MSU_SLS_15
Definition: ss7_as.h:50
SS7_AS_CTR_RX_MSU_SLS_1
@ SS7_AS_CTR_RX_MSU_SLS_1
Definition: ss7_as.h:36
SS7_AS_CTR_TX_MSU_SLS_5
@ SS7_AS_CTR_TX_MSU_SLS_5
Definition: ss7_as.h:57
SS7_AS_CTR_RX_MSU_SLS_2
@ SS7_AS_CTR_RX_MSU_SLS_2
Definition: ss7_as.h:37
SS7_AS_CTR_TX_MSU_SLS_3
@ SS7_AS_CTR_TX_MSU_SLS_3
Definition: ss7_as.h:55
SS7_AS_CTR_RX_MSU_SLS_5
@ SS7_AS_CTR_RX_MSU_SLS_5
Definition: ss7_as.h:40
SS7_AS_CTR_TX_MSU_SLS_10
@ SS7_AS_CTR_TX_MSU_SLS_10
Definition: ss7_as.h:62
SS7_AS_CTR_RX_MSU_SLS_8
@ SS7_AS_CTR_RX_MSU_SLS_8
Definition: ss7_as.h:43
SS7_AS_CTR_TX_MSU_SLS_12
@ SS7_AS_CTR_TX_MSU_SLS_12
Definition: ss7_as.h:64
SS7_AS_CTR_RX_MSU_SLS_4
@ SS7_AS_CTR_RX_MSU_SLS_4
Definition: ss7_as.h:39
SS7_AS_CTR_TX_MSU_SLS_9
@ SS7_AS_CTR_TX_MSU_SLS_9
Definition: ss7_as.h:61
SS7_AS_CTR_TX_MSU_SLS_2
@ SS7_AS_CTR_TX_MSU_SLS_2
Definition: ss7_as.h:54
SS7_AS_CTR_TX_MSU_SLS_0
@ SS7_AS_CTR_TX_MSU_SLS_0
Definition: ss7_as.h:52
SS7_AS_CTR_TX_MSU_TOTAL
@ SS7_AS_CTR_TX_MSU_TOTAL
Definition: ss7_as.h:51
SS7_AS_CTR_RX_MSU_SLS_7
@ SS7_AS_CTR_RX_MSU_SLS_7
Definition: ss7_as.h:42
SS7_AS_CTR_RX_MSU_DISCARD
@ SS7_AS_CTR_RX_MSU_DISCARD
Definition: ss7_as.h:33
SS7_AS_CTR_TX_MSU_SLS_11
@ SS7_AS_CTR_TX_MSU_SLS_11
Definition: ss7_as.h:63
SS7_AS_CTR_TX_MSU_SLS_6
@ SS7_AS_CTR_TX_MSU_SLS_6
Definition: ss7_as.h:58
SS7_AS_CTR_RX_MSU_SLS_6
@ SS7_AS_CTR_RX_MSU_SLS_6
Definition: ss7_as.h:41
SS7_AS_CTR_RX_MSU_SLS_14
@ SS7_AS_CTR_RX_MSU_SLS_14
Definition: ss7_as.h:49
SS7_AS_CTR_RX_MSU_SLS_9
@ SS7_AS_CTR_RX_MSU_SLS_9
Definition: ss7_as.h:44
SS7_AS_CTR_TX_MSU_SLS_13
@ SS7_AS_CTR_TX_MSU_SLS_13
Definition: ss7_as.h:65
SS7_AS_CTR_RX_MSU_SLS_13
@ SS7_AS_CTR_RX_MSU_SLS_13
Definition: ss7_as.h:48
SS7_AS_CTR_RX_MSU_SLS_12
@ SS7_AS_CTR_RX_MSU_SLS_12
Definition: ss7_as.h:47
SS7_AS_CTR_TX_MSU_SLS_1
@ SS7_AS_CTR_TX_MSU_SLS_1
Definition: ss7_as.h:53
SS7_AS_CTR_RX_MSU_SLS_3
@ SS7_AS_CTR_RX_MSU_SLS_3
Definition: ss7_as.h:38
SS7_AS_CTR_RX_MSU_SLS_11
@ SS7_AS_CTR_RX_MSU_SLS_11
Definition: ss7_as.h:46
SS7_AS_CTR_RX_MSU_SLS_0
@ SS7_AS_CTR_RX_MSU_SLS_0
Definition: ss7_as.h:35
SS7_AS_CTR_TX_MSU_SLS_4
@ SS7_AS_CTR_TX_MSU_SLS_4
Definition: ss7_as.h:56
osmo_ss7_as_count_asp
unsigned int osmo_ss7_as_count_asp(const struct osmo_ss7_as *as)
Determine amount of ASPs associated to an AS.
Definition: ss7_as.c:319
ss7_as_del_asp
int ss7_as_del_asp(struct osmo_ss7_as *as, struct osmo_ss7_asp *asp)
Delete given ASP from given AS.
Definition: ss7_as.c:222
ss7_internal.h
osmo_mtp_transfer_param
Definition: mtp_sap.h:42
osmo_ss7_as_esls_entry
Definition: ss7_as.h:79
osmo_ss7_as_esls_entry::normal_asp
struct osmo_ss7_asp * normal_asp
Definition: ss7_as.h:81
osmo_ss7_as_esls_entry::alt_asp
struct osmo_ss7_asp * alt_asp
Definition: ss7_as.h:83
osmo_ss7_as
Definition: ss7_as.h:86
osmo_ss7_as::routing_key
struct osmo_ss7_routing_key routing_key
Definition: ss7_as.h:125
osmo_ss7_as::opc_shift
uint8_t opc_shift
Definition: ss7_as.h:156
osmo_ss7_as::sls_shift
uint8_t sls_shift
Definition: ss7_as.h:150
osmo_ss7_as::recovery_timeout_msec
uint32_t recovery_timeout_msec
Definition: ss7_as.h:131
osmo_ss7_as::aesls_table
struct osmo_ss7_as_esls_entry aesls_table[NUM_AS_EXT_SLS]
Definition: ss7_as.h:104
osmo_ss7_as::opc_enabled
bool opc_enabled
Definition: ss7_as.h:134
osmo_ss7_as::list
struct llist_head list
entry in 'ref osmo_ss7_instance.as_list
Definition: ss7_as.h:88
osmo_ss7_as::last_asp_idx_assigned
uint8_t last_asp_idx_assigned
Definition: ss7_as.h:143
osmo_ss7_as::description
char * description
Definition: ss7_as.h:123
osmo_ss7_as::rkm_dyn_allocated
bool rkm_dyn_allocated
Were we dynamically allocated by RKM?
Definition: ss7_as.h:95
osmo_ss7_as::loadshare
struct osmo_ss7_as::@23::@25 loadshare
osmo_ss7_as::ctrg
struct rate_ctr_group * ctrg
Rate Counter Group.
Definition: ss7_as.h:101
osmo_ss7_as::asps
struct osmo_ss7_asp * asps[16]
Definition: ss7_as.h:141
osmo_ss7_as::last_asp_idx_sent
uint8_t last_asp_idx_sent
Definition: ss7_as.h:144
osmo_ss7_as::name
char * name
Definition: ss7_as.h:122
osmo_ss7_as::opc
uint32_t opc
Definition: ss7_as.h:136
osmo_ss7_as::mode_set_by_vty
bool mode_set_by_vty
Definition: ss7_as.h:128
osmo_ss7_as::fi
struct osmo_fsm_inst * fi
AS FSM.
Definition: ss7_as.h:92
osmo_ss7_as::simple_client_allocated
bool simple_client_allocated
Were we allocated by "simple client" support?
Definition: ss7_as.h:98
osmo_ss7_as::dpc
uint32_t dpc
Definition: ss7_as.h:137
osmo_ss7_as::opc_sls
bool opc_sls
Definition: ss7_as.h:152
osmo_ss7_as::mode
enum osmo_ss7_as_traffic_mode mode
Definition: ss7_as.h:126
osmo_ss7_as::proto
enum osmo_ss7_asp_protocol proto
Definition: ss7_as.h:124
osmo_ss7_as::sccp_mode
enum osmo_ss7_as_patch_sccp_mode sccp_mode
Definition: ss7_as.h:138
osmo_ss7_as::inst
struct osmo_ss7_instance * inst
Definition: ss7_as.h:89
osmo_ss7_as::cfg
struct osmo_ss7_as::@23 cfg
osmo_ss7_as::mode_set_by_peer
bool mode_set_by_peer
Definition: ss7_as.h:130
osmo_ss7_as::qos_class
uint8_t qos_class
Definition: ss7_as.h:132
osmo_ss7_as::pc_override
struct osmo_ss7_as::@23::@24 pc_override
osmo_ss7_as::dpc_enabled
bool dpc_enabled
Definition: ss7_as.h:135
osmo_ss7_asp
Definition: ss7_asp.h:45
osmo_ss7_instance
Definition: ss7_instance.h:45
osmo_ss7_routing_key
Definition: osmo_ss7.h:142
xua_msg
Definition: xua_msg.h:31