Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-qnet-device.cc
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.cc
11 * @brief Defines q2ns::QNetDevice.
12 */
13
14#include "ns3/q2ns-qnet-device.h"
15
16#include "ns3/q2ns-qchannel.h"
17#include "q2ns-qnetworker.h"
18
19#include "ns3/log.h"
20#include "ns3/node.h"
21
22namespace q2ns {
23
24NS_LOG_COMPONENT_DEFINE("QNetDevice");
25NS_OBJECT_ENSURE_REGISTERED(QNetDevice);
26
27
28
29ns3::TypeId QNetDevice::GetTypeId(void) {
30 static ns3::TypeId tid = ns3::TypeId("q2ns::QNetDevice")
31 .SetParent<ns3::NetDevice>()
32 .SetGroupName("q2ns")
33 .AddConstructor<QNetDevice>();
34 return tid;
35}
36
37
38
39QNetDevice::QNetDevice() = default;
40
41
42
44 networker_ = &networker;
45}
46
47
48
49void QNetDevice::AttachChannel(ns3::Ptr<QChannel> ch) {
50 channel_ = ch;
51}
52
53
54
55bool QNetDevice::Send(std::shared_ptr<Qubit> q) {
56 if (channel_) {
57 return channel_->SendFrom(this, std::move(q));
58 }
59
60 return false;
61}
62
63
64
65void QNetDevice::ReceiveFromChannel(std::shared_ptr<Qubit> q, const QMapInstance& map) {
66 NS_ASSERT_MSG(networker_, "ReceiveFromChannel called without a bound networker");
67 networker_->ReceiveFromDevice(std::move(q), map);
68}
69
70
71
72ns3::Ptr<ns3::Channel> QNetDevice::GetChannel() const {
73 return channel_;
74}
75
76
77
78void QNetDevice::SetNode(ns3::Ptr<ns3::Node> node) {
79 node_ = node;
80}
81
82
83
84ns3::Ptr<ns3::Node> QNetDevice::GetNode() const {
85 return node_;
86}
87
88
89
90void QNetDevice::SetIfIndex(std::uint32_t i) {
91 ifIndex_ = i;
92}
93
94
95
96std::uint32_t QNetDevice::GetIfIndex() const {
97 return ifIndex_;
98}
99
100} // namespace q2ns
Minimal quantum net device that bridges a QChannel and a QNetworker.
void BindNetworker(QNetworker &networker)
Bind the owning networker.
QNetDevice()
Default constructor.
ns3::Ptr< ns3::Node > GetNode() const override
Get the owning ns-3 node.
bool Send(std::shared_ptr< Qubit > q)
Send a qubit through the attached channel.
std::uint32_t GetIfIndex() const override
Get the interface index assigned by the owning node.
ns3::Ptr< ns3::Node > node_
Owning ns-3 node.
std::uint32_t ifIndex_
Interface index.
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.
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.
Internal helper owned by QNode for node-local quantum networking.
void ReceiveFromDevice(std::shared_ptr< Qubit > q, const QMapInstance &map)
Handle a qubit delivered from a channel.
std::function< void(QNode &, std::shared_ptr< Qubit > &)> QMapInstance
Per-transmission quantum map callable applied to a received qubit.
Definition q2ns-types.h:71
Declares q2ns::QNetworker, an internal per-node networking component for quantum transmission and rec...