Skip to content

Commit

Permalink
Update monitor function signature
Browse files Browse the repository at this point in the history
XRootD change the function signature in xrootd/xrootd@314852e
  • Loading branch information
djw8605 committed May 29, 2020
1 parent 69b277b commit 84920ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
13 changes: 8 additions & 5 deletions src/tcpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ XrdVERSIONINFO(TcpMonPin,XRootDTCP);



XrdTcpMonPin* TcpMonPin::getInstance(const char *parms,
XrdTcpMonPin* myPinObject::getInstance(const char *parms,
XrdOucEnv &envR,
XrdSysLogger &logR,
XrdTcpMonPin *prevP)
Expand All @@ -26,14 +26,15 @@ TCPStats::TCPStats(XrdXrootdGStream* gs)
this->stream = gs;
}

void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident)
void TCPStats::Monitor(XrdNetAddrInfo &netInfo, XrdTcpMonPin::LinkInfo &lnkInfo, int liLen)
{


tcp_info tcp_info;
socklen_t tcp_info_length = sizeof(tcp_info);
int sockopt_rc = getsockopt( fd, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length );
int sockopt_rc = getsockopt( lnkInfo.fd, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length );
if ( sockopt_rc == 0 ) {
std::string returnedJSON = TCPStats::GenerateJSON(tcp_info, netInfo);
std::string returnedJSON = TCPStats::GenerateJSON(tcp_info, netInfo, lnkInfo.bytesIn, lnkInfo.bytesOut);

// Insert the JSON into the gstream
// Include the null terminated character in the count
Expand All @@ -43,7 +44,7 @@ void TCPStats::Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident)

}

std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo)
std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo, long long bytesIn, long long bytesOut)
{
picojson::object wrapper;
wrapper["type"] = picojson::value("tcpstats");
Expand All @@ -60,6 +61,8 @@ std::string TCPStats::GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo)
wrapper["lost"] = picojson::value(static_cast<double>(tcp_info.tcpi_lost));
wrapper["retrans"] = picojson::value(static_cast<double>(tcp_info.tcpi_retrans));
wrapper["reordering"] = picojson::value(static_cast<double>(tcp_info.tcpi_reordering));
wrapper["bytes_in"] = picojson::value(static_cast<double>(bytesIn));
wrapper["bytes_out"] = picojson::value(static_cast<double>(bytesOut));

return picojson::value(wrapper).serialize();
}
Expand Down
12 changes: 6 additions & 6 deletions src/tcpstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
class TCPStats: public XrdTcpMonPin {

public:
void Monitor(int fd, XrdNetAddrInfo &netInfo, const char *tident);
static std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo);
void Monitor(XrdNetAddrInfo &netInfo, XrdTcpMonPin::LinkInfo &lnkInfo, int liLen);
static std::string GenerateJSON(tcp_info& tcp_info, XrdNetAddrInfo& netInfo, long long bytesIn, long long bytesOut);

TCPStats(XrdXrootdGStream* gs);
virtual ~TCPStats() {};
Expand All @@ -24,13 +24,13 @@ class TCPStats: public XrdTcpMonPin {
};


class TcpMonPin : public XrdOucPinObject<XrdTcpMonPin>
class myPinObject : public XrdOucPinObject<XrdTcpMonPin>
{
public:
TcpMonPin() {};
virtual ~TcpMonPin() {};
myPinObject() {};
virtual ~myPinObject() {};
XrdTcpMonPin *getInstance(const char *parms,
XrdOucEnv &envR,
XrdSysLogger &logR,
XrdTcpMonPin *prevP);
};
} TcpMonPin;
10 changes: 8 additions & 2 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TCPTest : public ::testing::Test {

m_logger = std::unique_ptr<XrdSysLogger>(new XrdSysLogger());

auto new_instance = std::unique_ptr<TcpMonPin>(new TcpMonPin());
auto new_instance = std::unique_ptr<myPinObject>(new myPinObject());
ASSERT_TRUE(new_instance != nullptr);

XrdTcpMonPin *prevP = nullptr;
Expand Down Expand Up @@ -79,7 +79,10 @@ TEST_F(TCPTest, GenerateJSON) {
name.sin_addr = *(struct in_addr *) hostinfo->h_addr;
XrdNetAddr xrdnetaddr(&name);

std::string returned_json = TCPStats::GenerateJSON(tcp_info, xrdnetaddr);
long long bytesIn = 10;
long long bytesOut = 11;

std::string returned_json = TCPStats::GenerateJSON(tcp_info, xrdnetaddr, bytesIn, bytesOut);

// Parse the returned JSON
picojson::value v;
Expand All @@ -94,6 +97,9 @@ TEST_F(TCPTest, GenerateJSON) {
ASSERT_EQ(v.get<picojson::object>()["lost"].get<double>(), 5);
ASSERT_EQ(v.get<picojson::object>()["retrans"].get<double>(), 6);
ASSERT_EQ(v.get<picojson::object>()["reordering"].get<double>(), 7);
ASSERT_EQ(v.get<picojson::object>()["bytes_in"].get<double>(), 10);
ASSERT_EQ(v.get<picojson::object>()["bytes_out"].get<double>(), 11);


//std::cout << returned_json;

Expand Down

0 comments on commit 84920ba

Please sign in to comment.