Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-qnetworker.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-qnetworker.h
11 * @brief Declares q2ns::QNetworker, an internal per-node networking component
12 * for quantum transmission and reception.
13 */
14
15#pragma once
16
17#include "ns3/callback.h"
18#include "ns3/ptr.h"
19
20#include "ns3/q2ns-types.h"
21
22#include <cstdint>
23#include <memory>
24#include <unordered_map>
25#include <vector>
26
27namespace ns3 {
28class NetDevice;
29} // namespace ns3
30
31namespace q2ns {
32
33class Qubit;
34class QNode;
35class QNetDevice;
36
37/**
38 * @ingroup q2ns_network
39 * @class QNetworker
40 * @brief Internal helper owned by QNode for node-local quantum networking.
41 *
42 * QNetworker is not intended to be the main user-facing API. Instead, users should send qubits and
43 * register receive callbacks through QNode, which delegates network-facing behavior to its internal
44 * QNetworker.
45 *
46 * Responsibilities:
47 * - Maintain a list of node-local quantum interfaces backed by QNetDevice.
48 * - Maintain a minimal host-route table mapping destination node id to
49 * outgoing interface index.
50 * - Send local qubits toward a destination node using the configured route.
51 * - Accept qubits delivered from a channel, adopt them into the owning node,
52 * apply any sampled channel map, and notify the registered receive callback.
53 */
55public:
56 /**
57 * @brief Construct a networker bound to an owning node.
58 * @param [in] owner Owning node.
59 */
60 explicit QNetworker(QNode& owner_);
61
62 /**
63 * @brief Register a quantum device as an outgoing interface. Analogue of
64 * Ipv4L3Protocol::AddInterface(dev).
65 *
66 * The supplied device must be a QNetDevice.
67 *
68 * @param dev NetDevice to register.
69 * @return Interface index assigned to the registered device.
70 */
71 uint32_t AddInterface(ns3::Ptr<ns3::NetDevice> dev);
72
73 /**
74 * @brief Add or replace a host route for a destination node.
75 *
76 * The route maps a destination node id to an outgoing interface index.
77 *
78 * @param dstNodeId Destination node identifier.
79 * @param oif Outgoing interface index.
80 */
81 void AddRoute(uint32_t dstNodeId, uint32_t oif);
82
83 /**
84 * @brief Send a local qubit toward a destination node.
85 *
86 * The qubit must be local to the owning node and not lost. The destination
87 * must have a configured host route that resolves to a valid outgoing
88 * interface and attached channel.
89 *
90 * On successful acceptance by the outgoing device, the qubit location is
91 * updated to the channel before transmission proceeds.
92 *
93 * @param q Qubit to send.
94 * @param dstNodeId Destination node identifier.
95 * @return True if the outgoing device accepted the transmission request,
96 * false otherwise.
97 */
98 bool Send(std::shared_ptr<Qubit> q, uint32_t dstNodeId);
99
100 /**
101 * @brief Handle a qubit delivered from a channel.
102 *
103 * The qubit is first adopted into the owning node. If a sampled QMapInstance
104 * is provided, it is then applied. If the qubit is not lost after that
105 * processing, the registered receive callback is invoked.
106 *
107 * @param q Delivered qubit.
108 * @param map Sampled per-transmission channel map to apply on receipt.
109 */
110 void ReceiveFromDevice(std::shared_ptr<Qubit> q, const QMapInstance& map);
111
112 /**
113 * @brief Set the application-level receive callback.
114 * @param cb Callback invoked for qubits successfully delivered to this node.
115 */
117
118 /**
119 * @brief Get the registered outgoing interfaces.
120 * @return Read-only reference to the interface table.
121 */
122 const std::vector<ns3::Ptr<QNetDevice>>& GetInterfaces() const {
123 return m_ifaces;
124 }
125
126private:
127 QNode& owner_; //!< Owning node.
128
129 std::vector<ns3::Ptr<QNetDevice>> m_ifaces; //!< Outgoing interfaces by index.
130 std::unordered_map<uint32_t, uint32_t> m_hostRoutes; //!< Host routes: dst node id to oif.
131 RecvCallback recvCallback_; //!< Application-level receive callback.
132};
133} // namespace q2ns
Internal helper owned by QNode for node-local quantum networking.
const std::vector< ns3::Ptr< QNetDevice > > & GetInterfaces() const
Get the registered outgoing interfaces.
void AddRoute(uint32_t dstNodeId, uint32_t oif)
Add or replace a host route for a destination node.
void SetRecvCallback(RecvCallback cb)
Set the application-level receive callback.
std::vector< ns3::Ptr< QNetDevice > > m_ifaces
Outgoing interfaces by index.
bool Send(std::shared_ptr< Qubit > q, uint32_t dstNodeId)
Send a local qubit toward a destination node.
QNode & owner_
Owning node.
RecvCallback recvCallback_
Application-level receive callback.
uint32_t AddInterface(ns3::Ptr< ns3::NetDevice > dev)
Register a quantum device as an outgoing interface. Analogue of Ipv4L3Protocol::AddInterface(dev).
void ReceiveFromDevice(std::shared_ptr< Qubit > q, const QMapInstance &map)
Handle a qubit delivered from a channel.
std::unordered_map< uint32_t, uint32_t > m_hostRoutes
Host routes: dst node id to oif.
Main user-facing per-node API for quantum operations and transmission.
Definition q2ns-qnode.h:63
ns3::Callback< void, std::shared_ptr< Qubit > > RecvCallback
Callback invoked when a qubit is successfully received at a node.
Definition q2ns-types.h:82
std::function< void(QNode &, std::shared_ptr< Qubit > &)> QMapInstance
Per-transmission quantum map callable applied to a received qubit.
Definition q2ns-types.h:71