Device Emulation (contd.): Fixed bug where DeviceNeighborList.device_index did not match the correct device in PortDeviceList
This commit is contained in:
parent
26ceb2f9df
commit
259dafa3e9
@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "../common/emulproto.pb.h"
|
#include "../common/emulproto.pb.h"
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
|
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
@ -162,16 +161,7 @@ int DeviceManager::deviceCount()
|
|||||||
void DeviceManager::getDeviceList(
|
void DeviceManager::getDeviceList(
|
||||||
OstProto::PortDeviceList *deviceList)
|
OstProto::PortDeviceList *deviceList)
|
||||||
{
|
{
|
||||||
// We want to return a sorted deviceList. However, deviceList_
|
foreach(Device *device, sortedDeviceList_) {
|
||||||
// is a QHash (unsorted) instead of a QMap (sorted) because
|
|
||||||
// QHash is faster. So here we use a temporary QMap to sort the
|
|
||||||
// list that will be returned
|
|
||||||
QMap<DeviceKey, Device*> list;
|
|
||||||
foreach(Device *device, deviceList_) {
|
|
||||||
list.insert(device->key(), device);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(Device *device, list) {
|
|
||||||
OstEmul::Device *dev =
|
OstEmul::Device *dev =
|
||||||
deviceList->AddExtension(OstEmul::port_device);
|
deviceList->AddExtension(OstEmul::port_device);
|
||||||
device->getConfig(dev);
|
device->getConfig(dev);
|
||||||
@ -279,7 +269,7 @@ void DeviceManager::getDeviceNeighbors(
|
|||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
foreach(Device *device, deviceList_) {
|
foreach(Device *device, sortedDeviceList_) {
|
||||||
OstEmul::DeviceNeighborList *neighList =
|
OstEmul::DeviceNeighborList *neighList =
|
||||||
neighborList->AddExtension(OstEmul::devices);
|
neighborList->AddExtension(OstEmul::devices);
|
||||||
neighList->set_device_index(count++);
|
neighList->set_device_index(count++);
|
||||||
@ -476,6 +466,7 @@ void DeviceManager::enumerateDevices(
|
|||||||
device = new Device(this);
|
device = new Device(this);
|
||||||
*device = dk;
|
*device = dk;
|
||||||
deviceList_.insert(dk.key(), device);
|
deviceList_.insert(dk.key(), device);
|
||||||
|
sortedDeviceList_.insert(dk.key(), device);
|
||||||
|
|
||||||
dk.setMac(kBcastMac);
|
dk.setMac(kBcastMac);
|
||||||
bcastList_.insert(dk.key(), device);
|
bcastList_.insert(dk.key(), device);
|
||||||
@ -491,6 +482,7 @@ void DeviceManager::enumerateDevices(
|
|||||||
}
|
}
|
||||||
qDebug("enumerate(del): %s", qPrintable(device->config()));
|
qDebug("enumerate(del): %s", qPrintable(device->config()));
|
||||||
delete device;
|
delete device;
|
||||||
|
sortedDeviceList_.take(dk.key()); // already freed above
|
||||||
|
|
||||||
dk.setMac(kBcastMac);
|
dk.setMac(kBcastMac);
|
||||||
bcastList_.take(dk.key()); // device already freed above
|
bcastList_.take(dk.key()); // device already freed above
|
||||||
|
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QMap>
|
||||||
#include <QMultiHash>
|
#include <QMultiHash>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
@ -71,7 +72,8 @@ private:
|
|||||||
|
|
||||||
AbstractPort *port_;
|
AbstractPort *port_;
|
||||||
QHash<uint, OstProto::DeviceGroup*> deviceGroupList_;
|
QHash<uint, OstProto::DeviceGroup*> deviceGroupList_;
|
||||||
QHash<DeviceKey, Device*> deviceList_;
|
QHash<DeviceKey, Device*> deviceList_; // fast access to devices
|
||||||
|
QMap<DeviceKey, Device*> sortedDeviceList_; // sorted access to devices
|
||||||
QMultiHash<DeviceKey, Device*> bcastList_;
|
QMultiHash<DeviceKey, Device*> bcastList_;
|
||||||
QHash<quint16, uint> tpidList_; // Key: TPID, Value: RefCount
|
QHash<quint16, uint> tpidList_; // Key: TPID, Value: RefCount
|
||||||
};
|
};
|
||||||
|
@ -1166,6 +1166,12 @@ def test_multiEmulDevPerVlan(request, drone, ports, dut, dut_ports,
|
|||||||
assert cap_pkts.count('\n') == 1
|
assert cap_pkts.count('\n') == 1
|
||||||
os.remove('capture.pcap')
|
os.remove('capture.pcap')
|
||||||
|
|
||||||
|
#
|
||||||
|
# TODO
|
||||||
|
# * Verify that device_index in OstEmul.DeviceNeighborList matches the
|
||||||
|
# correct device in OstEmul.PortDeviceList
|
||||||
|
# * Verify ARP/NDP resolution in a bridging topology
|
||||||
|
#
|
||||||
import pytest
|
import pytest
|
||||||
pytest.main(__file__)
|
pytest.main(__file__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user