Device Emulation (contd.): GUI now fetches ARP/NDP also from server and display summary counts - resolved/total

This commit is contained in:
Srivats P 2016-03-12 18:56:35 +05:30
parent 7c87e2130a
commit 941d522451
6 changed files with 173 additions and 10 deletions

View File

@ -33,6 +33,8 @@ enum {
kIp4Gateway,
kIp6Address,
kIp6Gateway,
kArpInfo,
kNdpInfo,
kFieldCount
};
@ -42,7 +44,9 @@ static QStringList columns_ = QStringList()
<< "IPv4 Address"
<< "IPv4 Gateway"
<< "IPv6 Address"
<< "IPv6 Gateway";
<< "IPv6 Gateway"
<< "ARP"
<< "NDP";
DeviceModel::DeviceModel(QObject *parent)
: QAbstractTableModel(parent)
@ -188,6 +192,28 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const
}
return QVariant();
case kArpInfo:
switch (role) {
case Qt::DisplayRole:
return QString("%1/%2")
.arg(port_->numArpResolved(devIdx))
.arg(port_->numArp(devIdx));
default:
break;
}
return QVariant();
case kNdpInfo:
switch (role) {
case Qt::DisplayRole:
return QString("%1/%2")
.arg(port_->numNdpResolved(devIdx))
.arg(port_->numNdp(devIdx));
default:
break;
}
return QVariant();
default:
Q_ASSERT(false); // unreachable!
break;
@ -201,7 +227,7 @@ void DeviceModel::setPort(Port *port)
{
port_ = port;
if (port_)
connect(port_, SIGNAL(deviceListChanged()), SLOT(updateDeviceList()));
connect(port_, SIGNAL(deviceInfoChanged()), SLOT(updateDeviceList()));
reset();
}

View File

@ -797,8 +797,81 @@ void Port::insertDevice(const OstEmul::Device &device)
devices_.append(dev);
}
void Port::deviceListRefreshed()
// ------------- Device Neighbors (ARP/NDP) ------------- //
const OstEmul::DeviceNeighborList* Port::deviceNeighbors(int deviceIndex)
{
emit deviceListChanged();
if ((deviceIndex < 0) || (deviceIndex >= numDevices())) {
qWarning("%s: index %d out of range (0 - %d)", __FUNCTION__,
deviceIndex, numDevices() - 1);
return NULL;
}
return deviceNeighbors_.value(deviceIndex);
}
int Port::numArp(int deviceIndex)
{
if (deviceNeighbors_.contains(deviceIndex))
return deviceNeighbors_.value(deviceIndex)->arp_size();
return 0;
}
int Port::numArpResolved(int deviceIndex)
{
if (arpResolvedCount_.contains(deviceIndex))
return arpResolvedCount_.value(deviceIndex);
return 0;
}
int Port::numNdp(int deviceIndex)
{
if (deviceNeighbors_.contains(deviceIndex))
return deviceNeighbors_.value(deviceIndex)->ndp_size();
return 0;
}
int Port::numNdpResolved(int deviceIndex)
{
if (ndpResolvedCount_.contains(deviceIndex))
return ndpResolvedCount_.value(deviceIndex);
return 0;
}
void Port::clearDeviceNeighbors()
{
arpResolvedCount_.clear();
ndpResolvedCount_.clear();
qDeleteAll(deviceNeighbors_);
deviceNeighbors_.clear();
}
void Port::insertDeviceNeighbors(const OstEmul::DeviceNeighborList &neighList)
{
int count;
OstEmul::DeviceNeighborList *neighbors =
new OstEmul::DeviceNeighborList(neighList);
deviceNeighbors_.insert(neighList.device_index(), neighbors);
count = 0;
for (int i = 0; i < neighbors->arp_size(); i++)
if (neighbors->arp(i).mac())
count++;
arpResolvedCount_.insert(neighbors->device_index(), count);
count = 0;
for (int i = 0; i < neighbors->ndp_size(); i++)
if (neighbors->ndp(i).mac())
count++;
ndpResolvedCount_.insert(neighbors->device_index(), count);
}
void Port::deviceInfoRefreshed()
{
emit deviceInfoChanged();
}

View File

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#define _PORT_H
#include <QDir>
#include <QHash>
#include <QList>
#include <QString>
#include <QTemporaryFile>
@ -30,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
//class StreamModel;
namespace OstEmul {
class Device;
class DeviceNeighborList;
}
class Port : public QObject {
@ -58,6 +60,9 @@ class Port : public QObject {
QList<quint32> lastSyncDeviceGroupList_;
QList<OstProto::DeviceGroup*> deviceGroups_;
QList<OstEmul::Device*> devices_;
QHash<quint32, OstEmul::DeviceNeighborList*> deviceNeighbors_;
QHash<quint32, quint32> arpResolvedCount_;
QHash<quint32, quint32> ndpResolvedCount_;
uint newStreamId();
void updateStreamOrdinalsFromIndex();
@ -189,13 +194,24 @@ public:
//! Used by MyService::Stub to update from config received from server
void clearDeviceList();
void insertDevice(const OstEmul::Device &device);
void deviceListRefreshed();
const OstEmul::DeviceNeighborList* deviceNeighbors(int deviceIndex);
int numArp(int deviceIndex);
int numArpResolved(int deviceIndex);
int numNdp(int deviceIndex);
int numNdpResolved(int deviceIndex);
//! Used by MyService::Stub to update from config received from server
void clearDeviceNeighbors();
void insertDeviceNeighbors(const OstEmul::DeviceNeighborList &neighList);
void deviceInfoRefreshed();
signals:
void portRateChanged(int portGroupId, int portId);
void portDataChanged(int portGroupId, int portId);
void streamListChanged(int portGroupId, int portId);
void deviceListChanged();
void deviceInfoChanged();
};

View File

@ -522,10 +522,11 @@ void PortGroup::processModifyStreamAck(int portIndex,
delete controller;
}
void PortGroup::getDeviceList(int portIndex)
void PortGroup::getDeviceInfo(int portIndex)
{
OstProto::PortId *portId;
OstProto::PortDeviceList *deviceList;
OstProto::PortNeighborList *neighList;
PbRpcController *controller;
Q_ASSERT(portIndex < mPorts.size());
@ -541,6 +542,15 @@ void PortGroup::getDeviceList(int portIndex)
serviceStub->getDeviceList(controller, portId, deviceList,
NewCallback(this, &PortGroup::processDeviceList,
portIndex, controller));
portId = new OstProto::PortId;
portId->set_id(mPorts[portIndex]->id());
neighList = new OstProto::PortNeighborList;
controller = new PbRpcController(portId, neighList);
serviceStub->getDeviceNeighbors(controller, portId, neighList,
NewCallback(this, &PortGroup::processDeviceNeighbors,
portIndex, controller));
}
void PortGroup::processDeviceList(int portIndex, PbRpcController *controller)
@ -571,7 +581,42 @@ void PortGroup::processDeviceList(int portIndex, PbRpcController *controller)
mPorts[portIndex]->insertDevice(
deviceList->GetExtension(OstEmul::port_device, i));
}
mPorts[portIndex]->deviceListRefreshed();
_exit:
delete controller;
}
void PortGroup::processDeviceNeighbors(
int portIndex, PbRpcController *controller)
{
OstProto::PortNeighborList *neighList
= static_cast<OstProto::PortNeighborList*>(controller->response());
qDebug("In %s (portIndex = %d)", __FUNCTION__, portIndex);
if (controller->Failed())
{
qDebug("%s: rpc failed(%s)", __FUNCTION__,
qPrintable(controller->ErrorString()));
goto _exit;
}
Q_ASSERT(portIndex < numPorts());
if (neighList->port_id().id() != mPorts[portIndex]->id())
{
qDebug("Invalid portId %d (expected %d) received for portIndex %d",
neighList->port_id().id(), mPorts[portIndex]->id(), portIndex);
goto _exit;
}
mPorts[portIndex]->clearDeviceNeighbors();
for(int i = 0; i < neighList->ExtensionSize(OstEmul::devices); i++) {
mPorts[portIndex]->insertDeviceNeighbors(
neighList->GetExtension(OstEmul::devices, i)); // FIXME: change extn id
}
mPorts[portIndex]->deviceInfoRefreshed();
_exit:
delete controller;

View File

@ -111,6 +111,7 @@ public:
void processModifyDeviceGroupAck(int portIndex, PbRpcController *controller);
void processDeviceList(int portIndex, PbRpcController *controller);
void processDeviceNeighbors(int portIndex, PbRpcController *controller);
void modifyPort(int portId, OstProto::Port portConfig);
void processModifyPortAck(PbRpcController *controller);
@ -172,7 +173,7 @@ private slots:
public slots:
void when_configApply(int portIndex);
void getDeviceList(int portIndex);
void getDeviceInfo(int portIndex);
};

View File

@ -166,6 +166,8 @@ PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
// FIXME: hardcoding
deviceList->resizeColumnToContents(1); // Vlan Id(s)
deviceList->resizeColumnToContents(6); // ARP Info
deviceList->resizeColumnToContents(7); // NDP Info
// Initially we don't have any ports/streams/devices
// - so send signal triggers
@ -973,5 +975,5 @@ void PortsWindow::on_refresh_clicked()
Q_ASSERT(curPortGroup.isValid());
Q_ASSERT(plm->isPortGroup(curPortGroup));
plm->portGroup(curPortGroup).getDeviceList(plm->port(curPort).id());
plm->portGroup(curPortGroup).getDeviceInfo(plm->port(curPort).id());
}