-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathopen5gs_dbconf.sh
More file actions
executable file
·302 lines (277 loc) · 7.42 KB
/
Copy pathopen5gs_dbconf.sh
File metadata and controls
executable file
·302 lines (277 loc) · 7.42 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
version=0.9.0
display_help() {
echo "open5gs_dbconf.sh: Open5GS Database Configuration Tool ($version)"
echo "COMMANDS:" >&2
echo " add {imsi [ip] key opc [apn]}: adds a user to the database with default values"
echo " remove {imsi}: removes a user from the database"
echo " reset: WIPES OUT the database and restores it to an empty default"
echo " static_ip {imsi ip4}: adds a static IP assignment to an already-existing user"
echo " static_ip6 {imsi ip6}: adds a static IPv6 assignment to an already-existing user"
echo " type {imsi type}: changes the PDN-Type of the first PDN: 0 = IPv4, 1 = IPv6, 2 = IPv4v6, 3 = v4 OR v6"
echo " help: displays this message and exits"
echo " speed {imsi dl_value dl_unit ul_value ul_unit}: dl_unit 0=bps 1=Kbps 2=Mbps 3=Gbps 4=Tbps "
echo " default values are as follows: APN \"internet\", dl_bw/ul_bw 1 Gbps, PGW address is 127.0.0.3, IPv4 only"
}
if [ "$#" -lt 1 ]; then
display_help
exit 1
fi
if [ "$1" = "help" ]; then
display_help
exit 1
fi
if [ "$1" = "add" ]; then
if [ "$#" -eq 4 ]; then
IMSI=$2
KI=$3
OPC=$4
mongo --eval "db.subscribers.update(
{\"imsi\" : \"$IMSI\"},
{ \$setOnInsert: {
\"imsi\" : \"$IMSI\",
\"slice\":[ {
\"_id\" : new ObjectId(),
\"sst\" : NumberInt(1),
\"default_indicator\": true,
\"session\": [ {
\"name\" : \"$APN\",
\"type\" : NumberInt(1),
\"qos\" : {
\"index\" : NumberInt(9),
\"arp\" : {
\"priority_level\" : NumberInt(8),
\"pre_emption_vulnerability\" : NumberInt(2),
\"pre_emption_capability\" : NumberInt(1)
}
},
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"pcc_rule\" : [ ]
} ]
} ],
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"subscribed_rau_tau_timer\" : NumberInt(12),
\"network_access_mode\" : NumberInt(0),
\"subscriber_status\" : NumberInt(0),
\"access_restriction_data\" : NumberInt(32),
\"security\" : {
\"k\" : \"$KI\",
\"amf\" : \"8000\",
\"op\" : null,
\"opc\" : \"$OPC\"
}
} },
upsert=true);" open5gs
exit 0
fi
if [ "$#" -eq 5 ]; then
IMSI=$2
IP=$3
KI=$4
OPC=$5
mongo --eval "db.subscribers.update(
{\"imsi\" : \"$IMSI\"},
{ \$setOnInsert: {
\"imsi\" : \"$IMSI\",
\"slice\":[ {
\"_id\" : new ObjectId(),
\"sst\" : NumberInt(1),
\"default_indicator\": true,
\"session\": [ {
\"name\" : \"internet\",
\"type\" : NumberInt(1),
\"qos\" : {
\"index\" : NumberInt(9),
\"arp\" : {
\"priority_level\" : NumberInt(8),
\"pre_emption_vulnerability\" : NumberInt(2),
\"pre_emption_capability\" : NumberInt(1)
}
},
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"ue\" : {
\"addr\" : \"$IP\"
},
\"pcc_rule\" : [ ]
} ]
} ],
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"subscribed_rau_tau_timer\" : NumberInt(12),
\"network_access_mode\" : NumberInt(0),
\"subscriber_status\" : NumberInt(0),
\"access_restriction_data\" : NumberInt(32),
\"security\" : {
\"k\" : \"$KI\",
\"amf\" : \"8000\",
\"op\" : null,
\"opc\" : \"$OPC\"
}
} },
upsert=true);" open5gs
exit 0
fi
if [ "$#" -eq 6 ]; then
IMSI=$2
IP=$3
KI=$4
OPC=$5
APN=$6
mongo --eval "db.subscribers.update(
{\"imsi\" : \"$IMSI\"},
{ \$setOnInsert: {
\"imsi\" : \"$IMSI\",
\"slice\":[ {
\"_id\" : new ObjectId(),
\"sst\" : NumberInt(1),
\"default_indicator\": true,
\"session\": [ {
\"name\" : \"$APN\",
\"type\" : NumberInt(1),
\"qos\" : {
\"index\" : NumberInt(9),
\"arp\" : {
\"priority_level\" : NumberInt(8),
\"pre_emption_vulnerability\" : NumberInt(2),
\"pre_emption_capability\" : NumberInt(1)
}
},
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"ue\" : {
\"addr\" : \"$IP\"
},
\"pcc_rule\" : [ ]
} ]
} ],
\"ambr\" : {
\"downlink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
},
\"uplink\" : {
\"value\": NumberInt(1000000000),
\"unit\": NumberInt(0)
}
},
\"subscribed_rau_tau_timer\" : NumberInt(12),
\"network_access_mode\" : NumberInt(0),
\"subscriber_status\" : NumberInt(0),
\"access_restriction_data\" : NumberInt(32),
\"security\" : {
\"k\" : \"$KI\",
\"amf\" : \"8000\",
\"op\" : null,
\"opc\" : \"$OPC\"
}
} },
upsert=true);" open5gs
exit 0
fi
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh add imsi [ip] key opc [apn]\""
exit 1
fi
if [ "$1" = "remove" ]; then
if [ "$#" -ne 2 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh remove imsi\""
exit 1
fi
IMSI=$2
mongo --eval "db.subscribers.remove({\"imsi\": \"$IMSI\"});" open5gs
exit 0
fi
if [ "$1" = "reset" ]; then
if [ "$#" -ne 1 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh reset\""
exit 1
fi
mongo --eval "db.subscribers.remove({});" open5gs
exit 0
fi
if [ "$1" = "static_ip" ]; then
if [ "$#" -ne 3 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh static_ip imsi ip\""
exit 1
fi
IMSI=$2
IP=$3
mongo --eval "db.subscribers.update({\"imsi\": \"$IMSI\"},{\$set: { \"pdn.0.ue.addr\": \"$IP\" }});" open5gs
exit 0
fi
if [ "$1" = "static_ip6" ]; then
if [ "$#" -ne 3 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh static_ip6 imsi ip\""
exit 1
fi
IMSI=$2
IP=$3
mongo --eval "db.subscribers.update({\"imsi\": \"$IMSI\"},{\$set: { \"pdn.0.ue.addr6\": \"$IP\" }});" open5gs
exit 0
fi
if [ "$1" = "type" ]; then
if [ "$#" -ne 3 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh type imsi type\""
exit 1
fi
IMSI=$2
TYPE=$3
mongo --eval "db.subscribers.update({\"imsi\": \"$IMSI\"},{\$set: { \"pdn.0.type\": NumberInt($TYPE) }});" open5gs
exit 0
fi
if [ "$1" = "speed" ]; then
if [ "$#" -ne 6 ]; then
echo "dbconf.sh: incorrect number of args, format is \"open5gs_dbconf.sh speed imsi dl_value dl_unit_value ul_value ul_unit_value \""
exit 1
fi
IMSI=$2
DL_VALUE=$3
DL_UNIT=$4
UL_VALUE=$5
UL_UNIT=$6
mongo --eval "db.subscribers.update({\"imsi\": \"$IMSI\"},{\$set : { \"ambr\": {\"downlink\": {\"value\": NumberInt($DL_VALUE), \"unit\": NumberInt($DL_UNIT)}, \"uplink\": {\"value\": NumberInt($UL_VALUE),\"unit\": ($UL_UNIT) } } }});" open5gs
exit 0
fi
display_help