summaryrefslogtreecommitdiffstats
path: root/src/stateless/rx/trex_stateless_rx_port_mngr.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-10-31 11:09:56 +0200
committerimarom <imarom@cisco.com>2016-11-02 15:07:32 +0200
commit02ab06b1cf8886be0a6fde5360497b4fa968d3a3 (patch)
tree7c30cd45abda75b9c45e61134eb48cdc43367aec /src/stateless/rx/trex_stateless_rx_port_mngr.cpp
parent124e1d4772507ad159d1f786aa1ffe5bb7d3b4cf (diff)
RX software features - some new files
Diffstat (limited to 'src/stateless/rx/trex_stateless_rx_port_mngr.cpp')
-rw-r--r--src/stateless/rx/trex_stateless_rx_port_mngr.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/stateless/rx/trex_stateless_rx_port_mngr.cpp b/src/stateless/rx/trex_stateless_rx_port_mngr.cpp
new file mode 100644
index 00000000..8a0fd613
--- /dev/null
+++ b/src/stateless/rx/trex_stateless_rx_port_mngr.cpp
@@ -0,0 +1,83 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+ Copyright (c) 2016-2016 Cisco Systems, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+#include "bp_sim.h"
+#include "trex_stateless_rx_port_mngr.h"
+#include "common/captureFile.h"
+
+RXPacketRecorder::RXPacketRecorder() {
+ m_writer = NULL;
+ m_limit = 0;
+ m_epoch = -1;
+}
+
+RXPacketRecorder::~RXPacketRecorder() {
+ stop();
+}
+
+void
+RXPacketRecorder::start(const std::string &pcap, uint32_t limit) {
+ m_writer = CCapWriterFactory::CreateWriter(LIBPCAP, (char *)pcap.c_str());
+ if (m_writer == NULL) {
+ std::stringstream ss;
+ ss << "unable to create PCAP file: " << pcap;
+ throw TrexException(ss.str());
+ }
+
+ assert(limit > 0);
+ m_limit = limit;
+}
+
+void
+RXPacketRecorder::stop() {
+ if (m_writer) {
+ delete m_writer;
+ m_writer = NULL;
+ }
+}
+
+void
+RXPacketRecorder::handle_pkt(const rte_mbuf_t *m) {
+ if (!m_writer) {
+ return;
+ }
+
+ dsec_t now = now_sec();
+ if (m_epoch < 0) {
+ m_epoch = now;
+ }
+
+ dsec_t dt = now - m_epoch;
+
+ CPktNsecTimeStamp t_c(dt);
+ m_pkt.time_nsec = t_c.m_time_nsec;
+ m_pkt.time_sec = t_c.m_time_sec;
+
+ const uint8_t *p = rte_pktmbuf_mtod(m, uint8_t *);
+ m_pkt.pkt_len = m->pkt_len;
+ memcpy(m_pkt.raw, p, m->pkt_len);
+
+ m_writer->write_packet(&m_pkt);
+
+ m_limit--;
+ if (m_limit == 0) {
+ stop();
+ }
+}