Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-teleportation-app.h
Go to the documentation of this file.
1/*-----------------------------------------------------------------------------
2 * Q2NS - Quantum Network Simulator
3 * Copyright (c) 2026 quantuminternet.it
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *---------------------------------------------------------------------------*/
9/**
10 * @file q2ns-teleportation-app.h
11 * @brief Declares q2ns::TeleportationApp, the teleportation ns-3 Application.
12 */
13#pragma once
14
15#include "ns3/application.h"
16#include "ns3/data-rate.h"
17#include "ns3/ipv4-address.h"
18#include "ns3/ptr.h"
19#include "ns3/socket.h"
20#include "ns3/traced-callback.h"
21
22#include <cstdint>
23#include <string>
24
25namespace ns3 {
26class Packet;
27class Address;
28class PacketSink;
29class Application; // base class already included via application.h
30} // namespace ns3
31
32namespace q2ns {
33
34class NetController;
35class QNode;
36class Qubit;
37class QState;
38
39
40class TeleportationApp final : public ns3::Application {
41public:
42 static ns3::TypeId GetTypeId();
43
45 ~TeleportationApp() override = default;
46
47 // ns3::Application
48 void StartApplication() override;
49 void StopApplication() override;
50
51 // Inject central orchestrator (not an ns-3 Object, so we use a plain setter)
53
54 // User must set the state to be teleported
55 void SetTeleportState(const std::shared_ptr<QState>& state);
56
57 // TraceSources
58 // Source-side (Alice) local events
59 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSourceStart; // when Alice starts session
60 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSourceBellDone; // Bell measurement done
61 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSourceCtrlSent; // 2-bit ctrl sent
62
63 // Sink-side (Bob) local events
64 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSinkStart; // when Bob starts session
65 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSinkQArrive; // qubits arrived
66 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSinkCtrlArrive; // ctrl bits arrived
67 ns3::TracedCallback<uint64_t, ns3::Time> m_traceSinkCorrection; // correction completed
68
69private:
70 std::string m_role; // "source" | "sink"
71 ns3::Ptr<q2ns::QNode> m_peerQNode;
72 std::shared_ptr<QState> m_teleportState;
73 ns3::Ipv4Address m_peer; // ctrl peer addr (used by source)
74 uint16_t m_ctrlPort{7000}; // per-session port
75 std::string m_ctrlProto; // "udp" | "tcp"
76 std::string m_backend; // "stab" | "ket" | ...
77 std::string m_targetQubitTag; // e.g., "teleport_target"
78 uint64_t m_sessionId{0};
79 ns3::Time m_sessionStart{ns3::Seconds(0.0)};
80
81 q2ns::NetController* m_nc{nullptr}; // central orchestrator (non-owning)
82 ns3::Ptr<ns3::Packet> m_pendingCtrlPkt; // Pending ctrl packet for TCP connect-complete
83 ns3::Ptr<ns3::PacketSink> m_ctrlSink; // sink (on Bob)
84 ns3::Ptr<ns3::Application> m_ctrlSender; // one-shot sender (on Alice)
85
86 void DoSourceStart();
87 void DoSinkStart();
88
89 void OnTcpConnectSuccess(ns3::Ptr<ns3::Socket> s);
90 void OnTcpConnectFail(ns3::Ptr<ns3::Socket> s);
91
92 void QubitArrivalHandler(std::shared_ptr<Qubit> q);
93
94 void OnCtrlRx(ns3::Ptr<const ns3::Packet> pkt, const ns3::Address& from);
95
96 void SendCtrlBits(uint8_t m1, uint8_t m2);
97
98 void TryApplyCorrection();
99 bool m_haveCtrl{false};
100 bool m_haveQ{false};
101 uint8_t m_m1{0}, m_m2{0};
102};
103
104} // namespace q2ns
Main user-facing facade for creating and configuring a quantum network.
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSourceBellDone
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSourceCtrlSent
void OnTcpConnectSuccess(ns3::Ptr< ns3::Socket > s)
~TeleportationApp() override=default
ns3::Ptr< ns3::Application > m_ctrlSender
ns3::Ptr< ns3::PacketSink > m_ctrlSink
void SetTeleportState(const std::shared_ptr< QState > &state)
q2ns::NetController * m_nc
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSinkCorrection
void QubitArrivalHandler(std::shared_ptr< Qubit > q)
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSourceStart
void OnTcpConnectFail(ns3::Ptr< ns3::Socket > s)
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSinkStart
ns3::Ptr< ns3::Packet > m_pendingCtrlPkt
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSinkQArrive
static ns3::TypeId GetTypeId()
void SetNetController(NetController *nc)
void OnCtrlRx(ns3::Ptr< const ns3::Packet > pkt, const ns3::Address &from)
std::shared_ptr< QState > m_teleportState
ns3::Ptr< q2ns::QNode > m_peerQNode
ns3::TracedCallback< uint64_t, ns3::Time > m_traceSinkCtrlArrive
void SendCtrlBits(uint8_t m1, uint8_t m2)
uint8_t m2
uint8_t m1