SOLA
Loading...
Searching...
No Matches
socket_manager.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_UTILS_SOCKET_MANAGER_H_
18#define DAISI_UTILS_SOCKET_MANAGER_H_
19
20#include <string>
21#include <vector>
22
23#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25
26namespace daisi {
27
28enum class SocketType { kUDP, kTCP };
29
31public:
33 static SocketManager &get() {
34 static SocketManager utils;
35 return utils;
36 }
37
38 ns3::Ptr<ns3::Socket> createSocket(SocketType type, bool localhost = false);
39
40 void registerNode(std::vector<ns3::Ipv4Address> addresses, const ns3::Ptr<ns3::Node> &node,
42
43 // Unregister as active node
44 void unregisterNode(const ns3::Ptr<ns3::Node> &node);
45
46private:
47 SocketManager() = default;
48
49 struct NetworkInfo {
50 ns3::Ptr<ns3::Node> node;
51 ns3::Ipv4Address address;
52 uint16_t next_free_port;
53 std::string tag;
54 };
55
56 using Context = uint32_t; // ns-3 context
57
58 std::unordered_map<Context, std::vector<NetworkInfo>> nodes_;
59};
60
61} // namespace daisi
62
63#endif
Definition socket_manager.h:30
static SocketManager & get()
Getter for singleton.
Definition socket_manager.h:33