---
title: Charmhub | Deploy SD-CORE 5G UPF using Charmhub - The Open Operator Collection
description: Deploy the latest version of SD-CORE 5G UPF as a Kubernetes Operator
  on any cloud.
url: https://charmhub.io/sdcore-upf/libraries/fiveg_n4
---

# SD-CORE 5G UPF

[Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

* [Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

Platform:

edge 68

```
juju deploy sdcore-upf --channel edge
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#drawer)

## charms.sdcore\_upf.v0.fiveg\_n4

* [*Docstrings*Docstrings](https://charmhub.io/sdcore-upf/libraries/fiveg_n4)
  [*Code*Source code](https://charmhub.io/sdcore-upf/libraries/fiveg_n4/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.sdcore_upf.v0.fiveg_n4
    ```

    [Download fiveg\_n4.py](https://charmhub.io/sdcore-upf/libraries/fiveg_n4/download)
  + *Last updated* 20 Sep 2023
  + *Revision* Library version 0.2

Library for the `fiveg_n4` relation.

This library contains the Requires and Provides classes for handling the `fiveg_n4`
interface.

The purpose of this library is to integrate a charm claiming to be able to provide
information required to establish communication over the N4 interface with a charm
claiming to be able to consume this information.

To get started using the library, you need to fetch the library using `charmcraft`.

```
cd some-charm
charmcraft fetch-lib charms.sdcore_upf.v0.fiveg_n4
```

Add the following libraries to the charm's `requirements.txt` file:

* pydantic
* pytest-interface-tester

Charms providing the `fiveg_n4` relation should use `N4Provides`.
Typical usage of this class would look something like:

```
```python
...
from charms.sdcore_upf.v0.fiveg_n4 import N4Provides
...

class SomeProviderCharm(CharmBase):

    def __init__(self, *args):
        ...
        self.fiveg_n4 = N4Provides(charm=self, relation_name="fiveg_n4")
        ...
        self.framework.observe(self.fiveg_n4.on.fiveg_n4_request, self._on_fiveg_n4_request)

    def _on_fiveg_n4_request(self, event):
        ...
        self.fiveg_n4.publish_upf_n4_information(
            relation_id=event.relation_id,
            upf_hostname=hostname,
            upf_port=n4_port,
        )
```

And a corresponding section in charm's `metadata.yaml`:
```
provides:
    fiveg_n4:  # Relation name
        interface: fiveg_n4  # Relation interface
```
```

Charms that require the `fiveg_n4` relation should use `N4Requires`.
Typical usage of this class would look something like:

```
```python
...
from charms.sdcore_upf.v0.fiveg_n4 import N4Requires
...

class SomeRequirerCharm(CharmBase):

    def __init__(self, *args):
        ...
        self.fiveg_n4 = N4Requires(charm=self, relation_name="fiveg_n4")
        ...
        self.framework.observe(self.upf.on.fiveg_n4_available, self._on_fiveg_n4_available)

    def _on_fiveg_n4_available(self, event):
        upf_hostname = event.upf_hostname,
        upf_port = event.upf_port,
        # Do something with the UPF's hostname and port
```

And a corresponding section in charm's `metadata.yaml`:
```
requires:
    fiveg_n4:  # Relation name
        interface: fiveg_n4  # Relation interface
```
```

---

Index

* [class FivegN4ProviderAppData](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#fivegn4providerappdata)
* [class ProviderSchema](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#providerschema)
* [def data\_matches\_provider\_schema(
  data
  )](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#data_matches_provider_schema)
* [class FiveGN4RequestEvent](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#fivegn4requestevent)
* + [def \_\_init\_\_(
    self,
    handle,
    relation\_id)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#fivegn4requestevent-__init__)
* + [def snapshot(
    self)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#fivegn4requestevent-snapshot)
* + [def restore(
    self,
    snapshot)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#fivegn4requestevent-restore)
* [class N4ProviderCharmEvents](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4providercharmevents)
* [class N4Provides](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4provides)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4provides-__init__)
* + [def publish\_upf\_n4\_information(
    self,
    relation\_id,
    upf\_hostname,
    upf\_n4\_port)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4provides-publish_upf_n4_information)
* [class N4AvailableEvent](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4availableevent)
* + [def \_\_init\_\_(
    self,
    handle,
    upf\_hostname,
    upf\_port)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4availableevent-__init__)
* + [def snapshot(
    self)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4availableevent-snapshot)
* + [def restore(
    self,
    snapshot)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4availableevent-restore)
* [class N4RequirerCharmEvents](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4requirercharmevents)
* [class N4Requires](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4requires)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/sdcore-upf/libraries/fiveg_n4#n4requires-__init__)

#### class FivegN4ProviderAppData

Description

Provider app data for fiveg\_n4. None

#### class ProviderSchema

Description

Provider schema for fiveg\_n4. None

#### def data\_matches\_provider\_schema(data: dict)

Returns whether data matches provider schema.

Arguments

data
(dict)

Data to be validated.

Returns

True if data matches provider schema, False otherwise.

#### class FiveGN4RequestEvent

Description

Dataclass for the `fiveg_n4` request event. None

Methods

FiveGN4RequestEvent.
\_\_init\_\_(

*self*

,
handle

,
relation\_id: int
)

Description

Sets relation id. None

FiveGN4RequestEvent.
snapshot(

*self*
)

Description

Returns event data. None

FiveGN4RequestEvent.
restore(

*self*

,
snapshot
)

Description

Restores event data. None

#### class N4ProviderCharmEvents

Description

Custom events for the N4Provider. None

#### class N4Provides

Description

Class to be instantiated by provider of the `fiveg_n4`. None

Methods

N4Provides.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

Observes relation joined event.

Arguments

charm

Juju charm

relation\_name
(str)

Relation name

N4Provides.
publish\_upf\_n4\_information(

*self*

,
relation\_id: int

,
upf\_hostname: str

,
upf\_n4\_port: int
)

Sets UPF's hostname and port in the relation data.

Arguments

relation\_id
(str)

Relation ID

upf\_hostname
(str)

UPF's hostname

upf\_n4\_port
(int)

Port on which UPF accepts N4 communication

#### class N4AvailableEvent

Description

Dataclass for the `fiveg_n4` available event. None

Methods

N4AvailableEvent.
\_\_init\_\_(

*self*

,
handle

,
upf\_hostname: str

,
upf\_port: int
)

Description

Sets UPF's hostname and port. None

N4AvailableEvent.
snapshot(

*self*
)

Description

Returns event data. None

N4AvailableEvent.
restore(

*self*

,
snapshot
)

Description

Restores event data. None

#### class N4RequirerCharmEvents

Description

Custom events for the N4Requirer. None

#### class N4Requires

Description

Class to be instantiated by requirer of the `fiveg_n4`. None

Methods

N4Requires.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

Observes relation joined and relation changed events.

Arguments

charm

Juju charm

relation\_name
(str)

Relation name
