diff --git a/server/devicemanager.cpp b/server/devicemanager.cpp
index 6e140f2..013fe7e 100644
--- a/server/devicemanager.cpp
+++ b/server/devicemanager.cpp
@@ -26,7 +26,6 @@ along with this program. If not, see
#include "../common/emulproto.pb.h"
-#include
#include
#define __STDC_FORMAT_MACROS
@@ -162,16 +161,7 @@ int DeviceManager::deviceCount()
void DeviceManager::getDeviceList(
OstProto::PortDeviceList *deviceList)
{
- // We want to return a sorted deviceList. However, deviceList_
- // 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 list;
- foreach(Device *device, deviceList_) {
- list.insert(device->key(), device);
- }
-
- foreach(Device *device, list) {
+ foreach(Device *device, sortedDeviceList_) {
OstEmul::Device *dev =
deviceList->AddExtension(OstEmul::port_device);
device->getConfig(dev);
@@ -279,7 +269,7 @@ void DeviceManager::getDeviceNeighbors(
{
int count = 0;
- foreach(Device *device, deviceList_) {
+ foreach(Device *device, sortedDeviceList_) {
OstEmul::DeviceNeighborList *neighList =
neighborList->AddExtension(OstEmul::devices);
neighList->set_device_index(count++);
@@ -476,6 +466,7 @@ void DeviceManager::enumerateDevices(
device = new Device(this);
*device = dk;
deviceList_.insert(dk.key(), device);
+ sortedDeviceList_.insert(dk.key(), device);
dk.setMac(kBcastMac);
bcastList_.insert(dk.key(), device);
@@ -491,6 +482,7 @@ void DeviceManager::enumerateDevices(
}
qDebug("enumerate(del): %s", qPrintable(device->config()));
delete device;
+ sortedDeviceList_.take(dk.key()); // already freed above
dk.setMac(kBcastMac);
bcastList_.take(dk.key()); // device already freed above
diff --git a/server/devicemanager.h b/server/devicemanager.h
index 2a9adf5..9d472e6 100644
--- a/server/devicemanager.h
+++ b/server/devicemanager.h
@@ -23,6 +23,7 @@ along with this program. If not, see
#include "device.h"
#include
+#include
#include
#include
@@ -71,7 +72,8 @@ private:
AbstractPort *port_;
QHash deviceGroupList_;
- QHash deviceList_;
+ QHash deviceList_; // fast access to devices
+ QMap sortedDeviceList_; // sorted access to devices
QMultiHash bcastList_;
QHash tpidList_; // Key: TPID, Value: RefCount
};
diff --git a/test/emultest.py b/test/emultest.py
index c54730f..2760edd 100644
--- a/test/emultest.py
+++ b/test/emultest.py
@@ -1166,6 +1166,12 @@ def test_multiEmulDevPerVlan(request, drone, ports, dut, dut_ports,
assert cap_pkts.count('\n') == 1
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
pytest.main(__file__)