ud3tn/doc/sqlite-storage.md
Maximilian Nitsch 4596f7a221 doc: Add SQLite storage documentation
Adds a brief description of the SQLite-based storage and a guide on how
to interact with the storage.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-04-15 11:05:21 +02:00

2.3 KiB

SQLite Storage

The SQLite-based persistent storage back-end is implemented in μD3TN as a ordinary CLA. Bundles that are sent via this CLA are written to an SQLite database instead of being transferred to another node. Saved bundles are therefore available beyond the lifetime of the μD3TN and can also be fed back into the μD3TN. From the point of view of the μD3TN, feeding back bundles is no different from receiving bundles via a CLA.

To interact with the SQLite storage, for example to delete bundles or send them to μD3TN, special commands can be sent to a local application agent that is connected to the SQLiteCLA. The protocol spoken by SQLiteAgent is based on Protobuf and allows to apply an operation to a set of packages selected by the destination EID.

How to interact with the storage

  1. Run μD3TN with enabled MTCP and SQLite CLA

    ./build/posix/ud3tn --cla "sqlite:ud3tn.sqlite;mtcp:*,4224"
    
  2. Run a second μD3TN instance as receiver

    ./build/posix/ud3tn --eid dtn://a.dtn/ --aap-socket ud3tn-a.socket --cla "mtcp:*,4225"
    
  3. Connect a receiver to the second μD3TN instance

    python tools/aap/aap_receive.py --socket ud3tn-a.socket --agentid bundlesink
    
  4. Configure a contact to the destination node via the SQLiteCLA

    python tools/aap/aap_config.py --schedule 1 10 100000 dtn://a.dtn/ sqlite
    
  5. Send a bundle to dtn://a.dtn

    python tools/aap/aap_send.py dtn://a.dtn/bundlesink "Hello"
    
  6. Query the database to verify the bundle is stored

    sqlite3 ud3tn.sqlite "SELECT source, destination, creation_timestamp, hex(bundle) FROM bundles;"
    
  7. Configure a contact

    python tools/aap/aap_config.py --schedule 1 60 100000 dtn://a.dtn/ mtcp:localhost:4225
    
  8. Send a command to the SQLiteAgent to inject the stored bundle back to μD3TN

    python tools/aap/aap_sqlite_agent.py push "dtn://a.dtn*"
    
  9. Verify the bundle is received by aap_receive

  10. Send a command to the SQLiteAgent to delete the stored bundle

    python tools/aap/aap_sqlite_agent.py delete "dtn://a.dtn*"
    
  11. Query the database to verify the bundle is deleted

    sqlite3 ud3tn.sqlite "SELECT source, destination, creation_timestamp, hex(bundle) FROM bundles;"