Device Emulation (contd.) - StreamBase::frameValue() now returns truncated packet content and length instead of bailing out if the passed in buffer size is less than the packet length. This is useful for some of the device emulation code which needs packet content only uptil the IP header but not beyond, so we don't need to unnecessarily create the entire packet with payload for these cases
This commit is contained in:
parent
07dd945f50
commit
f1ff9e2616
@ -525,16 +525,18 @@ int StreamBase::frameCount() const
|
||||
return count;
|
||||
}
|
||||
|
||||
// Returns packet length - if bufMaxSize < frameLen(), returns truncated
|
||||
// length i.e. bufMaxSize
|
||||
int StreamBase::frameValue(uchar *buf, int bufMaxSize, int frameIndex) const
|
||||
{
|
||||
int pktLen, len = 0;
|
||||
int size, pktLen, len = 0;
|
||||
|
||||
pktLen = frameLen(frameIndex);
|
||||
|
||||
// pktLen is adjusted for CRC/FCS which will be added by the NIC
|
||||
pktLen -= kFcsSize;
|
||||
|
||||
if ((pktLen < 0) || (pktLen > bufMaxSize))
|
||||
if (pktLen <= 0)
|
||||
return 0;
|
||||
|
||||
ProtocolListIterator *iter;
|
||||
@ -548,17 +550,23 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int frameIndex) const
|
||||
proto = iter->next();
|
||||
ba = proto->protocolFrameValue(frameIndex);
|
||||
|
||||
if (len + ba.size() < bufMaxSize)
|
||||
memcpy(buf+len, ba.constData(), ba.size());
|
||||
len += ba.size();
|
||||
size = qMin(ba.size(), bufMaxSize-len);
|
||||
memcpy(buf+len, ba.constData(), size);
|
||||
len += size;
|
||||
|
||||
if (len == bufMaxSize)
|
||||
break;
|
||||
}
|
||||
delete iter;
|
||||
|
||||
// Pad with zero, if required
|
||||
if (len < pktLen)
|
||||
memset(buf+len, 0, pktLen-len);
|
||||
// Pad with zero, if required and if we have space
|
||||
if ((len < pktLen) && (len < bufMaxSize)) {
|
||||
size = qMin(pktLen-len, bufMaxSize-len);
|
||||
memset(buf+len, 0, size);
|
||||
len += size;
|
||||
}
|
||||
|
||||
return pktLen;
|
||||
return len;
|
||||
}
|
||||
|
||||
quint64 StreamBase::deviceMacAddress(int frameIndex) const
|
||||
|
@ -447,7 +447,7 @@ def test_multiEmulDevNoVlan(drone, ports, dut, dut_ports, dut_ip,
|
||||
s = stream_cfg.stream.add()
|
||||
s.stream_id.id = stream_id.stream_id[i].id
|
||||
s.core.is_enabled = True
|
||||
s.core.frame_len = 80 # FIXME: change to 128
|
||||
s.core.frame_len = 1024
|
||||
s.control.packets_per_sec = 100
|
||||
s.control.num_packets = 10
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user