free5gc / smf

Apache License 2.0
19 stars 95 forks source link

Add REST APIs to user_plane_information (upNodes, links). #68

Closed aviweit closed 1 year ago

aviweit commented 1 year ago

This PR addresses the task item mentioned in pkg/factory/factory.go ("Support configuration update from REST api") It introduces the below REST APIs:

Get upNodes

List list_user_plane_information upNodes

curl -H "Content-type: application/json" -X GET http://<smf_ip_address>:<smf_port>/upi/v1/upNodes

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Return:

    status - 200
    list of upNode elements (json)

Post upNodes

Add upNodes to user_plane_information

curl -H "Content-type: application/json" -X POST -d '{ "upNodes": {...} }' http://<smf_ip_address>:<smf_port>/upi/v1/upNodes

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Data payload:

  list of upNode elements keyed by their names (json)

Return:

    status - 200

Example:

curl -X POST \
  http://127.0.0.1:8000/upi/v1/upNodes \
  -H 'content-type: application/json' \
  -d '{
  "upNodes": {
      "UPF-2": {
          "type": "UPF",
          "nodeID": "upf-2.free5gc.org",
          "sNssaiUpfInfos": [
              {
                  "sNssai": {"sst": 1, "sd": "010203"},
                  "dnnUpfInfoList": [
                      {
                          "dnn": "internet",
                          "pools": [{"cidr": "10.62.0.0/16"}]
                      }
                  ]
              }
          ],
          "interfaces": [
              {
                  "interfaceType": "N3",
                  "endpoints": ["upf-2.free5gc.org"],
                  "networkInstance": "internet"
              }
          ]
      }
  }
}'

Get links

List list_user_plane_information links

curl -H "Content-type: application/json" -X GET http://<smf_ip_address>:<smf_port>/upi/v1/links

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Return:

    status - 200
    list of link elements (json)

Post links

Add links to user_plane_information

curl -H "Content-type: application/json" -X POST -d '{ "links": [...] }' http://<smf_ip_address>:<smf_port>/upi/v1/links

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Data payload:

  list of link elements (json)

Return:

    status - 200

Example:

curl -X POST \
  http://127.0.0.1:8000/upi/v1/links \
  -H 'content-type: application/json' \
  -d '{
  "links": [
      {
          "A": "gNB",
          "B": "UPF-2"
      }
  ]
}'
aviweit commented 1 year ago

Hi @tim-ywliu , Can you please review this PR? Thanks.

aviweit commented 1 year ago

I suggest to create a different PR to support delete, since it is more complex (e.g. release pdu session(s) of the deleted upf, terminate its heartbeat thread (if exists), ensure topology is consistent after upf is deleted, etc..). What do you think?

tim-ywliu commented 1 year ago

@aviweit

Why not use one api to new upNodes & links together?

aviweit commented 1 year ago

Why not use one api to new upNodes & links together?

@tim-ywliu , thanks, I am looking into it.

aviweit commented 1 year ago

Update PR to use single API for GET/POST

Get upNodesLinks

List list_user_plane_information upNodes and links

curl -H "Content-type: application/json" -X GET http://<smf_ip_address>:<smf_port>/upi/v1/upNodesLinks

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Return:

    status - 200
    list of upNode and link elements (json)

Post upNodesLinks

Add upNodes and links to user_plane_information

curl -H "Content-type: application/json" -X POST -d '{ "upNodes": {...}, "links": [] }' http://<smf_ip_address>:<smf_port>/upi/v1/upNodesLinks

REST path:

    smf_ip_address - ipaddress of SMF service
    smf_port       - the service port

Data payload:

  list of upNode and link elements (json)

Return:

    status - 200

Example:

curl -X POST \
  http://127.0.0.1:8000/upi/v1/upNodesLinks \
  -H 'content-type: application/json' \
  -d '{
  "upNodes": {
      "UPF-2": {
          "type": "UPF",
          "nodeID": "upf-2.free5gc.org",
          "sNssaiUpfInfos": [
              {
                  "sNssai": {"sst": 1, "sd": "010203"},
                  "dnnUpfInfoList": [
                      {
                          "dnn": "internet",
                          "pools": [{"cidr": "10.62.0.0/16"}]
                      }
                  ]
              }
          ],
          "interfaces": [
              {
                  "interfaceType": "N3",
                  "endpoints": ["upf-2.free5gc.org"],
                  "networkInstance": "internet"
              }
          ]
      }
  },
  "links": [
      {
          "A": "gNB",
          "B": "UPF-2"
      }
  ]
}'
aviweit commented 1 year ago

Hi @tim-ywliu , I have unified REST APIs into a single one and added checks to ignore existing SMF links. Can you please review? Thanks.

tim-ywliu commented 1 year ago

LGTM, thanks.