SOLA
Loading...
Searching...
No Matches
sola_helper.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_MANAGER_HELPER_H_
18#define DAISI_MANAGER_HELPER_H_
19
20#include "ns3/application-container.h"
21#include "ns3/ipv4-address.h"
22#include "ns3/object-factory.h"
23#include "ns3/uinteger.h"
24#include "utils/socket_manager.h"
25#include "utils/sola_utils.h"
26
27namespace daisi {
28
29template <typename T> void installApplication(ns3::Ptr<ns3::Node> node) {
30 ns3::ObjectFactory factory;
31 factory.SetTypeId(T::GetTypeId());
32 ns3::Ptr<ns3::Application> app = factory.Create<T>();
33 node->AddApplication(app);
34}
35
36inline void registerNodes(ns3::NodeContainer container) {
37 for (uint64_t i = 0; i < container.GetN(); i++) {
38 std::vector<ns3::Ipv4Address> addresses = daisi::getAddressesForNode(container, i);
39 SocketManager::get().registerNode(addresses, container.Get(i), 2000);
40 }
41}
42
43// @brief Helper to setup the same application on all passed nodes,
44// starting at 0 seconds
45template <typename App> inline void setupApplication(ns3::NodeContainer container) {
46 for (uint64_t i = 0; i < container.GetN(); i++) {
47 installApplication<App>(container.Get(i));
48 container.Get(i)->GetApplication(0)->SetStartTime(ns3::MilliSeconds(0));
49 }
50}
51
52} // namespace daisi
53#endif
static SocketManager & get()
Getter for singleton.
Definition socket_manager.h:33