Commit 41334de3 authored by Juraj Sloboda's avatar Juraj Sloboda Committed by Matej Feder

Fixes and improvements

parent 12bda5ae
.scannerwork
*~
.idea
__pycache__
*.swp
*.egg-info
__pycache__
.idea
.scannerwork
# Log files
*.log
......@@ -333,7 +333,7 @@ class BPAgent:
logger.info('BP Agent is receiving bundle')
last_bundle_segment = False
bundle_data = b''
bundle_data = bytearray()
while not last_bundle_segment:
data_segment, _, last_bundle_segment = await conn.recv()
bundle_data += data_segment
......
......@@ -5,7 +5,9 @@ from datetime import timedelta
from ..encoding.bundle7 import Bundle, BundleAgeBlock, BundleProcFlag, BundleStatusReport, CreationTimestamp, HopCountBlock,\
PayloadBlock, PreviousNodeBlock, PrimaryBlock, ReasonCode, StatusCode, dtn_start, print_hex
primary_block = PrimaryBlock(
if __name__ == '__main__':
primary_block = PrimaryBlock(
bundle_proc_flags=BundleProcFlag.MUST_NOT_BE_FRAGMENTED
| BundleProcFlag.CONTAINS_MANIFEST
| BundleProcFlag.REPORT_DELIVERY
......@@ -14,40 +16,40 @@ primary_block = PrimaryBlock(
source="dtn:none",
report_to="dtn:none",
creation_time=CreationTimestamp(dtn_start, 0),
)
)
payload = PayloadBlock(b"Hello world!")
payload = PayloadBlock(b"Hello world!")
# Extension blocks
previous_node = PreviousNodeBlock("dtn:GS4")
hop_count = HopCountBlock(30, 0)
bundle_age = BundleAgeBlock(0)
# Extension blocks
previous_node = PreviousNodeBlock("dtn:GS4")
hop_count = HopCountBlock(30, 0)
bundle_age = BundleAgeBlock(0)
bundle = Bundle([
bundle = Bundle([
primary_block,
previous_node,
hop_count,
bundle_age,
payload,
])
])
# Bundle Status Report "Received bundle"
status_report = BundleStatusReport(infos=StatusCode.RECEIVED_BUNDLE,
# Bundle Status Report "Received bundle"
status_report = BundleStatusReport(infos=StatusCode.RECEIVED_BUNDLE,
reason=ReasonCode.NO_INFO,
bundle=bundle,
time=dtn_start + timedelta(seconds=10))
status_report_bundle = Bundle([
status_report_bundle = Bundle([
PrimaryBlock(
bundle_proc_flags=BundleProcFlag.ADMINISTRATIVE_RECORD,
destination=bundle.primary_block.report_to,
),
status_report,
])
])
print_hex(bundle.serialize())
# print_hex(status_report_bundle.serialize())
# print_hex(status_report.serialize())
print_hex(bundle.serialize())
# print_hex(status_report_bundle.serialize())
# print_hex(status_report.serialize())
with open("bundle.cbor", "wb") as fd:
with open("bundle.cbor", "wb") as fd:
fd.write(bundle.serialize())
{
"variables": [],
"info": {
"_postman_id": "674f0f56-6140-48b9-9005-c9af60133dc1",
"name": "pyDTN",
"_postman_id": "f4152c73-3342-2db8-a7cc-ad417f396372",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "schedule contact",
"request": {
"url": "http://localhost:8080/config",
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json",
"description": ""
"value": "application/json"
},
{
"key": "Content-Type",
"value": "application/json",
"description": ""
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"messages\": [\n {\n \"eid\": \"dtn:1\",\n \"cla_address\": \"127.0.0.1:42420\",\n \"start_offset\": 10,\n \"end_offset\": 600\n }\n ]\n}"
"raw": "{\n \"messages\": [\n {\n \"eid\": \"dtn://pyDTN-2.dtn\",\n \"cla_address\": \"172.25.2.11:2002\",\n \"start_offset\": 5,\n \"end_offset\": 20\n }\n ]\n}"
},
"description": ""
"url": {
"raw": "http://localhost:8082/config",
"protocol": "http",
"host": [
"localhost"
],
"port": "8082",
"path": [
"config"
]
}
},
"response": []
},
{
"name": "send Bundle",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": " @\n @\n @\n @\n `@` @: `@ @ '@@@@@, @@ @@# @ @@ :@@#\n +@ @@ @; @' #@ @@, '@# @@@+, @ @@ ,@,.@@\n @@ #@ ;@ @@ @`#@ @: @@: @ @@ @;\n @;`@` @` #@@, ;@ @` .@@# ;@ @@ @ `@# @#\n ,@@+ #@ @.#@ @::@ :@ #@ @ @@ @:@' `@+\n @@ #@@@@@ @ ;@ @ `@ +@'+ ::` @ @.@@ @@; `@@,\n ;@@@ @# @; @@ @# '@@ @':. .;@`@@ @,@' ;@+\n @, @, `@.@ @ @ `@#.#,` +,@ @@ @ `@# `@\n @@ ;@ @@# @@@ @'@@@@@@`@@ @@ @ @@ @\n #@ @@ ;@ .@ `@: ,'@.@ @@ @ @@ @` #@\n .@ @+ @ @ .@`:.`:. @@ @ @@ #@@@@\n @@+:` `\n @@+,\n @@\n"
},
"url": {
"raw": "http://localhost:8080/bundle?destination=dtn:1",
"raw": "http://localhost:8081/bundle?source=dtn://pyDTN-1.dtn/postman&destination=dtn://pyDTN-2.dtn/demo_app",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"port": "8081",
"path": [
"bundle"
],
"query": [
{
"key": "destination",
"value": "dtn:1",
"equals": true,
"description": ""
}
],
"variable": []
"key": "source",
"value": "dtn://pyDTN-1.dtn/postman"
},
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json",
"description": ""
"key": "destination",
"value": "dtn://pyDTN-2.dtn/demo_app"
}
]
}
],
"body": {
"mode": "raw",
"raw": " @\n @\n @\n @\n `@` @: `@ @ '@@@@@, @@ @@# @ @@ :@@#\n +@ @@ @; @' #@ @@, '@# @@@+, @ @@ ,@,.@@\n @@ #@ ;@ @@ @`#@ @: @@: @ @@ @;\n @;`@` @` #@@, ;@ @` .@@# ;@ @@ @ `@# @#\n ,@@+ #@ @.#@ @::@ :@ #@ @ @@ @:@' `@+\n @@ #@@@@@ @ ;@ @ `@ +@'+ ::` @ @.@@ @@; `@@,\n ;@@@ @# @; @@ @# '@@ @':. .;@`@@ @,@' ;@+\n @, @, `@.@ @ @ `@#.#,` +,@ @@ @ `@# `@\n @@ ;@ @@# @@@ @'@@@@@@`@@ @@ @ @@ @\n #@ @@ ;@ .@ `@: ,'@.@ @@ @ @@ @` #@\n .@ @+ @ @ .@`:.`:. @@ @ @@ #@@@@\n @@+:` `\n @@+,\n @@\n"
},
"description": ""
},
"response": []
}
......
......@@ -10,6 +10,6 @@ sleep 3
# pyDTN-1 sends bundle to pyDTN-2
echo "Sending bundle"
curl -H "Content-Type: application/json" --data-binary @X-works.txt "http://localhost:8081/bundle?source=dtn://pyDTN-2.dtn/send.sh&destination=dtn://pyDTN-2.dtn/demo_app" || exit 1
curl -H "Content-Type: application/json" --data-binary @X-works.txt "http://localhost:8081/bundle?source=dtn://pyDTN-1.dtn/send.sh&destination=dtn://pyDTN-2.dtn/demo_app" || exit 1
echo OK
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment