From 45bbccebb62a0f0e943df7cb993b994514c467eb Mon Sep 17 00:00:00 2001 From: Maximilian Nitsch Date: Thu, 19 Nov 2020 12:38:39 +0100 Subject: [PATCH] Prepare PyPi packages To distribute the pyD3TN DTN protocol implementations as well as the uD3TN python utilities on PyPi, the Python code is organized in separate directories and the PyPi packaging guideline is applied. The restructuring also requires an adjustment of the imports in the scripts in tools/ and test/. Signed-off-by: Maximilian Nitsch --- .gitlab-ci.yml | 2 +- LICENSE-3RD-PARTY.txt | 2 +- LICENSE.txt | 8 ++-- Makefile | 8 ++-- README.md | 7 +-- components/ud3tn/crc.c | 6 +-- doc/python-venv.md | 6 +-- pyd3tn/.gitignore | 4 ++ pyd3tn/LICENSE | 27 ++++++++++++ pyd3tn/README.md | 39 ++++++++++++++++ pyd3tn/pyd3tn/__init__.py | 5 +++ {pyupcn => pyd3tn/pyd3tn}/bundle6.py | 0 {pyupcn => pyd3tn/pyd3tn}/bundle7.py | 10 ----- {pyupcn => pyd3tn/pyd3tn}/crc.py | 0 {pyupcn => pyd3tn/pyd3tn}/helpers.py | 0 {pyupcn => pyd3tn/pyd3tn}/mtcp.py | 2 +- {pyupcn => pyd3tn/pyd3tn}/sdnv.py | 0 {pyupcn => pyd3tn/pyd3tn}/spp.py | 2 +- {pyupcn => pyd3tn/pyd3tn}/tcpcl.py | 4 +- pyd3tn/setup.py | 20 +++++++++ python-ud3tn-utils/.gitignore | 4 ++ python-ud3tn-utils/LICENSE | 27 ++++++++++++ python-ud3tn-utils/README.md | 44 +++++++++++++++++++ python-ud3tn-utils/setup.py | 19 ++++++++ python-ud3tn-utils/ud3tn_utils/__init__.py | 5 +++ .../ud3tn_utils/aap/__init__.py | 11 +++++ .../ud3tn_utils/aap/aap_client.py | 2 +- .../ud3tn_utils/aap/aap_message.py | 5 ++- .../ud3tn_utils/config.py | 32 +++++++++++--- pyupcn/__init__.py | 1 - pyupcn/install.py | 29 ------------ pyupcn/requirements.txt | 2 - test/integration/helpers.py | 4 +- test/integration/test_bundle_routing.py | 9 ++-- test/integration/test_bundle_send_receive.py | 15 ++++--- tools/aap/aap_config.py | 5 ++- tools/aap/aap_receive.py | 2 +- tools/aap/aap_send.py | 2 +- tools/aap/aap_test.py | 2 +- tools/cla/mtcp_sink.py | 4 +- tools/cla/mtcp_test.py | 9 ++-- tools/cla/tcpcl_sink.py | 2 +- tools/cla/tcpcl_test.py | 9 ++-- tools/cla/tcpspp_test.py | 9 ++-- 44 files changed, 298 insertions(+), 107 deletions(-) create mode 100644 pyd3tn/.gitignore create mode 100644 pyd3tn/LICENSE create mode 100644 pyd3tn/README.md create mode 100644 pyd3tn/pyd3tn/__init__.py rename {pyupcn => pyd3tn/pyd3tn}/bundle6.py (100%) rename {pyupcn => pyd3tn/pyd3tn}/bundle7.py (99%) rename {pyupcn => pyd3tn/pyd3tn}/crc.py (100%) rename {pyupcn => pyd3tn/pyd3tn}/helpers.py (100%) rename {pyupcn => pyd3tn/pyd3tn}/mtcp.py (98%) rename {pyupcn => pyd3tn/pyd3tn}/sdnv.py (100%) rename {pyupcn => pyd3tn/pyd3tn}/spp.py (99%) rename {pyupcn => pyd3tn/pyd3tn}/tcpcl.py (99%) create mode 100644 pyd3tn/setup.py create mode 100644 python-ud3tn-utils/.gitignore create mode 100644 python-ud3tn-utils/LICENSE create mode 100644 python-ud3tn-utils/README.md create mode 100644 python-ud3tn-utils/setup.py create mode 100644 python-ud3tn-utils/ud3tn_utils/__init__.py create mode 100644 python-ud3tn-utils/ud3tn_utils/aap/__init__.py rename tools/aap/aapclient.py => python-ud3tn-utils/ud3tn_utils/aap/aap_client.py (98%) rename pyupcn/aap.py => python-ud3tn-utils/ud3tn_utils/aap/aap_message.py (96%) rename pyupcn/agents.py => python-ud3tn-utils/ud3tn_utils/config.py (78%) delete mode 100644 pyupcn/__init__.py delete mode 100644 pyupcn/install.py delete mode 100644 pyupcn/requirements.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 36df4db..713a8a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -174,7 +174,7 @@ python-stylecheck: script: - make virtualenv # We ignore the alignment spaces in pyupcn and bare except in the tests. - - source .venv/bin/activate && python -m flake8 pyupcn test/integration tools/aap tools/cla --max-complexity=12 --per-file-ignores='pyupcn/*.py:E221,test/integration/*:E722' + - source .venv/bin/activate && python -m flake8 pyd3tn python-ud3tn-utils test/integration tools/aap tools/cla --max-complexity=12 --per-file-ignores='python-ud3tn-utils/ud3tn_utils/*.py:E221,pyd3tn/*.py:E221,test/integration/*:E722' clang-tidy-posix: stage: code_quality_test diff --git a/LICENSE-3RD-PARTY.txt b/LICENSE-3RD-PARTY.txt index b56a488..939f69e 100644 --- a/LICENSE-3RD-PARTY.txt +++ b/LICENSE-3RD-PARTY.txt @@ -533,7 +533,7 @@ OF SUCH DAMAGE. - Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams - external/unity/* - Copyright (c) 2015 Bastian Molkenthin - - pyupcn/crc.py + - pyd3tn/pyd3tn/crc.py Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.txt b/LICENSE.txt index c2f7b55..9801e70 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,8 @@ -The source code available in the components/, include/, pyupcn/, test/ and -tools/ folders and subfolders of them and not explicitly mentioned to be -taken from other sources is distributed under the following license: +The source code available in the components/, include/, test/ and tools/ +folders and subfolders of them and not explicitly mentioned to be taken from +other sources is distributed under the license provided below. The Python +modules available in pyd3tn/ and python-ud3tn-utils/ are subject to the +licenses documented in the module directories. Copyright (c) 2014-2020, µPCN team (see below) Copyright (c) 2020, µD3TN team and D3TN GmbH (Contact: contact@d3tn.com) diff --git a/Makefile b/Makefile index d98d724..da7ec0c 100644 --- a/Makefile +++ b/Makefile @@ -127,10 +127,9 @@ virtualenv: @python3 -m venv --without-pip $(VENV) @echo "Install latest pip package ..." @$(GET_PIP) - @echo "Install pyupcn to site-packages ..." - @$(VENV)/bin/python ./pyupcn/install.py - @echo "Install dependencies ..." - @$(PIP) install -U -r ./pyupcn/requirements.txt + @echo "Install local dependencies to site-packages..." + @$(PIP) install -U -e ./pyd3tn ./python-ud3tn-utils + @echo "Install additional dependencies ..." @$(PIP) install -U -r ./test/integration/requirements.txt @$(PIP) install -U -r ./tools/analysis/requirements.txt @$(PIP) install -U -r ./tools/cla/requirements.txt @@ -144,7 +143,6 @@ virtualenv: .PHONY: update-virtualenv update-virtualenv: $(PIP) install -U setuptools pip wheel - $(PIP) install -U -r ./pyupcn/requirements.txt $(PIP) install -U -r ./test/integration/requirements.txt $(PIP) install -U -r ./tools/analysis/requirements.txt $(PIP) install -U -r ./tools/cla/requirements.txt diff --git a/README.md b/README.md index 1c04b99..0a84a50 100644 --- a/README.md +++ b/README.md @@ -120,9 +120,10 @@ in `./doc/testing.md`. License ------- -The code in `./components`, `./include`, `./pyupcn`, `./test`, and `./tools` -has been developed specifically for µD3TN and is released under a BSD 3-clause -license. The license can be found in `./LICENSE.txt`. +The code in `./components`, `./include`, `./pyd3tn`, `./python-ud3tn-utils`, +`./test`, and `./tools` has been developed specifically for µD3TN and is +released under a BSD 3-clause license. The license can be found in +`./LICENSE.txt`, `./pyd3tn/LICENSE`, and `./python-ud3tn-utils/LICENSE`. External code ------------- diff --git a/components/ud3tn/crc.c b/components/ud3tn/crc.c index acbef3e..0633287 100644 --- a/components/ud3tn/crc.c +++ b/components/ud3tn/crc.c @@ -1,8 +1,8 @@ /** * CRC implementation based on lookup tables * - * The tables are generated by the Python module in "pyupcn/crc.py". This - * script is based on the JavaScript implementation on: + * The tables are generated by the Python module in "pyd3tn/pyd3tn/crc.py". + * This script is based on the JavaScript implementation on: * * http://www.sunshine2k.de/coding/javascript/crc/crc_js.html * @@ -188,7 +188,7 @@ uint16_t crc16_ccitt_false(const uint8_t *data, size_t len) * Initial value: 0xffffffff * Final XOR value: 0xffffffff * - * import pyupcn.crc as crc + * import pyd3tn.crc as crc * print(", ".join(hex(e) for e in crc.crc32_c.calculate_crc_table_reflected())) */ static const uint32_t crc32_table[256] = { diff --git a/doc/python-venv.md b/doc/python-venv.md index 2124696..c661560 100644 --- a/doc/python-venv.md +++ b/doc/python-venv.md @@ -6,7 +6,7 @@ test implementations. The scripts are located in the [tools/](tools/) directory. The integration test toolchain can be found in the [test/integration/](test/integration/) directory. Both leverage a Python 3 implementation of several DTN protocols and convergence layers, provided in the -[pyupcn/](pyupcn/) directory. +[pyd3tn/](pyd3tn/) directory. A [venv](https://docs.python.org/3/library/venv.html) is used to isolate the µD3TN Python environment from the system. The Makefile target `virtualenv` @@ -34,10 +34,10 @@ source .venv/bin/activate ``` The `tools/` directory is added to the virtualenv site-packages allowing the -import of packages residing in `tools/` like the `pyupcn` package, e.g. +import of packages residing in `tools/` like the `pyd3tn` package, e.g. ```python -from pyupcn.bundle7 import serialize_bundle7 +from pyd3tn.bundle7 import serialize_bundle7 serialize_bundle7("dtn:GS1", "dtn:GS2", b"Hello world!") ``` diff --git a/pyd3tn/.gitignore b/pyd3tn/.gitignore new file mode 100644 index 0000000..8f1becb --- /dev/null +++ b/pyd3tn/.gitignore @@ -0,0 +1,4 @@ +build/ +dist/ +*.egg-info/ + diff --git a/pyd3tn/LICENSE b/pyd3tn/LICENSE new file mode 100644 index 0000000..9ef403b --- /dev/null +++ b/pyd3tn/LICENSE @@ -0,0 +1,27 @@ +BSD 3-Clause License + +Copyright (c) 2014-2020, µPCN team +Copyright (c) 2020, µD3TN team and D3TN GmbH (Contact: contact@d3tn.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the µD3TN team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL the µD3TN team BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/pyd3tn/README.md b/pyd3tn/README.md new file mode 100644 index 0000000..9c50d3f --- /dev/null +++ b/pyd3tn/README.md @@ -0,0 +1,39 @@ +# pyD3TN + +pyD3TN is a collection of protocol implementations of the *Delay-Tolerant +Networking (DTN) Architecture* ([RFC4838][rfc4838]) for Python. + +Besides the *Bundle Protocol* implementations [BPv6][bpv6] and [BPv7][bpv7], +implementations of the *Convergence Layer Adapters* (CLAs) for TCP +([MTCP][mtcp], [TCPCLv3][tcpclv3]) and the Space Packet Protocol ([SPP][spp]) +are included. + +## Installation + +From source: + +```sh +git clone https://gitlab.com/d3tn/ud3tn +cd pyd3tn +python setup.py install +``` + +From [PyPi](https://pypi.org/project/pyD3TN/) directly: + +```sh +pip install pyd3tn +``` + +## Development + +pyD3TN is maintained as part of the µD3TN project and follows its development +processes. Please see the [µD3TN][ud3tn] repository for the code and further +information. + +[rfc4838]: https://tools.ietf.org/html/rfc4838 +[bpv6]: https://tools.ietf.org/html/rfc5050 +[bpv7]: https://tools.ietf.org/html/draft-ietf-dtn-bpbis-25 +[mtcp]: https://tools.ietf.org/html/draft-ietf-dtn-mtcpcl-00 +[tcpclv3]: https://tools.ietf.org/html/rfc7242 +[spp]: https://public.ccsds.org/Pubs/133x0b2e1.pdf +[ud3tn]: https://gitlab.com/d3tn/ud3tn diff --git a/pyd3tn/pyd3tn/__init__.py b/pyd3tn/pyd3tn/__init__.py new file mode 100644 index 0000000..d475ce3 --- /dev/null +++ b/pyd3tn/pyd3tn/__init__.py @@ -0,0 +1,5 @@ +"""Protocol implementations of the DTN architecture""" + +from . import bundle6, bundle7, mtcp, spp, tcpcl + +__all__ = ['bundle6', 'bundle7', 'mtcp', 'spp', 'tcpcl'] diff --git a/pyupcn/bundle6.py b/pyd3tn/pyd3tn/bundle6.py similarity index 100% rename from pyupcn/bundle6.py rename to pyd3tn/pyd3tn/bundle6.py diff --git a/pyupcn/bundle7.py b/pyd3tn/pyd3tn/bundle7.py similarity index 99% rename from pyupcn/bundle7.py rename to pyd3tn/pyd3tn/bundle7.py index e108d4b..65fc2ce 100644 --- a/pyupcn/bundle7.py +++ b/pyd3tn/pyd3tn/bundle7.py @@ -8,16 +8,6 @@ Dependencies: .. code:: bash pip install cbor - -Usage: - If you are in the root directory of the µPCN project you can simply run: - - .. code:: bash - - python3 -m tools.pyupcn - - This will execute the ``__main__.py`` script next to this file. - See PEP 3122 for more details about it. """ import struct import threading diff --git a/pyupcn/crc.py b/pyd3tn/pyd3tn/crc.py similarity index 100% rename from pyupcn/crc.py rename to pyd3tn/pyd3tn/crc.py diff --git a/pyupcn/helpers.py b/pyd3tn/pyd3tn/helpers.py similarity index 100% rename from pyupcn/helpers.py rename to pyd3tn/pyd3tn/helpers.py diff --git a/pyupcn/mtcp.py b/pyd3tn/pyd3tn/mtcp.py similarity index 98% rename from pyupcn/mtcp.py rename to pyd3tn/pyd3tn/mtcp.py index 7443ce0..3c65832 100644 --- a/pyupcn/mtcp.py +++ b/pyd3tn/pyd3tn/mtcp.py @@ -83,7 +83,7 @@ class MTCPConnection(MTCPSocket): .. code:: python - from pyupcn.mtcp import MTCPConnection + from pyd3tn.mtcp import MTCPConnection with MTCPConnection('127.0.0.1', 4224) as conn: conn.send(bundle) diff --git a/pyupcn/sdnv.py b/pyd3tn/pyd3tn/sdnv.py similarity index 100% rename from pyupcn/sdnv.py rename to pyd3tn/pyd3tn/sdnv.py diff --git a/pyupcn/spp.py b/pyd3tn/pyd3tn/spp.py similarity index 99% rename from pyupcn/spp.py rename to pyd3tn/pyd3tn/spp.py index bc20953..57380f2 100644 --- a/pyupcn/spp.py +++ b/pyd3tn/pyd3tn/spp.py @@ -346,7 +346,7 @@ class TCPSPPConnection(object): .. code:: python - from pyupcn.spp import TCPSPPConnection + from pyd3tn.spp import TCPSPPConnection with TCPSPPConnection('127.0.0.1', 4223) as conn: conn.send(bundle) diff --git a/pyupcn/tcpcl.py b/pyd3tn/pyd3tn/tcpcl.py similarity index 99% rename from pyupcn/tcpcl.py rename to pyd3tn/pyd3tn/tcpcl.py index c61dddb..b953669 100644 --- a/pyupcn/tcpcl.py +++ b/pyd3tn/pyd3tn/tcpcl.py @@ -78,7 +78,7 @@ class TCPCLConnection(object): .. code:: python - from pyupcn.tcpcl import TCPCLConnection + from pyd3tn.tcpcl import TCPCLConnection with TCPCLConnection('dtn://my-eid.dtn', '127.0.0.1', 4223) as conn: conn.send(bundle) @@ -270,7 +270,7 @@ class TCPCLServer(object): .. code:: python import asyncio - from pyupcn.tcpcl import TCPCLServer + from pyd3tn.tcpcl import TCPCLServer async def listen(): async with TCPCLServer('dtn:me', '127.0.0.1', 42420) as server: diff --git a/pyd3tn/setup.py b/pyd3tn/setup.py new file mode 100644 index 0000000..4ef4941 --- /dev/null +++ b/pyd3tn/setup.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import setuptools + +with open('README.md', 'r') as file: + long_description = file.read() + +setuptools.setup( + name='pyD3TN', + version='0.1.0', + author='D3TN GmbH', + author_email='contact@d3tn.com', + description='Collection of DTN protocol implementations', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://gitlab.com/d3tn/ud3tn', + packages=['pyd3tn'], + install_requires=['cbor'], + python_requires='>=3.7', +) diff --git a/python-ud3tn-utils/.gitignore b/python-ud3tn-utils/.gitignore new file mode 100644 index 0000000..8f1becb --- /dev/null +++ b/python-ud3tn-utils/.gitignore @@ -0,0 +1,4 @@ +build/ +dist/ +*.egg-info/ + diff --git a/python-ud3tn-utils/LICENSE b/python-ud3tn-utils/LICENSE new file mode 100644 index 0000000..9ef403b --- /dev/null +++ b/python-ud3tn-utils/LICENSE @@ -0,0 +1,27 @@ +BSD 3-Clause License + +Copyright (c) 2014-2020, µPCN team +Copyright (c) 2020, µD3TN team and D3TN GmbH (Contact: contact@d3tn.com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the µD3TN team nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL the µD3TN team BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/python-ud3tn-utils/README.md b/python-ud3tn-utils/README.md new file mode 100644 index 0000000..05df702 --- /dev/null +++ b/python-ud3tn-utils/README.md @@ -0,0 +1,44 @@ +# python-uD3TN-utils + +The Python package uD3TN-utils is a utility library to simplify the interaction +with the uD3TN daemon within python applications. + +The included `AAPClient` enables user-friendly communication with the uD3TN +daemon via local or remote sockets using the Application Agent Protocol (AAP). +Besides sending and receiving bundles, it is also possible to change the +configuration of the uD3TN daemon via AAP messages. + +## Installation + +From source: + +```sh +git clone https://gitlab.com/d3tn/ud3tn +cd python-ud3tn-utils +python setup.py install +``` + +From [PyPi](https://pypi.org/project/ud3tn-utils) directly: + +```sh +pip install ud3tn-utils +``` + +## Examples + +```python +from ud3tn_utils.aap import AAPUnixClient + +with AAPUnixClient() as aap_client: + aap_client.register() + aap_client.send_str(aap_client.eid(), "Hello World") + print(aap_client.receive()) +``` + +## Development + +pyD3TN is maintained as part of the µD3TN project and follows its development +processes. Please see the [µD3TN][ud3tn] repository for the code and further +information. + +[ud3tn]: https://gitlab.com/d3tn/ud3tn diff --git a/python-ud3tn-utils/setup.py b/python-ud3tn-utils/setup.py new file mode 100644 index 0000000..f0e7288 --- /dev/null +++ b/python-ud3tn-utils/setup.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import setuptools + +with open('README.md', 'r') as file: + long_description = file.read() + +setuptools.setup( + name='ud3tn-utils', + version='0.1.0', + author='D3TN GmbH', + author_email='contact@d3tn.com', + description='μD3TN Utilities', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://gitlab.com/d3tn/ud3tn', + packages=['ud3tn_utils', 'ud3tn_utils.aap'], + python_requires='>=3.6', +) diff --git a/python-ud3tn-utils/ud3tn_utils/__init__.py b/python-ud3tn-utils/ud3tn_utils/__init__.py new file mode 100644 index 0000000..da91de0 --- /dev/null +++ b/python-ud3tn-utils/ud3tn_utils/__init__.py @@ -0,0 +1,5 @@ +"""Python library for the µD3TN project""" + +from . import config + +__all__ = ['config'] diff --git a/python-ud3tn-utils/ud3tn_utils/aap/__init__.py b/python-ud3tn-utils/ud3tn_utils/aap/__init__.py new file mode 100644 index 0000000..81590e8 --- /dev/null +++ b/python-ud3tn-utils/ud3tn_utils/aap/__init__.py @@ -0,0 +1,11 @@ +from .aap_client import AAPClient, AAPTCPClient, AAPUnixClient +from .aap_message import AAPMessage, AAPMessageType, InsufficientAAPDataError + +__all__ = [ + 'AAPClient', + 'AAPTCPClient', + 'AAPUnixClient', + 'AAPMessage', + 'AAPMessageType', + 'InsufficientAAPDataError' +] diff --git a/tools/aap/aapclient.py b/python-ud3tn-utils/ud3tn_utils/aap/aap_client.py similarity index 98% rename from tools/aap/aapclient.py rename to python-ud3tn-utils/ud3tn_utils/aap/aap_client.py index 15f0377..4f51f01 100644 --- a/tools/aap/aapclient.py +++ b/python-ud3tn-utils/ud3tn_utils/aap/aap_client.py @@ -5,7 +5,7 @@ import logging import socket import uuid -from pyupcn.aap import AAPMessage, AAPMessageType, InsufficientAAPDataError +from .aap_message import AAPMessage, AAPMessageType, InsufficientAAPDataError logger = logging.getLogger(__name__) diff --git a/pyupcn/aap.py b/python-ud3tn-utils/ud3tn_utils/aap/aap_message.py similarity index 96% rename from pyupcn/aap.py rename to python-ud3tn-utils/ud3tn_utils/aap/aap_message.py index 21929f5..481f53d 100644 --- a/pyupcn/aap.py +++ b/python-ud3tn-utils/ud3tn_utils/aap/aap_message.py @@ -1,8 +1,9 @@ -"""uPCN Application Agent Protocol (AAP) Python implementation. +"""μD3TN Application Agent Protocol (AAP) Python implementation. Usage: Use the AAPMessage class to build, serialize, and parse AAP messages. - For a description of the protocol, see doc/upcn_aap.md. + For a description of the protocol, see + https://gitlab.com/d3tn/ud3tn/-/blob/master/doc/ud3tn_aap.md. """ import struct diff --git a/pyupcn/agents.py b/python-ud3tn-utils/ud3tn_utils/config.py similarity index 78% rename from pyupcn/agents.py rename to python-ud3tn-utils/ud3tn_utils/config.py index af7272b..d52f656 100644 --- a/pyupcn/agents.py +++ b/python-ud3tn-utils/ud3tn_utils/config.py @@ -3,11 +3,29 @@ import time import struct from collections import namedtuple -from .helpers import unix2dtn +from datetime import datetime, timezone + +UNIX_EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc) +DTN_EPOCH = datetime(2000, 1, 1, tzinfo=timezone.utc) +UNIX_TO_DTN_OFFSET = (DTN_EPOCH - UNIX_EPOCH).total_seconds() +assert UNIX_TO_DTN_OFFSET == 946684800 + + +def unix2dtn(unix_timestamp): + """Converts a given Unix timestamp into a DTN timestamp + + Its inversion is :func:`dtn2unix`. + + Args: + unix_timestamp: Unix timestamp + Returns: + numeric: DTN timestamp + """ + return unix_timestamp - UNIX_TO_DTN_OFFSET class RouterCommand(enum.IntEnum): - """uPCN Command Constants""" + """uD3TN Command Constants""" ADD = 1 UPDATE = 2 DELETE = 3 @@ -15,7 +33,7 @@ class RouterCommand(enum.IntEnum): Contact = namedtuple('Contact', ['start', 'end', 'bitrate']) -Contact.__doc__ = """named tuple holding upcn contact information +Contact.__doc__ = """named tuple holding uD3TN contact information Attrs: start (int): DTN timestamp when the contact starts @@ -45,8 +63,8 @@ def make_contact(start_offset, duration, bitrate): class ConfigMessage(object): - """upcn configuration message that can be processes by its config agent. - These messages are used to configure contacts in upcn. + """uD3TN configuration message that can be processes by its config agent. + These messages are used to configure contacts in uD3TN. Args: eid (str): The endpoint identifier of a contact @@ -73,7 +91,7 @@ class ConfigMessage(object): ) def __str__(self): - # missing escaping has to be addresses in uPCN + # missing escaping has to be addresses in uD3TN for part in [self.eid, self.cla_address] + self.reachable_eids: assert "(" not in part assert ")" not in part @@ -110,7 +128,7 @@ class ConfigMessage(object): class ManagementCommand(enum.IntEnum): - """uPCN Management Command Constants""" + """uD3TN Management Command Constants""" SET_TIME = 0 diff --git a/pyupcn/__init__.py b/pyupcn/__init__.py deleted file mode 100644 index 115437b..0000000 --- a/pyupcn/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Python tools for the µPCN project""" diff --git a/pyupcn/install.py b/pyupcn/install.py deleted file mode 100644 index 592909c..0000000 --- a/pyupcn/install.py +++ /dev/null @@ -1,29 +0,0 @@ -"""Simple installation script for Python modules in the tools/ directory of the -µPCN project. - -Usage: - Simply execute this script with the Python interpret of your choice. The - tools/ directory will be added to the system paths. - - .. code:: bash - - python tools/pyupcn/install.py -""" -import site -import os - -tools_dir = os.path.abspath(os.path.join(__file__, '../..')) -site_dir = site.getsitepackages()[0] - - -def install(): - """Adds a ``.pth`` file to the site-packages directory of the Python - interpreter executing this script. The .pth file contains the path to the - ``tools/`` directory of the µPCN project. - """ - with open(os.path.join(site_dir, 'pyupcn.pth'), 'w') as fd: - fd.write(tools_dir) - - -if __name__ == '__main__': - install() diff --git a/pyupcn/requirements.txt b/pyupcn/requirements.txt deleted file mode 100644 index d355f59..0000000 --- a/pyupcn/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -# Python dependencies for the pyupcn package -cbor diff --git a/test/integration/helpers.py b/test/integration/helpers.py index bd014c8..4864156 100644 --- a/test/integration/helpers.py +++ b/test/integration/helpers.py @@ -1,7 +1,7 @@ import os -from pyupcn.agents import ConfigMessage, RouterCommand -from pyupcn.bundle7 import Bundle, CRCType +from ud3tn_utils.config import ConfigMessage, RouterCommand +from pyd3tn.bundle7 import Bundle, CRCType USER_SELECTED_CLA = os.environ.get("CLA", None) TESTED_CLAS = [USER_SELECTED_CLA] if USER_SELECTED_CLA else [ diff --git a/test/integration/test_bundle_routing.py b/test/integration/test_bundle_routing.py index b340173..f36d1cf 100644 --- a/test/integration/test_bundle_routing.py +++ b/test/integration/test_bundle_routing.py @@ -4,9 +4,10 @@ import copy import pytest -from pyupcn.agents import ConfigMessage, make_contact -from pyupcn.bundle7 import serialize_bundle7, BundleProcFlag -from pyupcn.spp import TCPSPPConnection +from ud3tn_utils.config import ConfigMessage, make_contact + +from pyd3tn.bundle7 import serialize_bundle7, BundleProcFlag +from pyd3tn.spp import TCPSPPConnection from .helpers import ( TESTED_CLAS, @@ -113,7 +114,7 @@ def receive_and_check(conn, validate_func, is_frag_func, expected_bundles): print("Waiting to receive bundle #{}...".format(i)) try: bdl = conn.recv_bundle() - except: + except Exception: print("Reception did not finish.") raise decoded = validate_func(bdl, None) diff --git a/test/integration/test_bundle_send_receive.py b/test/integration/test_bundle_send_receive.py index 7791533..05cfdf6 100644 --- a/test/integration/test_bundle_send_receive.py +++ b/test/integration/test_bundle_send_receive.py @@ -3,12 +3,15 @@ import math import pytest -from pyupcn.agents import ConfigMessage, make_contact, serialize_set_time_cmd -from pyupcn.bundle7 import serialize_bundle7 -from pyupcn.bundle6 import serialize_bundle6 -from pyupcn.mtcp import MTCPConnection -from pyupcn.spp import TCPSPPConnection -from pyupcn.tcpcl import TCPCLConnection +from ud3tn_utils.config import ( + ConfigMessage, make_contact, serialize_set_time_cmd +) + +from pyd3tn.bundle7 import serialize_bundle7 +from pyd3tn.bundle6 import serialize_bundle6 +from pyd3tn.mtcp import MTCPConnection +from pyd3tn.spp import TCPSPPConnection +from pyd3tn.tcpcl import TCPCLConnection from .helpers import ( TESTED_CLAS, diff --git a/tools/aap/aap_config.py b/tools/aap/aap_config.py index db24c6a..866e41e 100644 --- a/tools/aap/aap_config.py +++ b/tools/aap/aap_config.py @@ -4,9 +4,10 @@ import argparse import logging -from pyupcn.agents import ConfigMessage, make_contact +from ud3tn_utils.aap import AAPTCPClient, AAPUnixClient + +from ud3tn_utils.config import ConfigMessage, make_contact -from aapclient import AAPTCPClient, AAPUnixClient from helpers import ( add_socket_group_parser_arguments, diff --git a/tools/aap/aap_receive.py b/tools/aap/aap_receive.py index f0ad77d..ea52126 100644 --- a/tools/aap/aap_receive.py +++ b/tools/aap/aap_receive.py @@ -5,7 +5,7 @@ import argparse import logging import sys -from aapclient import AAPUnixClient, AAPTCPClient +from ud3tn_utils.aap import AAPUnixClient, AAPTCPClient from helpers import add_common_parser_arguments, logging_level diff --git a/tools/aap/aap_send.py b/tools/aap/aap_send.py index 4dba28b..849f255 100644 --- a/tools/aap/aap_send.py +++ b/tools/aap/aap_send.py @@ -4,7 +4,7 @@ import argparse import logging -from aapclient import AAPUnixClient, AAPTCPClient +from ud3tn_utils.aap import AAPUnixClient, AAPTCPClient from helpers import add_common_parser_arguments, logging_level if __name__ == "__main__": diff --git a/tools/aap/aap_test.py b/tools/aap/aap_test.py index 272622c..5c0682c 100644 --- a/tools/aap/aap_test.py +++ b/tools/aap/aap_test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # encoding: utf-8 -from aapclient import AAPUnixClient +from ud3tn_utils.aap import AAPUnixClient AGENT_ID = "testagent" diff --git a/tools/cla/mtcp_sink.py b/tools/cla/mtcp_sink.py index 5f2d4ab..8862fd8 100644 --- a/tools/cla/mtcp_sink.py +++ b/tools/cla/mtcp_sink.py @@ -3,8 +3,8 @@ import socket import sys -from pyupcn.bundle7 import Bundle -from pyupcn.mtcp import MTCPSocket +from pyd3tn.bundle7 import Bundle +from pyd3tn.mtcp import MTCPSocket def main(): diff --git a/tools/cla/mtcp_test.py b/tools/cla/mtcp_test.py index 3acac70..ee8cdf3 100644 --- a/tools/cla/mtcp_test.py +++ b/tools/cla/mtcp_test.py @@ -3,10 +3,11 @@ import time -from pyupcn.agents import ConfigMessage, make_contact -from pyupcn.bundle7 import serialize_bundle7, Bundle -from pyupcn.bundle6 import serialize_bundle6 -from pyupcn.mtcp import MTCPConnection +from ud3tn_utils.config import ConfigMessage, make_contact + +from pyd3tn.bundle7 import serialize_bundle7, Bundle +from pyd3tn.bundle6 import serialize_bundle6 +from pyd3tn.mtcp import MTCPConnection SENDING_GS_DEF = ("dtn://sender.dtn", "sender") diff --git a/tools/cla/tcpcl_sink.py b/tools/cla/tcpcl_sink.py index 6b6e194..cc5c781 100644 --- a/tools/cla/tcpcl_sink.py +++ b/tools/cla/tcpcl_sink.py @@ -3,7 +3,7 @@ import logging import signal import asyncio -from pyupcn.tcpcl import TCPCLServer, logger +from pyd3tn.tcpcl import TCPCLServer, logger DEFAULT_INCOMING_EID = "dtn:1" diff --git a/tools/cla/tcpcl_test.py b/tools/cla/tcpcl_test.py index 2abeffe..6a0d55a 100644 --- a/tools/cla/tcpcl_test.py +++ b/tools/cla/tcpcl_test.py @@ -5,14 +5,15 @@ import time import socket import argparse -from pyupcn.tcpcl import ( +from ud3tn_utils.config import ConfigMessage, make_contact + +from pyd3tn.tcpcl import ( serialize_tcpcl_contact_header, decode_tcpcl_contact_header, serialize_tcpcl_single_bundle_segment, ) -from pyupcn.agents import ConfigMessage, make_contact -from pyupcn.bundle6 import serialize_bundle6 -from pyupcn.bundle7 import serialize_bundle7 +from pyd3tn.bundle6 import serialize_bundle6 +from pyd3tn.bundle7 import serialize_bundle7 DEFAULT_OUTGOING_EID = "dtn:2" DEFAULT_INCOMING_EID = "dtn:1" diff --git a/tools/cla/tcpspp_test.py b/tools/cla/tcpspp_test.py index a437861..2981746 100644 --- a/tools/cla/tcpspp_test.py +++ b/tools/cla/tcpspp_test.py @@ -2,10 +2,11 @@ import socket -from pyupcn.agents import ConfigMessage, make_contact -from pyupcn.bundle7 import serialize_bundle7, Bundle -from pyupcn.bundle6 import serialize_bundle6 -from pyupcn.spp import SPPPacket, SPPPacketHeader, SPPTimecode +from ud3tn_utils.config import ConfigMessage, make_contact + +from pyd3tn.bundle7 import serialize_bundle7, Bundle +from pyd3tn.bundle6 import serialize_bundle6 +from pyd3tn.spp import SPPPacket, SPPPacketHeader, SPPTimecode DEFAULT_OUTGOING_EID = "dtn:2"