Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-qnet-device.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-qnet-device.h
11 * @brief Declares q2ns::QNetDevice, a minimal quantum net device that bridges
12 * a QChannel and a QNetworker.
13 */
14
15#pragma once
16
17#include "ns3/net-device.h"
18#include "ns3/ptr.h"
19#include "ns3/traced-callback.h"
20#include "ns3/type-id.h"
21
22#include "ns3/q2ns-types.h"
23
24#include <cstdint>
25#include <memory>
26
27namespace q2ns {
28
29class Qubit;
30class QNetworker;
31class QChannel;
32
33/**
34 * @ingroup q2ns_network
35 * @class QNetDevice
36 * @brief Minimal quantum net device that bridges a QChannel and a QNetworker.
37 *
38 * QNetDevice is an internal plumbing component used by QNode and QNetworker.
39 * It is intentionally small: it forwards outgoing qubits to an attached
40 * QChannel and forwards incoming qubits from that channel to the bound
41 * QNetworker.
42 *
43 * The inherited ns-3 NetDevice interface is implemented only to the extent
44 * needed for integration with ns-3 nodes and channels.
45 *
46 * @see QChannel
47 * @see QNetworker
48 */
49class QNetDevice : public ns3::NetDevice {
50public:
51 /**
52 * @brief Get the ns-3 TypeId.
53 * @return TypeId for q2ns::QNetDevice.
54 */
55 static ns3::TypeId GetTypeId(void);
56
57 /**
58 * @brief Default constructor.
59 */
61
62 /**
63 * @brief Bind the owning networker.
64 *
65 * The bound networker is notified when a qubit is delivered from the attached
66 * channel.
67 *
68 * @param networker Owning QNetworker.
69 *
70 * @see ReceiveFromChannel
71 */
72 void BindNetworker(QNetworker& networker);
73
74 /**
75 * @brief Attach this device to a quantum channel.
76 *
77 * This is normally called by QChannel when wiring the link endpoints.
78 *
79 * @param ch Attached channel.
80 *
81 * @see QChannel::Connect
82 */
83 void AttachChannel(ns3::Ptr<QChannel> ch);
84
85 /**
86 * @brief Send a qubit through the attached channel.
87 *
88 * This method forwards the transmission request to the attached channel. It
89 * does not perform routing.
90 *
91 * @param q Qubit to send.
92 * @return True if the attached channel accepted the transmission request,
93 * false otherwise.
94 *
95 * @see QChannel::SendFrom
96 */
97 bool Send(std::shared_ptr<Qubit> q);
98
99 /**
100 * @brief Return the attached channel.
101 * @return Attached channel as an ns-3 Channel pointer, or nullptr if none is
102 * attached.
103 */
104 ns3::Ptr<ns3::Channel> GetChannel() const override;
105
106 /**
107 * @brief Set the owning ns-3 node.
108 * @param node Owning node.
109 */
110 void SetNode(ns3::Ptr<ns3::Node> node) override;
111
112 /**
113 * @brief Get the owning ns-3 node.
114 * @return Owning node.
115 */
116 ns3::Ptr<ns3::Node> GetNode() const override;
117
118 /**
119 * @brief Set the interface index assigned by the owning node.
120 * @param i Interface index.
121 */
122 void SetIfIndex(std::uint32_t i) override;
123
124 /**
125 * @brief Get the interface index assigned by the owning node.
126 * @return Interface index.
127 */
128 std::uint32_t GetIfIndex() const override;
129
130 void SetAddress(ns3::Address) override {}
131 ns3::Address GetAddress() const override {
132 return ns3::Address();
133 }
134 bool SetMtu(std::uint16_t) override {
135 return true;
136 }
137 std::uint16_t GetMtu() const override {
138 return 1500;
139 }
140 bool IsLinkUp() const override {
141 return true;
142 }
143 void AddLinkChangeCallback(ns3::Callback<void>) override {}
144 bool IsBroadcast() const override {
145 return false;
146 }
147 ns3::Address GetBroadcast() const override {
148 return ns3::Address();
149 }
150 bool IsMulticast() const override {
151 return false;
152 }
153 ns3::Address GetMulticast(ns3::Ipv4Address) const override {
154 return ns3::Address();
155 }
156 ns3::Address GetMulticast(ns3::Ipv6Address) const override {
157 return ns3::Address();
158 }
159 bool IsBridge() const override {
160 return false;
161 }
162 bool IsPointToPoint() const override {
163 return true;
164 }
165 bool NeedsArp() const override {
166 return false;
167 }
168 void SetReceiveCallback(ReceiveCallback) override {}
169 void SetPromiscReceiveCallback(PromiscReceiveCallback) override {}
170 bool SupportsSendFrom() const override {
171 return false;
172 }
173 bool Send(ns3::Ptr<ns3::Packet>, const ns3::Address&, std::uint16_t) override {
174 return false;
175 }
176 bool SendFrom(ns3::Ptr<ns3::Packet>, const ns3::Address&, const ns3::Address&,
177 std::uint16_t) override {
178 return false;
179 }
180
181private:
182 /**
183 * @brief Receive a qubit from the attached channel and forward it upward.
184 *
185 * The optional sampled QMapInstance represents per-transmission channel
186 * effects to be applied by the receiving networker.
187 *
188 * @param q Qubit received from the channel.
189 * @param map Sampled per-transmission channel map.
190 *
191 * @see QNetworker::ReceiveFromDevice
192 */
193 void ReceiveFromChannel(std::shared_ptr<Qubit> q, const QMapInstance& map = {});
194
195 std::uint32_t ifIndex_ = 0; //!< Interface index.
196 ns3::Ptr<ns3::Node> node_; //!< Owning ns-3 node.
197 ns3::Ptr<QChannel> channel_; //!< Attached quantum channel.
198 QNetworker* networker_ = nullptr; //!< Bound networker, not owned.
199
200 friend QChannel;
201};
202
203} // namespace q2ns
Minimal quantum net device that bridges a QChannel and a QNetworker.
ns3::Address GetBroadcast() const override
void SetPromiscReceiveCallback(PromiscReceiveCallback) override
void BindNetworker(QNetworker &networker)
Bind the owning networker.
ns3::Address GetMulticast(ns3::Ipv4Address) const override
QNetDevice()
Default constructor.
ns3::Ptr< ns3::Node > GetNode() const override
Get the owning ns-3 node.
bool Send(ns3::Ptr< ns3::Packet >, const ns3::Address &, std::uint16_t) override
void SetReceiveCallback(ReceiveCallback) override
bool IsLinkUp() const override
bool Send(std::shared_ptr< Qubit > q)
Send a qubit through the attached channel.
std::uint16_t GetMtu() const override
bool SupportsSendFrom() const override
std::uint32_t GetIfIndex() const override
Get the interface index assigned by the owning node.
ns3::Address GetAddress() const override
ns3::Ptr< ns3::Node > node_
Owning ns-3 node.
std::uint32_t ifIndex_
Interface index.
bool SendFrom(ns3::Ptr< ns3::Packet >, const ns3::Address &, const ns3::Address &, std::uint16_t) override
ns3::Address GetMulticast(ns3::Ipv6Address) const override
bool IsBridge() const override
bool SetMtu(std::uint16_t) override
void SetNode(ns3::Ptr< ns3::Node > node) override
Set the owning ns-3 node.
void SetIfIndex(std::uint32_t i) override
Set the interface index assigned by the owning node.
ns3::Ptr< QChannel > channel_
Attached quantum channel.
ns3::Ptr< ns3::Channel > GetChannel() const override
Return the attached channel.
QNetworker * networker_
Bound networker, not owned.
bool IsMulticast() const override
void SetAddress(ns3::Address) override
bool IsBroadcast() const override
bool IsPointToPoint() const override
void ReceiveFromChannel(std::shared_ptr< Qubit > q, const QMapInstance &map={})
Receive a qubit from the attached channel and forward it upward.
void AttachChannel(ns3::Ptr< QChannel > ch)
Attach this device to a quantum channel.
static ns3::TypeId GetTypeId(void)
Get the ns-3 TypeId.
bool NeedsArp() const override
void AddLinkChangeCallback(ns3::Callback< void >) override
Internal helper owned by QNode for node-local quantum networking.
std::function< void(QNode &, std::shared_ptr< Qubit > &)> QMapInstance
Per-transmission quantum map callable applied to a received qubit.
Definition q2ns-types.h:71