2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 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 _PORT_H
|
|
|
|
#define _PORT_H
|
|
|
|
|
|
|
|
#include <QDir>
|
2016-03-12 07:26:35 -06:00
|
|
|
#include <QHash>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QList>
|
2016-03-16 10:21:36 -05:00
|
|
|
#include <QSet>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QString>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
//class StreamModel;
|
2016-03-11 07:28:08 -06:00
|
|
|
namespace OstEmul {
|
|
|
|
class Device;
|
2016-03-12 07:26:35 -06:00
|
|
|
class DeviceNeighborList;
|
2016-03-11 07:28:08 -06:00
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
class Port : public QObject {
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
static uint mAllocStreamId;
|
2016-02-22 07:17:51 -06:00
|
|
|
static uint allocDeviceGroupId_;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
OstProto::Port d;
|
|
|
|
OstProto::PortStats stats;
|
|
|
|
QTemporaryFile *capFile_;
|
|
|
|
|
|
|
|
// FIXME(HI): consider removing mPortId as it is duplicated inside 'd'
|
|
|
|
quint32 mPortId;
|
|
|
|
quint32 mPortGroupId;
|
|
|
|
QString mUserAlias; // user defined
|
2017-09-14 10:08:13 -05:00
|
|
|
bool dirty_;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
double avgPacketsPerSec_;
|
|
|
|
double avgBitsPerSec_;
|
|
|
|
int numActiveStreams_;
|
|
|
|
|
|
|
|
QList<quint32> mLastSyncStreamList;
|
|
|
|
QList<Stream*> mStreams; // sorted by stream's ordinal value
|
|
|
|
|
2016-03-16 10:21:36 -05:00
|
|
|
QList<quint32> lastSyncDeviceGroupList_;
|
|
|
|
QSet<quint32> modifiedDeviceGroupList_;
|
2016-02-22 07:17:51 -06:00
|
|
|
QList<OstProto::DeviceGroup*> deviceGroups_;
|
2016-03-11 07:28:08 -06:00
|
|
|
QList<OstEmul::Device*> devices_;
|
2016-03-12 07:26:35 -06:00
|
|
|
QHash<quint32, OstEmul::DeviceNeighborList*> deviceNeighbors_;
|
|
|
|
QHash<quint32, quint32> arpResolvedCount_;
|
|
|
|
QHash<quint32, quint32> ndpResolvedCount_;
|
2016-02-05 07:36:14 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
uint newStreamId();
|
|
|
|
void updateStreamOrdinalsFromIndex();
|
|
|
|
void reorderStreamsByOrdinals();
|
|
|
|
|
2017-09-14 10:08:13 -05:00
|
|
|
void setDirty(bool dirty);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum AdminStatus { AdminDisable, AdminEnable };
|
|
|
|
|
|
|
|
// FIXME(HIGH): default args is a hack for QList operations on Port
|
|
|
|
Port(quint32 id = 0xFFFFFFFF, quint32 pgId = 0xFFFFFFFF);
|
|
|
|
~Port();
|
|
|
|
|
|
|
|
quint32 portGroupId() const { return mPortGroupId; }
|
2016-05-18 08:07:48 -05:00
|
|
|
const QString userAlias() const
|
|
|
|
{ return mUserAlias.isEmpty() ? name() : mUserAlias; }
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
quint32 id() const
|
|
|
|
{ return d.port_id().id(); }
|
|
|
|
const QString name() const
|
|
|
|
{ return QString().fromStdString(d.name()); }
|
2022-09-02 06:45:46 -05:00
|
|
|
const QString systemDescription() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return QString().fromStdString(d.description()); }
|
2022-09-02 06:45:46 -05:00
|
|
|
const QString userDescription() const
|
|
|
|
{ return QString().fromStdString(d.user_description()); }
|
|
|
|
const QString description() const
|
|
|
|
{
|
|
|
|
return userDescription().isEmpty() ?
|
|
|
|
systemDescription() : userDescription();
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
const QString notes() const
|
|
|
|
{ return QString().fromStdString(d.notes()); }
|
|
|
|
const QString userName() const
|
|
|
|
{ return QString().fromStdString(d.user_name()); }
|
2017-09-16 02:00:00 -05:00
|
|
|
AdminStatus adminStatus() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return (d.is_enabled()?AdminEnable:AdminDisable); }
|
2017-09-16 02:00:00 -05:00
|
|
|
bool hasExclusiveControl() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return d.is_exclusive_control(); }
|
2017-09-16 02:00:00 -05:00
|
|
|
OstProto::TransmitMode transmitMode() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return d.transmit_mode(); }
|
2017-12-03 01:29:26 -06:00
|
|
|
bool trackStreamStats() const
|
2017-12-02 23:56:09 -06:00
|
|
|
{ return d.is_tracking_stream_stats(); }
|
2021-11-07 07:35:11 -06:00
|
|
|
double speed() const
|
|
|
|
{ return d.speed(); }
|
|
|
|
double averageLoadRate() const
|
|
|
|
{ return d.speed() ? avgBitsPerSec_/(d.speed()*1e6) : 0; }
|
2017-09-16 02:00:00 -05:00
|
|
|
double averagePacketRate() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return avgPacketsPerSec_; }
|
2017-09-16 02:00:00 -05:00
|
|
|
double averageBitRate() const
|
2015-04-16 11:50:07 -05:00
|
|
|
{ return avgBitsPerSec_; }
|
|
|
|
|
|
|
|
//void setAdminEnable(AdminStatus status) { mAdminStatus = status; }
|
2016-05-18 08:07:48 -05:00
|
|
|
void setAlias(QString alias) { mUserAlias = alias; }
|
2015-04-16 11:50:07 -05:00
|
|
|
//void setExclusive(bool flag);
|
|
|
|
|
|
|
|
int numStreams() { return mStreams.size(); }
|
2017-09-14 10:08:13 -05:00
|
|
|
const Stream* streamByIndex(int index) const
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
Q_ASSERT(index < mStreams.size());
|
|
|
|
return mStreams[index];
|
|
|
|
}
|
2017-09-17 02:48:44 -05:00
|
|
|
Stream* mutableStreamByIndex(int index, bool assumeChange = true)
|
2017-09-14 10:08:13 -05:00
|
|
|
{
|
|
|
|
Q_ASSERT(index < mStreams.size());
|
2017-09-17 02:48:44 -05:00
|
|
|
if (assumeChange)
|
|
|
|
setDirty(true);
|
2017-09-14 10:08:13 -05:00
|
|
|
return mStreams[index];
|
|
|
|
}
|
2017-09-17 02:48:44 -05:00
|
|
|
void setLocalConfigChanged(bool changed)
|
|
|
|
{
|
|
|
|
setDirty(changed);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
OstProto::LinkState linkState()
|
|
|
|
{ return stats.state().link_state(); }
|
2018-12-03 09:44:05 -06:00
|
|
|
bool isTransmitting()
|
|
|
|
{ return stats.state().is_transmit_on(); }
|
|
|
|
bool isCapturing()
|
|
|
|
{ return stats.state().is_capture_on(); }
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
OstProto::PortStats getStats() { return stats; }
|
|
|
|
QTemporaryFile* getCaptureFile()
|
|
|
|
{
|
|
|
|
delete capFile_;
|
|
|
|
capFile_ = new QTemporaryFile(QString(QDir::tempPath())
|
|
|
|
.append("/")
|
2016-06-26 01:01:40 -05:00
|
|
|
.append(userAlias())
|
2015-04-16 11:50:07 -05:00
|
|
|
.append(".XXXXXX"));
|
|
|
|
return capFile_;
|
|
|
|
}
|
|
|
|
|
2016-04-15 08:33:52 -05:00
|
|
|
void protoDataCopyInto(OstProto::Port *data);
|
|
|
|
|
2017-09-14 10:08:13 -05:00
|
|
|
//! Used when config received from server
|
2015-04-16 11:50:07 -05:00
|
|
|
// FIXME(MED): naming inconsistency - PortConfig/Stream; also retVal
|
|
|
|
void updatePortConfig(OstProto::Port *port);
|
|
|
|
|
|
|
|
//! Used by StreamModel
|
|
|
|
//@{
|
|
|
|
bool newStreamAt(int index, OstProto::Stream const *stream = NULL);
|
|
|
|
bool deleteStreamAt(int index);
|
|
|
|
//@}
|
|
|
|
|
|
|
|
//! Used by MyService::Stub to update from config received from server
|
|
|
|
//@{
|
|
|
|
bool insertStream(uint streamId);
|
|
|
|
bool updateStream(uint streamId, OstProto::Stream *stream);
|
|
|
|
//@}
|
|
|
|
|
2017-09-14 10:08:13 -05:00
|
|
|
bool isDirty() { return dirty_; }
|
2015-04-16 11:50:07 -05:00
|
|
|
void getDeletedStreamsSinceLastSync(OstProto::StreamIdList &streamIdList);
|
|
|
|
void getNewStreamsSinceLastSync(OstProto::StreamIdList &streamIdList);
|
|
|
|
void getModifiedStreamsSinceLastSync(
|
|
|
|
OstProto::StreamConfigList &streamConfigList);
|
|
|
|
|
2016-03-04 16:36:36 -06:00
|
|
|
void getDeletedDeviceGroupsSinceLastSync(
|
|
|
|
OstProto::DeviceGroupIdList &streamIdList);
|
|
|
|
void getNewDeviceGroupsSinceLastSync(
|
|
|
|
OstProto::DeviceGroupIdList &streamIdList);
|
|
|
|
void getModifiedDeviceGroupsSinceLastSync(
|
|
|
|
OstProto::DeviceGroupConfigList &streamConfigList);
|
|
|
|
|
2016-05-14 09:19:07 -05:00
|
|
|
bool modifiablePortConfig(OstProto::Port &config) const;
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void when_syncComplete();
|
|
|
|
|
|
|
|
void setAveragePacketRate(double packetsPerSec);
|
|
|
|
void setAverageBitRate(double bitsPerSec);
|
2021-11-07 07:35:11 -06:00
|
|
|
void setAverageLoadRate(double loadPercent);
|
2015-04-16 11:50:07 -05:00
|
|
|
// FIXME(MED): Bad Hack! port should not need an external trigger to
|
|
|
|
// recalculate - refactor client side domain objects and model objects
|
|
|
|
void recalculateAverageRates();
|
|
|
|
void updateStats(OstProto::PortStats *portStats);
|
|
|
|
|
|
|
|
void duplicateStreams(const QList<int> &list, int count);
|
|
|
|
|
|
|
|
bool openStreams(QString fileName, bool append, QString &error);
|
|
|
|
bool saveStreams(QString fileName, QString fileType, QString &error);
|
|
|
|
|
2016-02-05 07:36:14 -06:00
|
|
|
// ------------ Device Group ----------- //
|
|
|
|
|
2016-02-22 07:17:51 -06:00
|
|
|
uint newDeviceGroupId();
|
2016-03-16 10:21:36 -05:00
|
|
|
int numDeviceGroups() const;
|
|
|
|
const OstProto::DeviceGroup* deviceGroupByIndex(int index) const;
|
|
|
|
OstProto::DeviceGroup* mutableDeviceGroupByIndex(int index);
|
2017-09-14 10:08:13 -05:00
|
|
|
const OstProto::DeviceGroup* deviceGroupById(uint deviceGroupId) const;
|
2016-02-22 07:17:51 -06:00
|
|
|
|
|
|
|
//! Used by StreamModel
|
|
|
|
//@{
|
|
|
|
bool newDeviceGroupAt(int index,
|
|
|
|
const OstProto::DeviceGroup *deviceGroup = NULL);
|
|
|
|
bool deleteDeviceGroupAt(int index);
|
|
|
|
//@}
|
2016-02-05 07:36:14 -06:00
|
|
|
|
|
|
|
//! Used by MyService::Stub to update from config received from server
|
|
|
|
//@{
|
|
|
|
bool insertDeviceGroup(uint deviceGroupId);
|
|
|
|
bool updateDeviceGroup(uint deviceGroupId,
|
|
|
|
OstProto::DeviceGroup *deviceGroup);
|
|
|
|
//@}
|
|
|
|
|
2016-03-11 07:28:08 -06:00
|
|
|
// ------------ Device ----------- //
|
|
|
|
|
|
|
|
int numDevices();
|
|
|
|
const OstEmul::Device* deviceByIndex(int index);
|
|
|
|
|
|
|
|
//! Used by MyService::Stub to update from config received from server
|
|
|
|
void clearDeviceList();
|
|
|
|
void insertDevice(const OstEmul::Device &device);
|
2016-03-12 07:26:35 -06:00
|
|
|
|
|
|
|
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();
|
2016-03-11 07:28:08 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
signals:
|
2017-09-14 10:08:13 -05:00
|
|
|
//! Used when local config changed and when config received from server
|
2015-04-16 11:50:07 -05:00
|
|
|
void portRateChanged(int portGroupId, int portId);
|
2017-09-14 10:08:13 -05:00
|
|
|
|
|
|
|
//! Used by MyService::Stub to update from config received from server
|
|
|
|
//@{
|
2015-04-16 11:50:07 -05:00
|
|
|
void portDataChanged(int portGroupId, int portId);
|
2016-03-12 07:26:35 -06:00
|
|
|
void deviceInfoChanged();
|
2017-09-14 10:08:13 -05:00
|
|
|
//@}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2017-09-14 10:08:13 -05:00
|
|
|
//! Used when local config changed
|
|
|
|
//@{
|
|
|
|
void streamListChanged(int portGroupId, int portId);
|
2017-09-16 01:42:43 -05:00
|
|
|
void localConfigChanged(int portGroupId, int portId, bool changed);
|
2017-09-14 10:08:13 -05:00
|
|
|
//@}
|
2015-04-16 11:50:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|