Device Emulation (contd.): Implemented display of NDP Cache Device Detail; also fixed missing clear of NDP cache on server
This commit is contained in:
parent
853802b997
commit
7561b09c1e
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "devicemodel.h"
|
||||
|
||||
#include "arpstatusmodel.h"
|
||||
#include "ndpstatusmodel.h"
|
||||
#include "port.h"
|
||||
|
||||
#include "emulproto.pb.h"
|
||||
@ -57,6 +58,7 @@ DeviceModel::DeviceModel(QObject *parent)
|
||||
{
|
||||
port_ = NULL;
|
||||
arpStatusModel_ = new ArpStatusModel(this);
|
||||
ndpStatusModel_ = new NdpStatusModel(this);
|
||||
}
|
||||
|
||||
int DeviceModel::rowCount(const QModelIndex &parent) const
|
||||
@ -236,7 +238,6 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
qWarning("%s: Unsupported field #%d", __FUNCTION__, field);
|
||||
|
||||
_exit:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@ -258,6 +259,8 @@ QAbstractItemModel* DeviceModel::detailModel(const QModelIndex &index)
|
||||
arpStatusModel_->setDeviceIndex(port_, index.row());
|
||||
return arpStatusModel_;
|
||||
case kNdpInfo:
|
||||
ndpStatusModel_->setDeviceIndex(port_, index.row());
|
||||
return ndpStatusModel_;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class ArpStatusModel;
|
||||
class NdpStatusModel;
|
||||
class Port;
|
||||
|
||||
class DeviceModel: public QAbstractTableModel
|
||||
@ -49,6 +50,7 @@ private:
|
||||
|
||||
Port *port_;
|
||||
ArpStatusModel *arpStatusModel_;
|
||||
NdpStatusModel *ndpStatusModel_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
155
client/ndpstatusmodel.cpp
Normal file
155
client/ndpstatusmodel.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
Copyright (C) 2016 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 "ndpstatusmodel.h"
|
||||
|
||||
#include "port.h"
|
||||
|
||||
#include "emulproto.pb.h"
|
||||
|
||||
#include "uint128.h"
|
||||
#include <QHostAddress>
|
||||
|
||||
enum {
|
||||
kIp4Address,
|
||||
kMacAddress,
|
||||
kStatus,
|
||||
kFieldCount
|
||||
};
|
||||
|
||||
static QStringList columns_ = QStringList()
|
||||
<< "IPv6 Address"
|
||||
<< "Mac Address"
|
||||
<< "Status";
|
||||
|
||||
NdpStatusModel::NdpStatusModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
port_ = NULL;
|
||||
deviceIndex_ = -1;
|
||||
neighbors_ = NULL;
|
||||
}
|
||||
|
||||
int NdpStatusModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (!port_ || deviceIndex_ < 0 || parent.isValid())
|
||||
return 0;
|
||||
|
||||
return port_->numNdp(deviceIndex_);
|
||||
}
|
||||
|
||||
int NdpStatusModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return columns_.size();
|
||||
}
|
||||
|
||||
QVariant NdpStatusModel::headerData(
|
||||
int section,
|
||||
Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
switch (orientation) {
|
||||
case Qt::Horizontal:
|
||||
return columns_[section];
|
||||
case Qt::Vertical:
|
||||
return QString("%1").arg(section + 1);
|
||||
default:
|
||||
Q_ASSERT(false); // Unreachable
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant NdpStatusModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QString str;
|
||||
|
||||
if (!port_ || deviceIndex_ < 0 || !index.isValid())
|
||||
return QVariant();
|
||||
|
||||
int ndpIdx = index.row();
|
||||
int field = index.column();
|
||||
|
||||
Q_ASSERT(ndpIdx < port_->numNdp(deviceIndex_));
|
||||
Q_ASSERT(field < kFieldCount);
|
||||
|
||||
const OstEmul::NdpEntry &ndp = neighbors_->ndp(ndpIdx);
|
||||
|
||||
switch (field) {
|
||||
case kIp4Address:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return QHostAddress(
|
||||
UInt128(ndp.ip6().hi(),
|
||||
ndp.ip6().lo()).toArray())
|
||||
.toString();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
case kMacAddress:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return QString("%1").arg(ndp.mac(), 6*2, 16, QChar('0'))
|
||||
.replace(QRegExp("([0-9a-fA-F]{2}\\B)"), "\\1:")
|
||||
.toUpper();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
case kStatus:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return ndp.mac() ?
|
||||
QString("Resolved") : QString("Failed");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QVariant();
|
||||
|
||||
default:
|
||||
Q_ASSERT(false); // unreachable!
|
||||
break;
|
||||
}
|
||||
|
||||
qWarning("%s: Unsupported field #%d", __FUNCTION__, field);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void NdpStatusModel::setDeviceIndex(Port *port, int deviceIndex)
|
||||
{
|
||||
port_ = port;
|
||||
deviceIndex_ = deviceIndex;
|
||||
if (port_)
|
||||
neighbors_ = port_->deviceNeighbors(deviceIndex);
|
||||
reset();
|
||||
}
|
||||
|
||||
void NdpStatusModel::updateNdpStatus()
|
||||
{
|
||||
reset();
|
||||
}
|
55
client/ndpstatusmodel.h
Normal file
55
client/ndpstatusmodel.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (C) 2016 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/>
|
||||
*/
|
||||
|
||||
#ifndef _NDP_STATUS_MODEL_H
|
||||
#define _NDP_STATUS_MODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class Port;
|
||||
namespace OstEmul {
|
||||
class DeviceNeighborList;
|
||||
}
|
||||
|
||||
class NdpStatusModel: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NdpStatusModel(QObject *parent = 0);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
|
||||
void setDeviceIndex(Port *port, int deviceIndex);
|
||||
|
||||
public slots:
|
||||
void updateNdpStatus();
|
||||
|
||||
private:
|
||||
Port *port_;
|
||||
int deviceIndex_;
|
||||
const OstEmul::DeviceNeighborList *neighbors_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -41,6 +41,7 @@ HEADERS += \
|
||||
dumpview.h \
|
||||
hexlineedit.h \
|
||||
mainwindow.h \
|
||||
ndpstatusmodel.h \
|
||||
packetmodel.h \
|
||||
port.h \
|
||||
portconfigdialog.h \
|
||||
@ -84,6 +85,7 @@ SOURCES += \
|
||||
hexlineedit.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
ndpstatusmodel.cpp \
|
||||
packetmodel.cpp \
|
||||
port.cpp \
|
||||
portconfigdialog.cpp \
|
||||
|
@ -268,6 +268,7 @@ void Device::resolveGateway()
|
||||
void Device::clearNeighbors()
|
||||
{
|
||||
arpTable_.clear();
|
||||
ndpTable_.clear();
|
||||
}
|
||||
|
||||
// Resolve the Neighbor IP address for this to-be-transmitted pktBuf
|
||||
|
Loading…
Reference in New Issue
Block a user