Go to the documentation of this file.
1 /*
2  * PFPSim: Library for the Programmable Forwarding Plane Simulation Framework
3  *
4  * Copyright (C) 2016 Concordia Univ., Montreal
5  * Samar Abdi
6  * Umair Aftab
7  * Gordon Bailey
8  * Faras Dewal
9  * Shafigh Parsazad
10  * Eric Tremblay
11  *
12  * Copyright (C) 2016 Ericsson
13  * Bochra Boughzala
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28  * 02110-1301, USA.
29  */
30 
39 #ifndef CORE_DEBUGGER_DEBUGGERIPCSERVER_H_
40 #define CORE_DEBUGGER_DEBUGGERIPCSERVER_H_
41 #include <nanomsg/reqrep.h>
42 #include <nanomsg/nn.h>
43 #include <string>
44 #include <iostream>
45 #include <thread>
46 #include <mutex>
47 #include <condition_variable>
48 #include "DebuggerMessages.h"
49 #include "DebugDataManager.h"
50 #include "CPDebuggerInterface.h"
51 #include "../proto/PFPSimDebugger.pb.h"
52 
53 namespace pfp {
54 namespace core {
55 namespace db {
56 
62  public:
68  DebuggerIPCServer(std::string url, DebugDataManager *dm);
69 
74 
78  void start();
79 
83  void waitForRunCommand();
84 
89  std::mutex& getBkptMutex();
90 
95  std::mutex& getStopMutex();
96 
101  std::condition_variable& getBkptConditionVariable();
102 
107  std::condition_variable& getStopConditionVariable();
108 
113  bool getContinueCommand() const;
114 
119  void setContinueCommand(bool b);
120 
125  bool getStopped() const;
126 
131  void setStopped(bool b);
132 
137  void setReplyMessage(DebuggerMessage *message);
138 
143  void registerCP(CPDebuggerInterface *cp_debug_if);
144 
145  private:
147  int socket;
149  std::thread debug_req_thread;
151  bool kill_thread = false;
153  DebugDataManager *data_manager;
155  std::mutex start_mutex;
157  std::mutex bkpt_mutex;
160  std::mutex stop_mutex;
162  std::unique_lock<std::mutex> *ulock;
165  std::condition_variable bkpt_cv;
168  std::condition_variable stop_cv;
170  bool continue_command = false;
172  bool stopped = false;
174  bool run_called = false;
175 
177  DebuggerMessage *reply_message;
178 
180  CPDebuggerInterface *control_plane;
181 
186  void send(DebuggerMessage *message);
187 
192  PFPSimDebugger::DebugMsg* recv();
193 
198  void parseRequest(PFPSimDebugger::DebugMsg *request);
199 
203  void requestThread();
204 
208  void waitForStop();
209 
213  void handleRun(double time_ns = -1);
214  void handleContinue(double time_ns = -1);
215  void handleGetAllCounters();
216  void handleGetCounter(PFPSimDebugger::GetCounterMsg msg);
217  void handleSetBreakpoint(PFPSimDebugger::SetBreakpointMsg msg);
218  void handleGetAllBreakpoints();
219  void handleRemoveBreakpoint(PFPSimDebugger::RemoveBreakpointMsg msg);
220  void handleWhoAmI();
221  void handleNext();
222  void handleGetPacketList(PFPSimDebugger::GetPacketListMsg msg);
223  void handleSetWatchpoint(PFPSimDebugger::SetWatchpointMsg msg);
224  void handleGetAllWatchpoints();
225  void handleRemoveWatchpoint(PFPSimDebugger::RemoveWatchpointMsg msg);
226  void handleBacktrace(PFPSimDebugger::BacktraceMsg msg);
227  void handleEnableDisableBreakpoint(
228  PFPSimDebugger::EnableDisableBreakpointMsg msg);
229  void handleEnableDisableWatchpoint(
230  PFPSimDebugger::EnableDisableWatchpointMsg msg);
231  void handleIgnoreModule(PFPSimDebugger::IgnoreModuleMsg msg);
232  void handleGetAllIgnoreModules();
233  void handleGetSimulationTime();
234  void handleBreakOnPacketDrop(PFPSimDebugger::BreakOnPacketDropMsg msg);
235  void handleGetDroppedPackets();
236  void handleCPCommand(PFPSimDebugger::CPCommandMsg msg);
237  void handleGetTableEntries();
238 
242  void sendGenericReply();
243 
247  void sendRequestFailed();
248 };
249 
250 }; // namespace db
251 }; // namespace core
252 }; // namespace pfp
253 
254 #endif // CORE_DEBUGGER_DEBUGGERIPCSERVER_H_
std::condition_variable & getStopConditionVariable()
Get reference to condition variable used by the DebugObserver to notify the DebuggerIPCServer that th...
Definition: DebuggerIPCServer.cpp:79
Defines an interface to be implemented by Control Plane modules for compatibility with the debugger...
void waitForRunCommand()
Called via the DebugObserver after SystemC elaboration to halt the simulation until the run command i...
Definition: DebuggerIPCServer.cpp:63
Interface for Control Plane module that is necessary for it to work with pfpdb.
Definition: CPDebuggerInterface.h:57
std::condition_variable & getBkptConditionVariable()
Get reference to condition variable used to notify the DebugObserver that a continue or next command ...
Definition: DebuggerIPCServer.cpp:75
void setReplyMessage(DebuggerMessage *message)
Set the message that will be send to pfpdb the next time the simulation is halted.
Definition: DebuggerIPCServer.cpp:99
bool getStopped() const
Get whether the simulation has stopped.
Definition: DebuggerIPCServer.cpp:91
void registerCP(CPDebuggerInterface *cp_debug_if)
Called via the DebugObserver to register a Control Plane module to the debugger so that pfpdb may int...
Definition: DebuggerIPCServer.cpp:103
Base class for an messages that will be sent to pfpdb via the DebuggerIPCServer.
Definition: DebuggerMessages.h:58
Stores any data acquired from the simulation from the observer so that it may be fetched by the serve...
Definition: DebugDataManager.h:60
void start()
Starts the thread which services the requests from pfpdb.
Definition: DebuggerIPCServer.cpp:58
void setContinueCommand(bool b)
Set the flag indicating if the continue command has been received.
Definition: DebuggerIPCServer.cpp:87
Establishes communication with pfpdb python script and services its requests.
Definition: DebuggerIPCServer.h:61
std::mutex & getStopMutex()
Get reference to mutex used to halt DebuggerIPCServer while the simulation is running.
Definition: DebuggerIPCServer.cpp:71
Defines the message objects that can be sent as replies to pfpdb through the DebuggerIPCServer.
void setStopped(bool b)
Set flag that indicates if the simulation is stopped.
Definition: DebuggerIPCServer.cpp:95
std::mutex & getBkptMutex()
Get reference to mutex used to halt simulation when a breakpoint is hit.
Definition: DebuggerIPCServer.cpp:67
Defines class which stores any data about taht simulation that is required by pfpdb.
bool getContinueCommand() const
Get whether a continue command has been received.
Definition: DebuggerIPCServer.cpp:83
DebuggerIPCServer(std::string url, DebugDataManager *dm)
Constructor.
Definition: DebuggerIPCServer.cpp:45
~DebuggerIPCServer()
Destructor.
Definition: DebuggerIPCServer.cpp:51
PacketBase.h.
Definition: ConfigurationParameters.cpp:36