Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns-congestion-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_CONGESTION_HELPER_H
11#define Q2NS_CONGESTION_HELPER_H
12
13#include "ns3/data-rate.h"
14#include "ns3/ipv4-address.h"
15#include "ns3/node.h"
16#include "ns3/object.h"
17#include "ns3/ptr.h"
18
19#include <set>
20#include <string>
21#include <utility>
22#include <vector>
23
24namespace q2ns {
25
26// Describe one background flow from src -> dst
28 std::string src; // node name (Names::Add)
29 std::string dst; // node name (Names::Add)
30 std::string protocol{"udp"}; // "udp" | "tcp"
31 std::string source{"onoff"}; // "onoff" | "bulk" (Bulk only valid with TCP)
32 uint16_t dstPort{9000};
33 double rateMbps{1.0}; // used by OnOff (UDP or TCP). Bulk ignores this.
34 uint32_t packetSize{1000}; // bytes (SendSize for Bulk; PacketSize for OnOff)
35 double start_s{0.0}; // nominal start time
36 double stop_s{0.0}; // 0 => never stop (until Simulator::Stop)
37 std::string id; // optional tag for your bookkeeping
38};
39
41 std::vector<TrafficFlow> flows;
42 bool autoCreateSinks{true}; // install PacketSink on dst if true
43};
44
46public:
47 CongestionHelper() = default;
48
49 // Install all flows described by 'spec'
50 void Install(const TrafficSpec& spec);
51
52 // Utility: compute a TCP warm-up time so cwnd can sustain app rate.
53 // rttSec ~ 2 * one-way link delay; mssBytes = PacketSize; initCwndPkts ~10.
54 static double ComputeTcpWarmup(double rateMbps, double rttSec, uint32_t mssBytes = 1200,
55 double initCwndPkts = 10.0);
56
57private:
58 // utility
59 static ns3::Ptr<ns3::Node> FindNodeByName(const std::string& name);
60 static ns3::Ipv4Address FirstNonLoopback(ns3::Ptr<ns3::Node> node);
61
62 // prevent duplicate sink installs: track (dstNode, port, proto)
63 std::set<std::tuple<ns3::Ptr<ns3::Node>, uint16_t, std::string>> m_installedSinks;
64};
65
66} // namespace q2ns
67
68#endif // Q2NS_CONGESTION_HELPER_H
void Install(const TrafficSpec &spec)
static ns3::Ipv4Address FirstNonLoopback(ns3::Ptr< ns3::Node > node)
static double ComputeTcpWarmup(double rateMbps, double rttSec, uint32_t mssBytes=1200, double initCwndPkts=10.0)
static ns3::Ptr< ns3::Node > FindNodeByName(const std::string &name)
std::set< std::tuple< ns3::Ptr< ns3::Node >, uint16_t, std::string > > m_installedSinks
std::vector< TrafficFlow > flows