---
title: Charmhub | Deploy SD-Core AMF using Charmhub - The Open Operator Collection
description: Deploy the latest version of SD-Core AMF as a Kubernetes Operator on
  any cloud.
url: https://charmhub.io/sdcore-amf/libraries/fiveg_n2
---

# SD-Core AMF

[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 58

```
juju deploy sdcore-amf --channel edge
```

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

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

## charms.sdcore\_amf.v0.fiveg\_n2

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

    Fetch library

    ```
    charmcraft fetch-lib charms.sdcore_amf.v0.fiveg_n2
    ```

    [Download fiveg\_n2.py](https://charmhub.io/sdcore-amf/libraries/fiveg_n2/download)
  + *Last updated* 05 Jun 2023
  + *Revision* Library version 0.1

Library for the `fiveg_n2` relation.

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

The purpose of this library is to relate a charm claiming
to be able to provide or consume information on connectivity to the N2 plane.

##### Getting Started

From a charm directory, fetch the library using `charmcraft`:

```
charmcraft fetch-lib charms.sdcore_amf.v0.fiveg_n2
```

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

* pydantic
* pytest-interface-tester

###### Requirer charm

The requirer charm is the one requiring the N2 information.

Example:

```
from ops.charm import CharmBase
from ops.main import main

from charms.sdcore_amf.v0.fiveg_n2 import N2InformationAvailableEvent, N2Requires

logger = logging.getLogger(__name__)

class DummyFivegN2Requires(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)
        self.n2_requirer = N2Requires(self, "fiveg-n2")
        self.framework.observe(
            self.n2_requirer.on.n2_information_available, self._on_n2_information_available
        )

    def _on_n2_information_available(self, event: N2InformationAvailableEvent):
        amf_ip_address = event.amf_ip_address
        amf_hostname = event.amf_hostname
        amf_port = event.amf_port
        <do something with the amf IP, hostname and port>

if __name__ == "__main__":
    main(DummyFivegN2Requires)
```

###### Provider charm

The provider charm is the one providing the information about the N2 interface.

Example:

```
from ops.charm import CharmBase, RelationJoinedEvent
from ops.main import main

from charms.sdcore_amf.v0.fiveg_n2 import N2Provides

class DummyFivegN2ProviderCharm(CharmBase):

    HOST = "amf"
    PORT = 38412
    IP_ADDRESS = "192.168.70.132"

    def __init__(self, *args):
        super().__init__(*args)
        self.n2_provider = N2Provides(self, "fiveg-n2")
        self.framework.observe(
            self.on.fiveg_n2_relation_joined, self._on_fiveg_n2_relation_joined
        )

    def _on_fiveg_n2_relation_joined(self, event: RelationJoinedEvent):
        if self.unit.is_leader():
            self.n2_provider.set_n2_information(
                amf_ip_address=self.IP_ADDRESS,
                amf_hostname=self.HOST,
                amf_port=self.PORT,
            )

if __name__ == "__main__":
    main(DummyFivegN2ProviderCharm)
```

---

Index

* [class ProviderAppData](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#providerappdata)
* [class ProviderSchema](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#providerschema)
* [def data\_is\_valid(
  data
  )](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#data_is_valid)
* [class N2InformationAvailableEvent](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2informationavailableevent)
* + [def \_\_init\_\_(
    self,
    handle,
    amf\_ip\_address,
    amf\_hostname,
    amf\_port)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2informationavailableevent-__init__)
* + [def snapshot(
    self)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2informationavailableevent-snapshot)
* + [def restore(
    self,
    snapshot)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2informationavailableevent-restore)
* [class N2RequirerCharmEvents](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requirercharmevents)
* [class N2Requires](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requires)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requires-__init__)
* + [def amf\_ip\_address(
    self)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requires-amf_ip_address)
* + [def amf\_hostname(
    self)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requires-amf_hostname)
* + [def amf\_port(
    self)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2requires-amf_port)
* [class N2Provides](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2provides)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2provides-__init__)
* + [def set\_n2\_information(
    self,
    amf\_ip\_address,
    amf\_hostname,
    amf\_port)](https://charmhub.io/sdcore-amf/libraries/fiveg_n2#n2provides-set_n2_information)

#### class ProviderAppData

Description

Provider app data for fiveg\_n2. None

#### class ProviderSchema

Description

Provider schema for fiveg\_n2. None

#### def data\_is\_valid(data: dict)

Returns whether data is valid.

Arguments

data
(dict)

Data to be validated.

Returns

True if data is valid, False otherwise.

#### class N2InformationAvailableEvent

Description

Charm event emitted when N2 information is available. It carries the AMF hostname. None

Methods

N2InformationAvailableEvent.
\_\_init\_\_(

*self*

,
handle: Handle

,
amf\_ip\_address: str

,
amf\_hostname: str

,
amf\_port: int
)

Description

Init. None

N2InformationAvailableEvent.
snapshot(

*self*
)

Description

Returns snapshot. None

N2InformationAvailableEvent.
restore(

*self*

,
snapshot: dict
)

Description

Restores snapshot. None

#### class N2RequirerCharmEvents

Description

List of events that the N2 requirer charm can leverage. None

#### class N2Requires

Description

Class to be instantiated by the N2 requirer charm. None

Methods

N2Requires.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

Description

Init. None

N2Requires.
amf\_ip\_address(

*self*
)

Returns AMF IP address.

Returns

str

AMF IP address.

N2Requires.
amf\_hostname(

*self*
)

Returns AMF hostname.

Returns

str

AMF hostname.

N2Requires.
amf\_port(

*self*
)

Returns the port used to connect to the AMF host.

Returns

int

AMF port.

#### class N2Provides

Description

Class to be instantiated by the charm providing the N2 data. None

Methods

N2Provides.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
relation\_name: str
)

Description

Init. None

N2Provides.
set\_n2\_information(

*self*

,
amf\_ip\_address: str

,
amf\_hostname: str

,
amf\_port: int
)

Sets the hostname and the ngapp port in the application relation data.

Arguments

amf\_ip\_address
(str)

AMF IP address.

amf\_hostname
(str)

AMF hostname.

amf\_port
(int)

AMF NGAPP port.

Returns

None
