scc 2026.07
SystemC components library
tcp4tlm_client.h
1/*******************************************************************************
2 * Copyright 2026 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef TLM_SCC_TCP4TLM_CLIENT_H_
18#define TLM_SCC_TCP4TLM_CLIENT_H_
19
20#include "rigtorp/SPSCQueue.h"
21#include "scc/async_queue.h"
22#include "scc/peq.h"
23#include "tcp4tlm/client.h"
24#include "tcp4tlm/messages.h"
25#include "tcp4tlm/server.h"
26#include "tlm/scc/tlm_gp_shared.h"
27#include "tlm/scc/tlm_mm.h"
28#include <atomic>
29#include <boost/asio.hpp>
30#include <cci_configuration>
31#include <scc/report.h>
32#include <scc/utilities.h>
33#include <systemc>
34#include <tlm>
35#include <tlm_utils/simple_initiator_socket.h>
36#include <tlm_utils/simple_target_socket.h>
37#include <tlm_utils/tlm_quantumkeeper.h>
38
39namespace scc {
40
41struct tcp4tlm_client : public sc_core::sc_module, protected tcp4tlm::client<tcp4tlm::request_message, tcp4tlm::response_message> {
42 SC_HAS_PROCESS(tcp4tlm_client);
43
44 cci::cci_param<std::string> other_host_name{"other_host_name", ""};
45 cci::cci_param<unsigned> other_host_port{"other_host_port", 0};
46 cci::cci_param<unsigned> this_host_port{"this_host_port", 32000u};
47 cci::cci_param<bool> wall_time_simulation_speed{"wall_time_simulation_speed", false};
48 cci::cci_param<bool> write_no_response{"write_no_response", false};
49
50 tlm_utils::simple_target_socket<tcp4tlm_client, ::scc::LT> tsckt;
51
52 sc_core::sc_vector<sc_core::sc_out<bool>> signals{"signals"};
53
54 tcp4tlm_client(sc_core::sc_module_name name, size_t no_of_ports = 0);
55
56 virtual ~tcp4tlm_client();
57
59
60 void end_connection();
61
62protected:
63 void btransport_cb(tlm::tlm_generic_payload&, sc_core::sc_time&);
64 unsigned transport_dbg_cb(tlm::tlm_generic_payload&);
65 virtual void do_access(tlm::tlm_generic_payload& gp, sc_core::sc_time& delay, bool debug = false);
66 void timing_thread();
67 void start_of_simulation() override;
68 void end_of_simulation() override;
69 std::shared_ptr<tcp4tlm::response_message> resp_msg;
70
71private:
72#ifdef GENERATE_STATISTICS
73 std::vector<unsigned long> rtto, txt, rxt;
74
75public:
76 struct statistics {
77 std::vector<unsigned long> histogram;
78 unsigned long min, max;
79 unsigned long long sum;
80 tlm_genip::addr_decoder_if& indexer;
81 unsigned long count;
82 bool print_histogram;
83 statistics(tlm_genip::addr_decoder_if& indexer_, size_t hsize, unsigned long initval)
84 : histogram(hsize, 0)
85 , min(initval)
86 , max(initval)
87 , sum(initval)
88 , indexer(indexer_)
89 , count(1)
90 , print_histogram(false) {}
91 void updateStat(unsigned long rt);
92 };
93#endif
94};
95
96#ifdef GENERATE_STATISTICS
97inline ostream& operator<<(ostream& os, const tcp4tlm_client::statistics& stat) {
98 if(stat.print_histogram)
99 for(size_t i = 0; i < stat.histogram.size() - 1; ++i)
100 os << "\t[" << stat.indexer.getBaseAddr(i) / 1000 << "us;" << stat.indexer.getBaseAddr(i + 1) / 1000 << "us)\t-> "
101 << stat.histogram[i] << endl;
102 else
103 os << stat.min << "," << stat.sum / stat.count << "," << stat.max;
104 return os;
105}
106#endif
107
108inline void tcp4tlm_client::end_connection() {
109 SCCINFO(SCMOD) << "Sending shutdown message";
110 if(is_remote_connected()) {
111 auto smsg = tcp4tlm::make_sync_msg(sc_core::sc_time_stamp().value());
112 client_connection().write_data(smsg);
113 auto msg = tcp4tlm::make_notify_shutdown_msg();
114 client_connection().write_data(msg);
115 }
116}
117
118} // namespace scc
119
120#endif // TLM_SCC_TCP4TLM_CLIENT_H_
The connection class provides FlatBuffers framing primitives on top of a socket.
SCC TLM utilities.
std::ostream & operator<<(std::ostream &os, log const &val)
output the textual representation of the log level
Definition report.h:133