Skip to content

Commit 56238a8

Browse files
committed
Enhancement: Improved UPF routing and NAT handling
- Replaced static aether-ue-nat.service with dynamic aether-ue-nat.service.j2 - Updated install.yaml to use Jinja2 templating for NAT service - Improved 20-aether-core.network to dynamically add routes for additional UPFs - Modified add UPF module to check for existing routes before adding - Ensured consistent route management between core network and UPF installation Signed-off-by: hxngillani <[email protected]>
1 parent f9ade97 commit 56238a8

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

roles/router/tasks/install.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
---
2-
31
# TODO: running on master node for now (fix to run on multiple nodes)
42

53
- set_fact:
@@ -70,11 +68,6 @@
7068
when: inventory_hostname in groups['master_nodes']
7169
become: true
7270

73-
- name: Disable GRO flag on the {{ core.data_iface }} interface
74-
shell: ethtool -K {{ core.data_iface }} gro off
75-
when: inventory_hostname in groups['master_nodes']
76-
become: true
77-
7871
- name: find {{ core.data_iface }}'s netplan network directory
7972
shell: basename $(find /*/systemd/network -maxdepth 1 -not -type d -name '*{{ core.data_iface }}.network' -print)
8073
register: result
@@ -95,10 +88,12 @@
9588
when: inventory_hostname in groups['master_nodes']
9689
become: true
9790

98-
- name: copy aether-ue-nat.service to {{ systemd_system_dir }}/aether-ue-nat.service
91+
# Use Jinja template for `aether-ue-nat.service`
92+
- name: Generate aether-ue-nat.service dynamically
9993
template:
100-
src: roles/router/templates/systemd/aether-ue-nat.service
94+
src: roles/router/templates/systemd/aether-ue-nat.service.j2
10195
dest: "{{ systemd_system_dir }}/aether-ue-nat.service"
96+
mode: "0644"
10297
when: inventory_hostname in groups['master_nodes']
10398
become: true
10499

@@ -122,7 +117,7 @@
122117
when: inventory_hostname in groups['master_nodes']
123118
become: true
124119

125-
- name: restart systemd-networkd
120+
- name: Restart systemd-networkd
126121
systemd:
127122
name: systemd-networkd
128123
state: restarted

roles/router/templates/systemd/20-aether-core.network

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ Name=core
88
IPForward=yes
99
Address={{ core.upf.core_subnet }}
1010

11+
# Default UPF Route
1112
[Route]
1213
Gateway={{ core.upf.default_upf.ip.core }}
1314
Destination={{ core.upf.default_upf.ue_ip_pool }}
15+
16+
# Additional UPFs - Dynamically Generated Routes
17+
{% if core.upf.additional_upfs is defined and core.upf.additional_upfs %}
18+
{% for upf in core.upf.additional_upfs.values() %}
19+
[Route]
20+
Gateway={{ upf.ip.core }}
21+
Destination={{ upf.ue_ip_pool }}
22+
{% endfor %}
23+
{% endif %}

roles/router/templates/systemd/aether-ue-nat.service

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2022-present Open Networking Foundation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[Unit]
5+
Description=Aether UE NAT Setup
6+
After=network.target
7+
8+
[Service]
9+
Type=oneshot
10+
ExecStart=/bin/bash -c "\
11+
sudo iptables -t nat -C POSTROUTING -s {{ core.upf.default_upf.ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE || \
12+
sudo iptables -t nat -A POSTROUTING -s {{ core.upf.default_upf.ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE; \
13+
{% if '1' in core.upf.additional_upfs %} \
14+
sudo iptables -t nat -C POSTROUTING -s {{ core.upf.additional_upfs['1'].ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE || \
15+
sudo iptables -t nat -A POSTROUTING -s {{ core.upf.additional_upfs['1'].ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE; \
16+
{% endif %} \
17+
{% if '2' in core.upf.additional_upfs %} \
18+
sudo iptables -t nat -C POSTROUTING -s {{ core.upf.additional_upfs['2'].ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE || \
19+
sudo iptables -t nat -A POSTROUTING -s {{ core.upf.additional_upfs['2'].ue_ip_pool }} -o {{ core.data_iface }} -j MASQUERADE; \
20+
{% endif %} \
21+
"
22+
23+
[Install]
24+
WantedBy=multi-user.target

roles/upf/tasks/install.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454

5555
- name: configure route for upf traffic on gnbsim node
5656
shell: |
57+
ip route show | grep -q "{{ item.value.ue_ip_pool }} via {{ item.value.ip.core }}" || \
5758
ip route add {{ item.value.ue_ip_pool }} via {{ item.value.ip.core }}
5859
when: inventory_hostname in groups['master_nodes']
5960
with_dict: "{{ core.upf.additional_upfs}}"
6061
become: true
62+
6163
# ignore_errors: yes

0 commit comments

Comments
 (0)