lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

March 2026

  • 1 participants
  • 1933 discussions
[XS] Change in osmo-asf4-dfu[master]: dfu: make dfu_state/dfu_status volatile
by laforge 10 Mar '26

10 Mar '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42169?usp=email ) Change subject: dfu: make dfu_state/dfu_status volatile ...................................................................... dfu: make dfu_state/dfu_status volatile Both variable might be changed from IRQ and from main loop. Change-Id: I7ad5255064917c203cebe5ab54a5d457baa2f5ed --- M usb/class/dfu/device/dfudf.c M usb/class/dfu/device/dfudf.h 2 files changed, 4 insertions(+), 4 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved pespin: Looks good to me, but someone else must approve diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c index c62cafb..a067185 100644 --- a/usb/class/dfu/device/dfudf.c +++ b/usb/class/dfu/device/dfudf.c @@ -39,8 +39,8 @@ static const uint8_t usb_dfu_func_desc_bytes[] = {DFUD_IFACE_DESCB}; static const usb_dfu_func_desc_t* usb_dfu_func_desc = (usb_dfu_func_desc_t*)&usb_dfu_func_desc_bytes; -enum usb_dfu_state dfu_state = USB_DFU_STATE_DFU_IDLE; -enum usb_dfu_status dfu_status = USB_DFU_STATUS_OK; +volatile enum usb_dfu_state dfu_state = USB_DFU_STATE_DFU_IDLE; +volatile enum usb_dfu_status dfu_status = USB_DFU_STATUS_OK; uint8_t dfu_download_data[512]; uint16_t dfu_download_length = 0; diff --git a/usb/class/dfu/device/dfudf.h b/usb/class/dfu/device/dfudf.h index cee5845..818252d 100644 --- a/usb/class/dfu/device/dfudf.h +++ b/usb/class/dfu/device/dfudf.h @@ -38,9 +38,9 @@ #include "usb_protocol_dfu.h" /** Current DFU state */ -extern enum usb_dfu_state dfu_state; +extern volatile enum usb_dfu_state dfu_state; /**< Current DFU status */ -extern enum usb_dfu_status dfu_status; +extern volatile enum usb_dfu_status dfu_status; /** Downloaded data to be programmed in flash * -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42169?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: I7ad5255064917c203cebe5ab54a5d457baa2f5ed Gerrit-Change-Number: 42169 Gerrit-PatchSet: 3 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-asf4-dfu[master]: dfu: mainloop: work on a local copy of dfu_state
by laforge 10 Mar '26

10 Mar '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email ) Change subject: dfu: mainloop: work on a local copy of dfu_state ...................................................................... dfu: mainloop: work on a local copy of dfu_state Prevent race conditions between main loop and irq. Copy at the start of the loop the dfu state and work on it. Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944 --- M usb_start.c 1 file changed, 6 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/usb_start.c b/usb_start.c index 47e287f..13fbfd3 100644 --- a/usb_start.c +++ b/usb_start.c @@ -159,8 +159,11 @@ ASSERT(application_start_address > 0); while (true) { // main DFU infinite loop + enum usb_dfu_state last_dfu_state = dfu_state; + // run the second part of the USB DFU state machine handling non-USB aspects - if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state || USB_DFU_STATE_DFU_DNBUSY == dfu_state) { // there is some data to be flashed + if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state || + USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed LED_SYSTEM_off(); // switch LED off to indicate we are flashing if (dfu_download_length > 0) { // there is some data to be flashed int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash @@ -182,7 +185,7 @@ } LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume } - if (USB_DFU_STATE_DFU_MANIFEST == dfu_state) { // we can start manifestation (finish flashing) + if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing) // in theory every DFU files should have a suffix to with a CRC to check the data // in practice most downloaded files are just the raw binary with DFU suffix dfu_manifestation_complete = true; // we completed flashing and all checks @@ -192,7 +195,7 @@ dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; } } - if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == dfu_state) { + if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) { if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) { usb_dfu_reset(USB_EV_RESET, 0); // immediately reset } else { // wait for USB reset -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944 Gerrit-Change-Number: 42170 Gerrit-PatchSet: 4 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-asf4-dfu[master]: dfu: irq: replace if(states) with a switch case
by laforge 10 Mar '26

10 Mar '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email ) Change subject: dfu: irq: replace if(states) with a switch case ...................................................................... dfu: irq: replace if(states) with a switch case Improves the overview. No functional change. Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b --- M usb/class/dfu/device/dfudf.c 1 file changed, 7 insertions(+), 2 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c index a067185..76dcc9b 100644 --- a/usb/class/dfu/device/dfudf.c +++ b/usb/class/dfu/device/dfudf.c @@ -162,9 +162,11 @@ case USB_DFU_GETSTATUS: // get status // per DFU 1.1 spec, bState must report the state the device will enter // after this response, so perform state transitions before building response - if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state) { + switch (dfu_state) { + case USB_DFU_STATE_DFU_DNLOAD_SYNC: // download has not completed dfu_state = USB_DFU_STATE_DFU_DNBUSY; // switch to busy state - } else if (USB_DFU_STATE_DFU_MANIFEST_SYNC == dfu_state) { + break; + case USB_DFU_STATE_DFU_MANIFEST_SYNC: if (!dfu_manifestation_complete) { dfu_state = USB_DFU_STATE_DFU_MANIFEST; // go to manifest mode } else if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) { @@ -172,6 +174,9 @@ } else { // this should not happen (after manifestation the state should be dfuMANIFEST-WAIT-RESET if we are not manifest tolerant) dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; // wait for reset } + break; + default: + break; } response[0] = dfu_status; // set status response[1] = 10; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b Gerrit-Change-Number: 42171 Gerrit-PatchSet: 4 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: Hoernchen <ewild(a)sysmocom.de>
1 0
0 0
[S] Change in osmo-asf4-dfu[master]: dfu: usb_dfu() convert if() intos switch/case
by laforge 10 Mar '26

10 Mar '26
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email ) Change subject: dfu: usb_dfu() convert if() intos switch/case ...................................................................... dfu: usb_dfu() convert if() intos switch/case Improves the overview of the handled states. No functional change. Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a --- M usb_start.c 1 file changed, 10 insertions(+), 6 deletions(-) Approvals: laforge: Looks good to me, approved pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/usb_start.c b/usb_start.c index 13fbfd3..78711f1 100644 --- a/usb_start.c +++ b/usb_start.c @@ -162,8 +162,9 @@ enum usb_dfu_state last_dfu_state = dfu_state; // run the second part of the USB DFU state machine handling non-USB aspects - if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state || - USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed + switch (last_dfu_state) { + case USB_DFU_STATE_DFU_DNLOAD_SYNC: + case USB_DFU_STATE_DFU_DNBUSY: // there is some data to be flashed LED_SYSTEM_off(); // switch LED off to indicate we are flashing if (dfu_download_length > 0) { // there is some data to be flashed int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash @@ -184,8 +185,8 @@ dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue } LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume - } - if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing) + break; + case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing) // in theory every DFU files should have a suffix to with a CRC to check the data // in practice most downloaded files are just the raw binary with DFU suffix dfu_manifestation_complete = true; // we completed flashing and all checks @@ -194,13 +195,16 @@ } else { dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; } - } - if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) { + break; + case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET: if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) { usb_dfu_reset(USB_EV_RESET, 0); // immediately reset } else { // wait for USB reset usb_d_register_callback(USB_D_CB_EVENT, (FUNC_PTR)usb_dfu_reset); // register new USB reset event handler } + break; + default: + break; } } } -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a Gerrit-Change-Number: 42173 Gerrit-PatchSet: 4 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-asf4-dfu[master]: dfu: mainloop: work on a local copy of dfu_state
by laforge 10 Mar '26

10 Mar '26
Attention is currently required from: lynxis lazus, pespin. laforge has posted comments on this change by lynxis lazus. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email ) Change subject: dfu: mainloop: work on a local copy of dfu_state ...................................................................... Patch Set 4: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944 Gerrit-Change-Number: 42170 Gerrit-PatchSet: 4 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: pespin <pespin(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Comment-Date: Tue, 10 Mar 2026 09:43:41 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in osmo-asf4-dfu[master]: Replace snprintf() to free 4 kb
by laforge 10 Mar '26

10 Mar '26
Attention is currently required from: lynxis lazus. laforge has posted comments on this change by lynxis lazus. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42275?usp=email ) Change subject: Replace snprintf() to free 4 kb ...................................................................... Patch Set 2: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42275?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: Ide644648bda86d4ae77a6713d1e140a4b78ba835 Gerrit-Change-Number: 42275 Gerrit-PatchSet: 2 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Comment-Date: Tue, 10 Mar 2026 09:40:29 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[S] Change in osmo-asf4-dfu[master]: Improve comments on errata 2.6.10
by lynxis lazus 10 Mar '26

10 Mar '26
Attention is currently required from: mschramm, pespin. lynxis lazus has posted comments on this change by lynxis lazus. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42168?usp=email ) Change subject: Improve comments on errata 2.6.10 ...................................................................... Patch Set 2: (2 comments) Patchset: PS1: > The point here is: there is no such facility nor even a concept of a 'low-priority' WDT in this Cort […] Done PS1: > And what is the correct explanation? updated the comments, should be correct now. -- To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42168?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-asf4-dfu Gerrit-Branch: master Gerrit-Change-Id: I3c35f590a4e43d778e70f2f377e0d470c3a652b2 Gerrit-Change-Number: 42168 Gerrit-PatchSet: 2 Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-CC: mschramm <mschramm(a)sysmocom.de> Gerrit-Attention: mschramm <mschramm(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 10 Mar 2026 09:34:41 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: mschramm <mschramm(a)sysmocom.de> Comment-In-Reply-To: Hoernchen <ewild(a)sysmocom.de> Comment-In-Reply-To: lynxis lazus <lynxis(a)fe80.eu>
1 0
0 0
[M] Change in ...osmo-s1gw[master]: enb_registry: rework handling of eNB property updates
by fixeria 10 Mar '26

10 Mar '26
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/42299?usp=email ) Change subject: enb_registry: rework handling of eNB property updates ...................................................................... enb_registry: rework handling of eNB property updates The idea of an enb_event/0 containing the current MME connection state and the associated information (Global-eNB-ID, eNB/MME conn info) looked promising initially, however turned out to be impractical in light of ongoing MME pooling related changes. * remove type enb_state/0 * rename type enb_event/0 -> enb_prop/0 * rename function enb_event/2 -> enb_update/2 (now private) * enb_prop/0: separate the state from other properties * enb_update/2: accept a list of enb_prop/0 - enb_proplist/0 * add typed notify_*() helpers that group related property updates, ensuring consistency and serving as the sole public call sites * notify_mme_connecting(): explicitly clears mme_conn_info * openapi: EnbItem.state reflects the actual enb_proxy FSM state Change-Id: Ib5c5dedce729151cd7350390987fdd008b254ef4 Related: SYS#7052 --- M contrib/openapi.yaml M doc/osmo-s1gw-cli.md M priv/openapi.json M src/enb_proxy.erl M src/enb_registry.erl 5 files changed, 104 insertions(+), 63 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified fixeria: Looks good to me, approved osmith: Looks good to me, but someone else must approve diff --git a/contrib/openapi.yaml b/contrib/openapi.yaml index 307ae1c..7f81608 100644 --- a/contrib/openapi.yaml +++ b/contrib/openapi.yaml @@ -292,8 +292,8 @@ $ref: '#/components/schemas/Pid' state: type: string - enum: [connecting, connected, s1setup] - description: Connection state + enum: [unknown, wait_s1setup_req, connecting, wait_s1setup_rsp, connected] + description: eNB proxy state uptime: type: integer description: Uptime (in seconds) diff --git a/doc/osmo-s1gw-cli.md b/doc/osmo-s1gw-cli.md index 4a0bd22..be5ffc3 100644 --- a/doc/osmo-s1gw-cli.md +++ b/doc/osmo-s1gw-cli.md @@ -174,18 +174,18 @@ ``` OsmoS1GW# enb_list -| eNB handle | PID | Global-eNB-ID | State | eNB addr:port (aid) | MME addr:port (aid) | Uptime (s) | # E-RABs | -|--------------|-----------|-----------------|---------|-------------------------|-------------------------|--------------|------------| -| 0 | <0.699.0> | 001-01-0 | s1setup | 127.0.1.10:56767 (5706) | 127.0.2.10:36412 (5707) | 418 | 0 | -| 1 | <0.701.0> | 001-01-1 | s1setup | 127.0.1.10:54140 (5710) | 127.0.2.10:36412 (5711) | 33 | 3 | -| 2 | <0.703.0> | 001-01-2 | s1setup | 127.0.1.10:34076 (5714) | 127.0.2.10:36412 (5715) | 3600 | 20 | -| 3 | <0.705.0> | 001-01-3 | s1setup | 127.0.1.10:46501 (5718) | 127.0.2.10:36412 (5719) | 869 | 13 | -| 4 | <0.707.0> | 001-01-4 | s1setup | 127.0.1.10:35610 (5722) | 127.0.2.10:36412 (5723) | 18 | 0 | -| 5 | <0.709.0> | 001-01-5 | s1setup | 127.0.1.10:37610 (5726) | 127.0.2.10:36412 (5727) | 933 | 129 | -| 6 | <0.711.0> | 001-01-6 | s1setup | 127.0.1.10:58447 (5730) | 127.0.2.10:36412 (5741) | 535 | 6 | -| 7 | <0.713.0> | 001-01-7 | s1setup | 127.0.1.10:35842 (5732) | 127.0.2.10:36412 (5743) | 736 | 8 | -| 8 | <0.715.0> | 001-01-8 | s1setup | 127.0.1.10:57362 (5734) | 127.0.2.10:36412 (5745) | 521 | 99 | -| 9 | <0.717.0> | 001-01-9 | s1setup | 127.0.1.10:50955 (5736) | 127.0.2.10:36412 (5747) | 33 | 1 | +| eNB handle | PID | Global-eNB-ID | State | eNB addr:port (aid) | MME addr:port (aid) | Uptime (s) | # E-RABs | +|--------------|-----------|-----------------|-----------|-------------------------|-------------------------|--------------|------------| +| 0 | <0.699.0> | 001-01-0 | connected | 127.0.1.10:56767 (5706) | 127.0.2.10:36412 (5707) | 418 | 0 | +| 1 | <0.701.0> | 001-01-1 | connected | 127.0.1.10:54140 (5710) | 127.0.2.10:36412 (5711) | 33 | 3 | +| 2 | <0.703.0> | 001-01-2 | connected | 127.0.1.10:34076 (5714) | 127.0.2.10:36412 (5715) | 3600 | 20 | +| 3 | <0.705.0> | 001-01-3 | connected | 127.0.1.10:46501 (5718) | 127.0.2.10:36412 (5719) | 869 | 13 | +| 4 | <0.707.0> | 001-01-4 | connected | 127.0.1.10:35610 (5722) | 127.0.2.10:36412 (5723) | 18 | 0 | +| 5 | <0.709.0> | 001-01-5 | connected | 127.0.1.10:37610 (5726) | 127.0.2.10:36412 (5727) | 933 | 129 | +| 6 | <0.711.0> | 001-01-6 | connected | 127.0.1.10:58447 (5730) | 127.0.2.10:36412 (5741) | 535 | 6 | +| 7 | <0.713.0> | 001-01-7 | connected | 127.0.1.10:35842 (5732) | 127.0.2.10:36412 (5743) | 736 | 8 | +| 8 | <0.715.0> | 001-01-8 | connected | 127.0.1.10:57362 (5734) | 127.0.2.10:36412 (5745) | 521 | 99 | +| 9 | <0.717.0> | 001-01-9 | connected | 127.0.1.10:50955 (5736) | 127.0.2.10:36412 (5747) | 33 | 1 | ``` ### `enb_info` @@ -219,7 +219,7 @@ | eNB handle | 8 | | PID | <0.715.0> | | Global-eNB-ID | 001-01-8 | -| State | s1setup | +| State | connected | | eNB addr:port (aid) | 127.0.1.10:57362 (5734) | | MME addr:port (aid) | 127.0.2.10:36412 (5745) | | Uptime (s) | 521 | @@ -235,7 +235,7 @@ | eNB handle | 8 | | PID | <0.715.0> | | Global-eNB-ID | 001-01-8 | -| State | s1setup | +| State | connected | | eNB addr:port (aid) | 127.0.1.10:57362 (5734) | | MME addr:port (aid) | 127.0.2.10:36412 (5745) | | Uptime (s) | 521 | diff --git a/priv/openapi.json b/priv/openapi.json index c13d20c..6bcefdb 100644 --- a/priv/openapi.json +++ b/priv/openapi.json @@ -432,11 +432,13 @@ "state": { "type": "string", "enum": [ + "unknown", + "wait_s1setup_req", "connecting", - "connected", - "s1setup" + "wait_s1setup_rsp", + "connected" ], - "description": "Connection state" + "description": "eNB proxy state" }, "uptime": { "type": "integer", diff --git a/src/enb_proxy.erl b/src/enb_proxy.erl index 4495e31..0aa00db 100644 --- a/src/enb_proxy.erl +++ b/src/enb_proxy.erl @@ -58,8 +58,8 @@ -include("S1AP-Constants.hrl"). --type conn_info() :: #{state := atom(), - handler := pid(), +%% XXX: replace/merge with mme_registry:mme_info()? +-type conn_info() :: #{handler := pid(), mme_addr := inet:ip_address(), mme_port := inet:port_number(), enb_aid := gen_sctp:assoc_id(), @@ -115,7 +115,6 @@ init([EnbConnInfo, MmeConnCfg]) -> {ok, EnbHandle} = enb_registry:enb_register(), - enb_registry:enb_event(EnbHandle, {connecting, EnbConnInfo}), {ok, Pid} = s1ap_proxy:start_link(self()), {ok, wait_s1setup_req, #state{enb_aid = maps:get(aid, EnbConnInfo), @@ -132,6 +131,8 @@ %% WAIT_S1SETUP_REQ state wait_s1setup_req(enter, _OldState, S) -> ?LOG_INFO("State enter: ~p", [?FUNCTION_NAME]), + enb_registry:notify_enb_connected(S#state.enb_handle, + S#state.enb_conn_info), {next_state, ?FUNCTION_NAME, S, [{state_timeout, 5_000, s1setup_req_timeout}]}; @@ -158,7 +159,7 @@ S#state{genb_id_str = GlobalENBId}), %% signal the Global-eNB-ID to other modules s1ap_proxy:set_genb_id(S#state.handler, GlobalENBId), - enb_registry:enb_event(S#state.enb_handle, {s1setup, GENBId}), + enb_registry:notify_genb_id(S#state.enb_handle, GENBId), gtpu_kpi_enb_register(S#state{genb_id_str = GlobalENBId}), {next_state, connecting, S#state{s1setup_req = Data, @@ -180,6 +181,7 @@ connecting(enter, OldState, #state{mme_conn_cfg = MmeConnCfg} = S) -> ?LOG_INFO("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + enb_registry:notify_mme_connecting(S#state.enb_handle), %% Initiate connection establishment with the MME {ok, Sock} = sctp_client:connect(MmeConnCfg), %% loop transition to enable state_timeout @@ -222,6 +224,7 @@ %% WAIT_S1SETUP_RSP state wait_s1setup_rsp(enter, OldState, S) -> ?LOG_INFO("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), + enb_registry:notify_mme_wait_rsp(S#state.enb_handle), {next_state, ?FUNCTION_NAME, S, [{state_timeout, 5_000, s1setup_rsp_timeout}]}; @@ -288,11 +291,9 @@ %% CONNECTED state -connected(enter, OldState, - #state{enb_handle = Handle} = S) -> +connected(enter, OldState, S) -> ?LOG_INFO("State change: ~p -> ~p", [OldState, ?FUNCTION_NAME]), - MmeConnInfo = conn_info(?FUNCTION_NAME, S), - ok = enb_registry:enb_event(Handle, {?FUNCTION_NAME, MmeConnInfo}), + enb_registry:notify_mme_connected(S#state.enb_handle, conn_info(S)), {keep_state, S}; %% Handle an eNB -> MME data forwarding request (forward) @@ -338,9 +339,8 @@ %% Event handler for all states -handle_event(State, {call, From}, fetch_info, S) -> - Info = conn_info(State, S), - {keep_state_and_data, {reply, From, Info}}; +handle_event(_State, {call, From}, fetch_info, S) -> + {keep_state_and_data, {reply, From, conn_info(S)}}; handle_event(State, {call, From}, EventData, _S) -> ?LOG_ERROR("Unexpected call in state ~p: ~p", [State, EventData]), @@ -425,10 +425,9 @@ end. --spec conn_info(atom(), state()) -> conn_info(). -conn_info(State, #state{mme_conn_cfg = MmeConnCfg} = S) -> - Info = #{state => State, - handler => S#state.handler, +-spec conn_info(state()) -> conn_info(). +conn_info(#state{mme_conn_cfg = MmeConnCfg} = S) -> + Info = #{handler => S#state.handler, mme_addr => maps:get(raddr, MmeConnCfg), mme_port => maps:get(rport, MmeConnCfg), enb_aid => S#state.enb_aid, diff --git a/src/enb_registry.erl b/src/enb_registry.erl index 3c9e8ef..61f0c59 100644 --- a/src/enb_registry.erl +++ b/src/enb_registry.erl @@ -43,7 +43,11 @@ -export([start_link/0, enb_register/0, enb_unregister/1, - enb_event/2, + notify_enb_connected/2, + notify_genb_id/2, + notify_mme_connecting/1, + notify_mme_wait_rsp/1, + notify_mme_connected/2, fetch_enb_info/1, fetch_enb_list/0, fetch_enb_list/1, @@ -59,13 +63,11 @@ -type enb_handle() :: non_neg_integer(). --type enb_state() :: connecting %% S1GW -> MME connection in progress - | connected %% S1GW -> MME connection established - | s1setup. %% S1 SETUP procedure completed - --type enb_event() :: {connecting, sctp_server:conn_info()} - | {connected, enb_proxy:conn_info()} - | {s1setup, s1ap_utils:genb_id()}. +-type enb_prop() :: {state, atom()} + | {enb_conn_info, sctp_server:conn_info()} + | {mme_conn_info, undefined | enb_proxy:conn_info()} + | {genb_id, s1ap_utils:genb_id()}. +-type enb_proplist() :: [enb_prop()]. -type enb_filter() :: {genb_id_str, string()} | {enb_sctp_aid, gen_sctp:assoc_id()} @@ -76,7 +78,7 @@ -type enb_info() :: #{handle := enb_handle(), %% unique identifier of this eNB pid := pid(), %% pid() of the registrant mon_ref := reference(), %% monitor() reference - state := enb_state(), %% connection state + state := atom(), %% enb_proxy FSM state reg_time := integer(), %% registration time (monotonic) uptime := non_neg_integer(), %% seconds since reg_time genb_id => s1ap_utils:genb_id(), %% Global-eNB-ID @@ -91,7 +93,6 @@ }). -export_type([enb_handle/0, - enb_state/0, enb_info/0]). @@ -114,9 +115,34 @@ gen_server:call(?MODULE, {?FUNCTION_NAME, Handle}). --spec enb_event(enb_handle(), enb_event()) -> ok. -enb_event(Handle, Event) -> - gen_server:cast(?MODULE, {?FUNCTION_NAME, Handle, Event}). +%% eNB SCTP connection established; waiting for S1 SETUP REQUEST +-spec notify_enb_connected(enb_handle(), sctp_server:conn_info()) -> ok. +notify_enb_connected(Handle, ConnInfo) -> + enb_update(Handle, [{state, wait_s1setup_req}, {enb_conn_info, ConnInfo}]). + + +%% Global-eNB-ID is now known (from S1 SETUP REQUEST) +-spec notify_genb_id(enb_handle(), s1ap_utils:genb_id()) -> ok. +notify_genb_id(Handle, GENBId) -> + enb_update(Handle, [{genb_id, GENBId}]). + + +%% MME connection attempt in progress; clears any stale mme_conn_info +-spec notify_mme_connecting(enb_handle()) -> ok. +notify_mme_connecting(Handle) -> + enb_update(Handle, [{state, connecting}, {mme_conn_info, undefined}]). + + +%% MME SCTP link established; S1 SETUP REQUEST forwarded, awaiting response +-spec notify_mme_wait_rsp(enb_handle()) -> ok. +notify_mme_wait_rsp(Handle) -> + enb_update(Handle, [{state, wait_s1setup_rsp}]). + + +%% S1 SETUP complete; eNB is fully operational +-spec notify_mme_connected(enb_handle(), enb_proxy:conn_info()) -> ok. +notify_mme_connected(Handle, ConnInfo) -> + enb_update(Handle, [{state, connected}, {mme_conn_info, ConnInfo}]). -spec fetch_enb_info(enb_handle() | pid()) -> {ok, enb_info()} | error. @@ -168,7 +194,7 @@ EnbInfo = #{handle => Handle, pid => Pid, mon_ref => MonRef, - state => connecting, + state => unknown, reg_time => erlang:monotonic_time(), uptime => 0}, ?LOG_INFO("eNB (handle=~p, pid ~p) registered", [Handle, Pid]), @@ -229,12 +255,12 @@ {reply, {error, not_implemented}, S}. -handle_cast({enb_event, Handle, Event}, +handle_cast({enb_update, Handle, PropList}, #state{enbs = ENBs} = S) -> case maps:find(Handle, ENBs) of {ok, EnbInfo0} -> - ?LOG_INFO("eNB (handle=~p) event: ~p", [Handle, Event]), - EnbInfo1 = enb_handle_event(EnbInfo0, Event), + ?LOG_DEBUG("eNB (handle=~p) update: ~p", [Handle, PropList]), + EnbInfo1 = enb_update_proplist(EnbInfo0, PropList), {noreply, S#state{enbs = maps:update(Handle, EnbInfo1, ENBs)}}; error -> ?LOG_ERROR("eNB (handle=~p) is *not* registered", [Handle]), @@ -281,6 +307,11 @@ %% private API %% ------------------------------------------------------------------ +-spec enb_update(enb_handle(), enb_proplist()) -> ok. +enb_update(Handle, PropList) -> + gen_server:cast(?MODULE, {?FUNCTION_NAME, Handle, PropList}). + + -spec enb_metrics_register(string()) -> term(). enb_metrics_register(GlobalENBId) -> catch exometer:new(?S1GW_CTR_ENB_UPTIME(GlobalENBId), counter). @@ -293,24 +324,33 @@ enb_metrics_reset(_) -> ok. --spec enb_handle_event(enb_info(), enb_event()) -> enb_info(). -enb_handle_event(EnbInfo, {connecting, ConnInfo}) -> - EnbInfo#{state => connecting, - enb_conn_info => ConnInfo}; +-spec enb_update_proplist(enb_info(), enb_proplist()) -> enb_info(). +enb_update_proplist(EnbInfo, PropList) -> + lists:foldl(fun enb_update_prop/2, EnbInfo, PropList). -enb_handle_event(EnbInfo, {connected, ConnInfo}) -> - EnbInfo#{state => connected, - mme_conn_info => ConnInfo}; -enb_handle_event(EnbInfo, {s1setup, GENBId}) -> +-spec enb_update_prop(enb_info(), enb_prop()) -> enb_info(). +enb_update_prop({state, State}, EnbInfo) -> + EnbInfo#{state => State}; + +enb_update_prop({enb_conn_info, ConnInfo}, EnbInfo) -> + EnbInfo#{enb_conn_info => ConnInfo}; + +enb_update_prop({mme_conn_info, undefined}, EnbInfo) -> + maps:remove(mme_conn_info, EnbInfo); + +enb_update_prop({mme_conn_info, ConnInfo}, EnbInfo) -> + EnbInfo#{mme_conn_info => ConnInfo}; + +enb_update_prop({genb_id, GENBId}, EnbInfo) -> GlobalENBId = s1ap_utils:genb_id_str(GENBId), enb_metrics_register(GlobalENBId), - EnbInfo#{state => s1setup, - genb_id => GENBId, + EnbInfo#{genb_id => GENBId, genb_id_str => GlobalENBId}; -enb_handle_event(EnbInfo, Event) -> - ?LOG_ERROR("Unhandled event: ~p", [Event]), +enb_update_prop(Prop, EnbInfo) -> + ?LOG_ERROR("eNB (handle=~p) update: unknown property ~p", + [maps:get(handle, EnbInfo), Prop]), EnbInfo. -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/42299?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Ib5c5dedce729151cd7350390987fdd008b254ef4 Gerrit-Change-Number: 42299 Gerrit-PatchSet: 3 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in ...osmo-s1gw[master]: mme_registry: the MME registry (pool) implementation
by fixeria 10 Mar '26

10 Mar '26
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41281?usp=email ) ( 5 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: mme_registry: the MME registry (pool) implementation ...................................................................... mme_registry: the MME registry (pool) implementation Change-Id: Id5480222439bf93eca2e994b291c619dff823b01 Related: SYS#7052 --- A src/mme_registry.erl M src/osmo_s1gw_sup.erl A test/mme_registry_test.erl 3 files changed, 503 insertions(+), 1 deletion(-) Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved diff --git a/src/mme_registry.erl b/src/mme_registry.erl new file mode 100644 index 0000000..291c767 --- /dev/null +++ b/src/mme_registry.erl @@ -0,0 +1,283 @@ +%% Copyright (C) 2025 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> +%% Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de> +%% +%% All Rights Reserved +%% +%% SPDX-License-Identifier: AGPL-3.0-or-later +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU Affero General Public License as +%% published by the Free Software Foundation; either version 3 of the +%% License, or (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU Affero General Public License +%% along with this program. If not, see <https://www.gnu.org/licenses/>. +%% +%% Additional Permission under GNU AGPL version 3 section 7: +%% +%% If you modify this Program, or any covered work, by linking or +%% combining it with runtime libraries of Erlang/OTP as released by +%% Ericsson on https://www.erlang.org (or a modified version of these +%% libraries), containing parts covered by the terms of the Erlang Public +%% License (https://www.erlang.org/EPLICENSE) the licensors of this +%% Program grant you additional permission to convey the resulting work +%% without the need to license the runtime libraries of Erlang/OTP under +%% the GNU Affero General Public License. Corresponding Source for a +%% non-source form of such a combination shall include the source code +%% for the parts of the runtime libraries of Erlang/OTP used as well as +%% that of the covered work. + +-module(mme_registry). +-behaviour(gen_server). + +-export([init/1, + handle_info/2, + handle_call/3, + handle_cast/2, + terminate/2]). +-export([start_link/0, + mme_register/1, + mme_unregister/1, + mme_select/1, + fetch_mme_info/1, + fetch_mme_list/0, + shutdown/0]). + +-include_lib("kernel/include/logger.hrl"). + +-include("s1gw_metrics.hrl"). +-include("s1ap.hrl"). + + +-type mme_name() :: string(). + +-type mme_info() :: #{name := mme_name(), %% unique identifier of this MME + laddr => string() | inet:ip_address() | any, + raddr := string() | inet:ip_address(), + rport => inet:port_number(), + tac_list => [s1ap_utils:tac()] + }. + +-type mme_list() :: [mme_info()]. + +-type mme_select_params() :: #{enb_tacs => [s1ap_utils:tac()], %% TACs broadcasted by eNB + tried_mmes => [mme_name()] %% MMEs to exclude from selection + }. + +-export_type([mme_name/0, + mme_info/0, + mme_select_params/0]). + + +%% ------------------------------------------------------------------ +%% public API +%% ------------------------------------------------------------------ + +-spec start_link() -> {ok, pid()} | term(). +start_link() -> + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + + +-spec mme_register(mme_info()) -> ok | {error, term()}. +mme_register(MmeInfo) -> + gen_server:call(?MODULE, {?FUNCTION_NAME, MmeInfo}). + + +-spec mme_unregister(mme_name()) -> ok | {error, term()}. +mme_unregister(MmeName) -> + gen_server:call(?MODULE, {?FUNCTION_NAME, MmeName}). + + +-spec mme_select(mme_select_params()) -> {ok, mme_info()} | error. +mme_select(Params) -> + gen_server:call(?MODULE, {?FUNCTION_NAME, Params}). + + +-spec fetch_mme_info(mme_name()) -> {ok, mme_info()} | error. +fetch_mme_info(MmeName) -> + gen_server:call(?MODULE, {?FUNCTION_NAME, MmeName}). + + +-spec fetch_mme_list() -> mme_list(). +fetch_mme_list() -> + gen_server:call(?MODULE, ?FUNCTION_NAME). + + +-spec shutdown() -> ok. +shutdown() -> + gen_server:stop(?MODULE). + + +%% ------------------------------------------------------------------ +%% gen_server API +%% ------------------------------------------------------------------ + +init([]) -> + %% parse MMEs from the environment + MMEs = mme_list_from_env(), + {ok, MMEs}. + + +handle_call({mme_register, MmeInfo}, _From, MMEs0) -> + case mme_add(MmeInfo, MMEs0) of + {ok, MMEs1} -> + {reply, ok, MMEs1}; + {error, Error} -> + {reply, {error, Error}, MMEs0} + end; + +handle_call({mme_unregister, MmeName}, _From, MMEs0) -> + case mme_del(MmeName, MMEs0) of + {ok, MMEs1} -> + %% TODO: kill all eNB connections? + {reply, ok, MMEs1}; + {error, Error} -> + {reply, {error, Error}, MMEs0} + end; + +handle_call({mme_select, Params}, _From, MMEs) -> + Reply = mme_select(Params, MMEs), + {reply, Reply, MMEs}; + +handle_call({fetch_mme_info, MmeName}, _From, MMEs) -> + Reply = mme_find(MmeName, MMEs), + {reply, Reply, MMEs}; + +handle_call(fetch_mme_list, _From, MMEs) -> + {reply, MMEs, MMEs}; + +handle_call(Info, From, MMEs) -> + ?LOG_ERROR("unknown ~p() from ~p: ~p", [?FUNCTION_NAME, From, Info]), + {reply, {error, not_implemented}, MMEs}. + + +handle_cast(Info, MMEs) -> + ?LOG_ERROR("unknown ~p(): ~p", [?FUNCTION_NAME, Info]), + {noreply, MMEs}. + + +handle_info(Info, MMEs) -> + ?LOG_ERROR("unknown ~p(): ~p", [?FUNCTION_NAME, Info]), + {noreply, MMEs}. + + +terminate(Reason, _MMEs) -> + ?LOG_NOTICE("Terminating, reason ~p", [Reason]), + ok. + + +%% ------------------------------------------------------------------ +%% private API +%% ------------------------------------------------------------------ + +%% Match the given MME by name and raddr/rport fields +-spec mme_match(mme_info(), map()) -> true | false. +mme_match(#{name := Name}, + #{name := Name}) -> true; + +mme_match(#{raddr := Addr, rport := Port}, + #{raddr := Addr, rport := Port}) -> true; + +mme_match(_, _) -> false. + + +%% Match the given MME by eNB's TAC list +-spec mme_match_by_tac(MmeInfo, EnbTACs) -> true | false + when MmeInfo :: mme_info(), + EnbTACs :: [s1ap_utils:tac()]. +mme_match_by_tac(#{tac_list := []}, _EnbTACs) -> + %% empty MME TAC list => this MME allows all TACs + true; + +mme_match_by_tac(#{tac_list := MmeTACs}, EnbTACs) -> + %% eNB's TACs must be a subset of MME's TACs + lists:subtract(EnbTACs, MmeTACs) == []. + + +%% Add a new MME if it does not already exist +-spec mme_add(mme_info(), mme_list()) -> {ok, mme_list()} | {error, term()}. +mme_add(MmeInfo0, MMEs) -> + %% assign defaults, parse local/remote addresses + MmeName = maps:get(name, MmeInfo0), + LAddr = sctp_common:parse_addr(maps:get(laddr, MmeInfo0, any)), + RAddr = sctp_common:parse_addr(maps:get(raddr, MmeInfo0)), + RPort = maps:get(rport, MmeInfo0, ?S1AP_PORT), + TACs = maps:get(tac_list, MmeInfo0, []), + MmeInfo1 = MmeInfo0#{laddr => LAddr, + raddr => RAddr, + rport => RPort, + tac_list => TACs}, + %% check for duplicates + case lists:any(fun(E) -> mme_match(E, MmeInfo1) end, MMEs) of + true -> + ?LOG_ERROR("MME (name=~p / ~p:~p) is *already* registered", + [MmeName, RAddr, RPort]), + {error, already_registered}; + false -> + ?LOG_INFO("MME (name=~p, ~p:~p) registered", + [MmeName, RAddr, RPort]), + {ok, MMEs ++ [MmeInfo1]} + end. + + +%% Remove an MME by name +-spec mme_del(mme_name(), mme_list()) -> {ok, mme_list()} | {error, term()}. +mme_del(MmeName, MMEs0) -> + Fun = fun(E) -> not mme_match(E, #{name => MmeName}) end, + case lists:filter(Fun, MMEs0) of + MMEs0 -> %% unchanged list means nothing was filtered out + ?LOG_ERROR("MME (name=~p) is *not* registered", [MmeName]), + {error, not_registered}; + MMEs1 -> + ?LOG_INFO("MME (name=~p) unregistered", [MmeName]), + {ok, MMEs1} + end. + + +%% Select an MME from the pool +-spec mme_select(Params, MMEs) -> Result + when Params :: mme_select_params(), + MMEs :: mme_list(), + Result :: {ok, mme_info()} | error. +mme_select(Params, MMEs0) -> + %% filter out MMEs that the caller has already tried + TriedMMEs = maps:get(tried_mmes, Params, []), + MMEs1 = lists:filter(fun(#{name := Name}) -> not lists:member(Name, TriedMMEs) end, MMEs0), + %% filter out MMEs that do not permit eNB's TAC(s) + EnbTACs = maps:get(enb_tacs, Params, []), + MMEs2 = lists:filter(fun(MmeInfo) -> mme_match_by_tac(MmeInfo, EnbTACs) end, MMEs1), + %% finally, try selecting an MME + case MMEs2 of + [MmeInfo | _] -> {ok, MmeInfo}; + [] -> error + end. + + +%% Find an MME by name +-spec mme_find(mme_name(), mme_list()) -> {ok, mme_info()} | error. +mme_find(MmeName, MMEs) -> + Fun = fun(E) -> mme_match(E, #{name => MmeName}) end, + case lists:filter(Fun, MMEs) of + [MmeInfo] -> {ok, MmeInfo}; + [] -> error + end. + + +-spec mme_list_from_env() -> mme_list(). +mme_list_from_env() -> + MMEs = osmo_s1gw:get_env(mme_pool, []), + lists:foldl(fun mme_add_from_env/2, [], MMEs). + + +-spec mme_add_from_env(mme_info(), mme_list()) -> mme_list(). +mme_add_from_env(MmeInfo, MMEs0) -> + {ok, MMEs1} = mme_add(MmeInfo, MMEs0), + MMEs1. + + +%% vim:set ts=4 sw=4 et: diff --git a/src/osmo_s1gw_sup.erl b/src/osmo_s1gw_sup.erl index 980b8f3..d661af6 100644 --- a/src/osmo_s1gw_sup.erl +++ b/src/osmo_s1gw_sup.erl @@ -71,6 +71,11 @@ 5000, worker, [enb_registry]}, + MmeRegistry = {mme_registry, {mme_registry, start_link, []}, + permanent, + 5000, + worker, + [mme_registry]}, SctpServer = {sctp_server, {sctp_server, start_link, [server_cfg()]}, permanent, 5000, @@ -94,7 +99,13 @@ [erf]}, s1gw_metrics:init(), - {ok, {{one_for_one, 5, 10}, [EnbRegistry, SctpServer, PfcpPeer, GtpuKpi, RestServer]}}. + {ok, {{one_for_one, 5, 10}, + [EnbRegistry, + MmeRegistry, + SctpServer, + PfcpPeer, + GtpuKpi, + RestServer]}}. %% ------------------------------------------------------------------ diff --git a/test/mme_registry_test.erl b/test/mme_registry_test.erl new file mode 100644 index 0000000..75db0ce --- /dev/null +++ b/test/mme_registry_test.erl @@ -0,0 +1,208 @@ +-module(mme_registry_test). + +-include_lib("eunit/include/eunit.hrl"). + + +%% ------------------------------------------------------------------ +%% setup functions +%% ------------------------------------------------------------------ + +%% default set of MMEs +-define(MMEs, [#{name => "mme0", raddr => "127.0.0.10"}, + #{name => "mme1", raddr => "127.0.0.11"}]). + +-define(TC(Fun, MMEs), {setup, + fun() -> start(MMEs) end, + fun stop/1, + Fun}). + + +start(MMEs) -> + osmo_s1gw:set_env(mme_pool, MMEs), + {ok, _} = mme_registry:start_link(). + + +stop(_) -> + mme_registry:shutdown(). + + +%% ------------------------------------------------------------------ +%% testcase descriptions +%% ------------------------------------------------------------------ + +mme_registry_test_() -> + [{"Test adding and deleting MMEs", + ?TC(fun test_add_del/1, ?MMEs)}, + {"Test fetching MME info", + ?TC(fun test_fetch/1, ?MMEs)}, + {"Test MME selection", + ?TC(fun test_select/1, ?MMEs)}, + {"Test MME selection (empty pool)", + ?TC(fun test_select_empty/1, [])}, + {"Test MME selection (TAC list)", + ?TC(fun test_select_tac_list/1, [])} + ]. + + +%% ------------------------------------------------------------------ +%% actual testcases +%% ------------------------------------------------------------------ + +test_add_del(_) -> + [%% "mme0" and "mme1" come pre-registered, register "mme2" + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme2", + raddr => "127.0.0.12"})), + %% duplicate name + ?_assertEqual({error, already_registered}, + mme_registry:mme_register(#{name => "mme2", + raddr => "127.0.0.13"})), + %% duplicate raddr:rport + ?_assertEqual({error, already_registered}, + mme_registry:mme_register(#{name => "mme3", + raddr => "127.0.0.12"})), + %% deleting previously registered MMEs + ?_assertEqual(ok, mme_registry:mme_unregister("mme0")), + ?_assertEqual(ok, mme_registry:mme_unregister("mme1")), + ?_assertEqual(ok, mme_registry:mme_unregister("mme2")), + %% deleting non-existent MMEs + ?_assertEqual({error, not_registered}, + mme_registry:mme_unregister("mme0")), + ?_assertEqual({error, not_registered}, + mme_registry:mme_unregister("mme1")), + ?_assertEqual({error, not_registered}, + mme_registry:mme_unregister("mme42"))]. + + +test_fetch(_) -> + [%% "mme0" and "mme1" come pre-registered, register "mme2" + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme2", + laddr => "192.168.1.100", + raddr => "192.168.1.101", + rport => 1337, + tac_list => [1, 3, 5]})), + %% test fetching a list of MMEs + ?_assertMatch([#{name := "mme0", raddr := {127,0,0,10}}, + #{name := "mme1", raddr := {127,0,0,11}}, + #{name := "mme2", raddr := {192,168,1,101}}], + mme_registry:fetch_mme_list()), + %% test fetching MMEs by name + ?_assertMatch({ok, #{name := "mme0", + laddr := any, + raddr := {127,0,0,10}, + rport := 36412}}, + mme_registry:fetch_mme_info("mme0")), + ?_assertMatch({ok, #{name := "mme1", + laddr := any, + raddr := {127,0,0,11}, + rport := 36412}}, + mme_registry:fetch_mme_info("mme1")), + ?_assertMatch({ok, #{name := "mme2", + laddr := {192,168,1,100}, + raddr := {192,168,1,101}, + rport := 1337, + tac_list := [1, 3, 5]}}, + mme_registry:fetch_mme_info("mme2")), + %% "mme3" is not registered + ?_assertEqual(error, + mme_registry:fetch_mme_info("mme3"))]. + + +test_select(_) -> + [%% "mme0" and "mme1" come pre-registered, register "mme2" + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme2", + raddr => "127.0.0.12"})), + %% no MMEs tried so far, fall back to the first entry ("mme0") + ?_assertMatch({ok, #{name := "mme0"}}, + mme_registry:mme_select(#{ })), + %% tried an MME, which is not in the registry anymore + ?_assertMatch({ok, #{name := "mme0"}}, + mme_registry:mme_select(#{tried_mmes => ["mme3"]})), + %% properly fill tried_mmes, expect the next MME to be selected + ?_assertMatch({ok, #{name := "mme0"}}, + mme_registry:mme_select(#{tried_mmes => []})), + ?_assertMatch({ok, #{name := "mme1"}}, + mme_registry:mme_select(#{tried_mmes => ["mme0"]})), + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => ["mme0", "mme1"]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme0", "mme1", "mme2"]}))]. + + +test_select_empty(_) -> + [%% the MME pool is empty, expect errors + ?_assertEqual(error, mme_registry:mme_select(#{ })), + ?_assertEqual(error, mme_registry:mme_select(#{tried_mmes => ["mme0"]})), + ?_assertEqual(error, mme_registry:mme_select(#{tried_mmes => ["mme1"]})), + ?_assertEqual(error, mme_registry:mme_select(#{tried_mmes => ["mme2"]}))]. + + +test_select_tac_list(_) -> + [%% the MME pool is empty, add MMEs with allowed TACs + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme0", + raddr => "127.0.0.10", + tac_list => [1337]})), + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme1", + raddr => "127.0.0.11", + tac_list => [4242]})), + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme2", + raddr => "127.0.0.12", + tac_list => [1337, 4242, 9999]})), + + %% eNB serving TAC=1337 => "mme0" and "mme2" are allowed + ?_assertMatch({ok, #{name := "mme0"}}, + mme_registry:mme_select(#{tried_mmes => [], + enb_tacs => [1337]})), + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => ["mme0"], + enb_tacs => [1337]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme0", "mme2"], + enb_tacs => [1337]})), + %% eNB serving TAC=4242 => "mme1" and "mme2" are allowed + ?_assertMatch({ok, #{name := "mme1"}}, + mme_registry:mme_select(#{tried_mmes => [], + enb_tacs => [4242]})), + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => ["mme1"], + enb_tacs => [4242]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme1", "mme2"], + enb_tacs => [4242]})), + %% eNB serving TAC=9999 => only "mme2" is allowed + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => [], + enb_tacs => [9999]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme2"], + enb_tacs => [9999]})), + %% eNB serving TACs=[1337, 4242] => only "mme2" is allowed + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => [], + enb_tacs => [1337, 4242]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme2"], + enb_tacs => [1337, 4242]})), + %% eNB serving TACs=[1337, 4242, 9999] => only "mme2" is allowed + ?_assertMatch({ok, #{name := "mme2"}}, + mme_registry:mme_select(#{tried_mmes => [], + enb_tacs => [1337, 4242, 9999]})), + ?_assertEqual(error, %% tried all MMEs, the pool is exhausted + mme_registry:mme_select(#{tried_mmes => ["mme2"], + enb_tacs => [1337, 4242, 9999]})), + %% eNB serving TAC=1111 => not allowed + ?_assertMatch(error, mme_registry:mme_select(#{enb_tacs => [1111]})), + %% eNB serving TACs=[1111, 1337] => not allowed + ?_assertMatch(error, mme_registry:mme_select(#{enb_tacs => [1111, 1337]})), + + %% add another MME that permits all TACs + ?_assertEqual(ok, mme_registry:mme_register(#{name => "mme3", + raddr => "127.0.0.13"})), + %% eNB serving TAC=1111 => only "mme3" is allowed + ?_assertMatch({ok, #{name := "mme3"}}, + mme_registry:mme_select(#{enb_tacs => [1111]})), + %% eNB serving TACs=[1111, 1337] => only "mme3" is allowed + ?_assertMatch({ok, #{name := "mme3"}}, + mme_registry:mme_select(#{enb_tacs => [1111, 1337]}))]. + + +%% vim:set ts=4 sw=4 et: -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41281?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Id5480222439bf93eca2e994b291c619dff823b01 Gerrit-Change-Number: 41281 Gerrit-PatchSet: 7 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in ...osmo-s1gw[master]: s1ap_utils_test: fix: expected value goes first
by fixeria 10 Mar '26

10 Mar '26
fixeria has submitted this change. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41761?usp=email ) ( 1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: s1ap_utils_test: fix: expected value goes first ...................................................................... s1ap_utils_test: fix: expected value goes first Change-Id: Ib7c6478b95a78c9797e86180a89c098e75b615e0 --- M test/s1ap_utils_test.erl 1 file changed, 2 insertions(+), 2 deletions(-) Approvals: pespin: Looks good to me, approved laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/test/s1ap_utils_test.erl b/test/s1ap_utils_test.erl index 1f3279b..ca63606 100644 --- a/test/s1ap_utils_test.erl +++ b/test/s1ap_utils_test.erl @@ -18,7 +18,7 @@ s1ap_setup_req_test_() -> {MsgType, IEs} = s1ap_utils:parse_pdu(s1ap_samples:s1_setup_req_pdu()), - [?_assertEqual(MsgType, {?'id-S1Setup', initiatingMessage}), + [?_assertEqual({?'id-S1Setup', initiatingMessage}, MsgType), ?_assertEqualIE(?'id-Global-ENB-ID', #{enb_id => 0, plmn_id => {"001", "01"}}), ?_assertEqualIE(?'id-eNBname', undefined), %% optional, not present @@ -27,7 +27,7 @@ s1ap_setup_rsp_test_() -> {MsgType, IEs} = s1ap_utils:parse_pdu(s1ap_samples:s1_setup_rsp_pdu()), - [?_assertEqual(MsgType, {?'id-S1Setup', successfulOutcome}), + [?_assertEqual({?'id-S1Setup', successfulOutcome}, MsgType), ?_assertEqualIE(?'id-MMEname', "open5gs-mme0"), ?_assertMatchIE(?'id-ServedGUMMEIs', [#'ServedGUMMEIsItem'{}]), ?_assertEqualIE(?'id-RelativeMMECapacity', 16#ff)]. -- To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41761?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: erlang/osmo-s1gw Gerrit-Branch: master Gerrit-Change-Id: Ib7c6478b95a78c9797e86180a89c098e75b615e0 Gerrit-Change-Number: 41761 Gerrit-PatchSet: 3 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • ...
  • 194
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.