blob: 7408a589a9055d5a56777090495839ad4fa3edea [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6import logging
7import subprocess
8
9from configuration.service_configs import (
10 load_override_config,
11 load_service_config,
12 save_override_config,
13)
14from orc8r.protos import magmad_pb2
15
16STATELESS_SERVICE_CONFIGS = [
17 ("mme", "use_stateless", True),
18 ("mobilityd", "persist_to_redis", True),
19 ("pipelined", "clean_restart", False),
20 ("pipelined", "redis_enabled", True),
21 ("sessiond", "support_stateless", True),
22]
23
24
25def check_stateless_agw():
26 num_stateful = 0
27 for service, config, value in STATELESS_SERVICE_CONFIGS:
28 if (
29 _check_stateless_service_config(service, config, value)
30 == magmad_pb2.CheckStatelessResponse.STATEFUL
31 ):
32 num_stateful += 1
33
34 if num_stateful == 0:
35 res = magmad_pb2.CheckStatelessResponse.STATELESS
36 elif num_stateful == len(STATELESS_SERVICE_CONFIGS):
37 res = magmad_pb2.CheckStatelessResponse.STATEFUL
38 else:
39 res = magmad_pb2.CheckStatelessResponse.CORRUPT
40
41 logging.debug(
42 "Check returning %s", magmad_pb2.CheckStatelessResponse.AGWMode.Name(
43 res,
44 ),
45 )
46 return res
47
48
49def enable_stateless_agw():
50 if check_stateless_agw() == magmad_pb2.CheckStatelessResponse.STATELESS:
51 logging.info("Nothing to enable, AGW is stateless")
52 for service, config, value in STATELESS_SERVICE_CONFIGS:
53 cfg = load_override_config(service) or {}
54 cfg[config] = value
55 save_override_config(service, cfg)
56
57 # restart Sctpd so that eNB connections are reset and local state cleared
58 _restart_sctpd()
59
60
61def disable_stateless_agw():
62 if check_stateless_agw() == magmad_pb2.CheckStatelessResponse.STATEFUL:
63 logging.info("Nothing to disable, AGW is stateful")
64 for service, config, value in STATELESS_SERVICE_CONFIGS:
65 cfg = load_override_config(service) or {}
66 cfg[config] = not value
67 save_override_config(service, cfg)
68
69 # restart Sctpd so that eNB connections are reset and local state cleared
70 _restart_sctpd()
71
72
73def _check_stateless_service_config(service, config_name, config_value):
74 service_config = load_service_config(service)
75 if service_config.get(config_name) == config_value:
76 logging.info("STATELESS\t%s -> %s", service, config_name)
77 return magmad_pb2.CheckStatelessResponse.STATELESS
78
79 logging.info("STATEFUL\t%s -> %s", service, config_name)
80 return magmad_pb2.CheckStatelessResponse.STATEFUL
81
82
83def _restart_sctpd():
84 logging.info("Restarting sctpd")
85 subprocess.call("service sctpd restart".split())