Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-classical-network-builder.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#pragma once
11
12#include "ns3/core-module.h"
13#include "ns3/csma-module.h"
14#include "ns3/internet-module.h"
15#include "ns3/network-module.h"
16#include "ns3/point-to-point-module.h"
17
18
19namespace ns3 {
20
21/**
22 * ClassicalNetworkBuilder:
23 * A high-level utility that builds arbitrary classical networks
24 * from user-specified topology data (nodes, links, LANs, etc.).
25 * Supports IPv4, IPv6, or dual stack; routing can be global,
26 * static (shortest-path), or none (single-LAN).
27 */
28class ClassicalNetworkBuilder : public Object {
29public:
30 enum class IpVersion { V4, V6, Dual };
32
33 struct Link {
34 std::string id;
35 std::string nodeA;
36 std::string nodeB;
37 std::string rate{"10Gbps"};
38 std::string delay{"1us"};
39 };
40
41 struct Lan {
42 std::string id;
43 std::vector<std::string> members;
44 std::string rate{"1Gbps"};
45 std::string delay{"1us"};
46 };
47
49 struct NodeEntry {
50 Ptr<Node> node;
51 std::vector<Ptr<NetDevice>> devices;
52 std::vector<Ipv4Address> v4Addrs;
53 std::vector<Ipv6Address> v6Addrs;
54 std::vector<uint32_t> ifaceIndex;
55 std::map<std::string, Ptr<NetDevice>> devBySegment;
56
57 struct IfaceInfo {
58 uint32_t ifIndexV4 = UINT32_MAX;
59 uint32_t ifIndexV6 = UINT32_MAX;
60 ns3::Ipv4Address v4{ns3::Ipv4Address("0.0.0.0")};
61 ns3::Ipv6Address v6{ns3::Ipv6Address::GetAny()};
62 ns3::Ipv6Address v6ll{ns3::Ipv6Address::GetLoopback()};
63 };
64 std::map<std::string, IfaceInfo> segIf; // segId -> iface info
65 };
66 std::map<std::string, NodeEntry> nodes;
67 bool hasIpv4{true};
68 bool hasIpv6{true};
69 };
70
71
73
74 // User-facing configuration
75 void SetIpVersion(IpVersion v);
76 void SetRouting(Routing r);
77 void AddLink(const Link& link);
78 void AddLan(const Lan& lan);
79 void SetDefaultDataRate(std::string rate);
80 void SetDefaultDelay(std::string delay);
81
82 // Attach physical ns-3 nodes by name before calling Build()
83 void AttachNode(std::string name, Ptr<Node> node);
84
85 // Build and return a ready-to-use handle
86 NetworkHandle Build();
87
88 // Routing synthesizer
89 void InstallStaticEndpointRoutes(const std::vector<std::string>& orderedPath,
90 NetworkHandle& handle, bool forIpv4, bool forIpv6);
92
93private:
94 // Internal build steps
96 void BuildLinks(NetworkHandle& handle);
97 void BuildLans(NetworkHandle& handle);
98 void AssignAddresses(NetworkHandle& handle);
99
100 std::map<std::string, Ptr<Node>> m_nodes;
101 std::vector<Link> m_links;
102 std::vector<Lan> m_lans;
103
106 std::string m_defRate{"10Gbps"};
107 std::string m_defDelay{"1us"};
108};
109
110} // namespace ns3
void InstallStaticShortestPaths(NetworkHandle &handle)
std::map< std::string, Ptr< Node > > m_nodes
void AttachNode(std::string name, Ptr< Node > node)
void InstallStaticEndpointRoutes(const std::vector< std::string > &orderedPath, NetworkHandle &handle, bool forIpv4, bool forIpv6)