14#include "ns3/q2ns-netcontroller.h"
16#include "ns3/q2ns-qchannel.h"
17#include "ns3/q2ns-qmap.h"
18#include "ns3/q2ns-qnet-device.h"
19#include "ns3/q2ns-qnode.h"
20#include "ns3/q2ns-qstate.h"
21#include "ns3/q2ns-qubit.h"
27#include "ns3/rng-seed-manager.h"
28#include "ns3/simulator.h"
36NS_LOG_COMPONENT_DEFINE(
"NetController");
56 NS_LOG_WARN(
"AssignStreams called more than once; streams will be reassigned.");
110 auto qnode = ns3::CreateObject<QNode>(
registry_);
112 const uint32_t
id = qnode->GetId();
115 if (!label.empty()) {
116 ns3::Names::Add(label, qnode);
123 auto it =
nodes_.find(nodeId);
124 if (it !=
nodes_.end() && it->second) {
133 NS_LOG_WARN(
"InstallQuantumLink rejected: null node.");
137 const uint32_t ida = a->GetId();
138 const uint32_t idb = b->GetId();
139 const auto key = std::make_pair(std::min(ida, idb), std::max(ida, idb));
143 NS_LOG_WARN(
"InstallQuantumLink reused existing channel for nodes " << ida <<
" and " << idb
148 auto devA = ns3::CreateObject<QNetDevice>();
149 auto devB = ns3::CreateObject<QNetDevice>();
150 auto chan = ns3::CreateObject<QChannel>();
156 chan->Connect(devA, devB);
161 const uint32_t ifA = a->networker_->AddInterface(devA);
162 const uint32_t ifB = b->networker_->AddInterface(devB);
164 a->networker_->AddRoute(idb, ifA);
165 b->networker_->AddRoute(ida, ifB);
171std::vector<ns3::Ptr<QChannel>>
173 std::vector<ns3::Ptr<QChannel>> channels;
174 if (nodes.size() < 2) {
178 channels.reserve(nodes.size() - 1);
180 for (std::size_t i = 0; i + 1 < nodes.size(); ++i) {
181 const auto& a = nodes[i];
182 const auto& b = nodes[i + 1];
185 NS_LOG_WARN(
"InstallQuantumChain skipped link at positions " << i <<
" and " << (i + 1)
186 <<
" because a node was null.");
191 NS_LOG_WARN(
"InstallQuantumChain skipped self-link at positions " << i <<
" and " << (i + 1)
202std::vector<ns3::Ptr<QChannel>>
204 std::vector<ns3::Ptr<QChannel>> channels;
205 if (nodes.size() < 2) {
209 const std::size_t n = nodes.size();
210 channels.reserve((n * (n - 1)) / 2);
212 for (std::size_t i = 0; i < n; ++i) {
213 const auto& a = nodes[i];
215 NS_LOG_WARN(
"InstallQuantumAllToAll skipped all pairs involving null node at position "
220 for (std::size_t j = i + 1; j < n; ++j) {
221 const auto& b = nodes[j];
224 NS_LOG_WARN(
"InstallQuantumAllToAll skipped pair at positions "
225 << i <<
" and " << j <<
" because a node was null.");
230 NS_LOG_WARN(
"InstallQuantumAllToAll skipped self-link at positions " << i <<
" and " << j
244 NS_LOG_WARN(
"GetChannel rejected: null node.");
248 const uint32_t ida = a->GetId();
249 const uint32_t idb = b->GetId();
250 const auto key = std::make_pair(std::min(ida, idb), std::max(ida, idb));
254 NS_LOG_WARN(
"GetChannel failed: no channel connects the provided nodes.");
std::map< std::pair< uint32_t, uint32_t >, ns3::Ptr< QChannel > > channels_
Undirected link map keyed by sorted endpoint ids.
QStateRegistry registry_
Shared state registry.
QStateRegistry & GetRegistry()
Access the shared state registry.
void EnsureStreamsAssigned_()
Ensure RNG streams have been assigned before simulation activity begins.
int64_t nextStream_
Next stream index to assign.
ns3::Ptr< QChannel > GetChannel(ns3::Ptr< QNode > a, ns3::Ptr< QNode > b)
Return the QChannel connecting two nodes.
int64_t AssignStreams(int64_t stream)
Assign RNG streams to q2ns-owned random sources.
std::vector< ns3::Ptr< QChannel > > InstallQuantumAllToAll(const std::vector< ns3::Ptr< QNode > > &nodes)
Connect a set of nodes with all-to-all quantum links.
QStateBackend GetQStateBackend()
Get the current default backend.
std::shared_ptr< QState > GetState(const std::shared_ptr< Qubit > &q) const
Convenience helper to get a qubit's current backend state.
ns3::Ptr< QNode > GetNode(uint32_t nodeId)
Return the QNode associated with a node id.
ns3::Ptr< QNode > CreateNode(const std::string &label="")
Create a QNode with an optional human-readable label.
ns3::Ptr< QChannel > InstallQuantumLink(ns3::Ptr< QNode > a, ns3::Ptr< QNode > b)
Install a duplex quantum link between two nodes.
bool streamsAssigned_
True once AssignStreams has been called.
NetController()
Default constructor.
std::unordered_map< uint32_t, ns3::Ptr< QNode > > nodes_
Node id to QNode map.
std::vector< ns3::Ptr< QChannel > > InstallQuantumChain(const std::vector< ns3::Ptr< QNode > > &nodes)
Connect a sequence of nodes as a linear chain.
void SetQStateBackend(QStateBackend b)
Set the default backend used for newly created quantum states.
Internal registry that owns backend states and tracks qubit membership and location.
QStateBackend GetDefaultBackend() const
Get the default backend used for newly created states.
void SetDefaultBackend(QStateBackend b)
Set the default backend used for newly created states.
std::vector< std::shared_ptr< QState > > GetStatesSortedById() const
Return all registered states sorted by state id.
std::shared_ptr< QState > GetState(StateId stateId) const
Get a backend state by state id.
void SetStreamAssigner(StreamAssigner fn)
Set the callback used to assign streams to newly created states.
Backend-agnostic interface for a quantum state object.
virtual int64_t AssignStreams(int64_t stream)
Assign RNG streams for deterministic randomness.
QStateBackend BackendFromString(std::string_view s)
Convert a backend name string to a QStateBackend enum value.
QStateBackend
Backend family used when creating new quantum states.
Declares q2ns::QNetworker, an internal per-node networking component for quantum transmission and rec...