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

Fixes and improvements

parent 12bda5ae
.scannerwork
*~ *~
.idea
__pycache__
*.swp *.swp
*.egg-info *.egg-info
__pycache__
.idea
.scannerwork
# Log files # Log files
*.log *.log
...@@ -333,7 +333,7 @@ class BPAgent: ...@@ -333,7 +333,7 @@ class BPAgent:
logger.info('BP Agent is receiving bundle') logger.info('BP Agent is receiving bundle')
last_bundle_segment = False last_bundle_segment = False
bundle_data = b'' bundle_data = bytearray()
while not last_bundle_segment: while not last_bundle_segment:
data_segment, _, last_bundle_segment = await conn.recv() data_segment, _, last_bundle_segment = await conn.recv()
bundle_data += data_segment bundle_data += data_segment
......
...@@ -5,49 +5,51 @@ from datetime import timedelta ...@@ -5,49 +5,51 @@ from datetime import timedelta
from ..encoding.bundle7 import Bundle, BundleAgeBlock, BundleProcFlag, BundleStatusReport, CreationTimestamp, HopCountBlock,\ from ..encoding.bundle7 import Bundle, BundleAgeBlock, BundleProcFlag, BundleStatusReport, CreationTimestamp, HopCountBlock,\
PayloadBlock, PreviousNodeBlock, PrimaryBlock, ReasonCode, StatusCode, dtn_start, print_hex PayloadBlock, PreviousNodeBlock, PrimaryBlock, ReasonCode, StatusCode, dtn_start, print_hex
primary_block = PrimaryBlock( if __name__ == '__main__':
bundle_proc_flags=BundleProcFlag.MUST_NOT_BE_FRAGMENTED
| BundleProcFlag.CONTAINS_MANIFEST primary_block = PrimaryBlock(
| BundleProcFlag.REPORT_DELIVERY bundle_proc_flags=BundleProcFlag.MUST_NOT_BE_FRAGMENTED
| BundleProcFlag.REPORT_STATUS_TIME, | BundleProcFlag.CONTAINS_MANIFEST
destination="dtn:GS2", | BundleProcFlag.REPORT_DELIVERY
source="dtn:none", | BundleProcFlag.REPORT_STATUS_TIME,
report_to="dtn:none", destination="dtn:GS2",
creation_time=CreationTimestamp(dtn_start, 0), source="dtn:none",
) report_to="dtn:none",
creation_time=CreationTimestamp(dtn_start, 0),
payload = PayloadBlock(b"Hello world!") )
# Extension blocks payload = PayloadBlock(b"Hello world!")
previous_node = PreviousNodeBlock("dtn:GS4")
hop_count = HopCountBlock(30, 0) # Extension blocks
bundle_age = BundleAgeBlock(0) previous_node = PreviousNodeBlock("dtn:GS4")
hop_count = HopCountBlock(30, 0)
bundle = Bundle([ bundle_age = BundleAgeBlock(0)
primary_block,
previous_node, bundle = Bundle([
hop_count, primary_block,
bundle_age, previous_node,
payload, hop_count,
]) bundle_age,
payload,
# Bundle Status Report "Received bundle" ])
status_report = BundleStatusReport(infos=StatusCode.RECEIVED_BUNDLE,
reason=ReasonCode.NO_INFO, # Bundle Status Report "Received bundle"
bundle=bundle, status_report = BundleStatusReport(infos=StatusCode.RECEIVED_BUNDLE,
time=dtn_start + timedelta(seconds=10)) reason=ReasonCode.NO_INFO,
bundle=bundle,
status_report_bundle = Bundle([ time=dtn_start + timedelta(seconds=10))
PrimaryBlock(
bundle_proc_flags=BundleProcFlag.ADMINISTRATIVE_RECORD, status_report_bundle = Bundle([
destination=bundle.primary_block.report_to, PrimaryBlock(
), bundle_proc_flags=BundleProcFlag.ADMINISTRATIVE_RECORD,
status_report, 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())
with open("bundle.cbor", "wb") as fd: # print_hex(status_report.serialize())
fd.write(bundle.serialize())
with open("bundle.cbor", "wb") as fd:
fd.write(bundle.serialize())
{ {
"variables": [],
"info": { "info": {
"_postman_id": "674f0f56-6140-48b9-9005-c9af60133dc1",
"name": "pyDTN", "name": "pyDTN",
"_postman_id": "f4152c73-3342-2db8-a7cc-ad417f396372", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
}, },
"item": [ "item": [
{ {
"name": "schedule contact", "name": "schedule contact",
"request": { "request": {
"url": "http://localhost:8080/config",
"method": "POST", "method": "POST",
"header": [ "header": [
{ {
"key": "Accept", "key": "Accept",
"value": "application/json", "value": "application/json"
"description": ""
}, },
{ {
"key": "Content-Type", "key": "Content-Type",
"value": "application/json", "value": "application/json"
"description": ""
} }
], ],
"body": { "body": {
"mode": "raw", "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": [] "response": []
}, },
{ {
"name": "send Bundle", "name": "send Bundle",
"request": { "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": { "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", "protocol": "http",
"host": [ "host": [
"localhost" "localhost"
], ],
"port": "8080", "port": "8081",
"path": [ "path": [
"bundle" "bundle"
], ],
"query": [ "query": [
{
"key": "source",
"value": "dtn://pyDTN-1.dtn/postman"
},
{ {
"key": "destination", "key": "destination",
"value": "dtn:1", "value": "dtn://pyDTN-2.dtn/demo_app"
"equals": true,
"description": ""
} }
], ]
"variable": [] }
},
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": " @\n @\n @\n @\n `@` @: `@ @ '@@@@@, @@ @@# @ @@ :@@#\n +@ @@ @; @' #@ @@, '@# @@@+, @ @@ ,@,.@@\n @@ #@ ;@ @@ @`#@ @: @@: @ @@ @;\n @;`@` @` #@@, ;@ @` .@@# ;@ @@ @ `@# @#\n ,@@+ #@ @.#@ @::@ :@ #@ @ @@ @:@' `@+\n @@ #@@@@@ @ ;@ @ `@ +@'+ ::` @ @.@@ @@; `@@,\n ;@@@ @# @; @@ @# '@@ @':. .;@`@@ @,@' ;@+\n @, @, `@.@ @ @ `@#.#,` +,@ @@ @ `@# `@\n @@ ;@ @@# @@@ @'@@@@@@`@@ @@ @ @@ @\n #@ @@ ;@ .@ `@: ,'@.@ @@ @ @@ @` #@\n .@ @+ @ @ .@`:.`:. @@ @ @@ #@@@@\n @@+:` `\n @@+,\n @@\n"
},
"description": ""
}, },
"response": [] "response": []
} }
......
...@@ -10,6 +10,6 @@ sleep 3 ...@@ -10,6 +10,6 @@ sleep 3
# pyDTN-1 sends bundle to pyDTN-2 # pyDTN-1 sends bundle to pyDTN-2
echo "Sending bundle" 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 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