# Diameter codec - encoder & decoder
- codec is based on RFC https://datatracker.ietf.org/doc/html/rfc6733
- no third party py libs dependencies
- very simple and straightforward to use
- python support: >= 3.6
### How to setup dev env
- apt install python3.6
- apt install python3.6-venv
- source venv/bin/activate
- pip install -r requirements.txt
- pylint src/main/python/codec/diameter/ --ignored-classes=_socketobject *.py
### How to build project
- pyb -v
- pyb -Q
### How to upload project to test.pypi with twine
- python -m twine upload --repository-url https://test.pypi.org/legacy/ target/dist/diameter-codec-<x.y.z>/dist/*
### How to upload project to pypi with twine (production)
- python -m twine upload target/dist/diameter-codec-<x.y.z>/dist/*
### How to push git tag
- git push origin v<x.y.z>
### How to encode and decode Capabilities-Exchange message
import os
import typing
from codec.diameter.diameter import DiameterHeader, Diameter, Avp
from codec.diameter.dictionary import DictionaryLayout, DefaultDictionaryLayout
cer_request: typing.Tuple = (
Avp("Product-Name", "hello"),
Avp("Origin-Realm", "zte.com.cn"),
Avp("Origin-Host", "dmtsrv001.zte.com.cn"),
Avp("Host-IP-Address", "192.168.0.1"),
Avp("Vendor-Id", 10415),
Avp("Product-Name", "dummy-product"),
Avp("Inband-Security-Id", 1),
Avp("Vendor-Specific-Application-Id", (
Avp("Vendor-Id", 10415),
Avp("Acct-Application-Id", 1),
Avp("Auth-Application-Id", 1),
)),
Avp("Vendor-Specific-Application-Id", (
Avp("Auth-Application-Id", 2),
Avp("Acct-Application-Id", 2),
Avp("Vendor-Id", 10415),
)),
)
header: DiameterHeader = DiameterHeader(application_id=0, command_code=257, avp_set=cer_request)
xml_dict_path: str = <path to diameter xml file>
dictionary_layout: DictionaryLayout = DefaultDictionaryLayout(xml_dict_path)
diameter: Diameter = Diameter(dictionary_layout)
encoded_header: bytes = self.diameter.encode(header) # send to TCP server
decoded_header: DiameterHeader = diameter.decode(encoded_header) # decoded on TCP server
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/3gpp-toolbox/diameter-codec",
"name": "diameter-codec",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "diameter codec rfc6733",
"author": "Kresimir Popovic",
"author_email": "kresimir.popovic@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f2/98/9829f1df9248fade0062a8d2f57c268a3701208e1348318896b03ff3c79f/diameter-codec-1.0.3.tar.gz",
"platform": null,
"description": "# Diameter codec - encoder & decoder \n- codec is based on RFC https://datatracker.ietf.org/doc/html/rfc6733 \n- no third party py libs dependencies \n- very simple and straightforward to use \n- python support: >= 3.6 \n \n### How to setup dev env \n- apt install python3.6 \n- apt install python3.6-venv \n- source venv/bin/activate \n- pip install -r requirements.txt\n- pylint src/main/python/codec/diameter/ --ignored-classes=_socketobject *.py\n \n### How to build project \n- pyb -v\n- pyb -Q\n\n### How to upload project to test.pypi with twine\n- python -m twine upload --repository-url https://test.pypi.org/legacy/ target/dist/diameter-codec-<x.y.z>/dist/*\n\n### How to upload project to pypi with twine (production)\n- python -m twine upload target/dist/diameter-codec-<x.y.z>/dist/*\n\n### How to push git tag\n- git push origin v<x.y.z>\n\n### How to encode and decode Capabilities-Exchange message\n\timport os \n\timport typing \n\tfrom codec.diameter.diameter import DiameterHeader, Diameter, Avp \n\tfrom codec.diameter.dictionary import DictionaryLayout, DefaultDictionaryLayout\t\n\tcer_request: typing.Tuple = ( \n Avp(\"Product-Name\", \"hello\"), \n Avp(\"Origin-Realm\", \"zte.com.cn\"), \n Avp(\"Origin-Host\", \"dmtsrv001.zte.com.cn\"), \n Avp(\"Host-IP-Address\", \"192.168.0.1\"), \n Avp(\"Vendor-Id\", 10415), \n Avp(\"Product-Name\", \"dummy-product\"), \n Avp(\"Inband-Security-Id\", 1), \n Avp(\"Vendor-Specific-Application-Id\", ( \n Avp(\"Vendor-Id\", 10415), \n Avp(\"Acct-Application-Id\", 1), \n Avp(\"Auth-Application-Id\", 1), \n )), \n Avp(\"Vendor-Specific-Application-Id\", ( \n Avp(\"Auth-Application-Id\", 2), \n Avp(\"Acct-Application-Id\", 2), \n Avp(\"Vendor-Id\", 10415), \n )), \n )\n header: DiameterHeader = DiameterHeader(application_id=0, command_code=257, avp_set=cer_request)\n xml_dict_path: str = <path to diameter xml file> \n\tdictionary_layout: DictionaryLayout = DefaultDictionaryLayout(xml_dict_path) \n\tdiameter: Diameter = Diameter(dictionary_layout)\n encoded_header: bytes = self.diameter.encode(header) #\tsend to TCP server \n decoded_header: DiameterHeader = diameter.decode(encoded_header) # decoded on TCP server\n",
"bugtrack_url": null,
"license": "European Union Public Licence 1.2 (EUPL 1.2)",
"summary": "",
"version": "1.0.3",
"split_keywords": [
"diameter",
"codec",
"rfc6733"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4dfd2b4a134dd34464a088a6526a394f88e3014aa11a43ec31eeac646980895a",
"md5": "9db8b459e40c6a352f4cd9394f3e0c37",
"sha256": "ed0e90fff9513f82d5c798c43a8834c3cffa2034a9a46ec7e8e6b6ea40a80a70"
},
"downloads": -1,
"filename": "diameter_codec-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9db8b459e40c6a352f4cd9394f3e0c37",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 12535,
"upload_time": "2023-04-27T08:21:03",
"upload_time_iso_8601": "2023-04-27T08:21:03.559831Z",
"url": "https://files.pythonhosted.org/packages/4d/fd/2b4a134dd34464a088a6526a394f88e3014aa11a43ec31eeac646980895a/diameter_codec-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f2989829f1df9248fade0062a8d2f57c268a3701208e1348318896b03ff3c79f",
"md5": "22ff890ab70e981cfbff3615dad7aa91",
"sha256": "632f8919292e7175437c50fef52c30ef3f15cae2a527f70c8ae8de0741e87eac"
},
"downloads": -1,
"filename": "diameter-codec-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "22ff890ab70e981cfbff3615dad7aa91",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11211,
"upload_time": "2023-04-27T08:21:05",
"upload_time_iso_8601": "2023-04-27T08:21:05.884921Z",
"url": "https://files.pythonhosted.org/packages/f2/98/9829f1df9248fade0062a8d2f57c268a3701208e1348318896b03ff3c79f/diameter-codec-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-27 08:21:05",
"github": false,
"gitlab": true,
"bitbucket": false,
"gitlab_user": "3gpp-toolbox",
"gitlab_project": "diameter-codec",
"lcname": "diameter-codec"
}