fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41104?usp=email )


Change subject: [REST] Implement ErabList and ErabInfo
......................................................................

[REST] Implement ErabList and ErabInfo

Change-Id: Ia98498143fd0e38030429171e42a0c4c4887df64
Related: SYS#7066
---
M contrib/openapi.yaml
M contrib/osmo-s1gw-cli.py
M priv/openapi.json
M src/rest_server.erl
4 files changed, 166 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw 
refs/changes/04/41104/1

diff --git a/contrib/openapi.yaml b/contrib/openapi.yaml
index 0041274..adf3e58 100644
--- a/contrib/openapi.yaml
+++ b/contrib/openapi.yaml
@@ -108,6 +108,34 @@
         '404':
           description: Unsuccessful outcome (eNB not found)

+  /erab-list:
+    get:
+      summary: Get E-RAB list for all eNBs
+      operationId: ErabList
+      responses:
+        '200':
+          description: A list of E-RABs
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ErabList'
+
+  /erab/{ErabId}:
+    get:
+      summary: Get information about a specific E-RAB
+      operationId: ErabInfo
+      parameters:
+        - $ref: '#/components/parameters/ErabId'
+      responses:
+        '200':
+          description: Successful outcome (E-RAB info)
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ErabItem'
+        '404':
+          description: Unsuccessful outcome (E-RAB not found)
+
 components:
   responses:
     OperationResult:
@@ -146,6 +174,18 @@
             description: eNB connection address/port
             example: enb-conn:192.168.1.1-34650

+    ErabId:
+      name: ErabId
+      in: path
+      description: E-RAB identifier (selector)
+      required: true
+      schema:
+        oneOf:
+          - type: string
+            pattern: '^pid:[0-9]+\.[0-9]+\.[0-9]+$'
+            description: Process ID
+            example: pid:0.33.1
+
   schemas:
     OperationResult:
       type: object
diff --git a/contrib/osmo-s1gw-cli.py b/contrib/osmo-s1gw-cli.py
index cb77709..8a65295 100755
--- a/contrib/osmo-s1gw-cli.py
+++ b/contrib/osmo-s1gw-cli.py
@@ -116,6 +116,16 @@
         with self.send_get_req(f'enb/{enb_id}/erab-list') as f:
             return json.load(f)

+    def erab_list(self) -> RESTResponse:
+        ''' ErabList :: Get E-RAB list for all eNBs '''
+        with self.send_get_req('erab-list') as f:
+            return json.load(f)
+
+    def erab_info(self, pid: str) -> RESTResponse:
+        ''' ErabInfo :: Get information about a specific E-RAB '''
+        with self.send_get_req(f'erab/pid:{pid}') as f:
+            return json.load(f)
+

 class OsmoS1GWCli(cmd2.Cmd):
     DESC = 'Interactive CLI for OsmoS1GW'
@@ -123,6 +133,7 @@
     CAT_METRICS = 'Metrics commands'
     CAT_PFCP = 'PFCP related commands'
     CAT_ENB = 'eNB related commands'
+    CAT_ERAB = 'E-RAB related commands'

     def __init__(self, argv):
         super().__init__(allow_cli_args=False, include_py=True)
@@ -297,6 +308,24 @@
         data = self.iface.enb_erab_list(enb_id)
         self.erab_list_print(data)

+    @cmd2.with_category(CAT_ERAB)
+    def do_erab_list(self, opts) -> None:
+        ''' Get E-RAB list for all eNBs '''
+        data = self.iface.erab_list()
+        self.erab_list_print(data)
+
+    erab_info_parser = cmd2.Cmd2ArgumentParser()
+    erab_info_parser.add_argument('-P', '--pid',
+                                  type=str, required=True,
+                                  help='E-RAB process ID (example: 0.33.1)')
+
+    @cmd2.with_argparser(erab_info_parser)
+    @cmd2.with_category(CAT_ERAB)
+    def do_erab_info(self, opts) -> None:
+        ''' Get information about a specific E-RAB '''
+        data = self.iface.erab_info(opts.pid)
+        self.erab_list_print([data])
+

 ap = argparse.ArgumentParser(prog='osmo-s1gw-cli', 
description=OsmoS1GWCli.DESC)

diff --git a/priv/openapi.json b/priv/openapi.json
index 07a11b8..bfe82a3 100644
--- a/priv/openapi.json
+++ b/priv/openapi.json
@@ -166,6 +166,50 @@
                     }
                 }
             }
+        },
+        "/erab-list": {
+            "get": {
+                "summary": "Get E-RAB list for all eNBs",
+                "operationId": "ErabList",
+                "responses": {
+                    "200": {
+                        "description": "A list of E-RABs",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/ErabList"
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        },
+        "/erab/{ErabId}": {
+            "get": {
+                "summary": "Get information about a specific E-RAB",
+                "operationId": "ErabInfo",
+                "parameters": [
+                    {
+                        "$ref": "#/components/parameters/ErabId"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "Successful outcome (E-RAB info)",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/ErabItem"
+                                }
+                            }
+                        }
+                    },
+                    "404": {
+                        "description": "Unsuccessful outcome (E-RAB not found)"
+                    }
+                }
+            }
         }
     },
     "components": {
@@ -221,6 +265,22 @@
                         }
                     ]
                 }
+            },
+            "ErabId": {
+                "name": "ErabId",
+                "in": "path",
+                "description": "E-RAB identifier (selector)",
+                "required": true,
+                "schema": {
+                    "oneOf": [
+                        {
+                            "type": "string",
+                            "pattern": "^pid:[0-9]+\\.[0-9]+\\.[0-9]+$",
+                            "description": "Process ID",
+                            "example": "pid:0.33.1"
+                        }
+                    ]
+                }
             }
         },
         "schemas": {
diff --git a/src/rest_server.erl b/src/rest_server.erl
index 2f805da..e1333c0 100644
--- a/src/rest_server.erl
+++ b/src/rest_server.erl
@@ -39,7 +39,9 @@
          pfcp_heartbeat/1,
          enb_list/1,
          enb_info/1,
-         enb_erab_list/1
+         enb_erab_list/1,
+         erab_list/1,
+         erab_info/1
         ]).

 -include_lib("kernel/include/logger.hrl").
@@ -120,6 +122,24 @@
     end.

 
+%% ErabList :: Get E-RAB list for all eNBs
+erab_list(#{}) ->
+    EnbList = enb_registry:fetch_enb_list(),
+    ErabList = lists:map(fun fetch_erab_list/1, EnbList),
+    {200, [], lists:flatten(ErabList)}.
+
+
+%% ErabInfo :: Get information about a specific E-RAB
+erab_info(#{path_parameters := PP}) ->
+    [{<< "ErabId" >>, << ID/bytes >>}] = PP,
+    case fetch_erab_info(ID) of
+        {ok, ErabInfo} ->
+            {200, [], ErabInfo};
+        error ->
+            {404, [], undefined}
+    end.
+
+
 %% ------------------------------------------------------------------
 %% private API
 %% ------------------------------------------------------------------
@@ -245,6 +265,22 @@
     error.


+-spec fetch_erab_info(binary()) -> {ok, erab_fsm:erab_info()} | error.
+fetch_erab_info(<< "pid:", Val/bytes >>) ->
+    Pid = parse_pid(Val),
+    %% guard against non-existent process IDs
+    %% TODO: check if the given Pid is actually an erab_fsm
+    try erab_list_item({pid, Pid}) of
+        ErabInfo -> {ok, ErabInfo}
+    catch
+        exit:{noproc, _} -> error
+    end;
+
+fetch_erab_info(ID) ->
+    ?LOG_ERROR("Unhandled E-RAB ID ~p", [ID]),
+    error.
+
+
 -spec fetch_erab_list(enb_registry:enb_info()) -> [map()].
 fetch_erab_list(#{mme_conn_info := ConnInfo}) ->
     Pid = maps:get(handler, ConnInfo), %% s1ap_proxy process pid

--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/41104?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Ia98498143fd0e38030429171e42a0c4c4887df64
Gerrit-Change-Number: 41104
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>

Reply via email to