Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns::NetController Class Reference

Main user-facing facade for creating and configuring a quantum network. More...

#include <q2ns-netcontroller.h>

Collaboration diagram for q2ns::NetController:

Public Member Functions

 NetController ()
 Default constructor.
 
QStateRegistryGetRegistry ()
 Access the shared state registry.
 
void SetQStateBackend (QStateBackend b)
 Set the default backend used for newly created quantum states.
 
void SetQStateBackend (std::string_view name)
 Set the default backend by name.
 
QStateBackend GetQStateBackend ()
 Get the current default backend.
 
int64_t AssignStreams (int64_t stream)
 Assign RNG streams to q2ns-owned random sources.
 
ns3::Ptr< QNodeCreateNode (const std::string &label="")
 Create a QNode with an optional human-readable label.
 
ns3::Ptr< QNodeGetNode (uint32_t nodeId)
 Return the QNode associated with a node id.
 
ns3::Ptr< QChannelInstallQuantumLink (ns3::Ptr< QNode > a, ns3::Ptr< QNode > b)
 Install a duplex quantum link between two nodes.
 
std::vector< ns3::Ptr< QChannel > > InstallQuantumChain (const std::vector< ns3::Ptr< QNode > > &nodes)
 Connect a sequence of nodes as a linear chain.
 
std::vector< ns3::Ptr< QChannel > > InstallQuantumAllToAll (const std::vector< ns3::Ptr< QNode > > &nodes)
 Connect a set of nodes with all-to-all quantum links.
 
ns3::Ptr< QChannelGetChannel (ns3::Ptr< QNode > a, ns3::Ptr< QNode > b)
 Return the QChannel connecting two nodes.
 
std::shared_ptr< QStateGetState (const std::shared_ptr< Qubit > &q) const
 Convenience helper to get a qubit's current backend state.
 

Private Member Functions

void EnsureStreamsAssigned_ ()
 Ensure RNG streams have been assigned before simulation activity begins.
 

Private Attributes

bool streamsAssigned_ = false
 True once AssignStreams has been called.
 
int64_t nextStream_ = 0
 Next stream index to assign.
 
QStateRegistry registry_
 Shared state registry.
 
std::unordered_map< uint32_t, ns3::Ptr< QNode > > nodes_
 Node id to QNode map.
 
std::map< std::pair< uint32_t, uint32_t >, ns3::Ptr< QChannel > > channels_
 Undirected link map keyed by sorted endpoint ids.
 

Detailed Description

Main user-facing facade for creating and configuring a quantum network.

NetController owns the shared QStateRegistry used by the q2ns network and provides convenience helpers to create QNodes, install QChannels, and query network objects by node or link.

Qubit creation and manipulation are normally performed through QNode. In contrast, NetController is primarily responsible for topology construction, shared configuration, and deterministic RNG stream assignment.

Responsibilities:

  • Own the shared QStateRegistry for the network.
  • Create and track QNode instances.
  • Install quantum links, chains, and all-to-all topologies.
  • Configure the default QState backend used for newly created states.
  • Assign RNG streams to q2ns-owned random sources.
See also
QNode
QChannel
QStateRegistry

Definition at line 65 of file q2ns-netcontroller.h.

Constructor & Destructor Documentation

◆ NetController()

q2ns::NetController::NetController ( )

Default constructor.

Definition at line 38 of file q2ns-netcontroller.cc.

References q2ns::QState::AssignStreams(), EnsureStreamsAssigned_(), nextStream_, registry_, q2ns::QStateRegistry::SetStreamAssigner(), and streamsAssigned_.

Here is the call graph for this function:

Member Function Documentation

◆ AssignStreams()

int64_t q2ns::NetController::AssignStreams ( int64_t  stream)

Assign RNG streams to q2ns-owned random sources.

This method should normally be called after the topology has been built and before the simulation is run. Streams are assigned deterministically from the provided starting index.

Parameters
streamStarting stream index.
Returns
Number of streams consumed.

Definition at line 54 of file q2ns-netcontroller.cc.

References channels_, q2ns::QStateRegistry::GetStatesSortedById(), nextStream_, registry_, and streamsAssigned_.

Referenced by EnsureStreamsAssigned_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateNode()

ns3::Ptr< QNode > q2ns::NetController::CreateNode ( const std::string &  label = "")

Create a QNode with an optional human-readable label.

The node is registered internally and bound to this controller's shared QStateRegistry.

Parameters
labelOptional human-readable label.
Returns
Pointer to the created QNode.
See also
GetNode
GetRegistry

Definition at line 109 of file q2ns-netcontroller.cc.

References nodes_, and registry_.

Referenced by q2ns::TeleportationHelper::BuildNodes(), main(), main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().

Here is the caller graph for this function:

◆ EnsureStreamsAssigned_()

void q2ns::NetController::EnsureStreamsAssigned_ ( )
private

Ensure RNG streams have been assigned before simulation activity begins.

This is used as an internal safety net so q2ns behaves deterministically even if the user calls ns3::Simulator::Run() directly instead of going through a controller-owned wrapper.

Definition at line 85 of file q2ns-netcontroller.cc.

References AssignStreams(), and streamsAssigned_.

Referenced by NetController().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChannel()

ns3::Ptr< QChannel > q2ns::NetController::GetChannel ( ns3::Ptr< QNode a,
ns3::Ptr< QNode b 
)

Return the QChannel connecting two nodes.

Parameters
aOne endpoint node.
bThe other endpoint node.
Returns
Pointer to the connecting QChannel, or nullptr if no such link exists.
See also
InstallQuantumLink

Definition at line 242 of file q2ns-netcontroller.cc.

References channels_.

◆ GetNode()

ns3::Ptr< QNode > q2ns::NetController::GetNode ( uint32_t  nodeId)

Return the QNode associated with a node id.

Parameters
nodeIdDesired node identifier.
Returns
Pointer to the matching QNode, or nullptr if none exists.
See also
CreateNode

Definition at line 122 of file q2ns-netcontroller.cc.

References nodes_.

◆ GetQStateBackend()

QStateBackend q2ns::NetController::GetQStateBackend ( )

Get the current default backend.

Returns
Current backend enum value.
See also
SetQStateBackend(QStateBackend)
SetQStateBackend(std::string_view)

Definition at line 105 of file q2ns-netcontroller.cc.

References q2ns::QStateRegistry::GetDefaultBackend(), and registry_.

Here is the call graph for this function:

◆ GetRegistry()

QStateRegistry & q2ns::NetController::GetRegistry ( )

Access the shared state registry.

Returns
Reference to the internal QStateRegistry.

Definition at line 93 of file q2ns-netcontroller.cc.

References registry_.

◆ GetState()

std::shared_ptr< QState > q2ns::NetController::GetState ( const std::shared_ptr< Qubit > &  q) const

Convenience helper to get a qubit's current backend state.

Parameters
qTarget qubit.
Returns
Shared pointer to the current QState, or nullptr if unknown.

Definition at line 261 of file q2ns-netcontroller.cc.

References q2ns::QStateRegistry::GetState(), and registry_.

Referenced by main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::TryCorrections(), and anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::TryCorrections().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InstallQuantumAllToAll()

std::vector< ns3::Ptr< QChannel > > q2ns::NetController::InstallQuantumAllToAll ( const std::vector< ns3::Ptr< QNode > > &  nodes)

Connect a set of nodes with all-to-all quantum links.

For N nodes, this installs one link for every unordered node pair. Existing links are left unchanged and their existing channel pointers are returned in the corresponding positions.

Parameters
nodesNode set.
See also
InstallQuantumLink
InstallQuantumChain

Definition at line 203 of file q2ns-netcontroller.cc.

References InstallQuantumLink().

Here is the call graph for this function:

◆ InstallQuantumChain()

std::vector< ns3::Ptr< QChannel > > q2ns::NetController::InstallQuantumChain ( const std::vector< ns3::Ptr< QNode > > &  nodes)

Connect a sequence of nodes as a linear chain.

For a sequence n0, n1, ..., n{k-1}, this installs links (n0,n1), (n1,n2), ..., (n{k-2},n{k-1}).

Existing links are left unchanged and their existing channel pointers are returned in the corresponding positions.

Parameters
nodesOrdered node sequence.
See also
InstallQuantumLink
InstallQuantumAllToAll

Definition at line 172 of file q2ns-netcontroller.cc.

References InstallQuantumLink().

Here is the call graph for this function:

◆ InstallQuantumLink()

ns3::Ptr< QChannel > q2ns::NetController::InstallQuantumLink ( ns3::Ptr< QNode a,
ns3::Ptr< QNode b 
)

Install a duplex quantum link between two nodes.

This method creates two QNetDevice instances and one QChannel, attaches one device to each node, and installs per-destination host routes so each node can send to the other over the created link.

Parameters
aFirst endpoint node.
bSecond endpoint node.
Returns
Pointer to the created QChannel, or the existing channel if the link already exists.
See also
GetChannel
InstallQuantumChain
InstallQuantumAllToAll

Definition at line 131 of file q2ns-netcontroller.cc.

References channels_, nextStream_, and streamsAssigned_.

Referenced by q2ns::EntanglementSwapHelper::BuildQuantum(), q2ns::TeleportationHelper::BuildQuantum(), InstallQuantumAllToAll(), InstallQuantumChain(), main(), main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().

Here is the caller graph for this function:

◆ SetQStateBackend() [1/2]

void q2ns::NetController::SetQStateBackend ( QStateBackend  b)

Set the default backend used for newly created quantum states.

Parameters
bBackend enum value.
See also
SetQStateBackend(std::string_view)
GetQStateBackend

Definition at line 97 of file q2ns-netcontroller.cc.

References registry_, and q2ns::QStateRegistry::SetDefaultBackend().

Referenced by main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetQStateBackend() [2/2]

void q2ns::NetController::SetQStateBackend ( std::string_view  name)

Set the default backend by name.

This is a convenience overload intended for CLI or configuration use.

Parameters
nameBackend name such as "ket", "dm", or "stab".
See also
SetQStateBackend(QStateBackend)
GetQStateBackend

Definition at line 101 of file q2ns-netcontroller.cc.

References q2ns::BackendFromString(), registry_, and q2ns::QStateRegistry::SetDefaultBackend().

Here is the call graph for this function:

Member Data Documentation

◆ channels_

std::map<std::pair<uint32_t, uint32_t>, ns3::Ptr<QChannel> > q2ns::NetController::channels_
private

Undirected link map keyed by sorted endpoint ids.

Definition at line 224 of file q2ns-netcontroller.h.

Referenced by AssignStreams(), GetChannel(), and InstallQuantumLink().

◆ nextStream_

int64_t q2ns::NetController::nextStream_ = 0
private

Next stream index to assign.

Definition at line 219 of file q2ns-netcontroller.h.

Referenced by AssignStreams(), InstallQuantumLink(), and NetController().

◆ nodes_

std::unordered_map<uint32_t, ns3::Ptr<QNode> > q2ns::NetController::nodes_
private

Node id to QNode map.

Definition at line 222 of file q2ns-netcontroller.h.

Referenced by CreateNode(), and GetNode().

◆ registry_

QStateRegistry q2ns::NetController::registry_
private

◆ streamsAssigned_

bool q2ns::NetController::streamsAssigned_ = false
private

True once AssignStreams has been called.

Definition at line 218 of file q2ns-netcontroller.h.

Referenced by AssignStreams(), EnsureStreamsAssigned_(), InstallQuantumLink(), and NetController().


The documentation for this class was generated from the following files: