Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-swap-helper.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#ifndef Q2NS_SWAP_HELPER_H
11#define Q2NS_SWAP_HELPER_H
12
13#include "ns3/node.h"
14#include "ns3/ptr.h"
15
16#include "ns3/q2ns-classical-network-builder.h"
17
18#include <cstdint>
19#include <memory>
20
21#include <string>
22#include <unordered_map>
23#include <vector>
24
25namespace q2ns {
26
27class NetController;
28class QNode;
29class SwapApp;
30
32 std::vector<std::string> path; // [A, R1, ..., Rk, B]
33 double start_s{0.0};
34 uint64_t sessionId{0};
35 uint16_t ctrlPort{0}; // 0 => helper auto-assigns
36 std::string protocol{"udp"}; // "udp" | "tcp"
37};
38
39// Classical link spec (unchanged)
40struct LinkSpec {
41 std::string u, v; // node names
42 double mbps{1.0};
43 std::string protocol{"udp"};
44 double delayNsPerKm{5000};
45 double distanceKm{0};
46 std::string queueMax{"128kB"};
47};
48
49// Quantum link spec (unchanged)
50struct QLinkSpec {
51 std::string u, v;
52 double distanceKm{0.0};
53 double delayNsPerKm{5000.0};
54};
55
57 uint32_t rounds{0}; // 0 => disabled; use explicit session start_s
58 double period_s{0.0}; // spacing between round starts
59 double jitter_s{0.0}; // +/- uniform jitter per session
60 uint64_t seed{0}; // RNG seed for reproducibility
61 bool Enabled() const {
62 return rounds > 0 && period_s > 0.0;
63 }
64};
65
67 std::vector<std::string> nodes;
68 std::vector<LinkSpec> classicalEdges;
69 std::vector<QLinkSpec> quantumEdges;
70 std::vector<SwapSessionSpec> sessions; // optional if a policy will generate them
71
72 // Optional global scheduling
73 RoundsConfig rounds{}; // if Enabled(), helper/policy assign round start times
74 std::string policyName{"all-at-once"}; // name looked up by the helper
75};
76
78public:
79 virtual ~ISwapPolicy() = default;
80 // Return a fully-specified list of sessions with start times (helper will install them)
81 virtual std::vector<SwapSessionSpec> PlanSessions(const SwapTopologySpec& topo) = 0;
82};
83
84// Built-in default policy: keep provided sessions; if rounds.Enabled(), replicate them across
85// rounds with start times T0 + r*period (+/- jitter).
86class AllAtOncePolicy final : public ISwapPolicy {
87public:
88 std::vector<SwapSessionSpec> PlanSessions(const SwapTopologySpec& topo) override;
89};
90
92public:
94 EntanglementSwapHelper& SetPortBase(uint16_t base);
95 EntanglementSwapHelper& SetPolicy(std::unique_ptr<ISwapPolicy> policy);
96 EntanglementSwapHelper& SetNodes(const std::map<std::string, ns3::Ptr<q2ns::QNode>>& nodes);
97
99 bool useIpv6, uint32_t ctrlPayloadBytes = 16);
100
101private:
102 uint16_t m_portBase{7000};
104 std::unique_ptr<ISwapPolicy> m_policy; // if null, use AllAtOncePolicy
105 std::unordered_map<std::string, ns3::Ptr<q2ns::QNode>> m_name2node;
106 std::unordered_map<std::string, ns3::Ptr<SwapApp>> m_appByNode; // one app per node
107
108 uint16_t AllocatePort(uint64_t sessionId) const;
110 void BuildQuantum(const SwapTopologySpec& spec);
111 void InstallUnifiedApps(const SwapTopologySpec& spec, const std::vector<SwapSessionSpec>& planned,
112 const ns3::ClassicalNetworkBuilder::NetworkHandle& net, bool useIpv6,
113 uint32_t ctrlPayloadBytes);
114};
115
116} // namespace q2ns
117
118#endif // Q2NS_SWAP_HELPER_H
std::vector< SwapSessionSpec > PlanSessions(const SwapTopologySpec &topo) override
void BuildQuantum(const SwapTopologySpec &spec)
std::unique_ptr< ISwapPolicy > m_policy
void Install(const SwapTopologySpec &spec, const ns3::ClassicalNetworkBuilder::NetworkHandle &net, bool useIpv6, uint32_t ctrlPayloadBytes=16)
void BindAppsOnProvidedNodes(const SwapTopologySpec &spec)
std::unordered_map< std::string, ns3::Ptr< SwapApp > > m_appByNode
std::unordered_map< std::string, ns3::Ptr< q2ns::QNode > > m_name2node
EntanglementSwapHelper & SetPolicy(std::unique_ptr< ISwapPolicy > policy)
uint16_t AllocatePort(uint64_t sessionId) const
void InstallUnifiedApps(const SwapTopologySpec &spec, const std::vector< SwapSessionSpec > &planned, const ns3::ClassicalNetworkBuilder::NetworkHandle &net, bool useIpv6, uint32_t ctrlPayloadBytes)
EntanglementSwapHelper & SetNetController(NetController *nc)
EntanglementSwapHelper & SetPortBase(uint16_t base)
EntanglementSwapHelper & SetNodes(const std::map< std::string, ns3::Ptr< q2ns::QNode > > &nodes)
virtual std::vector< SwapSessionSpec > PlanSessions(const SwapTopologySpec &topo)=0
virtual ~ISwapPolicy()=default
Main user-facing facade for creating and configuring a quantum network.
std::string protocol
std::string queueMax
std::vector< std::string > path
std::vector< std::string > nodes
std::vector< QLinkSpec > quantumEdges
std::vector< LinkSpec > classicalEdges
std::vector< SwapSessionSpec > sessions