def get_context(): """ Provide context to pass to Jinja2 for templating. """ context = {} cfg = load_service_config("dnsd") try: mconfig = load_service_mconfig('dnsd', DnsD()) except LoadConfigError as err: logging.warning("Error! Using default config because: %s", err) mconfig = DnsD() ip = get_ip_from_if_cidr(cfg['enodeb_interface']) if int(ip.split('/')[1]) < 16: logging.fatal("Large interface netmasks hang dnsmasq, consider using a " "netmask in range /16 - /24") raise Exception("Interface %s netmask is to large." % cfg['enodeb_interface']) dhcp_block_size = cfg['dhcp_block_size'] available_hosts = list(ipaddress.IPv4Interface(ip).network.hosts()) context['dhcp_server_enabled'] = mconfig.dhcp_server_enabled if dhcp_block_size < len(available_hosts): context['dhcp_range'] = { "lower": str(available_hosts[-dhcp_block_size]), "upper": str(available_hosts[-1]), } else: logging.fatal("Not enough available hosts to allocate a DHCP block of \ %d addresses." % (dhcp_block_size)) context['addresses'] = _get_addresses(cfg, mconfig) return context
def get_context(): """ Provide context to pass to Jinja2 for templating. """ context = {} cfg = load_service_config("dnsd") try: mconfig = load_service_mconfig("dnsd") except LoadConfigError as err: logging.warn("Error! Using default config because: %s", err) mconfig = DnsD() ip = get_ip_from_if_cidr(cfg['enodeb_interface']) dhcp_block_size = cfg['dhcp_block_size'] available_hosts = list(ipaddress.IPv4Interface(ip).network.hosts()) if dhcp_block_size < len(available_hosts): context['dhcp_range'] = { "lower": str(available_hosts[-dhcp_block_size]), "upper": str(available_hosts[-1]), } else: logging.fatal("Not enough available hosts to allocate a DHCP block of \ %d addresses." % (dhcp_block_size)) context['addresses'] = _get_addresses(cfg, mconfig) return context
def _get_iface_ip(service, iface_config): """ Get the interface IP given its name. """ iface_name = get_service_config_value(service, iface_config, "") return get_ip_from_if_cidr(iface_name)
def _get_context(): """ Create the context which has the interface IP and the OAI log level to use. """ mme_service_config = load_service_mconfig('mme', MME()) nat = _get_enable_nat(mme_service_config) if nat: iface_name = get_service_config_value( 'spgw', 'sgw_s5s8_up_iface_name', '', ) else: iface_name = get_service_config_value( 'spgw', 'sgw_s5s8_up_iface_name_non_nat', '', ) context = { "mme_s11_ip": _get_iface_ip("mme", "s11_iface_name"), "sgw_s11_ip": _get_iface_ip("spgw", "s11_iface_name"), 'sgw_s5s8_up_iface_name': iface_name, "remote_sgw_ip": get_service_config_value("mme", "remote_sgw_ip", ""), "s1ap_ip": _get_iface_ip("mme", "s1ap_iface_name"), "s1ap_ipv6": _get_iface_ipv6("mme", "s1ap_iface_name"), "s1ap_ipv6_enabled": get_service_config_value( "mme", "s1ap_ipv6_enabled", default=False, ), "oai_log_level": _get_oai_log_level(), "ipv4_dns": _get_primary_dns_ip(mme_service_config, "dns_iface_name"), "ipv4_sec_dns": _get_secondary_dns_ip(mme_service_config), "ipv4_p_cscf_address": _get_ipv4_pcscf_ip(mme_service_config), "ipv6_dns": _get_ipv6_dns_ip(mme_service_config), "ipv6_p_cscf_address": _get_ipv6_pcscf_ip(mme_service_config), "identity": _get_identity(), "relay_enabled": _get_relay_enabled(mme_service_config), "non_eps_service_control": _get_non_eps_service_control(mme_service_config, ), "csfb_mcc": _get_csfb_mcc(mme_service_config), "csfb_mnc": _get_csfb_mnc(mme_service_config), "lac": _get_lac(mme_service_config), "use_stateless": get_service_config_value("mme", "use_stateless", ""), "attached_enodeb_tacs": _get_attached_enodeb_tacs(mme_service_config), 'enable_nat': nat, "federated_mode_map": _get_federated_mode_map(mme_service_config), "restricted_plmns": _get_restricted_plmns(mme_service_config), "restricted_imeis": _get_restricted_imeis(mme_service_config), "congestion_control_enabled": _get_congestion_control_config(mme_service_config, ), "service_area_map": _get_service_area_maps(mme_service_config), "accept_combined_attach_tau_wo_csfb": get_service_config_value("mme", "accept_combined_attach_tau_wo_csfb", ""), "sentry_config": mme_service_config.sentry_config, "enable5g_features": _get_converged_core_config(mme_service_config), "amf_default_slice_service_type": _get_default_slice_service_type_config(mme_service_config, ), "amf_default_slice_differentiator": _get_default_slice_differentiator_type_config(mme_service_config, ), "amf_name": _get_amf_name_config(mme_service_config), "amf_region_id": _get_amf_region_id(mme_service_config), "amf_set_id": _get_amf_set_id(mme_service_config), "amf_pointer": _get_amf_pointer(mme_service_config), "default_dnn": _get_default_dnn_config(mme_service_config), "auth_retry_max_count": _get_default_auth_retry_count(), "auth_retry_interval": _get_default_auth_timer_expire_msec(), } context["s1u_ip"] = mme_service_config.ipv4_sgw_s1u_addr or _get_iface_ip( "spgw", "s1u_iface_name", ) context[ "s1u_ipv6"] = mme_service_config.ipv6_sgw_s1u_addr or _get_iface_ipv6( "spgw", "s1u_iface_name", ) try: sgw_s5s8_up_ip = get_ip_from_if_cidr(iface_name, IpPreference.IPV4_ONLY) except ValueError: # ignore the error to avoid MME crash logging.warning("Could not read IP of interface: %s", iface_name) sgw_s5s8_up_ip = "127.0.0.1/8" context["sgw_s5s8_up_ip"] = sgw_s5s8_up_ip # set ovs params for key in ( "ovs_bridge_name", "ovs_gtp_port_number", "ovs_mtr_port_number", "ovs_internal_sampling_port_number", "ovs_internal_sampling_fwd_tbl", "ovs_uplink_port_number", "ovs_uplink_mac", "pipelined_managed_tbl0", "ebpf_enabled", ): context[key] = get_service_config_value("spgw", key, "") context["enable_apn_correction"] = get_service_config_value( "mme", "enable_apn_correction", "", ) context["apn_correction_map_list"] = _get_apn_correction_map_list( mme_service_config, ) return context
def _get_context(): """ Create the context which has the interface IP and the OAI log level to use. """ mme_service_config = load_service_mconfig('mme', MME()) nat = _get_enable_nat(mme_service_config) if nat: iface_name = get_service_config_value( 'spgw', 'sgw_s5s8_up_iface_name', '', ) else: iface_name = get_service_config_value( 'spgw', 'sgw_s5s8_up_iface_name_non_nat', '', ) context = { "mme_s11_ip": _get_iface_ip("mme", "s11_iface_name"), "sgw_s11_ip": _get_iface_ip("spgw", "s11_iface_name"), 'sgw_s5s8_up_ip': get_ip_from_if_cidr(iface_name), 'sgw_s5s8_up_iface_name': iface_name, "remote_sgw_ip": get_service_config_value("mme", "remote_sgw_ip", ""), "s1ap_ip": _get_iface_ip("mme", "s1ap_iface_name"), "oai_log_level": _get_oai_log_level(), "ipv4_dns": _get_primary_dns_ip(mme_service_config, "dns_iface_name"), "ipv4_sec_dns": _get_secondary_dns_ip(mme_service_config), "ipv4_p_cscf_address": _get_ipv4_pcscf_ip(mme_service_config), "ipv6_dns": _get_ipv6_dns_ip(mme_service_config), "ipv6_p_cscf_address": _get_ipv6_pcscf_ip(mme_service_config), "identity": _get_identity(), "relay_enabled": _get_relay_enabled(mme_service_config), "non_eps_service_control": _get_non_eps_service_control(mme_service_config), "csfb_mcc": _get_csfb_mcc(mme_service_config), "csfb_mnc": _get_csfb_mnc(mme_service_config), "lac": _get_lac(mme_service_config), "use_stateless": get_service_config_value("mme", "use_stateless", ""), "attached_enodeb_tacs": _get_attached_enodeb_tacs(mme_service_config), 'enable_nat': nat, "federated_mode_map": _get_federated_mode_map(mme_service_config), "restricted_plmns": _get_restricted_plmns(mme_service_config), "restricted_imeis": _get_restricted_imeis(mme_service_config), } context["s1u_ip"] = mme_service_config.ipv4_sgw_s1u_addr or _get_iface_ip( "spgw", "s1u_iface_name") # set ovs params for key in ( "ovs_bridge_name", "ovs_gtp_port_number", "ovs_mtr_port_number", "ovs_internal_sampling_port_number", "ovs_internal_sampling_fwd_tbl", "ovs_uplink_port_number", "ovs_uplink_mac", "pipelined_managed_tbl0", ): context[key] = get_service_config_value("spgw", key, "") context["enable_apn_correction"] = get_service_config_value( "mme", "enable_apn_correction", "") context["apn_correction_map_list"] = _get_apn_correction_map_list( mme_service_config) return context