SOLA
Loading...
Searching...
No Matches
amr_logical_agent.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_CPPS_LOGICAL_AMR_AMR_LOGICAL_AGENT_H_
18#define DAISI_CPPS_LOGICAL_AMR_AMR_LOGICAL_AGENT_H_
19
20#include <memory>
21#include <string>
22
23#include "amr_logical_execution_state.h"
24#include "cpps/amr/amr_description.h"
25#include "cpps/amr/amr_topology.h"
26#include "cpps/amr/message/amr_state.h"
27#include "cpps/amr/message/serializer.h"
28#include "cpps/logical/logical_agent.h"
29#include "cpps/logical/task_management/task_management.h"
30#include "ns3/socket.h"
31#include "solanet/network_udp/message.h"
32#include "utils/structure_helpers.h"
33
34namespace daisi::cpps::logical {
35
37public:
38 AmrLogicalAgent(const AlgorithmConfig &config, bool first_node);
39
40 ~AmrLogicalAgent() override = default;
41
43 virtual void init();
44
45 void start() override;
46
47 void notifyTaskAssigned();
48
50 ns3::InetSocketAddress getServerAddress() const {
51 ns3::Address addr;
52 server_socket_->GetSockName(addr);
53 return ns3::InetSocketAddress::ConvertFrom(addr);
54 }
55
56private:
57 void initAlgorithms() override;
58
61 void messageReceiveFunction(const solanet::Message &msg) override;
62
65 void topicMessageReceiveFunction(const sola::TopicMessage &msg) override;
66
68 bool connectionRequest(ns3::Ptr<ns3::Socket> socket, const ns3::Address &addr);
69
72 void newConnectionCreated(ns3::Ptr<ns3::Socket> socket, const ns3::Address &addr);
73
74 void readFromPhysicalSocket(ns3::Ptr<ns3::Socket> socket);
75
76 void processMessageAmrDescription(const AmrDescription &description);
77 void processMessageAmrStatusUpdate(const AmrStatusUpdate &status_update);
78 void processMessageAmrOrderUpdate(const AmrOrderUpdate &order_update);
79
80 void sendTopologyToPhysical();
81 void sendTaskToPhysical();
82
83 void checkSendingNextTaskToPhysical();
84
85 void logAmrInfos();
86 void logPositionUpdate();
87 void forwardOrderUpdate();
88
89 void sendToPhysical(std::string payload);
90
92 void setServices();
93
94 AmrDescription description_;
95 bool description_set_ = false; // to avoid overriding
96
97 Topology topology_;
98
99 AmrLogicalExecutionState execution_state_;
100
104 ns3::Ptr<ns3::Socket> server_socket_;
105
108 ns3::Ptr<ns3::Socket> physical_socket_;
109
111 ns3::Address physical_address_;
112
113 std::shared_ptr<TaskManagement> task_management_;
114};
115} // namespace daisi::cpps::logical
116
117#endif
Definition amr_description.h:27
Definition amr_order_update.h:25
Definition amr_status_update.h:26
Definition amr_topology.h:26
Definition amr_logical_agent.h:36
ns3::InetSocketAddress getServerAddress() const
Get address from TCP socket listening on connections from AmrPhysicalAsset.
Definition amr_logical_agent.h:50
virtual void init()
Method called by the container on start. Initializing components such as Sola.
Definition amr_logical_agent.cpp:38
Definition amr_logical_execution_state.h:26
Definition logical_agent.h:32
Definition message.h:14
Modified Round Robin Algorithm that centrally assigns tasks of incoming material flows to the corresp...
Definition algorithm_config.h:22
Definition algorithm_config.h:31
Definition message.h:20