mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
arping ip and interface from client interface
This commit is contained in:
parent
c236cbf17b
commit
bf83c9b3e2
@ -1399,6 +1399,11 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
|
||||
if (detType == EIGER) {
|
||||
impl()->setEthernetInterface2(eth);
|
||||
}
|
||||
|
||||
// update locally to use for arping
|
||||
udpips.clear();
|
||||
udpips.push_back(arg.str());
|
||||
|
||||
// get mac address
|
||||
auto retval = sls::InterfaceNameToMac(eth);
|
||||
if (retval == 0) {
|
||||
@ -1431,6 +1436,9 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
|
||||
}
|
||||
impl()->setEthernetInterface2(eth);
|
||||
|
||||
// update locally to use for arping
|
||||
udpips.push_back(arg.str());
|
||||
|
||||
// get mac address
|
||||
auto retval = sls::InterfaceNameToMac(eth);
|
||||
if (retval == 0) {
|
||||
@ -1712,6 +1720,6 @@ int ClientInterface::set_arping(Interface &socket) {
|
||||
}
|
||||
verifyIdle(socket);
|
||||
LOG(logDEBUG1) << "Starting/ Killing arping thread:" << value;
|
||||
impl()->setArping(value);
|
||||
impl()->setArping(value, udpips);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
@ -192,4 +192,5 @@ class ClientInterface : private virtual slsDetectorDefs {
|
||||
|
||||
pid_t parentThreadId{0};
|
||||
pid_t tcpThreadId{0};
|
||||
std::vector<std::string> udpips;
|
||||
};
|
||||
|
@ -330,13 +330,21 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Implementation::getThreadIds() const {
|
||||
|
||||
bool Implementation::getArping() const { return threadArping->IsRunning(); }
|
||||
|
||||
void Implementation::setArping(const bool i) {
|
||||
pid_t Implementation::getArpingThreadId() const {
|
||||
return threadArping->GetThreadId();
|
||||
}
|
||||
|
||||
void Implementation::setArping(const bool i,
|
||||
const std::vector<std::string> ips) {
|
||||
if (i != threadArping->IsRunning()) {
|
||||
if (!i) {
|
||||
threadArping->StopRunning();
|
||||
} else {
|
||||
threadArping->ClearIpsAndInterfaces();
|
||||
threadArping->AddIpsAndInterfaces(eth[0], "10.0.0.1");
|
||||
threadArping->AddIpsAndInterfaces(eth[0], ips[0]);
|
||||
if (numUDPInterfaces == 2) {
|
||||
threadArping->AddIpsAndInterfaces(eth[1], ips[1]);
|
||||
}
|
||||
threadArping->StartRunning();
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ class Implementation : private virtual slsDetectorDefs {
|
||||
void setThreadIds(const pid_t parentTid, const pid_t tcpTid);
|
||||
std::array<pid_t, NUM_RX_THREAD_IDS> getThreadIds() const;
|
||||
bool getArping() const;
|
||||
void setArping(const bool i);
|
||||
pid_t getArpingThreadId() const;
|
||||
void setArping(const bool i, const std::vector<std::string> ips);
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
|
@ -11,6 +11,8 @@ ThreadArping::ThreadArping() {}
|
||||
|
||||
ThreadArping::~ThreadArping() { StopRunning(); }
|
||||
|
||||
pid_t ThreadArping::GetThreadId() const { return threadId; }
|
||||
|
||||
bool ThreadArping::IsRunning() const { return runningFlag; }
|
||||
|
||||
void ThreadArping::StartRunning() {
|
||||
@ -33,9 +35,8 @@ void ThreadArping::StartRunning() {
|
||||
|
||||
void ThreadArping::StopRunning() {
|
||||
pthread_cancel(threadObject);
|
||||
LOG(logINFOBLUE) << "Killing [ Arping Thread, Tid: " << threadId << "]";
|
||||
}
|
||||
runningFlag = false;
|
||||
LOG(logINFOBLUE) << "Killing [ Arping Thread, Tid: " << threadId << " ]";
|
||||
runningFlag = false;
|
||||
}
|
||||
|
||||
void ThreadArping::ClearIpsAndInterfaces() { arpInterfaceIp.clear(); }
|
||||
@ -47,14 +48,48 @@ void ThreadArping::AddIpsAndInterfaces(std::string interface, std::string ip) {
|
||||
void ThreadArping::RunningThread() {
|
||||
|
||||
threadId = syscall(SYS_gettid);
|
||||
LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << "]";
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Created [ Arping Thread, Tid: " << threadId << " ] for ";
|
||||
for (auto ethip : arpInterfaceIp) {
|
||||
os << "\n\t[ " << ethip.first << ", " << ethip.second << " ]";
|
||||
}
|
||||
LOG(logINFOBLUE) << os.str();
|
||||
}
|
||||
|
||||
// create the commands to ping necessary interfaces
|
||||
std::vector<std::string> commands;
|
||||
for (auto ethip : arpInterfaceIp) {
|
||||
std::ostringstream os;
|
||||
os << "arping -c 1 -U -I " << ethip.first << " " << ethip.second;
|
||||
// to read error messages
|
||||
os << " 2>&1";
|
||||
std::string cmd = os.str();
|
||||
commands.push_back(cmd);
|
||||
}
|
||||
|
||||
while (IsRunning()) {
|
||||
LOG(logINFOBLUE) << "Going to sleep";
|
||||
|
||||
// arping
|
||||
for (auto cmd : commands) {
|
||||
LOG(logDEBUG) << "Executing Arping Command: " << cmd;
|
||||
|
||||
// execute command and check for errors
|
||||
FILE *sysFile = popen(cmd.c_str(), "r");
|
||||
char output[MAX_STR_LENGTH] = {0};
|
||||
fgets(output, sizeof(output), sysFile);
|
||||
output[sizeof(output) - 1] = '\0';
|
||||
if (pclose(sysFile)) {
|
||||
LOG(logERROR) << "Executing cmd[" << cmd
|
||||
<< "]\n\tError Message : " << output;
|
||||
} else {
|
||||
LOG(logDEBUG) << output;
|
||||
}
|
||||
}
|
||||
|
||||
// wait for 60s
|
||||
usleep(60 * 1000 * 1000);
|
||||
}
|
||||
|
||||
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << "]";
|
||||
LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << " ]";
|
||||
}
|
@ -22,11 +22,13 @@ class ThreadArping : private virtual slsDetectorDefs {
|
||||
|
||||
pthread_t threadObject;
|
||||
std::vector<std::pair<std::string, std::string>> arpInterfaceIp;
|
||||
pid_t threadIds;
|
||||
std::vector<std::string> commands;
|
||||
pid_t threadId;
|
||||
|
||||
public:
|
||||
ThreadArping();
|
||||
virtual ~ThreadArping();
|
||||
pid_t GetThreadId() const;
|
||||
bool IsRunning() const;
|
||||
void StartRunning();
|
||||
void StopRunning();
|
||||
@ -39,5 +41,5 @@ class ThreadArping : private virtual slsDetectorDefs {
|
||||
* RunningMask is satisfied Then it exits the thread on its own if
|
||||
* killThread is true
|
||||
*/
|
||||
void RunningThread(std::string interface, std::string ip);
|
||||
void RunningThread();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user