2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2012 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This 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, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "abstractport.h"
|
|
|
|
|
|
|
|
#include "../common/abstractprotocol.h"
|
2019-02-05 07:01:43 -06:00
|
|
|
#include "../common/framevalueattrib.h"
|
2015-09-14 07:49:52 -05:00
|
|
|
#include "../common/streambase.h"
|
|
|
|
#include "devicemanager.h"
|
2018-07-26 10:23:33 -05:00
|
|
|
#include "interfaceinfo.h"
|
2015-11-04 07:20:08 -06:00
|
|
|
#include "packetbuffer.h"
|
2023-03-31 06:25:03 -05:00
|
|
|
#include "streamtiming.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QIODevice>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
AbstractPort::AbstractPort(int id, const char *device)
|
|
|
|
{
|
|
|
|
isUsable_ = true;
|
|
|
|
data_.mutable_port_id()->set_id(id);
|
|
|
|
data_.set_name(device);
|
|
|
|
|
|
|
|
//! \todo (LOW) admin enable/disable of port
|
|
|
|
data_.set_is_enabled(true);
|
|
|
|
|
|
|
|
data_.set_is_exclusive_control(false);
|
|
|
|
|
|
|
|
isSendQueueDirty_ = false;
|
2015-10-12 07:41:30 -05:00
|
|
|
rateAccuracy_ = kHighAccuracy;
|
2015-04-16 11:50:07 -05:00
|
|
|
linkState_ = OstProto::LinkStateUnknown;
|
|
|
|
minPacketSetSize_ = 1;
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
deviceManager_ = new DeviceManager(this);
|
2018-07-26 10:23:33 -05:00
|
|
|
interfaceInfo_ = NULL;
|
2015-09-14 07:49:52 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
maxStatsValue_ = ULLONG_MAX; // assume 64-bit stats
|
|
|
|
memset((void*) &stats_, 0, sizeof(stats_));
|
|
|
|
resetStats();
|
2023-03-31 06:25:03 -05:00
|
|
|
|
|
|
|
streamTiming_ = StreamTiming::instance();
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractPort::~AbstractPort()
|
|
|
|
{
|
2015-09-14 07:49:52 -05:00
|
|
|
delete deviceManager_;
|
2018-07-26 10:23:33 -05:00
|
|
|
delete interfaceInfo_;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::init()
|
|
|
|
{
|
2021-11-06 10:57:55 -05:00
|
|
|
if (interfaceInfo_) {
|
|
|
|
data_.set_speed(interfaceInfo_->speed);
|
|
|
|
data_.set_mtu(interfaceInfo_->mtu);
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:23:33 -05:00
|
|
|
if (deviceManager_)
|
|
|
|
deviceManager_->createHostDevices();
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-10-27 11:14:08 -05:00
|
|
|
/*! Can we modify Port with these params? Should modify cause port dirty? */
|
|
|
|
bool AbstractPort::canModify(const OstProto::Port &port, bool *dirty)
|
|
|
|
{
|
|
|
|
bool allow = true;
|
|
|
|
|
|
|
|
*dirty = false;
|
|
|
|
|
|
|
|
if (port.has_transmit_mode()
|
|
|
|
&& (port.transmit_mode() != data_.transmit_mode())) {
|
|
|
|
*dirty = true;
|
|
|
|
allow = !isTransmitOn();
|
|
|
|
}
|
|
|
|
|
2017-12-02 23:56:09 -06:00
|
|
|
if (port.has_is_tracking_stream_stats()
|
|
|
|
&& (port.is_tracking_stream_stats()
|
|
|
|
!= data_.is_tracking_stream_stats())) {
|
2016-11-21 07:09:55 -06:00
|
|
|
*dirty = true;
|
|
|
|
allow = !isTransmitOn();
|
|
|
|
}
|
2019-05-28 08:16:58 -05:00
|
|
|
if (*dirty)
|
|
|
|
isSendQueueDirty_ = true;
|
2016-11-21 07:09:55 -06:00
|
|
|
|
2016-10-27 11:14:08 -05:00
|
|
|
return allow;
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
bool AbstractPort::modify(const OstProto::Port &port)
|
|
|
|
{
|
2015-04-24 10:23:00 -05:00
|
|
|
bool ret = true;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
//! \todo Use reflection to find out which fields are set
|
2022-09-02 06:45:46 -05:00
|
|
|
if (port.has_user_description()) {
|
|
|
|
data_.set_user_description(port.user_description());
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (port.has_is_exclusive_control())
|
|
|
|
{
|
|
|
|
bool val = port.is_exclusive_control();
|
|
|
|
|
|
|
|
ret = setExclusiveControl(val);
|
|
|
|
if (ret)
|
|
|
|
data_.set_is_exclusive_control(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port.has_transmit_mode())
|
|
|
|
data_.set_transmit_mode(port.transmit_mode());
|
|
|
|
|
2017-12-02 23:56:09 -06:00
|
|
|
if (port.has_is_tracking_stream_stats())
|
|
|
|
ret |= setTrackStreamStats(port.is_tracking_stream_stats());
|
2016-11-21 07:09:55 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (port.has_user_name()) {
|
|
|
|
data_.set_user_name(port.user_name());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
DeviceManager* AbstractPort::deviceManager()
|
|
|
|
{
|
|
|
|
return deviceManager_;
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
StreamBase* AbstractPort::streamAtIndex(int index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(index < streamList_.size());
|
|
|
|
return streamList_.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamBase* AbstractPort::stream(int streamId)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
if ((uint)streamId == streamList_.at(i)->id())
|
|
|
|
return streamList_.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractPort::addStream(StreamBase *stream)
|
|
|
|
{
|
|
|
|
streamList_.append(stream);
|
|
|
|
isSendQueueDirty_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractPort::deleteStream(int streamId)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
StreamBase *stream;
|
|
|
|
|
|
|
|
if ((uint)streamId == streamList_.at(i)->id())
|
|
|
|
{
|
|
|
|
stream = streamList_.takeAt(i);
|
|
|
|
delete stream;
|
|
|
|
|
|
|
|
isSendQueueDirty_ = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::addNote(QString note)
|
|
|
|
{
|
|
|
|
QString notes = QString::fromStdString(data_.notes());
|
|
|
|
|
|
|
|
note.prepend("<li>");
|
|
|
|
note.append("</li>");
|
|
|
|
|
|
|
|
if (notes.isEmpty())
|
|
|
|
notes="<b>Limitation(s)</b><ul>";
|
|
|
|
else
|
|
|
|
notes.remove("</ul>");
|
|
|
|
|
|
|
|
notes.append(note);
|
|
|
|
notes.append("</ul>");
|
|
|
|
|
|
|
|
data_.set_notes(notes.toStdString());
|
|
|
|
}
|
|
|
|
|
2016-11-21 07:09:55 -06:00
|
|
|
bool AbstractPort::setTrackStreamStats(bool enable)
|
|
|
|
{
|
2017-12-02 23:56:09 -06:00
|
|
|
data_.set_is_tracking_stream_stats(enable);
|
2016-12-06 07:00:26 -06:00
|
|
|
|
2016-12-07 06:49:09 -06:00
|
|
|
return true;
|
2016-11-21 07:09:55 -06:00
|
|
|
}
|
|
|
|
|
2015-10-12 07:41:30 -05:00
|
|
|
AbstractPort::Accuracy AbstractPort::rateAccuracy()
|
|
|
|
{
|
|
|
|
return rateAccuracy_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractPort::setRateAccuracy(Accuracy accuracy)
|
|
|
|
{
|
|
|
|
rateAccuracy_ = accuracy;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-09 05:46:31 -06:00
|
|
|
int AbstractPort::updatePacketList()
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
switch(data_.transmit_mode())
|
|
|
|
{
|
|
|
|
case OstProto::kSequentialTransmit:
|
2019-02-09 05:46:31 -06:00
|
|
|
return updatePacketListSequential();
|
2015-04-16 11:50:07 -05:00
|
|
|
break;
|
|
|
|
case OstProto::kInterleavedTransmit:
|
2019-02-09 05:46:31 -06:00
|
|
|
return updatePacketListInterleaved();
|
2015-04-16 11:50:07 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false); // Unreachable!!!
|
|
|
|
break;
|
|
|
|
}
|
2019-02-09 05:46:31 -06:00
|
|
|
return 0;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 05:46:31 -06:00
|
|
|
int AbstractPort::updatePacketListSequential()
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2023-04-24 06:35:40 -05:00
|
|
|
quint64 duration = 0; // in nanosec
|
|
|
|
quint64 totalPkts = 0;
|
|
|
|
QList<uint> ttagMarkers;
|
2019-02-05 07:01:43 -06:00
|
|
|
FrameValueAttrib packetListAttrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
long sec = 0;
|
|
|
|
long nsec = 0;
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
// First sort the streams by ordinalValue
|
2019-07-26 10:54:25 -05:00
|
|
|
std::sort(streamList_.begin(), streamList_.end(), StreamBase::StreamLessThan);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
clearPacketList();
|
|
|
|
|
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
if (streamList_[i]->isEnabled())
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
ulong n, x, y;
|
|
|
|
ulong burstSize;
|
|
|
|
double ibg = 0;
|
|
|
|
quint64 ibg1 = 0, ibg2 = 0;
|
|
|
|
quint64 nb1 = 0, nb2 = 0;
|
|
|
|
double ipg = 0;
|
|
|
|
quint64 ipg1 = 0, ipg2 = 0;
|
|
|
|
quint64 npx1 = 0, npx2 = 0;
|
|
|
|
quint64 npy1 = 0, npy2 = 0;
|
|
|
|
quint64 loopDelay;
|
|
|
|
ulong frameVariableCount = streamList_[i]->frameVariableCount();
|
2023-04-24 06:35:40 -05:00
|
|
|
bool hasTtag = streamList_[i]->hasProtocol(
|
|
|
|
OstProto::Protocol::kSignFieldNumber);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
// We derive n, x, y such that
|
|
|
|
// n * x + y = total number of packets to be sent
|
|
|
|
|
|
|
|
switch (streamList_[i]->sendUnit())
|
|
|
|
{
|
2021-08-15 08:31:10 -05:00
|
|
|
case StreamBase::e_su_bursts:
|
2015-04-16 11:50:07 -05:00
|
|
|
burstSize = streamList_[i]->burstSize();
|
|
|
|
x = AbstractProtocol::lcm(frameVariableCount, burstSize);
|
2015-09-08 08:16:56 -05:00
|
|
|
n = ulong(burstSize * streamList_[i]->numBursts()) / x;
|
|
|
|
y = ulong(burstSize * streamList_[i]->numBursts()) % x;
|
2015-04-16 11:50:07 -05:00
|
|
|
if (streamList_[i]->burstRate() > 0)
|
|
|
|
{
|
|
|
|
ibg = 1e9/double(streamList_[i]->burstRate());
|
|
|
|
ibg1 = quint64(ceil(ibg));
|
|
|
|
ibg2 = quint64(floor(ibg));
|
|
|
|
nb1 = quint64((ibg - double(ibg2)) * double(x));
|
|
|
|
nb2 = x - nb1;
|
|
|
|
}
|
|
|
|
loopDelay = ibg2;
|
|
|
|
break;
|
2021-08-15 08:31:10 -05:00
|
|
|
case StreamBase::e_su_packets:
|
2015-04-16 11:50:07 -05:00
|
|
|
x = frameVariableCount;
|
|
|
|
n = 2;
|
|
|
|
while (x < minPacketSetSize_)
|
|
|
|
x = frameVariableCount*n++;
|
|
|
|
n = streamList_[i]->numPackets() / x;
|
|
|
|
y = streamList_[i]->numPackets() % x;
|
|
|
|
burstSize = x + y;
|
|
|
|
if (streamList_[i]->packetRate() > 0)
|
|
|
|
{
|
|
|
|
ipg = 1e9/double(streamList_[i]->packetRate());
|
|
|
|
ipg1 = quint64(ceil(ipg));
|
|
|
|
ipg2 = quint64(floor(ipg));
|
|
|
|
npx1 = quint64((ipg - double(ipg2)) * double(x));
|
|
|
|
npx2 = x - npx1;
|
|
|
|
npy1 = quint64((ipg - double(ipg2)) * double(y));
|
|
|
|
npy2 = y - npy1;
|
|
|
|
}
|
|
|
|
loopDelay = ipg2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled stream control unit %d",
|
|
|
|
streamList_[i]->sendUnit());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("\nframeVariableCount = %lu", frameVariableCount);
|
|
|
|
qDebug("n = %lu, x = %lu, y = %lu, burstSize = %lu",
|
|
|
|
n, x, y, burstSize);
|
|
|
|
|
|
|
|
qDebug("ibg = %g", ibg);
|
2018-05-20 03:03:38 -05:00
|
|
|
qDebug("ibg1 = %llu", ibg1);
|
|
|
|
qDebug("nb1 = %llu", nb1);
|
|
|
|
qDebug("ibg2 = %llu", ibg2);
|
|
|
|
qDebug("nb2 = %llu\n", nb2);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
qDebug("ipg = %g", ipg);
|
2018-05-20 03:03:38 -05:00
|
|
|
qDebug("ipg1 = %llu", ipg1);
|
|
|
|
qDebug("npx1 = %llu", npx1);
|
|
|
|
qDebug("npy1 = %llu", npy1);
|
|
|
|
qDebug("ipg2 = %llu", ipg2);
|
|
|
|
qDebug("npx2 = %llu", npx2);
|
|
|
|
qDebug("npy2 = %llu\n", npy2);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
if (n >= 1) {
|
2015-04-16 11:50:07 -05:00
|
|
|
loopNextPacketSet(x, n, 0, loopDelay);
|
2021-02-20 09:10:37 -06:00
|
|
|
qDebug("PacketSet: n = %lu, x = %lu", n, x);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
else if (n == 0)
|
|
|
|
x = 0;
|
|
|
|
|
2023-04-24 06:35:40 -05:00
|
|
|
quint64 pktCount = n*x + y;
|
2015-04-16 11:50:07 -05:00
|
|
|
for (uint j = 0; j < (x+y); j++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (j == 0 || frameVariableCount > 1)
|
|
|
|
{
|
2019-02-05 07:01:43 -06:00
|
|
|
FrameValueAttrib attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
len = streamList_[i]->frameValue(
|
2019-02-05 07:01:43 -06:00
|
|
|
pktBuf_, sizeof(pktBuf_), j, &attrib);
|
|
|
|
packetListAttrib += attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
if (len <= 0)
|
|
|
|
continue;
|
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
// Create a packet set for 'y' with repeat = 1
|
|
|
|
if (j == x) {
|
|
|
|
loopNextPacketSet(y, 1, 0, loopDelay);
|
|
|
|
qDebug("PacketSet: n = 1, y = %lu", y);
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
qDebug("q(%d, %d) sec = %lu nsec = %lu",
|
|
|
|
i, j, sec, nsec);
|
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
if (!appendToPacketList(sec, nsec, pktBuf_, len)) {
|
|
|
|
clearPacketList(); // don't leave it half baked/inconsitent
|
|
|
|
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
|
|
|
|
goto _out_of_memory;
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
if ((j > 0) && (((j+1) % burstSize) == 0))
|
|
|
|
{
|
|
|
|
nsec += (j < nb1) ? ibg1 : ibg2;
|
|
|
|
while (nsec >= long(1e9))
|
|
|
|
{
|
|
|
|
sec++;
|
|
|
|
nsec -= long(1e9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (j < x)
|
|
|
|
nsec += (j < npx1) ? ipg1 : ipg2;
|
|
|
|
else
|
|
|
|
nsec += ((j-x) < npy1) ? ipg1 : ipg2;
|
|
|
|
|
|
|
|
while (nsec >= long(1e9))
|
|
|
|
{
|
|
|
|
sec++;
|
|
|
|
nsec -= long(1e9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-24 06:35:40 -05:00
|
|
|
// Add a Ttag marker after every kTtagTimeInterval_ worth of pkts
|
|
|
|
if (hasTtag) {
|
|
|
|
uint ttagPktInterval = kTtagTimeInterval_*1e9/loopDelay;
|
|
|
|
for (uint k = 0; k < pktCount; k += ttagPktInterval)
|
|
|
|
ttagMarkers.append(totalPkts + k);
|
|
|
|
}
|
|
|
|
totalPkts += pktCount;
|
|
|
|
duration += pktCount*loopDelay; // in nanosecs
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
switch(streamList_[i]->nextWhat())
|
|
|
|
{
|
2021-08-15 08:52:17 -05:00
|
|
|
case StreamBase::e_nw_stop:
|
2015-04-16 11:50:07 -05:00
|
|
|
goto _stop_no_more_pkts;
|
|
|
|
|
2021-08-15 08:52:17 -05:00
|
|
|
case StreamBase::e_nw_goto_id:
|
2015-04-16 11:50:07 -05:00
|
|
|
/*! \todo (MED): define and use
|
|
|
|
streamList_[i].d.control().goto_stream_id(); */
|
|
|
|
|
|
|
|
/*! \todo (MED): assumes goto Id is less than current!!!!
|
|
|
|
To support goto to any id, do
|
|
|
|
if goto_id > curr_id then
|
|
|
|
i = goto_id;
|
|
|
|
goto restart;
|
|
|
|
else
|
|
|
|
returnToQIdx = 0;
|
|
|
|
*/
|
|
|
|
|
|
|
|
setPacketListLoopMode(true, 0,
|
|
|
|
streamList_[i]->sendUnit() ==
|
|
|
|
StreamBase::e_su_bursts ? ibg1 : ipg1);
|
|
|
|
goto _stop_no_more_pkts;
|
|
|
|
|
2021-08-15 08:52:17 -05:00
|
|
|
case StreamBase::e_nw_goto_next:
|
2015-04-16 11:50:07 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
qFatal("---------- %s: Unhandled case (%d) -----------",
|
|
|
|
__FUNCTION__, streamList_[i]->nextWhat() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // if (stream is enabled)
|
|
|
|
} // for (numStreams)
|
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
_out_of_memory:
|
2015-04-16 11:50:07 -05:00
|
|
|
_stop_no_more_pkts:
|
2023-04-24 06:35:40 -05:00
|
|
|
// See comments in updatePacketListInterleaved() for calc explanation
|
|
|
|
setPacketListTtagMarkers(ttagMarkers, ttagMarkers.isEmpty() ? 0 :
|
|
|
|
qMax(uint(kTtagTimeInterval_*1e9/(duration)),
|
|
|
|
1U) * totalPkts);
|
2015-04-16 11:50:07 -05:00
|
|
|
isSendQueueDirty_ = false;
|
2019-02-05 07:01:43 -06:00
|
|
|
|
2019-02-09 05:46:31 -06:00
|
|
|
qDebug("PacketListAttrib = %x",
|
|
|
|
static_cast<int>(packetListAttrib.errorFlags));
|
|
|
|
return static_cast<int>(packetListAttrib.errorFlags);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-09 05:46:31 -06:00
|
|
|
int AbstractPort::updatePacketListInterleaved()
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2019-02-05 07:01:43 -06:00
|
|
|
FrameValueAttrib packetListAttrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
int numStreams = 0;
|
|
|
|
quint64 minGap = ULLONG_MAX;
|
2023-04-17 01:29:00 -05:00
|
|
|
quint64 duration = quint64(1e3); // 1000ns (1us)
|
2023-04-21 08:02:17 -05:00
|
|
|
|
|
|
|
// TODO: convert the below to a QList of struct aggregating all list vars
|
2020-11-13 10:18:36 -06:00
|
|
|
QList<int> streamId;
|
2015-04-16 11:50:07 -05:00
|
|
|
QList<quint64> ibg1, ibg2;
|
|
|
|
QList<quint64> nb1, nb2;
|
|
|
|
QList<quint64> ipg1, ipg2;
|
|
|
|
QList<quint64> np1, np2;
|
|
|
|
QList<ulong> schedSec, schedNsec;
|
|
|
|
QList<ulong> pktCount, burstCount;
|
|
|
|
QList<ulong> burstSize;
|
|
|
|
QList<bool> isVariable;
|
2023-04-21 08:02:17 -05:00
|
|
|
QList<bool> hasTtag;
|
2015-04-16 11:50:07 -05:00
|
|
|
QList<QByteArray> pktBuf;
|
|
|
|
QList<ulong> pktLen;
|
2018-05-10 11:04:51 -05:00
|
|
|
int activeStreamCount = 0;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
2016-09-21 09:56:08 -05:00
|
|
|
clearPacketList();
|
2018-05-10 11:04:51 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
if (streamList_[i]->isEnabled())
|
|
|
|
activeStreamCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeStreamCount == 0)
|
2016-09-21 09:56:08 -05:00
|
|
|
{
|
|
|
|
isSendQueueDirty_ = false;
|
2019-02-09 05:46:31 -06:00
|
|
|
return 0;
|
2016-09-21 09:56:08 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
// First sort the streams by ordinalValue
|
2019-07-26 10:54:25 -05:00
|
|
|
std::sort(streamList_.begin(), streamList_.end(), StreamBase::StreamLessThan);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2023-04-17 01:29:00 -05:00
|
|
|
// FIXME: we are calculating n[bp][12], i[bp]g[12] for a duration of 1sec;
|
|
|
|
// this was fine when the actual packet list duration was also 1sec. But
|
|
|
|
// in the current code (post Turbo changes), the latter can be different!
|
2015-04-16 11:50:07 -05:00
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
if (!streamList_[i]->isEnabled())
|
|
|
|
continue;
|
|
|
|
|
2020-11-13 10:18:36 -06:00
|
|
|
streamId.append(i);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
double numBursts = 0;
|
|
|
|
double numPackets = 0;
|
|
|
|
|
|
|
|
quint64 _burstSize = 0;
|
|
|
|
double ibg = 0;
|
|
|
|
quint64 _ibg1 = 0, _ibg2 = 0;
|
|
|
|
quint64 _nb1 = 0, _nb2 = 0;
|
|
|
|
double ipg = 0;
|
|
|
|
quint64 _ipg1 = 0, _ipg2 = 0;
|
|
|
|
quint64 _np1 = 0, _np2 = 0;
|
|
|
|
|
2020-11-13 10:18:36 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
switch (streamList_[i]->sendUnit())
|
|
|
|
{
|
2021-08-15 08:31:10 -05:00
|
|
|
case StreamBase::e_su_bursts:
|
2015-04-16 11:50:07 -05:00
|
|
|
numBursts = streamList_[i]->burstRate();
|
2022-06-09 03:05:05 -05:00
|
|
|
_burstSize = streamList_[i]->burstSize();
|
2015-04-16 11:50:07 -05:00
|
|
|
if (streamList_[i]->burstRate() > 0)
|
|
|
|
{
|
|
|
|
ibg = 1e9/double(streamList_[i]->burstRate());
|
|
|
|
_ibg1 = quint64(ceil(ibg));
|
|
|
|
_ibg2 = quint64(floor(ibg));
|
|
|
|
_nb1 = quint64((ibg - double(_ibg2)) * double(numBursts));
|
|
|
|
_nb2 = quint64(numBursts) - _nb1;
|
|
|
|
}
|
|
|
|
break;
|
2021-08-15 08:31:10 -05:00
|
|
|
case StreamBase::e_su_packets:
|
2015-04-16 11:50:07 -05:00
|
|
|
numPackets = streamList_[i]->packetRate();
|
2022-06-09 03:05:05 -05:00
|
|
|
_burstSize = 1;
|
2015-04-16 11:50:07 -05:00
|
|
|
if (streamList_[i]->packetRate() > 0)
|
|
|
|
{
|
|
|
|
ipg = 1e9/double(streamList_[i]->packetRate());
|
|
|
|
_ipg1 = llrint(ceil(ipg));
|
|
|
|
_ipg2 = quint64(floor(ipg));
|
|
|
|
_np1 = quint64((ipg - double(_ipg2)) * double(numPackets));
|
|
|
|
_np2 = quint64(numPackets) - _np1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled stream control unit %d",
|
|
|
|
streamList_[i]->sendUnit());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qDebug("numBursts = %g, numPackets = %g\n", numBursts, numPackets);
|
|
|
|
|
|
|
|
qDebug("ibg = %g", ibg);
|
2018-05-20 03:03:38 -05:00
|
|
|
qDebug("ibg1 = %llu", _ibg1);
|
|
|
|
qDebug("nb1 = %llu", _nb1);
|
|
|
|
qDebug("ibg2 = %llu", _ibg2);
|
|
|
|
qDebug("nb2 = %llu\n", _nb2);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
qDebug("ipg = %g", ipg);
|
2018-05-20 03:03:38 -05:00
|
|
|
qDebug("ipg1 = %llu", _ipg1);
|
|
|
|
qDebug("np1 = %llu", _np1);
|
|
|
|
qDebug("ipg2 = %llu", _ipg2);
|
|
|
|
qDebug("np2 = %llu\n", _np2);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
|
|
|
|
if (_ibg2 && (_ibg2 < minGap))
|
|
|
|
minGap = _ibg2;
|
|
|
|
|
|
|
|
if (_ibg1 && (_ibg1 > duration))
|
|
|
|
duration = _ibg1;
|
|
|
|
|
|
|
|
ibg1.append(_ibg1);
|
|
|
|
ibg2.append(_ibg2);
|
|
|
|
|
|
|
|
nb1.append(_nb1);
|
|
|
|
nb2.append(_nb1);
|
|
|
|
|
|
|
|
burstSize.append(_burstSize);
|
|
|
|
|
|
|
|
if (_ipg2 && (_ipg2 < minGap))
|
|
|
|
minGap = _ipg2;
|
|
|
|
|
|
|
|
if (_np1)
|
|
|
|
{
|
|
|
|
if (_ipg1 && (_ipg1 > duration))
|
|
|
|
duration = _ipg1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_ipg2 && (_ipg2 > duration))
|
|
|
|
duration = _ipg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipg1.append(_ipg1);
|
|
|
|
ipg2.append(_ipg2);
|
|
|
|
|
|
|
|
np1.append(_np1);
|
|
|
|
np2.append(_np1);
|
|
|
|
|
|
|
|
schedSec.append(0);
|
|
|
|
schedNsec.append(0);
|
|
|
|
|
|
|
|
pktCount.append(0);
|
|
|
|
burstCount.append(0);
|
|
|
|
|
|
|
|
if (streamList_[i]->isFrameVariable())
|
|
|
|
{
|
|
|
|
isVariable.append(true);
|
|
|
|
pktBuf.append(QByteArray());
|
|
|
|
pktLen.append(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-05 07:01:43 -06:00
|
|
|
FrameValueAttrib attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
isVariable.append(false);
|
|
|
|
pktBuf.append(QByteArray());
|
|
|
|
pktBuf.last().resize(kMaxPktSize);
|
|
|
|
pktLen.append(streamList_[i]->frameValue(
|
2019-02-05 07:01:43 -06:00
|
|
|
(uchar*)pktBuf.last().data(), pktBuf.last().size(),
|
|
|
|
0, &attrib));
|
|
|
|
packetListAttrib += attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2023-04-21 08:02:17 -05:00
|
|
|
hasTtag.append(streamList_[i]->hasProtocol(
|
|
|
|
OstProto::Protocol::kSignFieldNumber));
|
2015-04-16 11:50:07 -05:00
|
|
|
numStreams++;
|
|
|
|
} // for i
|
|
|
|
|
2022-06-09 03:05:05 -05:00
|
|
|
// handle burst/packet rate = 0
|
|
|
|
// i.e. send all streams "simultaneously" as fast as possible
|
|
|
|
// as a result all streams will be at the same rate e.g. for 2 streams,
|
|
|
|
// it would 50% each; for 3 streams - all at 33.3% and so on
|
2022-06-09 04:41:55 -05:00
|
|
|
if (minGap == ULLONG_MAX) {
|
2022-06-09 03:05:05 -05:00
|
|
|
minGap = 1;
|
|
|
|
duration = 1;
|
|
|
|
}
|
|
|
|
|
2018-05-20 03:03:38 -05:00
|
|
|
qDebug("minGap = %llu", minGap);
|
|
|
|
qDebug("duration = %llu", duration);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
if (duration < minGap*100) {
|
|
|
|
duration = minGap*100;
|
|
|
|
qDebug("increase duration to %llu for better accuracy", duration);
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
uchar* buf;
|
|
|
|
int len;
|
2023-04-17 01:29:00 -05:00
|
|
|
const quint64 durSec = duration/ulong(1e9);
|
|
|
|
const quint64 durNsec = duration % ulong(1e9);
|
2015-04-16 11:50:07 -05:00
|
|
|
quint64 sec = 0;
|
|
|
|
quint64 nsec = 0;
|
|
|
|
quint64 lastPktTxSec = 0;
|
|
|
|
quint64 lastPktTxNsec = 0;
|
2023-04-17 01:29:00 -05:00
|
|
|
|
|
|
|
// Count total packets we are going to add, so that we can create
|
|
|
|
// an explicit packet set first
|
|
|
|
// TODO: Find less expensive way to do this counting
|
|
|
|
// FIXME: Turbo still thinks it has to create implicit packet set for
|
|
|
|
// interleaved mode - Turbo code should be changed once this is validated
|
2023-04-24 06:35:40 -05:00
|
|
|
quint64 totalPkts = 0;
|
2023-04-21 08:02:17 -05:00
|
|
|
QSet<int> ttagMarkerStreams;
|
|
|
|
QList<uint> ttagMarkers;
|
2023-04-17 01:29:00 -05:00
|
|
|
do
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numStreams; i++)
|
|
|
|
{
|
|
|
|
// If a packet is not scheduled yet, look at the next stream
|
|
|
|
if ((schedSec.at(i) > sec) || (schedNsec.at(i) > nsec))
|
|
|
|
continue;
|
|
|
|
|
2023-04-21 08:02:17 -05:00
|
|
|
// One marker per stream
|
2023-04-24 06:35:40 -05:00
|
|
|
// TODO: We should have a marker every 5s per stream if
|
|
|
|
// the pktList is > 5s
|
2023-04-21 08:02:17 -05:00
|
|
|
if (hasTtag.at(i) && !ttagMarkerStreams.contains(i)) {
|
|
|
|
ttagMarkerStreams.insert(i);
|
|
|
|
ttagMarkers.append(totalPkts);
|
|
|
|
}
|
|
|
|
|
2023-04-17 01:29:00 -05:00
|
|
|
for (uint j = 0; j < burstSize[i]; j++)
|
|
|
|
{
|
|
|
|
pktCount[i]++;
|
|
|
|
schedNsec[i] += (pktCount.at(i) < np1.at(i)) ?
|
|
|
|
ipg1.at(i) : ipg2.at(i);
|
|
|
|
while (schedNsec.at(i) >= 1e9)
|
|
|
|
{
|
|
|
|
schedSec[i]++;
|
|
|
|
schedNsec[i] -= long(1e9);
|
|
|
|
}
|
|
|
|
lastPktTxSec = sec;
|
|
|
|
lastPktTxNsec = nsec;
|
|
|
|
totalPkts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
burstCount[i]++;
|
|
|
|
schedNsec[i] += (burstCount.at(i) < nb1.at(i)) ?
|
|
|
|
ibg1.at(i) : ibg2.at(i);
|
|
|
|
while (schedNsec.at(i) >= 1e9)
|
|
|
|
{
|
|
|
|
schedSec[i]++;
|
|
|
|
schedNsec[i] -= long(1e9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsec += minGap;
|
|
|
|
while (nsec >= 1e9)
|
|
|
|
{
|
|
|
|
sec++;
|
|
|
|
nsec -= long(1e9);
|
|
|
|
}
|
2023-04-21 06:41:43 -05:00
|
|
|
} while ((sec < durSec) || ((sec == durSec) && (nsec < durNsec)));
|
2023-04-17 01:29:00 -05:00
|
|
|
|
|
|
|
// XXX: Ideally, for interleaved mode, we have a single packet set and
|
|
|
|
// the set's delay should be 0.
|
|
|
|
// However, Ttag and Turbo both use the set delay field to derive
|
|
|
|
// the set's avg pps (needed for their own functionality), so we set the
|
|
|
|
// avgDelay here instead of 0.
|
|
|
|
long avgDelay = (lastPktTxSec*long(1e9) + lastPktTxNsec
|
|
|
|
+ (durSec - lastPktTxSec)*long(1e9)
|
|
|
|
+ (durNsec - lastPktTxNsec))
|
|
|
|
/totalPkts;
|
|
|
|
loopNextPacketSet(totalPkts, 1, 0, avgDelay);
|
2023-04-21 08:02:17 -05:00
|
|
|
qDebug("Interleaved PacketSet of size %lld, duration %llu.%09llu "
|
|
|
|
"repeat 1 and avg delay %ldns",
|
|
|
|
totalPkts, durSec, durNsec, avgDelay);
|
2023-04-17 01:29:00 -05:00
|
|
|
|
|
|
|
// Reset working sched/counts before building the packet list
|
|
|
|
sec = nsec = 0;
|
|
|
|
lastPktTxSec = lastPktTxNsec = 0;
|
|
|
|
for (int i = 0; i < numStreams; i++)
|
|
|
|
{
|
|
|
|
schedSec[i] = 0;
|
|
|
|
schedNsec[i] = 0;
|
|
|
|
pktCount[i] = 0;
|
|
|
|
burstCount[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now build the packet list
|
2015-04-16 11:50:07 -05:00
|
|
|
do
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numStreams; i++)
|
|
|
|
{
|
|
|
|
// If a packet is not scheduled yet, look at the next stream
|
|
|
|
if ((schedSec.at(i) > sec) || (schedNsec.at(i) > nsec))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (uint j = 0; j < burstSize[i]; j++)
|
|
|
|
{
|
|
|
|
if (isVariable.at(i))
|
|
|
|
{
|
2019-02-05 07:01:43 -06:00
|
|
|
FrameValueAttrib attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
buf = pktBuf_;
|
2020-11-13 10:18:36 -06:00
|
|
|
len = streamList_[streamId.at(i)]->frameValue(pktBuf_, sizeof(pktBuf_),
|
2019-02-05 07:01:43 -06:00
|
|
|
pktCount[i], &attrib);
|
|
|
|
packetListAttrib += attrib;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf = (uchar*) pktBuf.at(i).data();
|
|
|
|
len = pktLen.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
continue;
|
|
|
|
|
2023-04-21 08:02:17 -05:00
|
|
|
qDebug("q(%d) TS = %llu.%09llu", i, sec, nsec);
|
2021-02-20 09:10:37 -06:00
|
|
|
if (!appendToPacketList(sec, nsec, buf, len)) {
|
|
|
|
clearPacketList(); // don't leave it half baked/inconsitent
|
|
|
|
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
|
|
|
|
goto _out_of_memory;
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
lastPktTxSec = sec;
|
|
|
|
lastPktTxNsec = nsec;
|
|
|
|
|
|
|
|
pktCount[i]++;
|
|
|
|
schedNsec[i] += (pktCount.at(i) < np1.at(i)) ?
|
|
|
|
ipg1.at(i) : ipg2.at(i);
|
|
|
|
while (schedNsec.at(i) >= 1e9)
|
|
|
|
{
|
|
|
|
schedSec[i]++;
|
|
|
|
schedNsec[i] -= long(1e9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
burstCount[i]++;
|
|
|
|
schedNsec[i] += (burstCount.at(i) < nb1.at(i)) ?
|
|
|
|
ibg1.at(i) : ibg2.at(i);
|
|
|
|
while (schedNsec.at(i) >= 1e9)
|
|
|
|
{
|
|
|
|
schedSec[i]++;
|
|
|
|
schedNsec[i] -= long(1e9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsec += minGap;
|
|
|
|
while (nsec >= 1e9)
|
|
|
|
{
|
|
|
|
sec++;
|
|
|
|
nsec -= long(1e9);
|
|
|
|
}
|
2023-04-21 06:41:43 -05:00
|
|
|
} while ((sec < durSec) || ((sec == durSec) && (nsec < durNsec)));
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
{
|
2021-02-20 09:10:37 -06:00
|
|
|
qint64 delaySec = durSec - lastPktTxSec;
|
|
|
|
qint64 delayNsec = durNsec - lastPktTxNsec;
|
|
|
|
while (delayNsec < 0)
|
|
|
|
{
|
|
|
|
delayNsec += long(1e9);
|
|
|
|
delaySec--;
|
|
|
|
}
|
2023-04-21 08:02:17 -05:00
|
|
|
qDebug("loop Delay = %lld.%09lld", delaySec, delayNsec);
|
2021-02-20 09:10:37 -06:00
|
|
|
setPacketListLoopMode(true, delaySec, delayNsec);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
2021-02-20 09:10:37 -06:00
|
|
|
|
2023-04-21 08:02:17 -05:00
|
|
|
// XXX: TTag repeat interval calculation:
|
|
|
|
// CASE 1. pktListDuration < kTtagTimeInterval:
|
|
|
|
// e.g. if pktListDuration is 1sec and TtagTimerInterval is 5s, we
|
|
|
|
// skip 5 times total packets before we repeat the markers
|
|
|
|
// CASE 2. pktListDuration > kTtagTimeInterval:
|
|
|
|
// e.g. if pktListDuration is 7sec and TtagTimerInterval is 5s, we
|
|
|
|
// skip repeat markers every pktList iteration
|
|
|
|
setPacketListTtagMarkers(ttagMarkers, ttagMarkers.isEmpty() ? 0 :
|
|
|
|
qMax(uint(kTtagTimeInterval_*1e9
|
|
|
|
/(durSec*1e9+durNsec)),
|
|
|
|
1U) * totalPkts);
|
|
|
|
|
2021-02-20 09:10:37 -06:00
|
|
|
_out_of_memory:
|
2015-04-16 11:50:07 -05:00
|
|
|
isSendQueueDirty_ = false;
|
2019-02-05 07:01:43 -06:00
|
|
|
|
2019-02-09 05:46:31 -06:00
|
|
|
qDebug("PacketListAttrib = %x",
|
|
|
|
static_cast<int>(packetListAttrib.errorFlags));
|
|
|
|
return static_cast<int>(packetListAttrib.errorFlags);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
void AbstractPort::stats(PortStats *stats)
|
|
|
|
{
|
|
|
|
stats->rxPkts = (stats_.rxPkts >= epochStats_.rxPkts) ?
|
|
|
|
stats_.rxPkts - epochStats_.rxPkts :
|
|
|
|
stats_.rxPkts + (maxStatsValue_ - epochStats_.rxPkts);
|
|
|
|
stats->rxBytes = (stats_.rxBytes >= epochStats_.rxBytes) ?
|
|
|
|
stats_.rxBytes - epochStats_.rxBytes :
|
|
|
|
stats_.rxBytes + (maxStatsValue_ - epochStats_.rxBytes);
|
|
|
|
stats->rxPps = stats_.rxPps;
|
|
|
|
stats->rxBps = stats_.rxBps;
|
|
|
|
|
|
|
|
stats->txPkts = (stats_.txPkts >= epochStats_.txPkts) ?
|
|
|
|
stats_.txPkts - epochStats_.txPkts :
|
|
|
|
stats_.txPkts + (maxStatsValue_ - epochStats_.txPkts);
|
|
|
|
stats->txBytes = (stats_.txBytes >= epochStats_.txBytes) ?
|
|
|
|
stats_.txBytes - epochStats_.txBytes :
|
|
|
|
stats_.txBytes + (maxStatsValue_ - epochStats_.txBytes);
|
|
|
|
stats->txPps = stats_.txPps;
|
|
|
|
stats->txBps = stats_.txBps;
|
|
|
|
|
|
|
|
stats->rxDrops = (stats_.rxDrops >= epochStats_.rxDrops) ?
|
|
|
|
stats_.rxDrops - epochStats_.rxDrops :
|
|
|
|
stats_.rxDrops + (maxStatsValue_ - epochStats_.rxDrops);
|
|
|
|
stats->rxErrors = (stats_.rxErrors >= epochStats_.rxErrors) ?
|
|
|
|
stats_.rxErrors - epochStats_.rxErrors :
|
|
|
|
stats_.rxErrors + (maxStatsValue_ - epochStats_.rxErrors);
|
|
|
|
stats->rxFifoErrors = (stats_.rxFifoErrors >= epochStats_.rxFifoErrors) ?
|
|
|
|
stats_.rxFifoErrors - epochStats_.rxFifoErrors :
|
|
|
|
stats_.rxFifoErrors + (maxStatsValue_ - epochStats_.rxFifoErrors);
|
|
|
|
stats->rxFrameErrors = (stats_.rxFrameErrors >= epochStats_.rxFrameErrors) ?
|
|
|
|
stats_.rxFrameErrors - epochStats_.rxFrameErrors :
|
|
|
|
stats_.rxFrameErrors + (maxStatsValue_ - epochStats_.rxFrameErrors);
|
|
|
|
}
|
|
|
|
|
2023-03-31 06:25:03 -05:00
|
|
|
quint64 AbstractPort::streamTimingDelay(uint guid)
|
|
|
|
{
|
|
|
|
return streamTiming_->delay(id(), guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::clearStreamTiming(uint guid)
|
|
|
|
{
|
|
|
|
streamTiming_->clear(id(), guid);
|
|
|
|
}
|
|
|
|
|
2016-11-10 06:48:27 -06:00
|
|
|
void AbstractPort::streamStats(uint guid, OstProto::StreamStatsList *stats)
|
|
|
|
{
|
2021-02-20 09:10:37 -06:00
|
|
|
// In case stats are being maintained elsewhere
|
|
|
|
updateStreamStats();
|
|
|
|
|
2016-11-10 06:48:27 -06:00
|
|
|
if (streamStats_.contains(guid))
|
|
|
|
{
|
|
|
|
StreamStatsTuple sst = streamStats_.value(guid);
|
|
|
|
OstProto::StreamStats *s = stats->add_stream_stats();
|
|
|
|
|
|
|
|
s->mutable_stream_guid()->set_id(guid);
|
|
|
|
s->mutable_port_id()->set_id(id());
|
|
|
|
|
2022-02-21 10:50:59 -06:00
|
|
|
s->set_tx_duration(lastTransmitDuration());
|
2023-04-04 08:04:20 -05:00
|
|
|
s->set_latency(streamTimingDelay(guid));
|
2022-02-21 10:50:59 -06:00
|
|
|
|
2016-11-10 06:48:27 -06:00
|
|
|
s->set_tx_pkts(sst.tx_pkts);
|
|
|
|
s->set_tx_bytes(sst.tx_bytes);
|
|
|
|
s->set_rx_pkts(sst.rx_pkts);
|
|
|
|
s->set_rx_bytes(sst.rx_bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::streamStatsAll(OstProto::StreamStatsList *stats)
|
|
|
|
{
|
2021-02-20 09:10:37 -06:00
|
|
|
// In case stats are being maintained elsewhere
|
|
|
|
updateStreamStats();
|
|
|
|
|
2016-11-10 06:48:27 -06:00
|
|
|
// FIXME: change input param to a non-OstProto type and/or have
|
|
|
|
// a getFirst/Next like API?
|
2022-02-21 10:50:59 -06:00
|
|
|
double txDur = lastTransmitDuration();
|
2016-11-11 09:52:07 -06:00
|
|
|
StreamStatsIterator i(streamStats_);
|
2016-11-10 06:48:27 -06:00
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
i.next();
|
|
|
|
StreamStatsTuple sst = i.value();
|
|
|
|
OstProto::StreamStats *s = stats->add_stream_stats();
|
|
|
|
|
|
|
|
s->mutable_stream_guid()->set_id(i.key());
|
|
|
|
s->mutable_port_id()->set_id(id());
|
|
|
|
|
2022-02-21 10:50:59 -06:00
|
|
|
s->set_tx_duration(txDur);
|
2023-04-04 08:04:20 -05:00
|
|
|
s->set_latency(streamTimingDelay(i.key()));
|
2022-02-21 10:50:59 -06:00
|
|
|
|
2016-11-10 06:48:27 -06:00
|
|
|
s->set_tx_pkts(sst.tx_pkts);
|
|
|
|
s->set_tx_bytes(sst.tx_bytes);
|
|
|
|
s->set_rx_pkts(sst.rx_pkts);
|
|
|
|
s->set_rx_bytes(sst.rx_bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::resetStreamStats(uint guid)
|
|
|
|
{
|
|
|
|
streamStats_.remove(guid);
|
2023-03-31 06:25:03 -05:00
|
|
|
clearStreamTiming(guid);
|
2016-11-10 06:48:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::resetStreamStatsAll()
|
|
|
|
{
|
|
|
|
streamStats_.clear();
|
2023-03-31 06:25:03 -05:00
|
|
|
clearStreamTiming();
|
2016-11-10 06:48:27 -06:00
|
|
|
}
|
|
|
|
|
2015-11-04 07:20:08 -06:00
|
|
|
void AbstractPort::clearDeviceNeighbors()
|
|
|
|
{
|
|
|
|
deviceManager_->clearDeviceNeighbors();
|
2015-11-10 08:10:32 -06:00
|
|
|
isSendQueueDirty_ = true;
|
2015-11-04 07:20:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractPort::resolveDeviceNeighbors()
|
|
|
|
{
|
2016-03-17 09:42:13 -05:00
|
|
|
// For a user triggered 'Resolve Neighbors', the behaviour we want is
|
|
|
|
// IP not in cache - send ARP/NDP request
|
|
|
|
// IP present in cache, but unresolved - re-send ARP/NDP request
|
|
|
|
// IP present in cache and resolved - don't sent ARP/NDP
|
|
|
|
//
|
|
|
|
// Device does not resend ARP/NDP requests if the IP address is
|
|
|
|
// already present in the cache, irrespective of whether it is
|
|
|
|
// resolved or not (this is done to avoid sending duplicate requests).
|
|
|
|
//
|
|
|
|
// So, to get the behaviour we want, let's clear all unresolved neighbors
|
|
|
|
// before calling resolve
|
|
|
|
deviceManager_->clearDeviceNeighbors(Device::kUnresolvedNeighbors);
|
|
|
|
|
2016-01-28 08:31:19 -06:00
|
|
|
// Resolve gateway for each device first ...
|
|
|
|
deviceManager_->resolveDeviceGateways();
|
|
|
|
|
|
|
|
// ... then resolve neighbor for each unique frame of each stream
|
2015-11-04 07:20:08 -06:00
|
|
|
// NOTE:
|
|
|
|
// 1. All the frames may have the same destination ip,but may have
|
|
|
|
// different source ip so may belong to a different emulated device;
|
|
|
|
// so we cannot optimize and send only one ARP
|
|
|
|
// 2. For a unidirectional stream, at egress, this will create ARP
|
|
|
|
// entries on the DUT for each of the source addresses
|
|
|
|
//
|
|
|
|
// TODO(optimization): Identify if stream does not vary in srcIp or dstIp
|
|
|
|
// - in which case resolve for only one frame of the stream
|
|
|
|
for (int i = 0; i < streamList_.size(); i++)
|
|
|
|
{
|
|
|
|
const StreamBase *stream = streamList_.at(i);
|
|
|
|
int frameCount = stream->frameVariableCount();
|
|
|
|
|
|
|
|
for (int j = 0; j < frameCount; j++) {
|
2015-11-10 08:10:32 -06:00
|
|
|
// we need the packet contents only uptil the L3 header
|
|
|
|
int pktLen = stream->frameValue(pktBuf_, kMaxL3PktSize, j);
|
2015-11-04 07:20:08 -06:00
|
|
|
if (pktLen) {
|
|
|
|
PacketBuffer pktBuf(pktBuf_, pktLen);
|
|
|
|
deviceManager_->resolveDeviceNeighbor(&pktBuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 08:10:32 -06:00
|
|
|
isSendQueueDirty_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 AbstractPort::deviceMacAddress(int streamId, int frameIndex)
|
|
|
|
{
|
|
|
|
// we need the packet contents only uptil the L3 header
|
|
|
|
StreamBase *s = stream(streamId);
|
|
|
|
int pktLen = s->frameValue(pktBuf_, kMaxL3PktSize, frameIndex);
|
|
|
|
|
|
|
|
if (pktLen) {
|
|
|
|
PacketBuffer pktBuf(pktBuf_, pktLen);
|
|
|
|
return deviceManager_->deviceMacAddress(&pktBuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-11-04 07:20:08 -06:00
|
|
|
}
|
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
quint64 AbstractPort::neighborMacAddress(int streamId, int frameIndex)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2015-11-10 08:10:32 -06:00
|
|
|
// we need the packet contents only uptil the L3 header
|
|
|
|
StreamBase *s = stream(streamId);
|
|
|
|
int pktLen = s->frameValue(pktBuf_, kMaxL3PktSize, frameIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
if (pktLen) {
|
|
|
|
PacketBuffer pktBuf(pktBuf_, pktLen);
|
|
|
|
return deviceManager_->neighborMacAddress(&pktBuf);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
return 0;
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
2018-07-26 10:23:33 -05:00
|
|
|
|
|
|
|
const InterfaceInfo* AbstractPort::interfaceInfo() const
|
|
|
|
{
|
|
|
|
return interfaceInfo_;
|
|
|
|
}
|