{"id":25608139,"url":"https://github.com/robertpaulp/congestion-control-swift","last_synced_at":"2026-05-16T09:33:42.047Z","repository":{"id":257878526,"uuid":"804362618","full_name":"robertpaulp/Congestion-Control-Swift","owner":"robertpaulp","description":"PCOM (Communication Networks) project in C++","archived":false,"fork":false,"pushed_at":"2024-10-15T15:14:20.000Z","size":21511,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-21T20:18:54.399Z","etag":null,"topics":["congestion-control","cpp","htsim","swift-congestion-control"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertpaulp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-22T13:01:08.000Z","updated_at":"2024-11-26T21:51:58.000Z","dependencies_parsed_at":"2024-10-17T10:18:24.404Z","dependency_job_id":null,"html_url":"https://github.com/robertpaulp/Congestion-Control-Swift","commit_stats":null,"previous_names":["robertpaulp/congestion-control-swift"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robertpaulp/Congestion-Control-Swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertpaulp%2FCongestion-Control-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertpaulp%2FCongestion-Control-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertpaulp%2FCongestion-Control-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertpaulp%2FCongestion-Control-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertpaulp","download_url":"https://codeload.github.com/robertpaulp/Congestion-Control-Swift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertpaulp%2FCongestion-Control-Swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33096915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["congestion-control","cpp","htsim","swift-congestion-control"],"created_at":"2025-02-21T20:18:56.359Z","updated_at":"2026-05-16T09:33:42.030Z","avatar_url":"https://github.com/robertpaulp.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Congestion Control Swift like algorithm\n\n## Introduction\n\nThis project aims to implement a congestion control algorithm similar to Swift in HTSim. The Swift algorithm is a method, developed by Google in 2020, that aims to improve the performance of connections in data centers. It is designed to optimize data transmission in high-bandwidth, low-latency networks. It adjusts the sending rate based on network conditions to minimize latency while maximizing throughput. Swift uses precise, real-time measurements of network congestion to make fine-grained adjustments, avoiding drastic rate changes. By focusing on low-latency, high-speed data transfer, it improves user experience in modern internet environments.\n\nThe implementation presented here is built on top of the newReno congestion control algorithm and used in a faculty competition at Politehnica University of Bucharest. The goal of the competition is to implement an algorithm, chosen from a list of options, that excels in three specific scenarios : throughput at different latencies, fairness in a multi-flow scenario and latency under congestion. Using the Swift algorithm as a base, we succeded in obtaining a score of 823 out of 900, ranking *3rd* in the competition.\n\n## Table of contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Implementation](#implementation)\n- [References \u0026 Credits](#references--credits)\n\n## Installation\n\nThis project is powered by HTSim. For more information about HTSim check the\n[wiki](https://github.com/nets-cs-pub-ro/NDP/wiki).\n\nThis is the recommended way to run the project. You will need [jupyer lab](https://jupyter.org/install) on you pc.\n\n```bash\nsudo apt install python3-pip\npip3 install jupyterlab\n```\n\nTo run the notebook:\n\n```bash\njupyter lab\n# This will open a tab in your browser, open the Project_CongestionControl.ipynb notebook from there\n```\n\n## Implementation\n\nIt utilizes an *Additive Increase, Multiplicative Decrease (AIMD)* strategy to adjust the *congestion window (CWND)* size based on network feedback. The algorithm responds to *acknowledgments (ACKs)* by incrementally increasing the CWND, allowing more packets to be sent. Conversely, it reacts to *negative acknowledgments (NACKs)* or other signs of network congestion by reducing the CWND, aiming to relieve congestion. The implementation is also designed to reduce congestion through a combination of delayed feedback processing and dynamic scaling, where the congestion window is adjusted based on real-time measurements of the *round-trip time (RTT)* and packet acknowledgments.\n\n### Processing a NACK (Negative Acknowledgment)\nWhen the size of the queue is exceeded and a packet is dropped, a NACK is processed. The window is reduced to prevent further congestion. A retransmission is triggered, and the algorithm ensures that the CWND stays within its lower bound.\n\n```cpp\nvoid CCSrc::processNack(const CCNack\u0026 nack){    \n    _nacks_received++;    \n    _flightsize -= _mss; // Reduce the flight size\n\n    _can_decrease = (eventlist().now() - _t_last_decrease) \u003e= rtt;\n    \n    // Increment retransmit count, reset CWND if threshold reached\n    _retransmit_count++;\n    if (_retransmit_count \u003e= RETX_RESET_THRESHOLD) {\n        _cwnd = _min_cwnd;\n    } else {\n        if (_can_decrease) {\n            _cwnd = (1 - _max_mdf) * _cwnd;  // Multiplicative decrease\n        }\n    }\n\n    // Clamp to ensure CWND is within bounds\n    _cwnd = clamp(_min_cwnd, _cwnd, _max_cwnd);\n\n    // Update last decrease time if needed\n    if (_cwnd \u003c= _cwnd_prev) {\n        _t_last_decrease = eventlist().now();\n    }\n\n    _cwnd_prev = _cwnd;  // Save current CWND\n}\n```\n\n### Processing an ACK (Acknowledgment)\nWhen an ACK is received, the CWND is adjusted based on the delay and the receipt of the ACK. The algorithm uses additive increase for growth, with the possibility of multiplicative decrease if the network experiences congestion or delay exceeds the target.\n\n```cpp\nvoid CCSrc::processAck(const CCAck\u0026 ack) {\n    _acks_received++;\n    _flightsize -= _mss;  // Adjust flight size\n    \n    // Calculate round-trip time (RTT) based on the delay\n    double delay = timeAsMs(eventlist().now()) - timeAsMs(ack.ts());\n    simtime_picosec rtt = delay * 2;\n\n    // Handle duplicate ACKs for fast recovery\n    if (_cwnd/_mss == _last_ack_no) {\n        _duplicate_ack++;\n    } else {\n        _duplicate_ack = 0;\n        _last_ack_no = _cwnd/_mss;\n    }\n\n    if (_duplicate_ack \u003e= 3) {\n        // Fast Recovery\n        _retransmit_count = 0;\n        if (_can_decrease) {\n            _cwnd = (1 - _max_mdf) * _cwnd;\n        }\n    } else {\n        // Regular ACK processing, apply Additive Increase\n        _retransmit_count = 0;\n\n        if (delay \u003c _target_delay || !ack.is_ecn_marked()) {\n            // Additive increase of CWND\n            if (_cwnd \u003e= 1 * _mss) {\n                _cwnd += (_ai * _mss *_mss/ _cwnd) * _acks_received;\n            } else {\n                _cwnd += _ai * _acks_received * _mss;\n            }\n        } else {\n            // Delay exceeded target, apply multiplicative decrease\n            if (_can_decrease) {\n                double a = 1 - _betta * ((delay - _target_delay) / delay);\n                double b = 1 - _max_mdf;\n                _cwnd = max(a, b) * _cwnd;\n            }\n        }\n    }\n\n    // Clamp to enforce lower/upper CWND bounds\n    _cwnd = clamp(_min_cwnd, _cwnd, _max_cwnd);\n\n    // Update time of last decrease\n    if (_cwnd \u003c= _cwnd_prev) {\n        _t_last_decrease = eventlist().now();\n    }\n\n    _cwnd_prev = _cwnd;  // Save previous CWND value\n    _can_decrease = (eventlist().now() - _t_last_decrease) \u003e= rtt;\n}\n```\n\n## Reno vs Swift\n\n### Throughput at different latencies\n\nnewReno            |  Swift\n:-------------------------:|:-------------------------:\n![Reno_throughput](./README_imgs/reno_throughput.png)  |  ![Swift_throughput](./README_imgs/swift_throughput.png)\n\n- We can observe that the Swift algorithm has quite the same thoughput as the newReno algorithm, because both methods are based on the AIMD strategy.\n\n### Fairness in a multi-flow scenario\n\nnewReno            |  Swift\n:-------------------------:|:-------------------------:\n![Reno_fairness](./README_imgs/reno_fairness.png)  |  ![Swift_fairness](./README_imgs/swift_fairness.png)\n\n- In a multi-flow scenario, newReno fails to maintain fairness between connections, some users are experiencing a much lower throughput than others. On the other hand, Swift maintains a more balanced throughput across all connections.\n\n### Latency under congestion\n\nnewReno            |  Swift\n:-------------------------:|:-------------------------:\n![Reno_latency](./README_imgs/reno_latency.png)  |  ![Swift_latency](./README_imgs/swift_latency.png)\n\n- The Swift algorithm is able to maintain a lower latency under congestion compared to newReno. This is due to the fine-grained adjustments made by Swift to the congestion window, allowing it to respond more quickly to network conditions.\n\n## References \u0026 Credits\n\n* This project was developed by [Victor](https://github.com/Viktor09), [Robert](https://github.com/robertpaulp), [Alexandru](https://github.com/alexandrutrifu) and [Rares](https://github.com/rrsmart8).\n\n* The resources used:\n    * https://2022-cs244.github.io/papers/L5-swift.pdf\n    * https://github.com/ani2796/swift-start-ns3/blob/master/tcp-swiftstart.cc\n    * https://github.com/rsburke4/ns3-swift/blob/master/ns3/src/internet/model/tcp-swift.cc#L319","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertpaulp%2Fcongestion-control-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertpaulp%2Fcongestion-control-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertpaulp%2Fcongestion-control-swift/lists"}