Commit c582c928 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

software/ors-amarisoft: Add fixed-ips option for core network

This option will give fixed IP to each SIM card.
parent cd05ce47
......@@ -16,7 +16,7 @@
[template]
filename = instance.cfg
md5sum = 9b7ced53c256fa5b60c679c75ed03727
md5sum = 521c6ca69d512b318d48af4ba3271951
[amarisoft-stats.jinja2.py]
_update_hash_filename_ = amarisoft-stats.jinja2.py
......@@ -64,7 +64,7 @@ md5sum = 2d7558e4799818a5546850f735fbb399
[template-core-network]
_update_hash_filename_ = instance-core-network.jinja2.cfg
md5sum = ed92a5762932220e0337d6c254f18024
md5sum = 406580f0f28e22589edcbe8eee75783d
[template-ue-lte]
_update_hash_filename_ = instance-ue-lte.jinja2.cfg
......@@ -80,7 +80,7 @@ md5sum = c5f581ba01654b2aec46000abf8d0e35
[ue_db.jinja2.cfg]
filename = config/ue_db.jinja2.cfg
md5sum = d5afe12aa3e2e93d30455da51540cfdb
md5sum = eedea5eb1f0b7b9bd7834e0c15ed9555
[enb.jinja2.cfg]
filename = config/enb.jinja2.cfg
......@@ -96,7 +96,7 @@ md5sum = 003bf8098175415c975a10c102df6b8c
[mme.jinja2.cfg]
filename = config/mme.jinja2.cfg
md5sum = 3d7833ddba3242cedcd74c7db52390c6
md5sum = 713504eb854d5ca1067ca566cf70341b
[dnsmasq.jinja2.cfg]
filename = config/dnsmasq.jinja2.cfg
......
......@@ -71,7 +71,6 @@
first_ip_addr: "{{ netaddr.IPAddress(netaddr.IPNetwork(slap_configuration.get('tun-ipv4-network', '')).first) + 2 }}",
last_ip_addr: "{{ netaddr.IPAddress(netaddr.IPNetwork(slap_configuration.get('tun-ipv4-network', '')).last) - 1 }}",
{% endif %}
ip_addr_shift: 2,
p_cscf_addr: ["{{ slap_configuration.get('tun-ipv4-addr', '') }}"],
erabs: [
......
......@@ -13,6 +13,13 @@ ue_db: [
K: "{{ slave.get('k', '') }}",
impu: "{{ slave.get('impu', '') }}",
impi: "{{ slave.get('impi', '') }}",
{%- if "ip" in slave %}
pdn_list:[{
access_point_name: "internet",
default: true,
ipv4_addr: "{{ slave['ip'] }}"
}]
{%- endif %}
}
{%- endfor -%}
]
......
......@@ -44,6 +44,12 @@
"title": "Use IPv4",
"description": "Set to true to use IPv4 for AMF / MME addresses",
"type": "boolean"
},
"fixed_ips": {
"default": false,
"title": "Fixed IP for the UE",
"description": "Set to true to force a static IPv4 for each UE. If true, you cannot use more than 256 UE.",
"type": "boolean"
}
}
}
{%- set dns_slave_instance_list = [] %}
{%- set sim_slave_instance_list = [] %}
{%- set fixed_ip = slapparameter_dict.get("fixed_ips", False) %}
{%- for slave in slave_instance_list %}
{%- set slave_parameters = json_module.loads(slave['_']) %}
{%- if slave_parameters.get('subdomain', '') != '' %}
......@@ -19,8 +20,39 @@
recipe = slapos.cookbook:publish.serialised
-slave-reference = {{ slave_reference }}
info = Your SIM card with IMSI {{ slave_parameters.get('imsi', '') }} has been attached to service ${slap-configuration:instance-title}.
{%- if fixed_ip %}
ipv4 = ${sim-ip-configuration:{{slave_reference}}}
{%- endif %}
{%- endfor %}
[sim-ip-configuration]
recipe = slapos.recipe.build
sim-slave-instance-list = {{ dumps(sim_slave_instance_list) }}
ipv4-network = {{ slap_configuration.get('tun-ipv4-network', '') }}
init =
import netaddr
import json
network = netaddr.IPNetwork(options['ipv4-network'])
slave_list = options['sim-slave-instance-list']
# if we don't have enough IPv4 addresses in the network, don't force it
# should we make a promise fail ?
if len(slave_list) + 2 > network.size:
options['sim-with-ip-list'] = [json.loads(x['_']) for x in slave_list]
for s in slave_list:
options[s['slave_reference']] = "Too many SIM for the IPv4 network"
else:
# calculate the IP addresses of each SIM
sim_list = []
first_addr = netaddr.IPAddress(network.first)
for i, s in enumerate(sorted(slave_list, key=lambda x: json.loads(x['_'])['imsi'])):
ip = str(first_addr + 2 + i)
options[s['slave_reference']] = ip
slave_parameters = json.loads(s['_'])
slave_parameters['ip'] = ip
sim_list.append(slave_parameters)
options['sim-with-ip-list'] = sim_list
{%- for slave in dns_slave_instance_list %}
{%- set slave_parameters = json_module.loads(slave['_']) %}
{% set slave_reference = slave.get('slave_reference', '') %}
......@@ -70,7 +102,11 @@ configuration.gtp_addr = 127.0.1.100
configuration.ims_addr = 127.0.0.1
configuration.ims_bind = 127.0.0.2
ue_db_path = ${ue-db-config:output}
{%- if fixed_ip %}
sim_list = ${sim-ip-configuration:sim-with-ip-list}
{%- else %}
sim_list = {{ dumps(sim_slave_instance_list) }}
{%- endif %}
[monitor-httpd-conf-parameter]
httpd-include-file = {{ buildout_directory }}/etc/httpd-include-file.conf
......@@ -195,13 +231,10 @@ url = {{ ims_template }}
output = ${directory:etc}/ims.cfg
[ue-db-config]
recipe = slapos.recipe.template:jinja2
<= config-base
url = {{ ue_db_template }}
filename = ue_db.cfg
extensions = jinja2.ext.do
output = ${directory:etc}/${:filename}
output = ${directory:etc}/ue_db.cfg
context =
import json_module json
section slap_configuration slap-configuration
[mme-config]
......
......@@ -335,6 +335,7 @@ extra-context =
raw dnsmasq_location ${dnsmasq:location}
key dnsmasq_config_path dnsmasq-config:output
key slave_instance_list slap-configuration:slave-instance-list
section slap_configuration slap-configuration
[dynamic-template-ue-lte]
< = jinja2-template-base
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment