-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
today KatranMonitor storing packets on a disk in pcap format. sometime it is more usefull to store em in memory and allow for remote client get em (e.g. through thrift/grpc call). in this diff i'm adding such ability by implementing IOBufWriter Tested By: modified katran_tester. making sure that iobuf contains proper pcap data (by writing this data in a file in tester, and then reading w/ tcpdump)
- Loading branch information
Showing
11 changed files
with
212 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
#include "katran/lib/IOBufWriter.h" | ||
#include <cstring> | ||
|
||
namespace katran { | ||
|
||
IOBufWriter::IOBufWriter(folly::IOBuf* iobuf) | ||
: iobuf_(iobuf) {} | ||
|
||
void IOBufWriter::writeData(const void* ptr, std::size_t size) { | ||
::memcpy(static_cast<void*>(iobuf_->writableTail()), ptr, size); | ||
iobuf_->append(size); | ||
} | ||
|
||
bool IOBufWriter::available(std::size_t amount) { | ||
return iobuf_->tailroom() >= amount; | ||
} | ||
|
||
bool IOBufWriter::restart() { | ||
iobuf_->clear(); | ||
return true; | ||
} | ||
|
||
} // namespace katran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <folly/io/IOBuf.h> | ||
|
||
#include "katran/lib/DataWriter.h" | ||
|
||
namespace katran { | ||
|
||
/** | ||
* IOBufWriter is used to write pcap-data into IOBuf. | ||
*/ | ||
class IOBufWriter : public DataWriter { | ||
public: | ||
/** | ||
* @param unique_ptr<IOBuf> iobuf for packets to written into | ||
*/ | ||
explicit IOBufWriter(folly::IOBuf* iobuf); | ||
|
||
void writeData(const void* ptr, std::size_t size) override; | ||
|
||
bool available(std::size_t amount) override; | ||
|
||
bool restart() override; | ||
|
||
bool stop() override {return true;} | ||
|
||
private: | ||
folly::IOBuf* iobuf_; | ||
}; | ||
|
||
} // namespace katran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.