- StreamModel no longer a friend of Stream

- PacketModel refactored by moving protocol specific stuff into Stream and xxxProtocol classes
This commit is contained in:
Srivats P. 2008-08-24 04:39:08 +00:00
parent f220482876
commit c7f4c1dec9
25 changed files with 2528 additions and 887 deletions

View File

@ -3,3 +3,12 @@ all:
$(MAKE) -C common $(MAKE) -C common
$(MAKE) -C server $(MAKE) -C server
$(MAKE) -C client $(MAKE) -C client
clean:
$(MAKE) -C rpc $@
$(MAKE) -C common $@
$(MAKE) -C server $@
$(MAKE) -C client $@
qmake:
for %%d in (rpc common server client) cd %%d; qmake; cd..;

View File

@ -4,8 +4,11 @@
PacketModel::PacketModel(Stream *pStream, QObject *parent) PacketModel::PacketModel(Stream *pStream, QObject *parent)
{ {
mpStream = pStream; mpStream = pStream;
#ifdef NEW_IMPL
// Nothing else
#else
populatePacketProtocols(); populatePacketProtocols();
#if 1
registerFrameTypeProto(); registerFrameTypeProto();
registerVlanProto(); registerVlanProto();
registerIpProto(); registerIpProto();
@ -23,17 +26,25 @@ int PacketModel::rowCount(const QModelIndex &parent) const
{ {
IndexId parentId; IndexId parentId;
// Parent - Invalid i.e. Invisible Root. // Parent == Invalid i.e. Invisible Root.
// Children - Protocol (Top Level) Items // ==> Children are Protocol (Top Level) Items
if (!parent.isValid()) if (!parent.isValid())
#ifdef NEW_IMPL
return mpStream->numProtocols();
#else
return protoCount(); return protoCount();
#endif
// Parent - Valid Item // Parent - Valid Item
parentId.w = parent.internalId(); parentId.w = parent.internalId();
switch(parentId.ws.type) switch(parentId.ws.type)
{ {
case ITYP_PROTOCOL: case ITYP_PROTOCOL:
#ifdef NEW_IMPL
return mpStream->protocol(parentId.ws.protocol)->numFields();
#else
return fieldCount(parentId.ws.protocol); return fieldCount(parentId.ws.protocol);
#endif
case ITYP_FIELD: case ITYP_FIELD:
return 0; return 0;
default: default:
@ -126,7 +137,11 @@ _exit:
QVariant PacketModel::data(const QModelIndex &index, int role) const QVariant PacketModel::data(const QModelIndex &index, int role) const
{ {
IndexId id; IndexId id;
#ifdef NEW_IMPL
// Nothing
#else
ProtocolInfo proto; ProtocolInfo proto;
#endif
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
@ -138,12 +153,24 @@ QVariant PacketModel::data(const QModelIndex &index, int role) const
switch(id.ws.type) switch(id.ws.type)
{ {
case ITYP_PROTOCOL: case ITYP_PROTOCOL:
#ifdef NEW_IMPL
return QString("%1 (%2)")
.arg(mpStream->protocol(id.ws.protocol)->protocolShortName())
.arg(mpStream->protocol(id.ws.protocol)->protocolName());
#else
return protoName(id.ws.protocol); return protoName(id.ws.protocol);
#endif
case ITYP_FIELD: case ITYP_FIELD:
#ifdef NEW_IMPL
return mpStream->protocol(id.ws.protocol)->fieldName(index.row()) +
QString(" : ") +
mpStream->protocol(id.ws.protocol)->fieldTextValue(index.row());
#else
return fieldName(id.ws.protocol, index.row()) + return fieldName(id.ws.protocol, index.row()) +
QString(" : ") + QString(" : ") +
fieldTextValue(id.ws.protocol, index.row()).toString(); fieldTextValue(id.ws.protocol, index.row()).toString();
#endif
default: default:
qWarning("%s: Unhandled ItemType", __FUNCTION__); qWarning("%s: Unhandled ItemType", __FUNCTION__);
@ -154,12 +181,29 @@ QVariant PacketModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
#ifdef NEW_IMPL
// required methods all part of the Stream class
#else
/* /*
** --------------- Private Stuff ----------------- ** --------------- Private Stuff -----------------
** FIXME(MED): Move these to the Stream Class ** FIXME(MED): Move these to the Stream Class
** **
*/ */
/*!
Looking at the stream's protocols and populate an ordered list of
protocols accordingly. The order of protocols will be in the order of
protocol headers viz.
- None/Eth2/802.3 (Mac Addr)
- LLC
- SNAP
- SVLAN
- CVLAN
- L3 (IP/ARP)
- L4 (TCP/UDP/ICMP/IGMP)
*/
void PacketModel::populatePacketProtocols() void PacketModel::populatePacketProtocols()
{ {
int proto; int proto;
@ -167,9 +211,8 @@ void PacketModel::populatePacketProtocols()
// Clear the protocols list // Clear the protocols list
mPacketProtocols.clear(); mPacketProtocols.clear();
#if 0 // FIXME: protobuf
// Check and populate L2 Protocol // Check and populate L2 Protocol
switch(mpStream->proto.ft) switch(mpStream->frameType())
{ {
case Stream::e_ft_none: case Stream::e_ft_none:
proto = PTYP_L2_NONE; proto = PTYP_L2_NONE;
@ -195,71 +238,80 @@ void PacketModel::populatePacketProtocols()
break; break;
default: default:
qDebug("%s: Unsupported frametype", __FUNCTION__); qDebug("%s: Unsupported frametype %d", __FUNCTION__,
mpStream->frameType());
proto = PTYP_INVALID; proto = PTYP_INVALID;
} }
mPacketProtocols.append(proto); mPacketProtocols.append(proto);
// Check and populate VLANs, if present // Check and populate VLANs, if present
if (mpStream->l2.eth.vlanMask & VM_SVLAN_TAGGED) if (mpStream->vlan()->vlanFlags().testFlag(VlanProtocol::VlanSvlanTagged))
mPacketProtocols.append(PTYP_SVLAN); mPacketProtocols.append(PTYP_SVLAN);
if (mpStream->l2.eth.vlanMask & VM_CVLAN_TAGGED) if (mpStream->vlan()->vlanFlags().testFlag(VlanProtocol::VlanCvlanTagged))
mPacketProtocols.append(PTYP_CVLAN); mPacketProtocols.append(PTYP_CVLAN);
// Check and populate L3 protocols // Check and populate L3 protocols
if (mpStream->proto.protoMask & PM_L3_PROTO_NONE) switch (mpStream->l3Proto())
goto _data;
switch(mpStream->proto.etherType)
{ {
case ETH_TYP_IP: case Stream::e_l3_none :
goto _data;
break;
case Stream::e_l3_ip :
proto = PTYP_L3_IP; proto = PTYP_L3_IP;
break; break;
case ETH_TYP_ARP: case Stream::e_l3_arp:
proto = PTYP_L3_ARP; proto = PTYP_L3_ARP;
break; break;
default: default:
qDebug("%s: Unsupported ethtype", __FUNCTION__); qDebug("%s: Unsupported L3 Proto %d", __FUNCTION__,
mpStream->l3Proto());
proto = PTYP_INVALID; proto = PTYP_INVALID;
} }
mPacketProtocols.append(proto); mPacketProtocols.append(proto);
if (mpStream->proto.protoMask & PM_L4_PROTO_NONE) // Check and populate L4 protocol
goto _data; switch(mpStream->l4Proto())
switch(mpStream->proto.ipProto)
{ {
case IP_PROTO_TCP: case Stream::e_l4_none:
goto _data;
break;
case Stream::e_l4_tcp:
proto = PTYP_L4_TCP; proto = PTYP_L4_TCP;
break; break;
case IP_PROTO_UDP: case Stream::e_l4_udp:
proto = PTYP_L4_UDP; proto = PTYP_L4_UDP;
break; break;
case IP_PROTO_ICMP: case Stream::e_l4_icmp:
proto = PTYP_L4_ICMP; proto = PTYP_L4_ICMP;
break; break;
case IP_PROTO_IGMP: case Stream::e_l4_igmp:
proto = PTYP_L4_IGMP; proto = PTYP_L4_IGMP;
break; break;
default: default:
qDebug("%s: Unsupported ipProto", __FUNCTION__); qDebug("%s: Unsupported L4 Proto %d", __FUNCTION__,
mpStream->l4Proto());
proto = PTYP_INVALID; proto = PTYP_INVALID;
}; };
mPacketProtocols.append(proto); mPacketProtocols.append(proto);
_data: _data:
mPacketProtocols.append(PTYP_DATA); mPacketProtocols.append(PTYP_DATA);
#endif
} }
/*!
Returns the count of protocols in the current stream
*/
int PacketModel::protoCount() const int PacketModel::protoCount() const
{ {
return mPacketProtocols.count(); return mPacketProtocols.count();
} }
/*!
Returns the count of fields in the given protocol
*/
int PacketModel::fieldCount(int protocol) const int PacketModel::fieldCount(int protocol) const
{ {
ProtocolInfo proto; ProtocolInfo proto;
@ -375,25 +427,22 @@ QVariant PacketModel::ethField(int field, int role) const
FieldInfo info; FieldInfo info;
// FIXME(MED): Mac Addr formatting // FIXME(MED): Mac Addr formatting
#if 0 // FIXME protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("Destination Mac Address"); info.name = QString("Destination Mac Address");
info.textValue = QString("%1%2"). info.textValue = QString("%1").
arg(mpStream->l2.eth.dstMacMshw, 4, BASE_HEX, QChar('0')). arg(mpStream->mac()->dstMac(), 12, BASE_HEX, QChar('0'));
arg(mpStream->l2.eth.dstMacLsw, 8, BASE_HEX, QChar('0'));
break; break;
case 1: case 1:
info.name = QString("Source Mac Address"); info.name = QString("Source Mac Address");
info.textValue = QString("%1%2"). info.textValue = QString("%1").
arg(mpStream->l2.eth.srcMacMshw, 4, BASE_HEX, QChar('0')). arg(mpStream->mac()->srcMac(), 12, BASE_HEX, QChar('0'));
arg(mpStream->l2.eth.srcMacLsw, 8, BASE_HEX, QChar('0'));
break; break;
case 2: case 2:
info.name = QString("Type"); info.name = QString("Type");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->proto.etherType, 4, BASE_HEX, QChar('0')); arg(mpStream->eth2()->type(), 4, BASE_HEX, QChar('0'));
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -411,7 +460,6 @@ QVariant PacketModel::ethField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -419,23 +467,22 @@ QVariant PacketModel::llcField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME: protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("DSAP"); info.name = QString("DSAP");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->proto.dsap, 2, BASE_HEX, QChar('0')); arg(mpStream->llc()->dsap(), 2, BASE_HEX, QChar('0'));
break; break;
case 1: case 1:
info.name = QString("SSAP"); info.name = QString("SSAP");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->proto.ssap, 2, BASE_HEX, QChar('0')); arg(mpStream->llc()->ssap(), 2, BASE_HEX, QChar('0'));
break; break;
case 2: case 2:
info.name = QString("Control"); info.name = QString("Control");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->proto.ctl, 2, BASE_HEX, QChar('0')); arg(mpStream->llc()->ctl(), 2, BASE_HEX, QChar('0'));
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -453,7 +500,6 @@ QVariant PacketModel::llcField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -461,19 +507,17 @@ QVariant PacketModel::snapField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME: protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("OUI"); info.name = QString("OUI");
info.textValue = QString("0x%1%2"). info.textValue = QString("0x%1").
arg(mpStream->proto.ouiMsb, 2, BASE_HEX, QChar('0')). arg(mpStream->snap()->oui(), 6, BASE_HEX, QChar('0'));
arg(mpStream->proto.ouiLshw, 4, BASE_HEX, QChar('0'));
break; break;
case 1: case 1:
info.name = QString("Type"); info.name = QString("Type");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->proto.etherType, 4, BASE_HEX, QChar('0')); arg(mpStream->eth2()->type(), 4, BASE_HEX, QChar('0'));
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -491,7 +535,6 @@ QVariant PacketModel::snapField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -499,28 +542,27 @@ QVariant PacketModel::svlanField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME: protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("TPID"); info.name = QString("TPID");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l2.eth.stpid, 4, BASE_HEX, QChar('0')); arg(mpStream->vlan()->stpid(), 4, BASE_HEX, QChar('0'));
break; break;
case 1: case 1:
info.name = QString("PCP"); info.name = QString("PCP");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l2.eth.svlanPrio); arg(mpStream->vlan()->svlanPrio());
break; break;
case 2: case 2:
info.name = QString("DE"); info.name = QString("DE");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l2.eth.svlanCfi); arg(mpStream->vlan()->svlanCfi());
break; break;
case 3: case 3:
info.name = QString("VlanId"); info.name = QString("VlanId");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l2.eth.svlanId); arg(mpStream->vlan()->svlanId());
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -538,7 +580,6 @@ QVariant PacketModel::svlanField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -547,66 +588,65 @@ QVariant PacketModel::ipField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME: protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("Version"); info.name = QString("Version");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l3.ip.ver); arg(mpStream->ip()->ver());
break; break;
case 1: case 1:
info.name = QString("Header Length"); info.name = QString("Header Length");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l3.ip.hdrLen); arg(mpStream->ip()->hdrLen());
break; break;
case 2: case 2:
info.name = QString("TOS/DSCP"); info.name = QString("TOS/DSCP");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l3.ip.tos, 2, BASE_HEX, QChar('0')); arg(mpStream->ip()->tos(), 2, BASE_HEX, QChar('0'));
break; break;
case 3: case 3:
info.name = QString("Total Length"); info.name = QString("Total Length");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l3.ip.totLen); arg(mpStream->ip()->totLen());
break; break;
case 4: case 4:
info.name = QString("ID"); info.name = QString("ID");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l3.ip.id, 2, BASE_HEX, QChar('0')); arg(mpStream->ip()->id(), 2, BASE_HEX, QChar('0'));
break; break;
case 5: case 5:
info.name = QString("Flags"); info.name = QString("Flags");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l3.ip.flags, 2, BASE_HEX, QChar('0')); // FIXME(HIGH) arg(mpStream->ip()->flags(), 2, BASE_HEX, QChar('0')); // FIXME(HIGH)
break; break;
case 6: case 6:
info.name = QString("Fragment Offset"); info.name = QString("Fragment Offset");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l3.ip.fragOfs); arg(mpStream->ip()->fragOfs());
break; break;
case 7: case 7:
info.name = QString("TTL"); info.name = QString("TTL");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l3.ip.ttl); arg(mpStream->ip()->ttl());
break; break;
case 8: case 8:
info.name = QString("Protocol Type"); info.name = QString("Protocol Type");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l3.ip.proto, 2, BASE_HEX, QChar('0')); arg(mpStream->ip()->proto(), 2, BASE_HEX, QChar('0'));
break; break;
case 9: case 9:
info.name = QString("Checksum"); info.name = QString("Checksum");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l3.ip.cksum, 4, BASE_HEX, QChar('0')); arg(mpStream->ip()->cksum(), 4, BASE_HEX, QChar('0'));
break; break;
case 10: case 10:
info.name = QString("Source IP"); info.name = QString("Source IP");
info.textValue = QHostAddress(mpStream->l3.ip.srcIp).toString(); info.textValue = QHostAddress(mpStream->ip()->srcIp()).toString();
break; break;
case 11: case 11:
info.name = QString("Destination IP"); info.name = QString("Destination IP");
info.textValue = QHostAddress(mpStream->l3.ip.dstIp).toString(); info.textValue = QHostAddress(mpStream->ip()->dstIp()).toString();
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -624,7 +664,6 @@ QVariant PacketModel::ipField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -633,58 +672,57 @@ QVariant PacketModel::tcpField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME: protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("Source Port"); info.name = QString("Source Port");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.srcPort); arg(mpStream->tcp()->srcPort());
break; break;
case 1: case 1:
info.name = QString("Destination Port"); info.name = QString("Destination Port");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.dstPort); arg(mpStream->tcp()->dstPort());
break; break;
case 2: case 2:
info.name = QString("Seq Number"); info.name = QString("Seq Number");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.seqNum); arg(mpStream->tcp()->seqNum());
break; break;
case 3: case 3:
info.name = QString("Ack Number"); info.name = QString("Ack Number");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.ackNum); arg(mpStream->tcp()->ackNum());
break; break;
case 4: case 4:
info.name = QString("Header Length"); info.name = QString("Header Length");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.hdrLen); arg(mpStream->tcp()->hdrLen());
break; break;
case 5: case 5:
info.name = QString("Reserved"); info.name = QString("Reserved");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.rsvd); arg(mpStream->tcp()->rsvd());
break; break;
case 6: case 6:
info.name = QString("Flags"); info.name = QString("Flags");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l4.tcp.flags, 2, BASE_HEX, QChar('0')); arg(mpStream->tcp()->flags(), 2, BASE_HEX, QChar('0'));
break; break;
case 7: case 7:
info.name = QString("Window"); info.name = QString("Window");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.flags); arg(mpStream->tcp()->flags());
break; break;
case 8: case 8:
info.name = QString("Checksum"); info.name = QString("Checksum");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l4.tcp.cksum, 4, BASE_HEX, QChar('0')); arg(mpStream->tcp()->cksum(), 4, BASE_HEX, QChar('0'));
break; break;
case 9: case 9:
info.name = QString("Urgent Pointer"); info.name = QString("Urgent Pointer");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.tcp.urgPtr); arg(mpStream->tcp()->urgPtr());
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -702,7 +740,6 @@ QVariant PacketModel::tcpField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -711,28 +748,27 @@ QVariant PacketModel::udpField(int field, int role) const
{ {
FieldInfo info; FieldInfo info;
#if 0 // FIXME:protobuf
switch(field) switch(field)
{ {
case 0: case 0:
info.name = QString("Source Port"); info.name = QString("Source Port");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.udp.srcPort); arg(mpStream->udp()->srcPort());
break; break;
case 1: case 1:
info.name = QString("Destination Port"); info.name = QString("Destination Port");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.udp.dstPort); arg(mpStream->udp()->dstPort());
break; break;
case 2: case 2:
info.name = QString("Total Length"); info.name = QString("Total Length");
info.textValue = QString("%1"). info.textValue = QString("%1").
arg(mpStream->l4.udp.totLen); arg(mpStream->udp()->totLen());
break; break;
case 3: case 3:
info.name = QString("Checksum"); info.name = QString("Checksum");
info.textValue = QString("0x%1"). info.textValue = QString("0x%1").
arg(mpStream->l4.udp.cksum, 4, BASE_HEX, QChar('0')); arg(mpStream->udp()->cksum(), 4, BASE_HEX, QChar('0'));
break; break;
default: default:
info.name = QString(); info.name = QString();
@ -750,7 +786,6 @@ QVariant PacketModel::udpField(int field, int role) const
} }
Q_ASSERT(1 == 1); // Unreachable code Q_ASSERT(1 == 1); // Unreachable code
#endif
return QVariant(); return QVariant();
} }
@ -900,3 +935,4 @@ void PacketModel::registerData()
registerProto(PTYP_DATA, "Data", "data"); registerProto(PTYP_DATA, "Data", "data");
} }
#endif

View File

@ -4,6 +4,8 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include "stream.h" #include "stream.h"
#define NEW_IMPL // FIXME(HI) - Use this and remove old one
class PacketModel: public QAbstractItemModel class PacketModel: public QAbstractItemModel
{ {
@ -27,11 +29,15 @@ private:
quint16 type; quint16 type;
#define ITYP_PROTOCOL 1 #define ITYP_PROTOCOL 1
#define ITYP_FIELD 2 #define ITYP_FIELD 2
quint16 protocol; quint16 protocol; // protocol is valid for both ITYPs
} ws; } ws;
} IndexId; } IndexId;
Stream *mpStream; Stream *mpStream;
#ifdef NEW_IMPL
// Nothing - required stuff is part of Stream Class
#else
QList<uint> mPacketProtocols; QList<uint> mPacketProtocols;
typedef struct typedef struct
@ -49,6 +55,8 @@ private:
QList<FieldInfo> fieldList; QList<FieldInfo> fieldList;
} ProtocolInfo; } ProtocolInfo;
//! Contains registration info (name, size etc) for all protocols
// and fields within the protocol
QList<ProtocolInfo> mProtocols; QList<ProtocolInfo> mProtocols;
void registerProto(uint handle, char *name, char *abbr); void registerProto(uint handle, char *name, char *abbr);
void registerField(uint protoHandle, char *name, char *abbr); void registerField(uint protoHandle, char *name, char *abbr);
@ -102,6 +110,8 @@ private:
#define PTYP_INVALID 0 #define PTYP_INVALID 0
#define PTYP_DATA 0xFF #define PTYP_DATA 0xFF
#endif // NEW_IMPL
#define FROL_NAME 1 #define FROL_NAME 1
#define FROL_TEXT_VALUE 2 #define FROL_TEXT_VALUE 2

View File

@ -5,88 +5,177 @@
#include "port.h" #include "port.h"
#include "pbhelper.h" #include "pbhelper.h"
uint Port::mAllocStreamId = 0;
uint Port::newStreamId()
{
return mAllocStreamId++;
}
Port::Port(quint32 id, quint32 portGroupId) Port::Port(quint32 id, quint32 portGroupId)
{ {
d.set_port_id(id); mPortId = id;
d.mutable_port_id()->set_id(id);
mPortGroupId = portGroupId; mPortGroupId = portGroupId;
#if 0 // PB
// FIXME(HI): TEST only
for(int i = 0; i < 10; i++)
mPortStats[i] = mPortGroupId*10000+mPortId*100+i;
#endif
} }
void Port::updatePortConfig(OstProto::PortConfig *portConfig) void Port::updatePortConfig(OstProto::Port *port)
{ {
d.MergeFrom(*port);
}
PbHelper pbh; void Port::updateStreamOrdinalsFromIndex()
{
for (int i=0; i < mStreams.size(); i++)
mStreams[i].setOrdinal(i);
}
pbh.update(&d, portConfig); void Port::reorderStreamsByOrdinals()
#if 0 {
const ::google::protobuf::Message::Reflection *ref1; qSort(mStreams);
::google::protobuf::Message::Reflection *ref2; }
std::vector<const ::google::protobuf::FieldDescriptor*> list;
bool Port::newStreamAt(int index)
{
Stream s;
if (index > mStreams.size())
return false;
s.setId(newStreamId());
mStreams.insert(index, s);
updateStreamOrdinalsFromIndex();
return true;
}
bool Port::deleteStreamAt(int index)
{
if (index >= mStreams.size())
return false;
mStreams.removeAt(index);
updateStreamOrdinalsFromIndex();
return true;
}
bool Port::insertStream(uint streamId)
{
Stream s;
s.setId(streamId);
// FIXME(MED): If a stream with id already exists, what do we do?
mStreams.append(s);
// Update mAllocStreamId to take into account the stream id received
// from server
if (mAllocStreamId <= streamId)
mAllocStreamId = streamId + 1;
return true;
}
bool Port::updateStream(uint streamId, OstProto::Stream *stream)
{
int i, streamIndex;
for (i = 0; i < mStreams.size(); i++)
{
if (streamId == mStreams[i].id())
goto _found;
}
qDebug("%s: Invalid stream id %d", __FUNCTION__, streamId);
return false;
_found:
streamIndex = i;
mStreams[streamIndex].update(stream);
reorderStreamsByOrdinals();
return true;
}
void Port::getDeletedStreamsSinceLastSync(
OstProto::StreamIdList &streamIdList)
{
streamIdList.clear_stream_id();
for (int i = 0; i < mLastSyncStreamList.size(); i++)
{
int j;
for (j = 0; j < mStreams.size(); j++)
{
if (mLastSyncStreamList[i] == mStreams[j].id())
break;
}
if (j < mStreams.size())
{
// stream still exists!
continue;
}
else
{
// stream has been deleted since last sync
OstProto::StreamId *s;
s = streamIdList.add_stream_id();
s->set_id(mLastSyncStreamList.at(i));
}
}
}
void Port::getNewStreamsSinceLastSync(
OstProto::StreamIdList &streamIdList)
{
streamIdList.clear_stream_id();
for (int i = 0; i < mStreams.size(); i++)
{
if (mLastSyncStreamList.contains(mStreams[i].id()))
{
// existing stream!
continue;
}
else
{
// new stream!
OstProto::StreamId *s;
s = streamIdList.add_stream_id();
s->set_id(mStreams[i].id());
}
}
}
void Port::getModifiedStreamsSinceLastSync(
OstProto::StreamConfigList &streamConfigList)
{
qDebug("In %s", __FUNCTION__); qDebug("In %s", __FUNCTION__);
ref1 = portConfig.GetReflection(); //streamConfigList.mutable_port_id()->set_id(mPortId);
ref1->ListFields(&list); for (int i = 0; i < mStreams.size(); i++)
ref2 = d.GetReflection();
for (uint i=0; i < list.size(); i++)
{ {
const ::google::protobuf::FieldDescriptor *f1, *f2; OstProto::Stream *s;
f1 = list[i]; s = streamConfigList.add_stream();
f2 = d.GetDescriptor()->FindFieldByName(f1->name()); mStreams[i].getConfig(mPortId, s);
switch(f2->type())
{
case ::google::protobuf::FieldDescriptor::TYPE_UINT32:
ref2->SetUInt32(f2, ref1->GetUInt32(f1));
break;
case ::google::protobuf::FieldDescriptor::TYPE_BOOL:
ref2->SetBool(f2, ref1->GetBool(f1));
break;
case ::google::protobuf::FieldDescriptor::TYPE_STRING:
ref2->SetString(f2, ref1->GetString(f1));
break;
default:
qDebug("unhandled Field Type");
break;
} }
}
if (msg->GetDescriptor() != OstProto::PortConfig::descriptor())
{
qDebug("%s: invalid Message Descriptor (%s)", __FUNCTION__,
msg->GetDescriptor()->name());
goto _error_exit;
}
portConfig = msg;
// check for "required" param
if (!portConfig.has_port_id())
{
qDebug("%s: invalid Message Descriptor (%s)", __FUNCTION__,
msg->GetDescriptor()->name());
goto _error_exit;
}
#endif
} }
void Port::insertDummyStreams()
//
// ----------- SLOTS -------------
//
void Port::when_syncComplete()
{ {
mStreams.append(*(new Stream)); qSort(mStreams);
mStreams[0].setName(QString("%1:%2:0").arg(portGroupId()).arg(id()));
#if 1 mLastSyncStreamList.clear();
mStreams.append(*(new Stream)); for (int i=0; i<mStreams.size(); i++)
mStreams[1].setName(QString("%1:%2:1").arg(portGroupId()).arg(id())); mLastSyncStreamList.append(mStreams[i].id());
#endif
} }

View File

@ -6,40 +6,27 @@
#include <QList> #include <QList>
#include "stream.h" #include "stream.h"
class StreamModel; //class StreamModel;
class Port { class Port {
#if 0 // PB //friend class StreamModel;
friend class PortStatsModel;
#endif
friend class StreamModel;
//friend class PbHelper;
// FIXME: non-friend mechanism
//friend QList<Stream>* StreamModel::currentPortStreamList(void);
private: private:
OstProto::PortConfig d; static uint mAllocStreamId;
OstProto::Port d;
// FIXME(HI): consider removing mPortId as it is duplicated inside 'd'
quint32 mPortId; quint32 mPortId;
quint32 mPortGroupId; quint32 mPortGroupId;
QString mUserAlias; // user defined QString mUserAlias; // user defined
QList<Stream> mStreams; QList<quint32> mLastSyncStreamList;
QList<Stream> mStreams; // sorted by stream's ordinal value
#if 0 // PB
quint32 mPortId;
QString mName;
QString mDescription;
AdminStatus mAdminStatus;
OperStatus mOperStatus;
ControlMode mControlMode;
quint32 mPortStats[10]; // FIXME(HI):Hardcoding
#endif
uint newStreamId();
void updateStreamOrdinalsFromIndex();
void reorderStreamsByOrdinals();
public: public:
enum AdminStatus { AdminDisable, AdminEnable }; enum AdminStatus { AdminDisable, AdminEnable };
enum OperStatus { OperDown, OperUp }; enum OperStatus { OperDown, OperUp };
@ -52,7 +39,7 @@ public:
const QString& userAlias() const { return mUserAlias; } const QString& userAlias() const { return mUserAlias; }
quint32 id() const quint32 id() const
{ return d.port_id(); } { return d.port_id().id(); }
const QString name() const const QString name() const
{ return QString().fromStdString(d.name()); } { return QString().fromStdString(d.name()); }
const QString description() const const QString description() const
@ -75,10 +62,34 @@ public:
void setAlias(QString &alias) { mUserAlias = alias; } void setAlias(QString &alias) { mUserAlias = alias; }
//void setExclusive(bool flag); //void setExclusive(bool flag);
void updatePortConfig(OstProto::PortConfig *portConfig); int numStreams() { return mStreams.size(); }
Stream& streamByIndex(int index)
{
Q_ASSERT(index < mStreams.size());
return mStreams[index];
}
// FIXME(HIGH): Only for testing // FIXME(MED): naming inconsistency - PortConfig/Stream; also retVal
void insertDummyStreams(); void updatePortConfig(OstProto::Port *port);
//! Used by StreamModel
//@{
bool newStreamAt(int index);
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);
//@}
void getDeletedStreamsSinceLastSync(OstProto::StreamIdList &streamIdList);
void getNewStreamsSinceLastSync(OstProto::StreamIdList &streamIdList);
void getModifiedStreamsSinceLastSync(
OstProto::StreamConfigList &streamConfigList);
void when_syncComplete();
}; };
#endif #endif

View File

@ -10,29 +10,12 @@ PortGroup::PortGroup(QHostAddress ip, quint16 port)
// Allocate an id for self // Allocate an id for self
mPortGroupId = PortGroup::mPortGroupAllocId++; mPortGroupId = PortGroup::mPortGroupAllocId++;
#if 0 // PB
// Init attributes for which we values were passed to us
mServerAddress = ip;
mServerPort = port;
// Init remaining attributes with defaults
mpSocket = new QTcpSocket(this);
#endif
rpcChannel = new PbRpcChannel(ip, port); rpcChannel = new PbRpcChannel(ip, port);
rpcController = new PbRpcController(); rpcController = new PbRpcController();
serviceStub = new OstProto::OstService::Stub(rpcChannel, serviceStub = new OstProto::OstService::Stub(rpcChannel,
OstProto::OstService::STUB_OWNS_CHANNEL); OstProto::OstService::STUB_OWNS_CHANNEL);
#if 0 // PB // FIXME(LOW):Can't for my life figure out why this ain't working!
// TODO: consider using QT's signal-slot autoconnect
connect(mpSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(on_mpSocket_stateChanged()));
connect(mpSocket, SIGNAL(connected()), this, SLOT(when_connected()));
connect(mpSocket, SIGNAL(disconnected()), this, SLOT(when_disconnected()));
connect(mpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(when_error(QAbstractSocket::SocketError)));
connect(mpSocket, SIGNAL(readyRead()), this, SLOT(when_dataAvail()));
#endif
// FIXME:Can't for my life figure out why this ain't working!
//QMetaObject::connectSlotsByName(this); //QMetaObject::connectSlotsByName(this);
connect(rpcChannel, SIGNAL(stateChanged(QAbstractSocket::SocketState)), connect(rpcChannel, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
this, SLOT(on_rpcChannel_stateChanged())); this, SLOT(on_rpcChannel_stateChanged()));
@ -52,92 +35,6 @@ PortGroup::~PortGroup()
delete serviceStub; delete serviceStub;
} }
#if 0 // PB
void PortGroup::connectToHost(QHostAddress ip, quint16 port)
{
rpcChannel->establish(ip, port)
}
void PortGroup::connectToHost()
{
qDebug("PortGroup::connectToHost()");
rpcChannel->establish()
}
void PortGroup::disconnectFromHost()
{
mpSocket->disconnectFromHost();
}
#endif
#if 0 // PB
// --------------------------------------------
// Private Methods
// --------------------------------------------
void PortGroup::ProcessMsg(const char *msg, quint32 size)
{
tCommHdr *hdr;
// TODO: For now, assuming we'll get a complete msg
// but need to fix this as this is a TCP stream
hdr = (tCommHdr*) msg;
if (hdr->ver != 1) // FIXME:hardcoding
{
qDebug("Rcvd msg with invalid version %d\n", hdr->ver);
goto _exit;
}
qDebug("msgType - %x\n", NTOHS(hdr->msgType));
switch (NTOHS(hdr->msgType))
{
case e_MT_CapabilityInfo:
ProcessCapabilityInfo(msg+sizeof(tCommHdr),
NTOHS(hdr->msgLen)-sizeof(tCommHdr));
break;
default:
qDebug("Rcvd msg with unrecognized msgType %d\n", NTOHS(hdr->msgType));
}
_exit:
return;
}
void PortGroup::ProcessCapabilityInfo(const char *msg, qint32 size)
{
tTlvPortCapability *cap = (tTlvPortCapability*) msg;
Port *p;
emit portListAboutToBeChanged(mPortGroupId);
while (size)
{
qDebug("size = %d, tlvType = %d, tlvLen = %d\n",
size, NTOHS(cap->tlvType), NTOHS(cap->tlvLen));
if (NTOHS(cap->tlvType) != e_TT_PortCapability)
{
qDebug("Unrecognized TLV Type %d\n", NTOHS(cap->tlvType));
goto _next;
}
p = new Port(NTOHL(cap->portId), mPortGroupId);
p->setName(cap->portName);
p->setDescription(cap->portDesc);
p->insertDummyStreams(); // FIXME: only for testing
qDebug("before port append\n");
mPorts.append(*p);
_next:
size -= NTOHS(cap->tlvLen);
cap = (tTlvPortCapability*)((char *)(cap) + NTOHS(cap->tlvLen));
}
emit portListChanged(mPortGroupId);
return;
}
#endif
// ------------------------------------------------ // ------------------------------------------------
// Slots // Slots
@ -161,18 +58,6 @@ void PortGroup::on_rpcChannel_connected()
rpcController->Reset(); rpcController->Reset();
serviceStub->getPortIdList(rpcController, &void_, portIdList, serviceStub->getPortIdList(rpcController, &void_, portIdList,
NewCallback(this, &PortGroup::processPortIdList, portIdList)); NewCallback(this, &PortGroup::processPortIdList, portIdList));
#if 0 // PB
// Ask for Port Capability
tCommHdr pkt;
pkt.ver = 1;
pkt.resv1 = 0;
pkt.resv2 = 0;
pkt.msgType = HTONS(e_MT_GetCapability);
pkt.msgLen = HTONS(8);
mpSocket->write((char*) &pkt, sizeof(pkt));
#endif
} }
void PortGroup::on_rpcChannel_disconnected() void PortGroup::on_rpcChannel_disconnected()
@ -190,20 +75,94 @@ void PortGroup::on_rpcChannel_error(QAbstractSocket::SocketError socketError)
emit portGroupDataChanged(this); emit portGroupDataChanged(this);
} }
#if 0 // PB void PortGroup::when_configApply(int portIndex, uint *cookie)
void PortGroup::when_dataAvail()
{ {
qDebug("dataAvail\n"); uint *op;
OstProto::Ack *ack;
QByteArray msg = mpSocket->read(1024); // FIXME: hardcoding Q_ASSERT(portIndex < mPorts.size());
ProcessMsg(msg.constData(), msg.size());
if (cookie == NULL)
{
// cookie[0]: op [0 - delete, 1 - add, 2 - modify, 3 - Done!]
// cookie[1]: *ack
cookie = new uint[2];
ack = new OstProto::Ack;
cookie[0] = (uint) 0;
cookie[1] = (uint) ack;
}
else
{
ack = (OstProto::Ack*) cookie[1];
}
Q_ASSERT(cookie != NULL);
op = &cookie[0];
switch (*op)
{
case 0:
{
OstProto::StreamIdList streamIdList;
qDebug("applying 'deleted streams' ...");
streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id());
mPorts[portIndex].getDeletedStreamsSinceLastSync(streamIdList);
(*op)++;
rpcController->Reset();
serviceStub->deleteStream(rpcController, &streamIdList, ack,
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
break;
}
case 1:
{
OstProto::StreamIdList streamIdList;
qDebug("applying 'new streams' ...");
streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id());
mPorts[portIndex].getNewStreamsSinceLastSync(streamIdList);
(*op)++;
rpcController->Reset();
serviceStub->addStream(rpcController, &streamIdList, ack,
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
break;
}
case 2:
{
OstProto::StreamConfigList streamConfigList;
qDebug("applying 'modified streams' ...");
streamConfigList.mutable_port_id()->set_id(mPorts[portIndex].id());
mPorts[portIndex].getModifiedStreamsSinceLastSync(streamConfigList);
(*op)++;
rpcController->Reset();
serviceStub->modifyStream(rpcController, &streamConfigList, ack,
::google::protobuf::NewCallback(this, &PortGroup::when_configApply, portIndex, cookie));
break;
}
case 3:
qDebug("apply completed");
delete cookie;
break;
default:
qDebug("%s: Unknown Op!!!", __FUNCTION__);
break;
}
} }
#endif
void PortGroup::processPortIdList(OstProto::PortIdList *portIdList) void PortGroup::processPortIdList(OstProto::PortIdList *portIdList)
{ {
int count;
qDebug("got a portlist ..."); qDebug("got a portlist ...");
if (rpcController->Failed()) if (rpcController->Failed())
@ -212,26 +171,21 @@ void PortGroup::processPortIdList(OstProto::PortIdList *portIdList)
goto _error_exit; goto _error_exit;
} }
count = portIdList->port_id_size();
qDebug("%s: portid count = %d", __FUNCTION__, count);
qDebug("%s: %s", __FUNCTION__, portIdList->DebugString().c_str());
emit portListAboutToBeChanged(mPortGroupId); emit portListAboutToBeChanged(mPortGroupId);
for(int i = 0; i < count; i++) for(int i = 0; i < portIdList->port_id_size(); i++)
{ {
Port *p; Port *p;
p = new Port(portIdList->port_id(i), mPortGroupId); p = new Port(portIdList->port_id(i).id(), mPortGroupId);
//p->setName("name");
//p->setDescription("Desc");
p->insertDummyStreams(); // FIXME: only for testing
qDebug("before port append\n"); qDebug("before port append\n");
mPorts.append(*p); mPorts.append(*p);
} }
emit portListChanged(mPortGroupId); emit portListChanged(mPortGroupId);
this->portIdList.CopyFrom(*portIdList);
// Request PortConfigList // Request PortConfigList
{ {
OstProto::PortConfigList *portConfigList; OstProto::PortConfigList *portConfigList;
@ -253,8 +207,6 @@ _exit:
void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList) void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList)
{ {
int count;
qDebug("In %s", __FUNCTION__); qDebug("In %s", __FUNCTION__);
if (rpcController->Failed()) if (rpcController->Failed())
@ -263,19 +215,15 @@ void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList)
goto _error_exit; goto _error_exit;
} }
count = portConfigList->list_size();
qDebug("%s: count = %d", __FUNCTION__, count);
qDebug("%s: <%s>", __FUNCTION__, portConfigList->DebugString().c_str());
emit portListAboutToBeChanged(mPortGroupId); emit portListAboutToBeChanged(mPortGroupId);
for(int i = 0; i < count; i++) for(int i = 0; i < portConfigList->port_size(); i++)
{ {
uint id; uint id;
id = portConfigList->list(i).port_id(); id = portConfigList->port(i).port_id().id();
// FIXME: don't mix port id & index into mPorts[] // FIXME: don't mix port id & index into mPorts[]
mPorts[id].updatePortConfig(portConfigList->mutable_list(i)); mPorts[id].updatePortConfig(portConfigList->mutable_port(i));
} }
emit portListChanged(mPortGroupId); emit portListChanged(mPortGroupId);
@ -283,6 +231,185 @@ void PortGroup::processPortConfigList(OstProto::PortConfigList *portConfigList)
// FIXME: check if we need new signals since we are not changing the // FIXME: check if we need new signals since we are not changing the
// number of ports, just the port data // number of ports, just the port data
if (numPorts() > 0)
getStreamIdList();
_error_exit: _error_exit:
delete portConfigList; delete portConfigList;
} }
void PortGroup::getStreamIdList(int portIndex,
OstProto::StreamIdList *streamIdList)
{
::OstProto::PortId portId;
qDebug("In %s", __FUNCTION__);
if (streamIdList == NULL)
{
// First invocation (uses default params) -
// request StreamIdList for first port
Q_ASSERT(portIndex == 0);
Q_ASSERT(numPorts() > 0);
streamIdList = new ::OstProto::StreamIdList();
goto _request;
}
qDebug("got a streamIdlist ...");
if (rpcController->Failed())
{
qDebug("%s: rpc failed", __FUNCTION__);
goto _next_port; // FIXME(MED): Partial RPC
}
Q_ASSERT(portIndex < numPorts());
if (streamIdList->port_id().id() != mPorts[portIndex].id())
{
qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d",
__FUNCTION__, streamIdList->port_id().id(), mPorts[portIndex].id(),
portIndex);
goto _next_port; // FIXME(MED): Partial RPC
}
// FIXME(MED): need to mPorts.clear()???
for(int i = 0; i < streamIdList->stream_id_size(); i++)
{
uint streamId;
streamId = streamIdList->stream_id(i).id();
mPorts[portIndex].insertStream(streamId);
}
_next_port:
// FIXME(HI): ideally we shd use signals/slots but this means
// we will have to use Port* instead of Port with QList<> -
// need to find a way for this
mPorts[portIndex].when_syncComplete();
portIndex++;
if (portIndex >= numPorts())
{
// We're done for all ports !!!
// FIXME(HI): some way to reset streammodel
delete streamIdList;
if (numPorts() > 0)
getStreamConfigList();
goto _exit;
}
_request:
portId.set_id(mPorts[portIndex].id());
streamIdList->Clear();
rpcController->Reset();
serviceStub->getStreamIdList(rpcController, &portId, streamIdList,
NewCallback(this, &PortGroup::getStreamIdList,
portIndex, streamIdList));
goto _exit;
_exit:
return;
}
void PortGroup::getStreamConfigList(int portIndex,
OstProto::StreamConfigList *streamConfigList)
{
OstProto::StreamIdList streamIdList;
qDebug("In %s", __PRETTY_FUNCTION__);
if (streamConfigList == NULL)
{
// First invocation using default params
// - request for first port
Q_ASSERT(portIndex == 0);
Q_ASSERT(numPorts() > 0);
streamConfigList = new OstProto::StreamConfigList;
goto _request;
}
qDebug("got a streamconfiglist");
if (rpcController->Failed())
{
qDebug("%s: rpc failed", __FUNCTION__);
goto _next_port;
}
Q_ASSERT(portIndex < numPorts());
if (streamConfigList->port_id().id() != mPorts[portIndex].id())
{
qDebug("%s: Invalid portId %d (expected %d) received for portIndex %d",
__FUNCTION__, streamConfigList->port_id().id(),
mPorts[portIndex].id(), portIndex);
goto _next_port; // FIXME(MED): Partial RPC
}
// FIXME(MED): need to mStreams.clear()???
for(int i = 0; i < streamConfigList->stream_size(); i++)
{
uint streamId;
streamId = streamConfigList->stream(i).stream_id().id();
mPorts[portIndex].updateStream(streamId,
streamConfigList->mutable_stream(i));
}
_next_port:
portIndex++;
if (portIndex >= numPorts())
{
// We're done for all ports !!!
// FIXME(HI): some way to reset streammodel
delete streamConfigList;
goto _exit;
}
_request:
qDebug("requesting stream config list ...");
streamIdList.Clear();
streamIdList.mutable_port_id()->set_id(mPorts[portIndex].id());
for (int j = 0; j < mPorts[portIndex].numStreams(); j++)
{
OstProto::StreamId *s;
s = streamIdList.add_stream_id();
s->set_id(mPorts[portIndex].streamByIndex(j).id());
}
streamConfigList->Clear();
rpcController->Reset();
serviceStub->getStreamConfig(rpcController,
&streamIdList, streamConfigList, NewCallback(this,
&PortGroup::getStreamConfigList, portIndex, streamConfigList));
_exit:
return;
}
void PortGroup::processModifyStreamAck(OstProto::Ack *ack)
{
qDebug("In %s", __FUNCTION__);
qDebug("Modify Successful!!");
// TODO(HI): Apply Button should now be disabled???!!!!???
}

View File

@ -31,7 +31,9 @@ private:
#endif #endif
PbRpcChannel *rpcChannel; PbRpcChannel *rpcChannel;
::google::protobuf::RpcController *rpcController; ::google::protobuf::RpcController *rpcController;
OstProto::OstService::Stub *serviceStub; ::OstProto::OstService::Stub *serviceStub;
::OstProto::PortIdList portIdList;
public: // FIXME(HIGH): member access public: // FIXME(HIGH): member access
QList<Port> mPorts; QList<Port> mPorts;
@ -61,6 +63,12 @@ public:
void processPortIdList(OstProto::PortIdList *portIdList); void processPortIdList(OstProto::PortIdList *portIdList);
void processPortConfigList(OstProto::PortConfigList *portConfigList); void processPortConfigList(OstProto::PortConfigList *portConfigList);
void getStreamIdList(int portIndex = 0,
OstProto::StreamIdList *streamIdList = NULL);
void getStreamConfigList(int portIndex = 0,
OstProto::StreamConfigList *streamConfigList = NULL);
void processModifyStreamAck(OstProto::Ack *ack);
signals: signals:
void portGroupDataChanged(PortGroup* portGroup); void portGroupDataChanged(PortGroup* portGroup);
void portListAboutToBeChanged(quint32 portGroupId); void portListAboutToBeChanged(quint32 portGroupId);
@ -71,6 +79,9 @@ private slots:
void on_rpcChannel_connected(); void on_rpcChannel_connected();
void on_rpcChannel_disconnected(); void on_rpcChannel_disconnected();
void on_rpcChannel_error(QAbstractSocket::SocketError socketError); void on_rpcChannel_error(QAbstractSocket::SocketError socketError);
public slots:
void when_configApply(int portIndex, uint *cookie = NULL);
#if 0 // PB #if 0 // PB
void on_rpcChannel_when_dataAvail(); void on_rpcChannel_when_dataAvail();
#endif #endif

View File

@ -31,6 +31,7 @@ public:
PortModel* getPortModel() { return &mPortGroupListModel; } PortModel* getPortModel() { return &mPortGroupListModel; }
PortStatsModel* getPortStatsModel() { return &mPortStatsModel; } PortStatsModel* getPortStatsModel() { return &mPortStatsModel; }
StreamModel* getStreamModel() { return &mStreamListModel; } StreamModel* getStreamModel() { return &mStreamListModel; }
bool isPortGroup(const QModelIndex& index); bool isPortGroup(const QModelIndex& index);
bool isPort(const QModelIndex& index); bool isPort(const QModelIndex& index);
PortGroup& portGroup(const QModelIndex& index); PortGroup& portGroup(const QModelIndex& index);

View File

@ -73,7 +73,8 @@ QVariant PortStatsModel::data(const QModelIndex &index, int role) const
{ {
#if 0 // PB #if 0 // PB
return pgl->mPortGroups.at(pgidx)->mPorts.at(pidx).mPortStats[index.row()]; return pgl->mPortGroups.at(pgidx)->mPorts.at(pidx).mPortStats[index.row()];
#endif return 0; //FIXME: Get actual port stats #endif
return 0; //FIXME: Get actual port stats
} }
else else
return QVariant(); return QVariant();

View File

@ -56,9 +56,13 @@ void PortsWindow::on_tvStreamList_activated(const QModelIndex & index)
qDebug("%s: invalid index", __FUNCTION__); qDebug("%s: invalid index", __FUNCTION__);
return; return;
} }
#if 0 // CleanedUp!
// FIXME(MED): This way of passing params must be changed // FIXME(MED): This way of passing params must be changed
scd = new StreamConfigDialog(plm->getStreamModel()->currentPortStreamList(), scd = new StreamConfigDialog(plm->getStreamModel()->currentPortStreamList(),
(uint) index.row(), this); (uint) index.row(), this);
#endif
scd = new StreamConfigDialog(plm->port(tvPortList->currentIndex()),
index.row(), this);
qDebug("stream list activated\n"); qDebug("stream list activated\n");
scd->exec(); // TODO: chk retval scd->exec(); // TODO: chk retval
delete scd; delete scd;
@ -206,7 +210,43 @@ _EXIT:
void PortsWindow::on_pbApply_clicked() void PortsWindow::on_pbApply_clicked()
{ {
{ QModelIndex curPort;
QModelIndex curPortGroup;
curPort = tvPortList->selectionModel()->currentIndex();
if (!curPort.isValid())
{
qDebug("%s: curPort is invalid", __FUNCTION__);
goto _exit;
}
if (!plm->isPort(curPort))
{
qDebug("%s: curPort is not a port", __FUNCTION__);
goto _exit;
}
curPortGroup = plm->getPortModel()->parent(curPort);
if (!curPortGroup.isValid())
{
qDebug("%s: curPortGroup is invalid", __FUNCTION__);
goto _exit;
}
if (!plm->isPortGroup(curPortGroup))
{
qDebug("%s: curPortGroup is not a portGroup", __FUNCTION__);
goto _exit;
}
// FIXME(HI): shd this be a signal?
//portGroup.when_configApply(port);
// FIXME(MED): mixing port id and index!!!
plm->portGroup(curPortGroup).when_configApply(plm->port(curPort).id());
_exit:
return;
#if 0
// TODO (LOW): This block is for testing only // TODO (LOW): This block is for testing only
QModelIndex current = tvPortList->selectionModel()->currentIndex(); QModelIndex current = tvPortList->selectionModel()->currentIndex();
@ -214,7 +254,7 @@ void PortsWindow::on_pbApply_clicked()
qDebug("current = %llx", current.internalId()); qDebug("current = %llx", current.internalId());
else else
qDebug("current is invalid"); qDebug("current is invalid");
} #endif
} }
void PortsWindow::on_actionNew_Port_Group_triggered() void PortsWindow::on_actionNew_Port_Group_triggered()

View File

@ -1,134 +1,851 @@
#include <stream.h> #include <QHostAddress>
#include "stream.h"
#include <google/protobuf/message.h>
#define BASE_HEX 16
QString MacProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("Destination Mac Address");
break;
case 1:
name = QString("Source Mac Address");
break;
default:
name = QString();
break;
}
return name;
}
QString MacProtocol::fieldTextValue(int index)
{
QString textValue;
// FIXME(MED): Mac Addr formatting
switch(index)
{
case 0:
textValue = QString("%1").
arg(dstMac(), 12, BASE_HEX, QChar('0'));
break;
case 1:
textValue = QString("%1").
arg(srcMac(), 12, BASE_HEX, QChar('0'));
break;
default:
textValue = QString();
break;
}
return textValue;
}
QByteArray MacProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString LlcProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("DSAP");
break;
case 1:
name = QString("SSAP");
break;
case 2:
name = QString("Control");
break;
default:
name = QString();
break;
}
return name;
}
QString LlcProtocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("0x%1").
arg(dsap(), 2, BASE_HEX, QChar('0'));
break;
case 1:
textValue = QString("0x%1").
arg(ssap(), 2, BASE_HEX, QChar('0'));
break;
case 2:
textValue = QString("0x%1").
arg(ctl(), 2, BASE_HEX, QChar('0'));
break;
default:
textValue = QString();
break;
}
return textValue;
}
QByteArray LlcProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString SnapProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("OUI");
break;
default:
name = QString();
break;
}
return name;
}
QString SnapProtocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("0x%1").
arg(oui(), 6, BASE_HEX, QChar('0'));
break;
default:
textValue = QString();
break;
}
return textValue;
}
QByteArray SnapProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString Eth2Protocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("Type");
break;
default:
name = QString();
break;
}
return name;
}
QString Eth2Protocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("0x%1").
arg(type(), 4, BASE_HEX, QChar('0'));
break;
default:
textValue = QString();
break;
}
return textValue;
}
QByteArray Eth2Protocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
int VlanProtocol::numFields()
{
if (isSingleTagged())
return 4;
else if (isDoubleTagged())
return 8;
else
{
Q_ASSERT(isUntagged());
return 0;
}
}
QString VlanProtocol::fieldName(int index)
{
QString name;
if (isDoubleTagged())
{
switch(index)
{
case 0:
name = QString("TPID");
break;
case 1:
name = QString("PCP");
break;
case 2:
name = QString("DE");
break;
case 3:
name = QString("VlanId");
break;
default:
index -= 4;
goto _single_tag;
}
goto _exit;
}
_single_tag:
switch(index)
{
case 0:
name = QString("TPID");
break;
case 1:
name = QString("Priority");
break;
case 2:
name = QString("CFI");
break;
case 3:
name = QString("VlanId");
break;
default:
name = QString();
break;
}
_exit:
return name;
}
QString VlanProtocol::fieldTextValue(int index)
{
QString textValue;
if (isDoubleTagged())
{
switch(index)
{
case 0:
textValue = QString("0x%1").
arg(stpid(), 4, BASE_HEX, QChar('0'));
break;
case 1:
textValue = QString("%1").
arg(svlanPrio());
break;
case 2:
textValue = QString("%1").
arg(svlanCfi());
break;
case 3:
textValue = QString("%1").
arg(svlanId());
break;
default:
index -= 4;
goto _single_tag;
}
goto _exit;
}
_single_tag:
switch(index)
{
case 0:
textValue = QString("0x%1").
arg(ctpid(), 4, BASE_HEX, QChar('0'));
break;
case 1:
textValue = QString("%1").
arg(cvlanPrio());
break;
case 2:
textValue = QString("%1").
arg(cvlanCfi());
break;
case 3:
textValue = QString("%1").
arg(cvlanId());
break;
default:
textValue = QString();
break;
}
_exit:
return textValue;
}
QByteArray VlanProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString IpProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("Version");
break;
case 1:
name = QString("Header Length");
break;
case 2:
name = QString("TOS/DSCP");
break;
case 3:
name = QString("Total Length");
break;
case 4:
name = QString("ID");
break;
case 5:
name = QString("Flags");
break;
case 6:
name = QString("Fragment Offset");
break;
case 7:
name = QString("TTL");
break;
case 8:
name = QString("Protocol Type");
break;
case 9:
name = QString("Checksum");
break;
case 10:
name = QString("Source IP");
break;
case 11:
name = QString("Destination IP");
break;
default:
name = QString();
}
return name;
}
QString IpProtocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("%1").
arg(ver());
break;
case 1:
textValue = QString("%1").
arg(hdrLen());
break;
case 2:
textValue = QString("0x%1").
arg(tos(), 2, BASE_HEX, QChar('0'));
break;
case 3:
textValue = QString("%1").
arg(totLen());
break;
case 4:
textValue = QString("0x%1").
arg(id(), 2, BASE_HEX, QChar('0'));
break;
case 5:
textValue = QString("0x%1").
arg(flags(), 2, BASE_HEX, QChar('0')); // FIXME(MED): bitmap?
break;
case 6:
textValue = QString("%1").
arg(fragOfs());
break;
case 7:
textValue = QString("%1").
arg(ttl());
break;
case 8:
textValue = QString("0x%1").
arg(proto(), 2, BASE_HEX, QChar('0'));
break;
case 9:
textValue = QString("0x%1").
arg(cksum(), 4, BASE_HEX, QChar('0'));
break;
case 10:
textValue = QHostAddress(srcIp()).toString();
break;
case 11:
textValue = QHostAddress(dstIp()).toString();
break;
default:
textValue = QString();
}
return textValue;
}
QByteArray IpProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString TcpProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("Source Port");
break;
case 1:
name = QString("Destination Port");
break;
case 2:
name = QString("Seq Number");
break;
case 3:
name = QString("Ack Number");
break;
case 4:
name = QString("Header Length");
break;
case 5:
name = QString("Reserved");
break;
case 6:
name = QString("Flags");
break;
case 7:
name = QString("Window");
break;
case 8:
name = QString("Checksum");
break;
case 9:
name = QString("Urgent Pointer");
break;
default:
name = QString();
}
return name;
}
QString TcpProtocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("%1").
arg(srcPort());
break;
case 1:
textValue = QString("%1").
arg(dstPort());
break;
case 2:
textValue = QString("%1").
arg(seqNum());
break;
case 3:
textValue = QString("%1").
arg(ackNum());
break;
case 4:
textValue = QString("%1").
arg(hdrLen());
break;
case 5:
textValue = QString("%1").
arg(rsvd());
break;
case 6:
textValue = QString("0x%1").
arg(flags(), 2, BASE_HEX, QChar('0'));
break;
case 7:
textValue = QString("%1").
arg(flags());
break;
case 8:
textValue = QString("0x%1").
arg(cksum(), 4, BASE_HEX, QChar('0'));
break;
case 9:
textValue = QString("%1").
arg(urgPtr());
break;
default:
textValue = QString();
}
return textValue;
}
QByteArray TcpProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
QString UdpProtocol::fieldName(int index)
{
QString name;
switch(index)
{
case 0:
name = QString("Source Port");
break;
case 1:
name = QString("Destination Port");
break;
case 2:
name = QString("Total Length");
break;
case 3:
name = QString("Checksum");
break;
default:
name = QString();
}
return name;
}
QString UdpProtocol::fieldTextValue(int index)
{
QString textValue;
switch(index)
{
case 0:
textValue = QString("%1").
arg(srcPort());
break;
case 1:
textValue = QString("%1").
arg(dstPort());
break;
case 2:
textValue = QString("%1").
arg(totLen());
break;
case 3:
textValue = QString("0x%1").
arg(cksum(), 4, BASE_HEX, QChar('0'));
break;
default:
textValue = QString();
}
return textValue;
}
QByteArray UdpProtocol::fieldRawValue(int index)
{
QByteArray rawValue;
return rawValue;
}
//-----------------------------------------------------
// Stream Class Methods
//-----------------------------------------------------
quint32 Stream::mAllocId = 0;
Stream::Stream() Stream::Stream()
{ {
mId = mAllocId++; mId = 0xFFFFFFFF;
mCore = new OstProto::StreamCore; mCore = new OstProto::StreamCore;
// mCore->set_port_id(0xFFFFFFFF);
// mCore->set_stream_id(mId);
mUnknown = new UnknownProtocol;
mMac = new MacProtocol; mMac = new MacProtocol;
mLlc = new LlcProtocol;
mSnap = new SnapProtocol;
mEth2 = new Eth2Protocol;
mVlan = new VlanProtocol;
mIp = new IpProtocol; mIp = new IpProtocol;
#if 0 mArp = new ArpProtocol;
// Default constructor
InitDefaultMeta(); mTcp = new TcpProtocol;
InitDefaultProto(); mUdp = new UdpProtocol;
InitDefaultL2(); mIcmp = new IcmpProtocol;
InitDefaultL3(); mIgmp = new IgmpProtocol;
InitDefaultL4(); }
#endif
void Stream::getConfig(uint portId, OstProto::Stream *s)
{
s->mutable_stream_id()->set_id(mId);
s->mutable_core()->CopyFrom(*mCore);
mMac->getConfig(s->mutable_mac());
mMac->getConfig(s->mutable_mac());
mLlc->getConfig(s->mutable_llc());
mSnap->getConfig(s->mutable_snap());
mEth2->getConfig(s->mutable_eth2());
mVlan->getConfig(s->mutable_vlan());
mIp->getConfig(s->mutable_ip());
mArp->getConfig(s->mutable_arp());
mTcp->getConfig(s->mutable_tcp());
mUdp->getConfig(s->mutable_udp());
mIcmp->getConfig(s->mutable_icmp());
mIgmp->getConfig(s->mutable_igmp());
}
// FIXME(HIGH): Replace this by some Protocol Registration mechanism at Init
#define PTYP_L2_NONE 1
#define PTYP_L2_ETH_2 2
#define PTYP_L2_802_3_RAW 3
#define PTYP_L2_802_3_LLC 4
#define PTYP_L2_SNAP 5
#define PTYP_VLAN 10
#define PTYP_L3_IP 30
#define PTYP_L3_ARP 31
#define PTYP_L4_TCP 40
#define PTYP_L4_UDP 41
#define PTYP_L4_ICMP 42
#define PTYP_L4_IGMP 43
#define PTYP_INVALID 0
#define PTYP_DATA 0xFF
void Stream::updateSelectedProtocols()
{
int proto;
// Clear the selected protocols list
selectedProtocols.clear();
// Check and populate L2 Protocol
switch(frameType())
{
case Stream::e_ft_none:
proto = PTYP_L2_NONE;
break;
case Stream::e_ft_eth_2:
selectedProtocols.append(PTYP_L2_NONE);
proto = PTYP_L2_ETH_2;
break;
case Stream::e_ft_802_3_raw:
selectedProtocols.append(PTYP_L2_NONE);
proto = PTYP_L2_802_3_RAW;
break;
case Stream::e_ft_802_3_llc:
selectedProtocols.append(PTYP_L2_NONE);
proto = PTYP_L2_802_3_LLC;
break;
case Stream::e_ft_snap:
selectedProtocols.append(PTYP_L2_NONE);
selectedProtocols.append(PTYP_L2_802_3_LLC);
proto = PTYP_L2_SNAP;
break;
default:
qDebug("%s: Unsupported frametype %d", __FUNCTION__,
frameType());
proto = PTYP_INVALID;
}
selectedProtocols.append(proto);
// Check and populate VLANs, if present
if (!vlan()->isUntagged())
selectedProtocols.append(PTYP_VLAN);
// Check and populate L3 protocols
switch (l3Proto())
{
case Stream::e_l3_none :
goto _data;
break;
case Stream::e_l3_ip :
proto = PTYP_L3_IP;
break;
case Stream::e_l3_arp:
proto = PTYP_L3_ARP;
break;
default:
qDebug("%s: Unsupported L3 Proto %d", __FUNCTION__,
l3Proto());
proto = PTYP_INVALID;
}
selectedProtocols.append(proto);
// Check and populate L4 protocol
switch(l4Proto())
{
case Stream::e_l4_none:
goto _data;
break;
case Stream::e_l4_tcp:
proto = PTYP_L4_TCP;
break;
case Stream::e_l4_udp:
proto = PTYP_L4_UDP;
break;
case Stream::e_l4_icmp:
proto = PTYP_L4_ICMP;
break;
case Stream::e_l4_igmp:
proto = PTYP_L4_IGMP;
break;
default:
qDebug("%s: Unsupported L4 Proto %d", __FUNCTION__,
l4Proto());
proto = PTYP_INVALID;
};
selectedProtocols.append(proto);
_data:
selectedProtocols.append(PTYP_DATA);
}
int Stream::numProtocols()
{
updateSelectedProtocols(); // FIXME(HI): shd not happen everytime
return selectedProtocols.size();
} }
#if 0 #if 0
void Stream::InitDefaultMeta() int Stream::protocolId(int index)
{ {
// TODO(LOW): Use #defines updateSelectedProtocols(); // FIXME(HI): shd not happen everytime
meta.patternMode = e_dp_fixed; if (index < selectedProtocols.size())
meta.pattern = 0x00000000; return selectedProtocols.at(index);
meta.dataStartOfs = 0; // FIXME(HIGH): this has to calculated else
meta.lenMode = e_fl_fixed; return -1;
meta.frameLen = 64;
meta.frameLenMin = 64;
meta.frameLenMax = 1518;
} }
int Stream::protocolIndex(int id)
void Stream::InitDefaultProto()
{ {
// TODO(LOW): Use #defines
proto.ft = e_ft_eth_2;
proto.dsap = 0x00;
proto.ssap = 0x00;
proto.ctl = 0x00;
proto.ouiMsb = 0x00;
proto.ouiLshw = 0x0000;
proto.protoMask = PM_L3_PROTO_NONE | PM_L4_PROTO_NONE;
proto.etherType = ETH_TYP_IP;
proto.ipProto = IP_PROTO_TCP;
}
void Stream::InitDefaultL2()
{
// TODO(LOW): Use #defines
l2.eth.dstMacMshw = 0x0000;
l2.eth.dstMacLsw = 0x00000001;
l2.eth.dstMacMode = e_mm_fixed;
l2.eth.dstMacCount = 16;
l2.eth.dstMacStep = 1;
l2.eth.srcMacMshw = 0x0000;
l2.eth.srcMacLsw = 0x00000002;
l2.eth.srcMacMode = e_mm_fixed;
l2.eth.srcMacCount = 16;
l2.eth.srcMacStep = 1;
l2.eth.vlanMask = VM_UNTAGGED;
l2.eth.ctpid = 0x8100;
l2.eth.cvlanPrio = 0;
l2.eth.cvlanCfi = 0;
l2.eth.cvlanId = 2;
l2.eth.stpid = 0x88a8;
l2.eth.svlanPrio = 0;
l2.eth.svlanCfi = 0;
l2.eth.svlanId = 2;
}
void Stream::InitDefaultL3()
{
InitDefaultL3Ip();
}
void Stream::InitDefaultL3Ip()
{
l3.ip.ipMask = STREAM_DEF_IP_MASK;
l3.ip.ver = STREAM_DEF_L3_IP_VER;
l3.ip.hdrLen = STREAM_DEF_L3_IP_HDR_LEN;
l3.ip.tos = STREAM_DEF_L3_IP_TOS;
l3.ip.totLen = STREAM_DEF_L3_IP_TOT_LEN;
l3.ip.id = STREAM_DEF_L3_IP_ID;
l3.ip.flags = STREAM_DEF_L3_IP_FLAGS;
l3.ip.fragOfs = STREAM_DEF_L3_IP_FRAG_OFS;
l3.ip.ttl = STREAM_DEF_L3_IP_TTL;
l3.ip.proto = STREAM_DEF_L3_IP_PROTO;
l3.ip.cksum = STREAM_DEF_L3_IP_CKSUM;
l3.ip.srcIp = STREAM_DEF_L3_IP_SRC_IP;
l3.ip.srcIpMode = STREAM_DEF_L3_IP_SRC_IP_MODE;
l3.ip.srcIpCount = STREAM_DEF_L3_IP_SRC_IP_COUNT;
l3.ip.srcIpMask = STREAM_DEF_L3_IP_SRC_IP_MASK;
l3.ip.dstIp = STREAM_DEF_L3_IP_DST_IP;
l3.ip.dstIpMode = STREAM_DEF_L3_IP_DST_IP_MODE;
l3.ip.dstIpCount = STREAM_DEF_L3_IP_DST_IP_COUNT;
l3.ip.dstIpMask = STREAM_DEF_L3_IP_DST_IP_MASK;
}
void Stream::InitDefaultL4()
{
InitDefaultL4Tcp();
InitDefaultL4Udp();
}
void Stream::InitDefaultL4Tcp()
{
l4.tcp.tcpMask = STREAM_DEF_L4_TCP_TCP_MASK;
l4.tcp.srcPort = STREAM_DEF_L4_TCP_SRC_PORT;
l4.tcp.dstPort = STREAM_DEF_L4_TCP_DST_PORT;
l4.tcp.seqNum = STREAM_DEF_L4_TCP_SEQ_NUM;
l4.tcp.ackNum = STREAM_DEF_L4_TCP_ACK_NUM;
l4.tcp.hdrLen = STREAM_DEF_L4_TCP_HDR_LEN;
l4.tcp.rsvd = STREAM_DEF_L4_TCP_RSVD;
l4.tcp.flags = STREAM_DEF_L4_TCP_FLAGS;
l4.tcp.window = STREAM_DEF_L4_TCP_WINDOW;
l4.tcp.cksum = STREAM_DEF_L4_TCP_CKSUM;
l4.tcp.urgPtr = STREAM_DEF_L4_TCP_URG_PTR;
}
void Stream::InitDefaultL4Udp()
{
l4.udp.udpMask = STREAM_DEF_L4_UDP_UDP_MASK;
l4.udp.srcPort = STREAM_DEF_L4_UDP_SRC_PORT;
l4.udp.dstPort = STREAM_DEF_L4_UDP_DST_PORT;
l4.udp.totLen = STREAM_DEF_L4_UDP_TOT_LEN;
l4.udp.cksum = STREAM_DEF_L4_UDP_CKSUM;
} }
#endif #endif
AbstractProtocol* Stream::protocol(int index)
{
int id;
updateSelectedProtocols(); // FIXME(HI): shd not happen everytime
id = selectedProtocols.at(index);
switch(id)
{
case PTYP_L2_NONE:
return mac();
case PTYP_L2_ETH_2:
return eth2();
case PTYP_L2_802_3_RAW:
return eth2(); // FIXME(HI): define a dot3 protocol?
case PTYP_L2_802_3_LLC:
return llc();
case PTYP_L2_SNAP:
return snap();
case PTYP_VLAN:
return vlan();
case PTYP_L3_IP:
return ip();
case PTYP_L3_ARP:
return arp();
case PTYP_L4_TCP:
return tcp();
case PTYP_L4_UDP:
return udp();
case PTYP_L4_ICMP:
return icmp();
case PTYP_L4_IGMP:
return igmp();
case PTYP_INVALID:
return mUnknown;
case PTYP_DATA:
return mUnknown; // FIXME(MED) define a "data" protocol?
default:
return mUnknown;
}
}

View File

@ -3,6 +3,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QString> #include <QString>
#include <QList>
#include "../common/protocol.pb.h" #include "../common/protocol.pb.h"
class StreamConfigDialog; class StreamConfigDialog;
@ -15,44 +16,55 @@ class PacketModel;
#define IP_PROTO_TCP 0x06 #define IP_PROTO_TCP 0x06
#define IP_PROTO_UDP 0x11 #define IP_PROTO_UDP 0x11
#if 0
// Protocols
struct {
FrameType ft;
quint16 protoMask;
#define PM_L3_PROTO_NONE 0x0001
#define PM_L3_PROTO_OTHER 0x0002
#define PM_L4_PROTO_NONE 0x0004
#define PM_L4_PROTO_OTHER 0x0008
quint16 etherType;
#define ETH_TYP_IP 0x0800
#define ETH_TYP_ARP 0x0806
quint16 ipProto;
#define IP_PROTO_ICMP 0x01
#define IP_PROTO_IGMP 0x02
#define IP_PROTO_TCP 0x06
#define IP_PROTO_UDP 0x11
} proto;
// L2
struct {
// Ethernet
} eth;
} l2;
#endif
class AbstractProtocol class AbstractProtocol
{ {
// TODO // TODO(LOW)
public:
/*!
Subclasses should return reference to their protocol specific
::google::protobuf::Message
*/
virtual ::google::protobuf::Message& data() = 0;
/*! Subclasses can directly use this method. No need for overload */
void getConfig(::google::protobuf::Message *msg)
{ msg->CopyFrom(data()); }
virtual QString protocolName()
{ return QString("AbstractProtocol"); }
virtual QString protocolShortName()
{ return QString("AbsProto"); }
virtual int numFields()
{ return 1; }
virtual QString fieldName(int index)
{ return QString("AbstractField"); }
virtual QString fieldTextValue(int index)
{ return QString("AbstractFieldValue"); }
virtual QByteArray fieldRawValue(int index)
{ return QByteArray(4, '\0'); }
};
class UnknownProtocol: public AbstractProtocol
{
OstProto::Ack d; // FIXME(HI): replace 'Ack' with something else
public:
virtual ~UnknownProtocol() {}
virtual ::google::protobuf::Message& data() { return d; }
virtual QString protocolName()
{ return QString("UnknownProtocol"); }
QString protocolShortName()
{ return QString("???Proto"); }
int numFields()
{ return 1; }
QString fieldName(int index)
{ return QString("UnknownField"); }
QString fieldTextValue(int index)
{ return QString("UnknownFieldValue"); }
QByteArray fieldRawValue(int index)
{ return QByteArray(4, '\0'); }
}; };
class MacProtocol : public AbstractProtocol class MacProtocol : public AbstractProtocol
@ -66,6 +78,10 @@ public:
MacAddrInc, MacAddrInc,
MacAddrDec MacAddrDec
}; };
virtual ~MacProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Mac mac) { d.MergeFrom(mac); return true; }
// Dst Mac // Dst Mac
quint64 dstMac() quint64 dstMac()
@ -110,6 +126,17 @@ public:
{ return d.src_mac_step(); } { return d.src_mac_step(); }
bool setSrcMacStep(quint16 srcMacStep) bool setSrcMacStep(quint16 srcMacStep)
{ d.set_src_mac_step(srcMacStep); return true; } { d.set_src_mac_step(srcMacStep); return true; }
virtual QString protocolName()
{ return QString("Media Access Control"); }
QString protocolShortName()
{ return QString("MAC"); }
int numFields()
{ return 2; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
class LlcProtocol : public AbstractProtocol class LlcProtocol : public AbstractProtocol
@ -118,6 +145,11 @@ private:
OstProto::Llc d; OstProto::Llc d;
public: public:
virtual ~LlcProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Llc llc) { d.MergeFrom(llc); return true; }
quint8 dsap() quint8 dsap()
{ return d.dsap(); } { return d.dsap(); }
bool setDsap(quint8 dsap) bool setDsap(quint8 dsap)
@ -133,6 +165,16 @@ public:
bool setCtl(quint8 ctl) bool setCtl(quint8 ctl)
{ d.set_ctl(ctl); return true; } { d.set_ctl(ctl); return true; }
virtual QString protocolName()
{ return QString("802.3 Logical Link Control"); }
QString protocolShortName()
{ return QString("LLC"); }
int numFields()
{ return 3; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
class SnapProtocol : public AbstractProtocol class SnapProtocol : public AbstractProtocol
@ -141,54 +183,179 @@ private:
OstProto::Snap d; OstProto::Snap d;
public: public:
virtual ~SnapProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Snap snap) { d.MergeFrom(snap); return true; }
quint32 oui() quint32 oui()
{ return d.oui(); } { return d.oui(); }
bool setOui(quint32 oui) bool setOui(quint32 oui)
{ d.set_oui(oui); return true; } { d.set_oui(oui); return true; }
// "Type" field: use from eth2
#if 0
quint16 type() quint16 type()
{ return d.type(); } { return d.type(); }
bool setType(quint16 type) bool setType(quint16 type)
{ d.set_type(type); return true; } { d.set_type(type); return true; }
#endif
virtual QString protocolName()
{ return QString("SubNetwork Access Protocol"); }
QString protocolShortName()
{ return QString("SNAP"); }
int numFields()
{ return 1; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
class Eth2Protocol : public AbstractProtocol class Eth2Protocol : public AbstractProtocol
{ {
private: private:
OstProto::Eth2 d; OstProto::Eth2 d;
public: public:
virtual ~Eth2Protocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Eth2 eth2) { d.MergeFrom(eth2); return true; }
quint16 type() quint16 type()
{ return d.type(); } { return d.type(); }
bool setType(quint16 type) bool setType(quint16 type)
{ d.set_type(type); return true; } { d.set_type(type); return true; }
virtual QString protocolName()
{ return QString("Protocol Type"); }
QString protocolShortName()
{ return QString("TYPE"); }
int numFields()
{ return 1; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
class VlanProtocol : public AbstractProtocol class VlanProtocol : public AbstractProtocol
{ {
// TODO OstProto::Vlan d;
#if 0 public:
quint16 vlanMask; virtual ~VlanProtocol() {}
#define VM_UNTAGGED 0x0000 virtual ::google::protobuf::Message& data() {return d;}
#define VM_CVLAN_TAGGED 0x0001 bool update(OstProto::Vlan vlan) { d.MergeFrom(vlan); return true; }
#define VM_CVLAN_TPID_OVERRIDE 0x0002
#define VM_SVLAN_TAGGED 0x0100
#define VM_SVLAN_TPID_OVERRIDE 0x0200
#define VM_SINGLE_TAGGED(mask) \ enum VlanFlag {
((mask & VM_CVLAN_TAGGED ) | (mask & VM_SVLAN_TAGGED)) VlanCvlanTagged = 0x01,
#define VM_DOUBLE_TAGGED(mask) \ VlanCtpidOverride = 0x02,
(mask & (VM_CVLAN_TAGGED | VM_SVLAN_TAGGED)) VlanSvlanTagged = 0x04,
VlanStpidOverride = 0x08,
};
Q_DECLARE_FLAGS(VlanFlags, VlanFlag);
quint16 ctpid; VlanFlags vlanFlags()
quint16 cvlanPrio : 3; {
quint16 cvlanCfi : 1; VlanFlags f;
quint16 cvlanId : 13;
quint16 stpid; if (d.is_cvlan_tagged()) f|= VlanCvlanTagged;
quint16 svlanPrio : 3; if (d.is_ctpid_override()) f|= VlanCtpidOverride;
quint16 svlanCfi : 1; if (d.is_svlan_tagged()) f|= VlanSvlanTagged;
quint16 svlanId : 13; if (d.is_stpid_override()) f|= VlanStpidOverride;
#endif
return f;
}
bool setVlanFlags(VlanFlags vlanFlags)
{
d.set_is_cvlan_tagged(vlanFlags.testFlag(VlanCvlanTagged));
d.set_is_ctpid_override(vlanFlags.testFlag(VlanCtpidOverride));
d.set_is_svlan_tagged(vlanFlags.testFlag(VlanSvlanTagged));
d.set_is_stpid_override(vlanFlags.testFlag(VlanStpidOverride));
return true;
}
bool isUntagged()
{
if (!d.is_cvlan_tagged() && !d.is_svlan_tagged())
return true;
else
return false;
}
bool isSingleTagged()
{
if (( d.is_cvlan_tagged() && !d.is_svlan_tagged()) ||
(!d.is_cvlan_tagged() && d.is_svlan_tagged()) )
return true;
else
return false;
}
bool isDoubleTagged()
{
if (d.is_cvlan_tagged() && d.is_svlan_tagged())
return true;
else
return false;
}
// CVLAN
quint16 ctpid()
{ return d.ctpid(); }
bool setCtpid(quint16 ctpid)
{ d.set_ctpid(ctpid); return true; }
quint8 cvlanPrio()
{ return (d.cvlan_tag() >> 13); }
bool setCvlanPrio(quint8 cvlanPrio)
{ d.set_cvlan_tag((d.cvlan_tag() & 0x1FFF) | ((cvlanPrio & 0x3) << 13));
return true; }
quint8 cvlanCfi()
{ return ((d.cvlan_tag() & 0x1000) >> 12); }
bool setCvlanCfi(quint8 cvlanCfi)
{ d.set_cvlan_tag((d.cvlan_tag() & 0xEFFF) | ((cvlanCfi & 0x01) << 12));
return true; }
quint16 cvlanId()
{ return (d.cvlan_tag() & 0x0FFF); }
bool setCvlanId(quint16 cvlanId)
{ d.set_cvlan_tag((d.cvlan_tag() & 0xF000) | ((cvlanId & 0x0FFF)));
return true; }
// SVLAN
quint16 stpid()
{ return d.stpid(); }
bool setStpid(quint16 stpid)
{ d.set_stpid(stpid); return true; }
quint8 svlanPrio()
{ return (d.svlan_tag() >> 13); }
bool setSvlanPrio(quint8 svlanPrio)
{ d.set_svlan_tag((d.svlan_tag() & 0x1FFF) | ((svlanPrio & 0x3) << 13));
return true; }
quint8 svlanCfi()
{ return ((d.svlan_tag() & 0x1000) >> 12); }
bool setSvlanCfi(quint8 svlanCfi)
{ d.set_svlan_tag((d.svlan_tag() & 0xEFFF) | ((svlanCfi & 0x01) << 12));
return true; }
quint16 svlanId()
{ return (d.svlan_tag() & 0x0FFF); }
bool setSvlanId(quint16 svlanId)
{ d.set_svlan_tag((d.svlan_tag() & 0xF000) | ((svlanId & 0x0FFF)));
return true; }
virtual QString protocolName()
{ return QString("Virtual Local Access Network"); }
QString protocolShortName()
{ return QString("VLAN"); }
int numFields();
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
// IP // IP
@ -198,6 +365,10 @@ private:
OstProto::Ip d; OstProto::Ip d;
public: public:
virtual ~IpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Ip ip) { d.MergeFrom(ip); return true; }
enum IpAddrMode { enum IpAddrMode {
IpAddrFixed, IpAddrFixed,
@ -209,8 +380,8 @@ public:
enum IpFlag { enum IpFlag {
IpOverrideVersion = 0x01, IpOverrideVersion = 0x01,
IpOverrideHdrLen = 0x02, IpOverrideHdrLen = 0x02,
IpOverrideTotLen = 0x03, IpOverrideTotLen = 0x04,
IpOverrideCksum = 0x04 IpOverrideCksum = 0x08
}; };
Q_DECLARE_FLAGS(IpFlags, IpFlag); Q_DECLARE_FLAGS(IpFlags, IpFlag);
@ -346,14 +517,31 @@ public:
bool setDstIpMask(quint32 dstIpMask) bool setDstIpMask(quint32 dstIpMask)
{ d.set_dst_ip_mask(dstIpMask); return true; } { d.set_dst_ip_mask(dstIpMask); return true; }
// TODO: Options // TODO(LOW): Options
virtual QString protocolName()
{ return QString("Internet Protocol version 4"); }
QString protocolShortName()
{ return QString("IPv4"); }
int numFields()
{ return 12; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(IpProtocol::IpFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(IpProtocol::IpFlags)
class ArpProtocol: public AbstractProtocol class ArpProtocol: public AbstractProtocol
{ {
// TODO: ARP // TODO(LOW): ARP
OstProto::Arp d;
public:
virtual ~ArpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Arp arp) { d.MergeFrom(arp); return true; }
}; };
// TCP // TCP
@ -363,6 +551,11 @@ private:
OstProto::Tcp d; OstProto::Tcp d;
public: public:
virtual ~TcpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Tcp tcp) { d.MergeFrom(tcp); return true; }
enum TcpFlag enum TcpFlag
{ {
TcpOverrideHdrLen = 0x01, TcpOverrideHdrLen = 0x01,
@ -402,7 +595,7 @@ public:
quint16 dstPort() quint16 dstPort()
{ return d.dst_port(); } { return d.dst_port(); }
bool setdstPort(quint16 dstPort) bool setDstPort(quint16 dstPort)
{ d.set_dst_port(dstPort); return true; } { d.set_dst_port(dstPort); return true; }
quint32 seqNum() quint32 seqNum()
@ -426,7 +619,7 @@ public:
{ d.set_hdrlen_rsvd((d.hdrlen_rsvd() & 0xF0) | rsvd); return true; } { d.set_hdrlen_rsvd((d.hdrlen_rsvd() & 0xF0) | rsvd); return true; }
// TODO: convert to enum maybe? // TODO(MED): convert to enum maybe?
quint8 flags() quint8 flags()
{ return d.flags(); } { return d.flags(); }
bool setFlags(quint8 flags) bool setFlags(quint8 flags)
@ -448,11 +641,21 @@ public:
bool setCksum(quint16 cksum) bool setCksum(quint16 cksum)
{ d.set_cksum(cksum); return true; } { d.set_cksum(cksum); return true; }
quint16 urg_ptr() quint16 urgPtr()
{ return d.urg_ptr(); } { return d.urg_ptr(); }
bool seturg_ptr(quint16 urg_ptr) bool setUrgPtr(quint16 urg_ptr)
{ d.set_urg_ptr(urg_ptr); return true; } { d.set_urg_ptr(urg_ptr); return true; }
virtual QString protocolName()
{ return QString("Transmission Control Protocol"); }
QString protocolShortName()
{ return QString("TCP"); }
int numFields()
{ return 10; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(TcpProtocol::TcpFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(TcpProtocol::TcpFlags)
@ -464,6 +667,11 @@ private:
OstProto::Udp d; OstProto::Udp d;
public: public:
virtual ~UdpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Udp udp) { d.MergeFrom(udp); return true; }
enum UdpFlag enum UdpFlag
{ {
UdpOverrideTotLen = 0x01, UdpOverrideTotLen = 0x01,
@ -503,7 +711,7 @@ public:
quint16 dstPort() quint16 dstPort()
{ return d.dst_port(); } { return d.dst_port(); }
bool setdstPort(quint16 dstPort) bool setDstPort(quint16 dstPort)
{ d.set_dst_port(dstPort); return true; } { d.set_dst_port(dstPort); return true; }
quint16 totLen() quint16 totLen()
@ -516,32 +724,78 @@ public:
bool setCksum(quint16 cksum) bool setCksum(quint16 cksum)
{ d.set_cksum(cksum); return true; } { d.set_cksum(cksum); return true; }
virtual QString protocolName()
{ return QString("User Datagram Protocol"); }
QString protocolShortName()
{ return QString("UDP"); }
int numFields()
{ return 4; }
QString fieldName(int index);
QString fieldTextValue(int index);
QByteArray fieldRawValue(int index);
}; };
class IcmpProtocol { class IcmpProtocol : public AbstractProtocol
// TODO: ICMP {
// TODO(LOW): ICMP
OstProto::Icmp d;
public:
virtual ~IcmpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Icmp icmp) { d.MergeFrom(icmp); return true; }
}; };
class IgmpProtocol { class IgmpProtocol : public AbstractProtocol
// TODO: IGMP {
// TODO(LOW): IGMP
OstProto::Igmp d;
public:
virtual ~IgmpProtocol() {}
virtual ::google::protobuf::Message& data() {return d;}
bool update(OstProto::Igmp igmp) { d.MergeFrom(igmp); return true; }
}; };
class Stream { class Stream {
static quint32 mAllocId;
quint32 mId; quint32 mId;
OstProto::StreamCore *mCore; OstProto::StreamCore *mCore;
UnknownProtocol *mUnknown;
MacProtocol *mMac; MacProtocol *mMac;
IpProtocol *mIp;
#if 0 LlcProtocol *mLlc;
friend class StreamConfigDialog; SnapProtocol *mSnap;
friend class StreamModel; Eth2Protocol *mEth2;
friend class PacketModel; VlanProtocol *mVlan;
#endif
IpProtocol *mIp;
ArpProtocol *mArp;
TcpProtocol *mTcp;
UdpProtocol *mUdp;
IcmpProtocol *mIcmp;
IgmpProtocol *mIgmp;
public:
MacProtocol* mac() { return mMac; }
LlcProtocol* llc() { return mLlc; }
SnapProtocol* snap() { return mSnap; }
Eth2Protocol* eth2() { return mEth2; }
VlanProtocol* vlan() { return mVlan; }
IpProtocol* ip() { return mIp; }
ArpProtocol* arp() { return mArp; }
TcpProtocol* tcp() { return mTcp; }
UdpProtocol* udp() { return mUdp; }
IcmpProtocol* icmp() { return mIcmp; }
IgmpProtocol* igmp() { return mIgmp; }
public: public:
enum FrameType { enum FrameType {
@ -566,17 +820,68 @@ public:
e_fl_random e_fl_random
}; };
enum L3Proto {
e_l3_none,
e_l3_ip,
e_l3_arp,
};
enum L4Proto {
e_l4_none,
e_l4_tcp,
e_l4_udp,
e_l4_icmp,
e_l4_igmp,
};
// ------------------------------------------------------- // -------------------------------------------------------
// Methods // Methods
// ------------------------------------------------------- // -------------------------------------------------------
Stream(); Stream();
bool operator < (const Stream &s) const
{ return(mCore->ordinal() < s.mCore->ordinal()); }
bool update(OstProto::Stream *stream)
{
mCore->MergeFrom(stream->core());
mMac->update(stream->mac());
mLlc->update(stream->llc());
mSnap->update(stream->snap());
mEth2->update(stream->eth2());
mVlan->update(stream->vlan());
mIp->update(stream->ip());
mArp->update(stream->arp());
mTcp->update(stream->tcp());
mUdp->update(stream->udp());
mIcmp->update(stream->icmp());
mIgmp->update(stream->igmp());
// FIXME(MED): Re-eval why not store complete OstProto::Stream
// instead of components
return true;
}
void getConfig(uint portId, OstProto::Stream *s);
quint32 id() quint32 id()
{ return mId;} { return mId;}
bool setId(quint32 id)
{ mId = id; return true;}
#if 0 // FIXME(HI): needed?
quint32 portId()
{ return mCore->port_id();}
bool setPortId(quint32 id)
{ mCore->set_port_id(id); return true;}
#endif
quint32 ordinal() quint32 ordinal()
{ return mCore->ordinal();} { return mCore->ordinal();}
bool setOrderdinal(quint32 ordinal) bool setOrdinal(quint32 ordinal)
{ mCore->set_ordinal(ordinal); return true; } { mCore->set_ordinal(ordinal); return true; }
bool isEnabled() const bool isEnabled() const
@ -606,6 +911,11 @@ public:
bool setPattern(quint32 pattern) bool setPattern(quint32 pattern)
{ mCore->set_pattern(pattern); return true; } { mCore->set_pattern(pattern); return true; }
// TODO(HI) : ?????
#if 0
quint16 dataStartOfs;
#endif
// Frame Length (includes CRC) // Frame Length (includes CRC)
FrameLengthMode lenMode() FrameLengthMode lenMode()
{ return (FrameLengthMode) mCore->len_mode(); } { return (FrameLengthMode) mCore->len_mode(); }
@ -628,25 +938,33 @@ public:
bool setFrameLenMax(quint16 frameLenMax) bool setFrameLenMax(quint16 frameLenMax)
{ mCore->set_frame_len_max(frameLenMax); return true; } { mCore->set_frame_len_max(frameLenMax); return true; }
// TODO L3Proto l3Proto()
{ return (L3Proto) mCore->l3_proto(); }
bool setL3Proto(L3Proto l3Proto)
{ mCore->set_l3_proto((OstProto::StreamCore::L3Proto) l3Proto);
return true; }
L4Proto l4Proto()
{ return (L4Proto) mCore->l4_proto(); }
bool setL4Proto(L4Proto l4Proto)
{ mCore->set_l4_proto((OstProto::StreamCore::L4Proto) l4Proto);
return true; }
//---------------------------------------------------------------
// Methods for use by Packet Model
//---------------------------------------------------------------
QList<int> selectedProtocols;
int numProtocols();
#if 0 #if 0
quint16 dataStartOfs; int protocolId(int index);
int protocolIndex(int id);
#endif #endif
AbstractProtocol* protocol(int index);
MacProtocol* mac() { return mMac; }
IpProtocol* ip() { return mIp; }
private: private:
#if 0 void updateSelectedProtocols();
void InitDefaultMeta();
void InitDefaultProto();
void InitDefaultL2();
void InitDefaultL3();
void InitDefaultL3Ip();
void InitDefaultL4();
void InitDefaultL4Tcp();
void InitDefaultL4Udp();
#endif
}; };
#endif #endif

View File

@ -2,34 +2,31 @@
#include "streamconfigdialog.h" #include "streamconfigdialog.h"
#include "stream.h" #include "stream.h"
// TODO(LOW): Remove
#include "modeltest.h" #include "modeltest.h"
StreamConfigDialog::StreamConfigDialog(QList<Stream> *streamList, // TODO(HI): Write HexLineEdit::setNum() and num() and use it in
uint streamIndex, QWidget *parent) : QDialog (parent) // Load/Store stream methods
StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
QWidget *parent) : QDialog (parent), mPort(port)
{ {
setupUi(this); setupUi(this);
setupUiExtra(); setupUiExtra();
// FIXME(MED): Assumption that streamlist and streamIndex are valid //mpStreamList = streamList;
mpStreamList = streamList;
mCurrentStreamIndex = streamIndex; mCurrentStreamIndex = streamIndex;
LoadCurrentStream(); LoadCurrentStream();
mpPacketModel = new PacketModel(&((*mpStreamList)[mCurrentStreamIndex]), mpPacketModel = new PacketModel(&mPort.streamByIndex(mCurrentStreamIndex),
this); this);
tvPacketTree->setModel(mpPacketModel); tvPacketTree->setModel(mpPacketModel);
mpPacketModelTester = new ModelTest(mpPacketModel); mpPacketModelTester = new ModelTest(mpPacketModel);
tvPacketTree->header()->hide(); tvPacketTree->header()->hide();
qDebug("stream %p %d/%d loaded",
mpStreamList, mCurrentStreamIndex, mpStreamList->size());
// FIXME(MED): Enable this navigation // FIXME(MED): Enable this navigation
#if 0 pbPrev->setDisabled(true);
pbPrev->setDisabled((currStreamIdx == 0)); pbNext->setDisabled(true);
pbNext->setDisabled((currStreamIdx == 2));
#endif
} }
void StreamConfigDialog::setupUiExtra() void StreamConfigDialog::setupUiExtra()
@ -304,7 +301,7 @@ void StreamConfigDialog::on_lePattern_editingFinished()
void StreamConfigDialog::LoadCurrentStream() void StreamConfigDialog::LoadCurrentStream()
{ {
Stream *pStream = &((*mpStreamList)[mCurrentStreamIndex]); Stream *pStream = &mPort.streamByIndex(mCurrentStreamIndex);
QString str; QString str;
qDebug("loading pStream %p", pStream); qDebug("loading pStream %p", pStream);
@ -342,19 +339,56 @@ void StreamConfigDialog::LoadCurrentStream()
break; break;
} }
// TODO leDsap->setText(uintToHexStr(pStream->llc()->dsap(), str, 1));
leSsap->setText(uintToHexStr(pStream->llc()->ssap(), str, 1));
leControl->setText(uintToHexStr(pStream->llc()->ctl(), str, 1));
leOui->setText(uintToHexStr(pStream->snap()->oui(), str, 3));
leType->setText(uintToHexStr(pStream->eth2()->type(), str, 2));
switch(pStream->l3Proto())
{
case Stream::e_l3_none:
rbL3None->setChecked(true);
break;
case Stream::e_l3_ip:
rbL3Ipv4->setChecked(true);
break;
case Stream::e_l3_arp:
rbL3Arp->setChecked(true);
break;
default:
qDebug("%s: unknown L3 Protocol %d", __FUNCTION__,
pStream->l3Proto());
}
switch(pStream->l4Proto())
{
case Stream::e_l4_none:
rbL4None->setChecked(true);
break;
case Stream::e_l4_tcp:
rbL4Tcp->setChecked(true);
break;
case Stream::e_l4_udp:
rbL4Udp->setChecked(true);
break;
case Stream::e_l4_icmp:
rbL4Icmp->setChecked(true);
break;
case Stream::e_l4_igmp:
rbL4Igmp->setChecked(true);
break;
default:
qDebug("%s: unknown l4 Protocol %d", __FUNCTION__,
pStream->l4Proto());
}
// PB (not needed anymore?)
#if 0 #if 0
leDsap->setText(uintToHexStr(pStream->proto.dsap, str, 1));
leSsap->setText(uintToHexStr(pStream->proto.ssap, str, 1));
leControl->setText(uintToHexStr(pStream->proto.ctl, str, 1));
leOui->setText(uintToHexStr((pStream->proto.ouiMsb << 16 + pStream->proto.ouiLshw), str, 3));
leType->setText(uintToHexStr(pStream->proto.etherType, str, 2));
// Check for specific supported protocols first ... // Check for specific supported protocols first ...
if (pStream->proto.etherType == ETH_TYP_IP) if (pStream->eth2()->type() == ETH_TYP_IP)
rbL3Ipv4->setChecked(TRUE); rbL3Ipv4->setChecked(TRUE);
else if (pStream->proto.etherType == ETH_TYP_ARP) else if (pStream->eth2()->type() == ETH_TYP_ARP)
rbL3Arp->setChecked(TRUE); rbL3Arp->setChecked(TRUE);
// ... then for None/Other // ... then for None/Other
@ -390,21 +424,29 @@ void StreamConfigDialog::LoadCurrentStream()
cmbSrcMacMode->setCurrentIndex(pStream->mac()->srcMacMode()); cmbSrcMacMode->setCurrentIndex(pStream->mac()->srcMacMode());
leSrcMacCount->setText(str.setNum(pStream->mac()->srcMacCount())); leSrcMacCount->setText(str.setNum(pStream->mac()->srcMacCount()));
leSrcMacStep->setText(str.setNum(pStream->mac()->srcMacStep())); leSrcMacStep->setText(str.setNum(pStream->mac()->srcMacStep()));
#if 0
cmbCvlanPrio->setCurrentIndex(pStream->l2.eth.cvlanPrio);
cmbCvlanCfi->setCurrentIndex(pStream->l2.eth.cvlanCfi);
leCvlanId->setText(str.setNum(pStream->l2.eth.cvlanId));
leCvlanTpid->setText(str.setNum(pStream->l2.eth.ctpid));
cbCvlanTpidOverride->setChecked((pStream->l2.eth.vlanMask & VM_CVLAN_TPID_OVERRIDE) > 0);
gbCvlan->setChecked((pStream->l2.eth.vlanMask & VM_CVLAN_TAGGED) > 0);
cmbSvlanPrio->setCurrentIndex(pStream->l2.eth.svlanPrio); {
cmbSvlanCfi->setCurrentIndex(pStream->l2.eth.svlanCfi); VlanProtocol *vlan = pStream->vlan();
leSvlanId->setText(str.setNum(pStream->l2.eth.svlanId)); VlanProtocol::VlanFlags f;
leSvlanTpid->setText(str.setNum(pStream->l2.eth.stpid));
cbSvlanTpidOverride->setChecked((pStream->l2.eth.vlanMask & VM_SVLAN_TPID_OVERRIDE) > 0); cmbCvlanPrio->setCurrentIndex(vlan->cvlanPrio());
gbSvlan->setChecked((pStream->l2.eth.vlanMask & VM_SVLAN_TAGGED) > 0); cmbCvlanCfi->setCurrentIndex(vlan->cvlanCfi());
#endif leCvlanId->setText(str.setNum(vlan->cvlanId()));
leCvlanTpid->setText(str.setNum(vlan->ctpid()));
cbCvlanTpidOverride->setChecked(vlan->vlanFlags().testFlag(
VlanProtocol::VlanCtpidOverride));
gbCvlan->setChecked(vlan->vlanFlags().testFlag(
VlanProtocol::VlanCvlanTagged));
cmbSvlanPrio->setCurrentIndex(vlan->svlanPrio());
cmbSvlanCfi->setCurrentIndex(vlan->svlanCfi());
leSvlanId->setText(str.setNum(vlan->svlanId()));
leSvlanTpid->setText(str.setNum(vlan->stpid()));
cbSvlanTpidOverride->setChecked(vlan->vlanFlags().testFlag(
VlanProtocol::VlanStpidOverride));
gbSvlan->setChecked(vlan->vlanFlags().testFlag(
VlanProtocol::VlanSvlanTagged));
}
} }
} }
@ -450,73 +492,75 @@ void StreamConfigDialog::LoadCurrentStream()
// L3 | ARP // L3 | ARP
{ {
// TODO // TODO(LOW)
} }
} }
#if 0
// L4 // L4
{ {
// L4 | TCP // L4 | TCP
{ {
leTcpSrcPort->setText(str.setNum(pStream->l4.tcp.srcPort)); leTcpSrcPort->setText(str.setNum(pStream->tcp()->srcPort()));
leTcpDstPort->setText(str.setNum(pStream->l4.tcp.dstPort)); leTcpDstPort->setText(str.setNum(pStream->tcp()->dstPort()));
leTcpSeqNum->setText(str.setNum(pStream->l4.tcp.seqNum)); leTcpSeqNum->setText(str.setNum(pStream->tcp()->seqNum()));
leTcpAckNum->setText(str.setNum(pStream->l4.tcp.ackNum)); leTcpAckNum->setText(str.setNum(pStream->tcp()->ackNum()));
leTcpHdrLen->setText(str.setNum(pStream->l4.tcp.hdrLen)); leTcpHdrLen->setText(str.setNum(pStream->tcp()->hdrLen()));
cbTcpHdrLenOverride->setChecked((pStream->l4.tcp.tcpMask & TM_OVERRIDE_HDRLEN) > 0); cbTcpHdrLenOverride->setChecked((pStream->tcp()->tcpFlags().
testFlag(TcpProtocol::TcpOverrideHdrLen)));
leTcpWindow->setText(str.setNum(pStream->l4.tcp.window)); leTcpWindow->setText(str.setNum(pStream->tcp()->window()));
leTcpCksum->setText(str.setNum(pStream->l4.tcp.cksum)); leTcpCksum->setText(str.setNum(pStream->tcp()->cksum()));
cbTcpCksumOverride->setChecked((pStream->l4.tcp.tcpMask & TM_OVERRIDE_CKSUM) > 0); cbTcpCksumOverride->setChecked((pStream->tcp()->tcpFlags().
testFlag(TcpProtocol::TcpOverrideCksum)));
leTcpUrgentPointer->setText(str.setNum(pStream->l4.tcp.urgPtr)); leTcpUrgentPointer->setText(str.setNum(pStream->tcp()->urgPtr()));
cbTcpFlagsUrg->setChecked((pStream->l4.tcp.flags & TCP_FLAG_URG) > 0); cbTcpFlagsUrg->setChecked((pStream->tcp()->flags() & TCP_FLAG_URG) > 0);
cbTcpFlagsAck->setChecked((pStream->l4.tcp.flags & TCP_FLAG_ACK) > 0); cbTcpFlagsAck->setChecked((pStream->tcp()->flags() & TCP_FLAG_ACK) > 0);
cbTcpFlagsPsh->setChecked((pStream->l4.tcp.flags & TCP_FLAG_PSH) > 0); cbTcpFlagsPsh->setChecked((pStream->tcp()->flags() & TCP_FLAG_PSH) > 0);
cbTcpFlagsRst->setChecked((pStream->l4.tcp.flags & TCP_FLAG_RST) > 0); cbTcpFlagsRst->setChecked((pStream->tcp()->flags() & TCP_FLAG_RST) > 0);
cbTcpFlagsSyn->setChecked((pStream->l4.tcp.flags & TCP_FLAG_SYN) > 0); cbTcpFlagsSyn->setChecked((pStream->tcp()->flags() & TCP_FLAG_SYN) > 0);
cbTcpFlagsFin->setChecked((pStream->l4.tcp.flags & TCP_FLAG_FIN) > 0); cbTcpFlagsFin->setChecked((pStream->tcp()->flags() & TCP_FLAG_FIN) > 0);
} }
// L4 | UDP // L4 | UDP
{ {
leUdpSrcPort->setText(str.setNum(pStream->l4.udp.srcPort)); leUdpSrcPort->setText(str.setNum(pStream->udp()->srcPort()));
leUdpDstPort->setText(str.setNum(pStream->l4.udp.dstPort)); leUdpDstPort->setText(str.setNum(pStream->udp()->dstPort()));
leUdpLength->setText(str.setNum(pStream->l4.udp.totLen)); leUdpLength->setText(str.setNum(pStream->udp()->totLen()));
cbUdpLengthOverride->setChecked((pStream->l4.udp.udpMask & UM_OVERRIDE_TOTLEN) > 0); cbUdpLengthOverride->setChecked((pStream->udp()->udpFlags().
testFlag(UdpProtocol::UdpOverrideTotLen)));
leUdpCksum->setText(str.setNum(pStream->l4.udp.cksum));
cbUdpCksumOverride->setChecked((pStream->l4.udp.udpMask & UM_OVERRIDE_CKSUM) > 0); leUdpCksum->setText(str.setNum(pStream->udp()->cksum()));
cbUdpCksumOverride->setChecked((pStream->udp()->udpFlags().
testFlag(UdpProtocol::UdpOverrideCksum)));
} }
// L4 | ICMP // L4 | ICMP
{ {
// TODO // TODO(LOW)
} }
// L4 | IGMP // L4 | IGMP
{ {
// TODO // TODO(LOW)
} }
} }
#endif
} }
void StreamConfigDialog::StoreCurrentStream() void StreamConfigDialog::StoreCurrentStream()
{ {
Stream *pStream = &(*mpStreamList)[mCurrentStreamIndex]; Stream *pStream = &mPort.streamByIndex(mCurrentStreamIndex);
QString str; QString str;
bool isOk; bool isOk;
qDebug("storing pStream %p", pStream); qDebug("storing pStream %p", pStream);
#if 1 // FIXME: Temp till we use protobuff accessors
// Meta Data // Meta Data
pStream->setPatternMode((Stream::DataPatternMode) cmbPatternMode->currentIndex()); pStream->setPatternMode((Stream::DataPatternMode) cmbPatternMode->currentIndex());
pStream->setPattern(lePattern->text().remove(QChar(' ')).toULong(&isOk, 16)); pStream->setPattern(lePattern->text().remove(QChar(' ')).toULong(&isOk, 16));
@ -525,7 +569,7 @@ void StreamConfigDialog::StoreCurrentStream()
pStream->setFrameLen(lePktLen->text().toULong(&isOk)); pStream->setFrameLen(lePktLen->text().toULong(&isOk));
pStream->setFrameLenMin(lePktLenMin->text().toULong(&isOk)); pStream->setFrameLenMin(lePktLenMin->text().toULong(&isOk));
pStream->setFrameLenMax(lePktLenMax->text().toULong(&isOk)); pStream->setFrameLenMax(lePktLenMax->text().toULong(&isOk));
#endif
// Protocols // Protocols
{ {
if (rbFtNone->isChecked()) if (rbFtNone->isChecked())
@ -540,28 +584,39 @@ void StreamConfigDialog::StoreCurrentStream()
pStream->setFrameType(Stream::e_ft_snap); pStream->setFrameType(Stream::e_ft_snap);
qDebug("store ft(%d)\n", pStream->frameType()); qDebug("store ft(%d)\n", pStream->frameType());
#if 0 pStream->llc()->setDsap(leDsap->text().remove(QChar(' ')).toULong(&isOk, 16));
pStream->proto.dsap = leDsap->text().remove(QChar(' ')).toULong(&isOk, 16); pStream->llc()->setSsap(leSsap->text().remove(QChar(' ')).toULong(&isOk, 16));
pStream->proto.ssap = leSsap->text().remove(QChar(' ')).toULong(&isOk, 16); pStream->llc()->setCtl(leControl->text().remove(QChar(' ')).toULong(&isOk, 16));
pStream->proto.ctl = leControl->text().remove(QChar(' ')).toULong(&isOk, 16); pStream->snap()->setOui(leOui->text().remove(QChar(' ')).toULong(&isOk, 16));
pStream->proto.ouiMsb = leOui->text().remove(QChar(' ')).toULong(&isOk, 16) >> 16; pStream->eth2()->setType(leType->text().remove(QChar(' ')).toULong(&isOk, 16));
pStream->proto.ouiLshw = 0x0000FFFF & leOui->text().remove(QChar(' ')).toULong(&isOk, 16);
pStream->proto.etherType = leType->text().remove(QChar(' ')).toULong(&isOk, 16);
pStream->proto.ipProto = leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16);
// Just check for None/Other - no need to do anything for specific supported protocols
pStream->proto.protoMask = 0;
if (rbL3None->isChecked()) if (rbL3None->isChecked())
pStream->proto.protoMask |= PM_L3_PROTO_NONE; pStream->setL3Proto(Stream::e_l3_none);
else if (rbL3Other->isChecked()) else if (rbL3Ipv4->isChecked())
pStream->proto.protoMask |= PM_L3_PROTO_OTHER; pStream->setL3Proto(Stream::e_l3_ip);
else if (rbL3Arp->isChecked())
pStream->setL3Proto(Stream::e_l3_arp);
else
{
qCritical("No L3 Protocol??? Problem in Code!!!");
pStream->setL3Proto(Stream::e_l3_none);
}
if (rbL4None->isChecked()) if (rbL4None->isChecked())
pStream->proto.protoMask |= PM_L4_PROTO_NONE; pStream->setL4Proto(Stream::e_l4_none);
else if (rbL4Other->isChecked()) else if (rbL4Tcp->isChecked())
pStream->proto.protoMask |= PM_L4_PROTO_OTHER; pStream->setL4Proto(Stream::e_l4_tcp);
#endif else if (rbL4Udp->isChecked())
pStream->setL4Proto(Stream::e_l4_udp);
else if (rbL4Icmp->isChecked())
pStream->setL4Proto(Stream::e_l4_icmp);
else if (rbL4Igmp->isChecked())
pStream->setL4Proto(Stream::e_l4_igmp);
else
{
qCritical("No L4 Protocol??? Problem in Code!!!");
pStream->setL4Proto(Stream::e_l4_none);
}
} }
// L2 // L2
@ -587,27 +642,30 @@ void StreamConfigDialog::StoreCurrentStream()
leSrcMacStep->text().toULong(&isOk)); leSrcMacStep->text().toULong(&isOk));
#if 0 {
pStream->l2.eth.vlanMask = 0; VlanProtocol *vlan = pStream->vlan();
VlanProtocol::VlanFlags f = 0;
pStream->l2.eth.cvlanPrio = cmbCvlanPrio->currentIndex(); vlan->setCvlanPrio(cmbCvlanPrio->currentIndex());
pStream->l2.eth.cvlanCfi = cmbCvlanCfi->currentIndex(); vlan->setCvlanCfi(cmbCvlanCfi->currentIndex());
pStream->l2.eth.cvlanId = leCvlanId->text().toULong(&isOk); vlan->setCvlanId(leCvlanId->text().toULong(&isOk));
pStream->l2.eth.ctpid = leCvlanTpid->text().remove(QChar(' ')).toULong(&isOk); vlan->setCtpid(leCvlanTpid->text().remove(QChar(' ')).toULong(&isOk));
if (cbCvlanTpidOverride->isChecked()) if (cbCvlanTpidOverride->isChecked())
pStream->l2.eth.vlanMask |= VM_CVLAN_TPID_OVERRIDE; f |= VlanProtocol::VlanCtpidOverride;
if (gbCvlan->isChecked()) if (gbCvlan->isChecked())
pStream->l2.eth.vlanMask |= VM_CVLAN_TAGGED; f |= VlanProtocol::VlanCvlanTagged;
pStream->l2.eth.svlanPrio = cmbSvlanPrio->currentIndex(); vlan->setSvlanPrio(cmbSvlanPrio->currentIndex());
pStream->l2.eth.svlanCfi = cmbSvlanCfi->currentIndex(); vlan->setSvlanCfi(cmbSvlanCfi->currentIndex());
pStream->l2.eth.svlanId = leSvlanId->text().toULong(&isOk); vlan->setSvlanId(leSvlanId->text().toULong(&isOk));
pStream->l2.eth.stpid = leSvlanTpid->text().remove(QChar(' ')).toULong(&isOk); vlan->setStpid(leSvlanTpid->text().remove(QChar(' ')).toULong(&isOk));
if (cbSvlanTpidOverride->isChecked()) if (cbSvlanTpidOverride->isChecked())
pStream->l2.eth.vlanMask |= VM_SVLAN_TPID_OVERRIDE; f |= VlanProtocol::VlanStpidOverride;
if (gbSvlan->isChecked()) if (gbSvlan->isChecked())
pStream->l2.eth.vlanMask |= VM_SVLAN_TAGGED; f |= VlanProtocol::VlanSvlanTagged;
#endif
vlan->setVlanFlags(f);
}
} }
} }
@ -616,7 +674,8 @@ void StreamConfigDialog::StoreCurrentStream()
// L3 | IP // L3 | IP
{ {
IpProtocol *ip = pStream->ip(); IpProtocol *ip = pStream->ip();
IpProtocol::IpFlags f; IpProtocol::IpFlags f = 0;
int ff = 0;
ip->setVer(leIpVersion->text().toULong(&isOk)); ip->setVer(leIpVersion->text().toULong(&isOk));
if (cbIpVersionOverride->isChecked()) if (cbIpVersionOverride->isChecked())
@ -634,7 +693,6 @@ void StreamConfigDialog::StoreCurrentStream()
ip->setId(leIpId->text().remove(QChar(' ')).toULong(&isOk, 16)); ip->setId(leIpId->text().remove(QChar(' ')).toULong(&isOk, 16));
ip->setFragOfs(leIpFragOfs->text().toULong(&isOk)); ip->setFragOfs(leIpFragOfs->text().toULong(&isOk));
int ff;
if (cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF; if (cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF;
if (cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF; if (cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF;
ip->setFlags(ff); ip->setFlags(ff);
@ -661,71 +719,79 @@ void StreamConfigDialog::StoreCurrentStream()
// L3 | ARP // L3 | ARP
{ {
// TODO // TODO(LOW)
} }
} }
// TODO
#if 0
// L4 // L4
{ {
// L4 | TCP // L4 | TCP
{ {
pStream->l4.tcp.tcpMask = 0; TcpProtocol *tcp = pStream->tcp();
TcpProtocol::TcpFlags f = 0;
int ff = 0;
pStream->l4.tcp.srcPort = leTcpSrcPort->text().toULong(&isOk); tcp->setSrcPort(leTcpSrcPort->text().toULong(&isOk));
pStream->l4.tcp.dstPort = leTcpDstPort->text().toULong(&isOk); tcp->setDstPort(leTcpDstPort->text().toULong(&isOk));
pStream->l4.tcp.seqNum = leTcpSeqNum->text().toULong(&isOk); tcp->setSeqNum(leTcpSeqNum->text().toULong(&isOk));
pStream->l4.tcp.ackNum = leTcpAckNum->text().toULong(&isOk); tcp->setAckNum(leTcpAckNum->text().toULong(&isOk));
pStream->l4.tcp.hdrLen = leTcpHdrLen->text().toULong(&isOk); tcp->setHdrLen(leTcpHdrLen->text().toULong(&isOk));
if (cbTcpHdrLenOverride->isChecked()) if (cbTcpHdrLenOverride->isChecked())
pStream->l4.tcp.tcpMask |= TM_OVERRIDE_HDRLEN; f |= TcpProtocol::TcpOverrideHdrLen;
pStream->l4.tcp.window = leTcpWindow->text().toULong(&isOk); tcp->setWindow(leTcpWindow->text().toULong(&isOk));
pStream->l4.tcp.cksum = leTcpCksum->text().remove(QChar(' ')).toULong(&isOk); tcp->setCksum(leTcpCksum->text().remove(QChar(' ')).toULong(&isOk));
if (cbTcpCksumOverride->isChecked()) if (cbTcpCksumOverride->isChecked())
pStream->l4.tcp.tcpMask |= TM_OVERRIDE_CKSUM; f |= TcpProtocol::TcpOverrideCksum;
pStream->l4.tcp.urgPtr = leTcpUrgentPointer->text().toULong(&isOk); tcp->setUrgPtr(leTcpUrgentPointer->text().toULong(&isOk));
pStream->l4.tcp.flags = 0; if (cbTcpFlagsUrg->isChecked()) ff |= TCP_FLAG_URG;
if (cbTcpFlagsUrg->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_URG; if (cbTcpFlagsAck->isChecked()) ff |= TCP_FLAG_ACK;
if (cbTcpFlagsAck->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_ACK; if (cbTcpFlagsPsh->isChecked()) ff |= TCP_FLAG_PSH;
if (cbTcpFlagsPsh->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_PSH; if (cbTcpFlagsRst->isChecked()) ff |= TCP_FLAG_RST;
if (cbTcpFlagsRst->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_RST; if (cbTcpFlagsSyn->isChecked()) ff |= TCP_FLAG_SYN;
if (cbTcpFlagsSyn->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_SYN; if (cbTcpFlagsFin->isChecked()) ff |= TCP_FLAG_FIN;
if (cbTcpFlagsFin->isChecked()) pStream->l4.tcp.flags |= TCP_FLAG_FIN; tcp->setFlags(ff);
tcp->setTcpFlags(f);
} }
// L4 | UDP // L4 | UDP
{ {
pStream->l4.udp.udpMask = 0; UdpProtocol *udp = pStream->udp();
UdpProtocol::UdpFlags f = 0;
pStream->l4.udp.srcPort = leUdpSrcPort->text().toULong(&isOk); udp->setSrcPort(leUdpSrcPort->text().toULong(&isOk));
pStream->l4.udp.dstPort = leUdpDstPort->text().toULong(&isOk); udp->setDstPort(leUdpDstPort->text().toULong(&isOk));
pStream->l4.udp.totLen = leUdpLength->text().toULong(&isOk); udp->setTotLen(leUdpLength->text().toULong(&isOk));
if (cbUdpLengthOverride->isChecked()) pStream->l4.udp.udpMask |= UM_OVERRIDE_TOTLEN;
pStream->l4.udp.cksum = leUdpCksum->text().remove(QChar(' ')).toULong(&isOk); if (cbUdpLengthOverride->isChecked())
if (cbUdpCksumOverride->isChecked()) pStream->l4.udp.udpMask |= UM_OVERRIDE_CKSUM; f |= UdpProtocol::UdpOverrideTotLen;
udp->setCksum(leUdpCksum->text().remove(QChar(' ')).toULong(&isOk));
if (cbUdpCksumOverride->isChecked())
f |= UdpProtocol::UdpOverrideCksum;
udp->setUdpFlags(f);
} }
// L4 | ICMP // L4 | ICMP
{ {
// TODO // TODO)(LOW)
} }
// L4 | IGMP // L4 | IGMP
{ {
// TODO // TODO(LOW)
} }
} }
#endif
} }
void StreamConfigDialog::on_pbOk_clicked() void StreamConfigDialog::on_pbOk_clicked()
{ {
// Store dialog contents into stream // Store dialog contents into stream

View File

@ -3,6 +3,7 @@
#include <QDialog> #include <QDialog>
#include "ui_streamconfigdialog.h" #include "ui_streamconfigdialog.h"
#include "port.h"
#include "stream.h" #include "stream.h"
#include "packetmodel.h" #include "packetmodel.h"
#include "modeltest.h" #include "modeltest.h"
@ -17,16 +18,18 @@
** **
*/ */
class StreamConfigDialog : public QDialog, public Ui::StreamConfigDialog class StreamConfigDialog : public QDialog, public Ui::StreamConfigDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
StreamConfigDialog(QList<Stream> *streamList, uint streamIndex, StreamConfigDialog(Port &port, uint streamIndex, QWidget *parent = 0);
QWidget *parent = 0);
~StreamConfigDialog(); ~StreamConfigDialog();
private: private:
QList<Stream> *mpStreamList; //QList<Stream> *mpStreamList;
Port& mPort;
uint mCurrentStreamIndex; uint mCurrentStreamIndex;
PacketModel *mpPacketModel; PacketModel *mpPacketModel;
ModelTest *mpPacketModelTester; ModelTest *mpPacketModelTester;

View File

@ -191,7 +191,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<item row="1" column="0" colspan="3" > <item row="1" column="0" colspan="3" >
<widget class="QTabWidget" name="twProto" > <widget class="QTabWidget" name="twProto" >
<property name="currentIndex" > <property name="currentIndex" >
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_7" > <widget class="QWidget" name="tab_7" >
<attribute name="title" > <attribute name="title" >
@ -390,6 +390,9 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</item> </item>
<item> <item>
<widget class="QRadioButton" name="rbL3Other" > <widget class="QRadioButton" name="rbL3Other" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" > <property name="text" >
<string>Other</string> <string>Other</string>
</property> </property>

View File

@ -15,7 +15,7 @@ int StreamModel::rowCount(const QModelIndex &parent) const
return 0; return 0;
if (mCurrentPort) if (mCurrentPort)
return mCurrentPort->mStreams.size(); return mCurrentPort->numStreams();
else else
return 0; return 0;
} }
@ -53,7 +53,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
// Check for row/column limits // Check for row/column limits
if (index.row() >= mCurrentPort->mStreams.size()) if (index.row() >= mCurrentPort->numStreams())
return QVariant(); return QVariant();
if (index.column() >= StreamMaxFields) if (index.column() >= StreamMaxFields)
@ -80,7 +80,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const
case StreamName: case StreamName:
{ {
if ((role == Qt::DisplayRole) || (role == Qt::EditRole)) if ((role == Qt::DisplayRole) || (role == Qt::EditRole))
return mCurrentPort->mStreams[index.row()].name(); return mCurrentPort->streamByIndex(index.row()).name();
else else
return QVariant(); return QVariant();
break; break;
@ -94,7 +94,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const
#endif #endif
if ((role == Qt::CheckStateRole) || (role == Qt::EditRole)) if ((role == Qt::CheckStateRole) || (role == Qt::EditRole))
{ {
if (mCurrentPort->mStreams[index.row()].isEnabled()) if (mCurrentPort->streamByIndex(index.row()).isEnabled())
return Qt::Checked; return Qt::Checked;
else else
return Qt::Unchecked; return Qt::Unchecked;
@ -121,11 +121,11 @@ bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int r
switch (index.column()) switch (index.column())
{ {
case StreamName: case StreamName:
mCurrentPort->mStreams[index.row()].setName(value.toString()); mCurrentPort->streamByIndex(index.row()).setName(value.toString());
return true; return true;
break; break;
case StreamStatus: case StreamStatus:
mCurrentPort->mStreams[index.row()].setIsEnabled(value.toBool()); mCurrentPort->streamByIndex(index.row()).setIsEnabled(value.toBool());
return true; return true;
break; break;
@ -178,7 +178,7 @@ bool StreamModel::insertRows(int row, int count, const QModelIndex &parent)
qDebug("insertRows() count = %d", count); qDebug("insertRows() count = %d", count);
beginInsertRows(QModelIndex(), row, row+count-1); beginInsertRows(QModelIndex(), row, row+count-1);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
mCurrentPort->mStreams.insert(row, Stream()); mCurrentPort->newStreamAt(row);
endInsertRows(); endInsertRows();
return true; return true;
@ -191,8 +191,7 @@ bool StreamModel::removeRows(int row, int count, const QModelIndex &parent)
beginRemoveRows(QModelIndex(), row, row+count-1); beginRemoveRows(QModelIndex(), row, row+count-1);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
// FIXME(HIGH): do we need to free the removed stream? mCurrentPort->deleteStreamAt(row);
mCurrentPort->mStreams.removeAt(row);
} }
endRemoveRows(); endRemoveRows();

View File

@ -37,9 +37,11 @@ class StreamModel : public QAbstractTableModel
bool removeRows (int row, int count, bool removeRows (int row, int count,
const QModelIndex & parent = QModelIndex()); const QModelIndex & parent = QModelIndex());
#if 0 // CleanedUp!
// FIXME(HIGH): This *is* like a kludge // FIXME(HIGH): This *is* like a kludge
QList<Stream>* currentPortStreamList() QList<Stream>* currentPortStreamList()
{ return &mCurrentPort->mStreams; } { return &mCurrentPort->mStreams; }
#endif
public slots: public slots:
void setCurrentPortIndex(const QModelIndex &current); void setCurrentPortIndex(const QModelIndex &current);

View File

@ -151,18 +151,18 @@ message StreamCore {
enum L3Proto { enum L3Proto {
e_l3_none = 0; e_l3_none = 0;
e_l3_other = 1; e_l3_ip = 1;
e_l3_ip = 2; e_l3_arp = 2;
e_l3_arp = 3; //e_l3_other = 3;
} }
enum L4Proto { enum L4Proto {
e_l4_none = 0; e_l4_none = 0;
e_l4_other = 1; e_l4_tcp = 1;
e_l4_tcp = 2; e_l4_udp = 2;
e_l4_udp = 3; e_l4_icmp = 3;
e_l4_icmp = 4; e_l4_igmp = 4;
e_l4_igmp = 5; //e_l4_other = 5;
} }
enum DataPatternMode { enum DataPatternMode {
@ -202,20 +202,21 @@ message StreamCore {
} }
message StreamId { message StreamId {
required uint32 port_id = 1; required uint32 id = 1;
required uint32 stream_id = 2;
} }
message Stream { message Stream {
required StreamId id = 1; required StreamId stream_id = 1;
optional StreamCore core = 2; optional StreamCore core = 2;
// Protocol data - L2 // Protocol data - L2
optional Mac mac = 51; optional Mac mac = 51;
optional Llc llc = 52; optional Llc llc = 52;
optional Snap snap = 53; optional Snap snap = 53;
optional Eth2 eth2 = 54; optional Eth2 eth2 = 54;
optional Vlan vlan = 55;
// Protocol data - L3 // Protocol data - L3
optional Ip ip = 61; optional Ip ip = 61;
@ -237,17 +238,22 @@ message Ack {
// TODO // TODO
} }
message PortId {
required uint32 id = 1;
}
message PortIdList { message PortIdList {
repeated uint32 port_id = 1; repeated PortId port_id = 1;
} }
message StreamIdList { message StreamIdList {
repeated StreamId id = 1; required PortId port_id = 1;
repeated StreamId stream_id = 2;
} }
message PortConfig { message Port {
required uint32 port_id = 1; required PortId port_id = 1;
optional string name = 2; optional string name = 2;
optional string description = 3; optional string description = 3;
optional bool is_enabled = 4; optional bool is_enabled = 4;
@ -256,11 +262,12 @@ message PortConfig {
} }
message PortConfigList { message PortConfigList {
repeated PortConfig list = 1; repeated Port port = 1;
} }
message StreamConfigList { message StreamConfigList {
repeated Stream stream = 1; required PortId port_id = 1;
repeated Stream stream = 2;
} }
message CaptureBuffer { message CaptureBuffer {
@ -283,7 +290,7 @@ service OstService {
rpc getPortIdList(Void) returns (PortIdList); rpc getPortIdList(Void) returns (PortIdList);
rpc getPortConfig(PortIdList) returns (PortConfigList); rpc getPortConfig(PortIdList) returns (PortConfigList);
rpc getStreamIdList(PortIdList) returns (StreamIdList); rpc getStreamIdList(PortId) returns (StreamIdList);
rpc getStreamConfig(StreamIdList) returns (StreamConfigList); rpc getStreamConfig(StreamIdList) returns (StreamConfigList);
rpc addStream(StreamIdList) returns (Ack); rpc addStream(StreamIdList) returns (Ack);
rpc deleteStream(StreamIdList) returns (Ack); rpc deleteStream(StreamIdList) returns (Ack);

View File

@ -9,15 +9,100 @@
class PbHelper class PbHelper
{ {
public: public:
// FIXME: Change msg from * to &
void ForceSetSingularDefault(::google::protobuf::Message *msg)
{
const ::google::protobuf::Descriptor *desc;
::google::protobuf::Message::Reflection *refl;
qDebug("In %s", __FUNCTION__);
desc = msg->GetDescriptor();
refl = msg->GetReflection();
for (int i=0; i < desc->field_count(); i++)
{
const ::google::protobuf::FieldDescriptor *f;
f = desc->field(i);
// Ensure field is singular and not already set
if (f->label() ==
::google::protobuf::FieldDescriptor::LABEL_REPEATED)
continue;
if (refl->HasField(f))
continue;
switch(f->type())
{
case ::google::protobuf::FieldDescriptor::TYPE_DOUBLE:
refl->SetDouble(f, refl->GetDouble(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_FLOAT:
refl->SetFloat(f, refl->GetFloat(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_INT32:
case ::google::protobuf::FieldDescriptor::TYPE_SINT32:
case ::google::protobuf::FieldDescriptor::TYPE_SFIXED32:
refl->SetInt32(f, refl->GetInt32(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_INT64:
case ::google::protobuf::FieldDescriptor::TYPE_SINT64:
case ::google::protobuf::FieldDescriptor::TYPE_SFIXED64:
refl->SetInt64(f, refl->GetInt64(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_UINT32:
case ::google::protobuf::FieldDescriptor::TYPE_FIXED32:
refl->SetUInt32(f, refl->GetUInt32(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_UINT64:
case ::google::protobuf::FieldDescriptor::TYPE_FIXED64:
refl->SetUInt64(f, refl->GetUInt64(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_BOOL:
refl->SetBool(f, refl->GetBool(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_ENUM:
refl->SetEnum(f, refl->GetEnum(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_STRING:
case ::google::protobuf::FieldDescriptor::TYPE_BYTES:
refl->SetString(f, refl->GetString(f));
break;
case ::google::protobuf::FieldDescriptor::TYPE_MESSAGE:
case ::google::protobuf::FieldDescriptor::TYPE_GROUP:
ForceSetSingularDefault(refl->MutableMessage(f)); // recursion!
break;
default:
qDebug("unhandled Field Type");
break;
}
}
}
bool update( bool update(
::google::protobuf::Message *target, ::google::protobuf::Message *target,
::google::protobuf::Message *source) ::google::protobuf::Message *source)
{ {
// FIXME(HI): Depracate: use MergeFrom() directly
qDebug("In %s", __FUNCTION__);
target->MergeFrom(*source);
return true;
#if 0
::google::protobuf::Message::Reflection *sourceRef; ::google::protobuf::Message::Reflection *sourceRef;
::google::protobuf::Message::Reflection *targetRef; ::google::protobuf::Message::Reflection *targetRef;
std::vector<const ::google::protobuf::FieldDescriptor*> srcFieldList; std::vector<const ::google::protobuf::FieldDescriptor*> srcFieldList;
qDebug("In %s", __FUNCTION__);
if (source->GetDescriptor()->full_name() != if (source->GetDescriptor()->full_name() !=
target->GetDescriptor()->full_name()) target->GetDescriptor()->full_name())
@ -54,13 +139,10 @@ public:
break; break;
} }
} }
return true;
_error_exit: _error_exit:
qDebug("%s: error!", __FUNCTION__); qDebug("%s: error!", __FUNCTION__);
return false; return false;
#endif
} }
}; };
#endif #endif

View File

@ -65,12 +65,22 @@ void PbRpcChannel::CallMethod(
::google::protobuf::Message *response, ::google::protobuf::Message *response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
char msg[1024]; // FIXME: hardcoding char msg[4096]; // FIXME: hardcoding
char *p = (char *)&msg; char *p = (char *)&msg;
int len; int len;
qDebug("In %s", __FUNCTION__); qDebug("In %s", __FUNCTION__);
if (!req->IsInitialized())
{
qDebug("RpcChannel: missing required fields in request");
qDebug(req->InitializationErrorString().c_str());
controller->SetFailed("Required fields missing");
done->Run();
return;
}
pendingMethodId = method->index(); pendingMethodId = method->index();
this->controller=controller; this->controller=controller;
this->done=done; this->done=done;
@ -91,7 +101,7 @@ void PbRpcChannel::CallMethod(
*((quint16*)(p+4)) = HTONS(len); // len *((quint16*)(p+4)) = HTONS(len); // len
qDebug("client(%s) sending %d bytes encoding <%s>", __FUNCTION__, len+8, qDebug("client(%s) sending %d bytes encoding <%s>", __FUNCTION__, len+8,
req->ShortDebugString().c_str()); req->DebugString().c_str());
BUFDUMP(msg, len+8); BUFDUMP(msg, len+8);
mpSocket->write(msg, len + 8); mpSocket->write(msg, len + 8);
@ -99,7 +109,7 @@ void PbRpcChannel::CallMethod(
void PbRpcChannel::on_mpSocket_readyRead() void PbRpcChannel::on_mpSocket_readyRead()
{ {
char msg[1024]; // FIXME: hardcoding; char msg[4096]; // FIXME: hardcoding;
char *p = (char*)&msg; char *p = (char*)&msg;
int msgLen; int msgLen;
quint16 type, method, len, rsvd; quint16 type, method, len, rsvd;
@ -146,6 +156,13 @@ void PbRpcChannel::on_mpSocket_readyRead()
qDebug("client(%s): Parsed as %s", __FUNCTION__, qDebug("client(%s): Parsed as %s", __FUNCTION__,
response->DebugString().c_str()); response->DebugString().c_str());
if (!response->IsInitialized())
{
qDebug("RpcChannel: missing required fields in response");
qDebug(response->InitializationErrorString().c_str());
controller->SetFailed("Required fields missing");
}
pendingMethodId = -1; pendingMethodId = -1;
controller = NULL; controller = NULL;

View File

@ -37,7 +37,7 @@ bool RpcServer::registerService(::google::protobuf::Service *service,
void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcController) void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcController)
{ {
char msg[1024]; // FIXME: hardcoding char msg[4096]; // FIXME: hardcoding
char *p = (char *)&msg; char *p = (char *)&msg;
int len; int len;
@ -50,6 +50,13 @@ void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcCo
goto _exit; goto _exit;
} }
if (!resp->IsInitialized())
{
qDebug("response missing required fields!!");
qDebug(resp->InitializationErrorString().c_str());
goto _exit;
}
*((quint16*)(p+0)) = HTONS(PB_MSG_TYPE_RESPONSE); // type TODO:RESPONSE *((quint16*)(p+0)) = HTONS(PB_MSG_TYPE_RESPONSE); // type TODO:RESPONSE
*((quint16*)(p+2)) = HTONS(pendingMethodId); // method *((quint16*)(p+2)) = HTONS(pendingMethodId); // method
*((quint16*)(p+6)) = HTONS(0); // rsvd *((quint16*)(p+6)) = HTONS(0); // rsvd
@ -60,9 +67,9 @@ void RpcServer::done(::google::protobuf::Message *resp, PbRpcController *PbRpcCo
len = resp->ByteSize(); len = resp->ByteSize();
(*(quint16*)(p+4)) = HTONS(len); // len (*(quint16*)(p+4)) = HTONS(len); // len
qDebug("Server(%s): sending %d bytest to client encoding <%s>", qDebug("Server(%s): sending %d bytes to client encoding <%s>",
__FUNCTION__, len + 8, resp->DebugString().c_str()); __FUNCTION__, len + 8, resp->DebugString().c_str());
BUFDUMP(msg, len + 8); //BUFDUMP(msg, len + 8);
clientSock->write(msg, len + 8); clientSock->write(msg, len + 8);
@ -116,7 +123,7 @@ void RpcServer::when_error(QAbstractSocket::SocketError socketError)
void RpcServer::when_dataAvail() void RpcServer::when_dataAvail()
{ {
char msg[1024]; // FIXME: hardcoding; char msg[4096]; // FIXME: hardcoding;
int msgLen; int msgLen;
char *p = (char*) &msg; char *p = (char*) &msg;
quint16 type, method, len, rsvd; quint16 type, method, len, rsvd;
@ -128,13 +135,14 @@ void RpcServer::when_dataAvail()
LogInt(QString(QByteArray(msg, msgLen).toHex())); LogInt(QString(QByteArray(msg, msgLen).toHex()));
qDebug("Server %s: rcvd %d bytes", __FUNCTION__, msgLen); qDebug("Server %s: rcvd %d bytes", __FUNCTION__, msgLen);
BUFDUMP(msg, msgLen); //BUFDUMP(msg, msgLen);
type = NTOHS(GET16(p+0)); type = NTOHS(GET16(p+0));
qDebug("GET16 = %d/%d, type = %d", GET16(p+0), NTOHS(GET16(p+0)), type);
method = NTOHS(GET16(p+2)); method = NTOHS(GET16(p+2));
len = NTOHS(GET16(p+4)); len = NTOHS(GET16(p+4));
rsvd = NTOHS(GET16(p+6)); rsvd = NTOHS(GET16(p+6));
qDebug("type = %d, method = %d, len = %d, rsvd = %d",
type, method, len, rsvd);
if (type != PB_MSG_TYPE_REQUEST) if (type != PB_MSG_TYPE_REQUEST)
{ {
@ -165,9 +173,22 @@ void RpcServer::when_dataAvail()
// Serialized data starts from offset 8 // Serialized data starts from offset 8
req->ParseFromArray((void*) (msg+8), len); req->ParseFromArray((void*) (msg+8), len);
if (!req->IsInitialized())
{
qDebug("Missing required fields in request");
qDebug(req->InitializationErrorString().c_str());
delete req;
delete resp;
goto _error_exit;
}
qDebug("Server(%s): successfully parsed as <%s>", __FUNCTION__,
resp->DebugString().c_str());
controller = new PbRpcController; controller = new PbRpcController;
qDebug("before service->callmethod()");
service->CallMethod(methodDesc, controller, req, resp, service->CallMethod(methodDesc, controller, req, resp,
NewCallback(this, &RpcServer::done, resp, controller)); NewCallback(this, &RpcServer::done, resp, controller));

View File

@ -3,6 +3,28 @@
#define LOG(...) {sprintf(logStr, __VA_ARGS__); host->Log(logStr);} #define LOG(...) {sprintf(logStr, __VA_ARGS__); host->Log(logStr);}
int MyService::getStreamIndex(unsigned int portIdx,
unsigned int streamId)
{
int i;
// note: index and id are interchageable for port but not for stream
Q_ASSERT(portIdx < numPorts);
for (i = 0; i < portInfo[portIdx].streamList.size(); i++)
{
if (streamId == portInfo[portIdx].streamList.at(i).d.stream_id().id())
goto _found;
}
qDebug("%s: stream id %d not found", __PRETTY_FUNCTION__, streamId);
return -1;
_found:
return i;
}
MyService::MyService(AbstractHost *host) MyService::MyService(AbstractHost *host)
{ {
pcap_if_t *dev; pcap_if_t *dev;
@ -28,14 +50,8 @@ MyService::MyService(AbstractHost *host)
portInfo = new PortInfo[numPorts]; portInfo = new PortInfo[numPorts];
/* Populate and Print the list */ /* Populate and Print the list */
for(i=0, dev=alldevs; dev!=NULL; i++, dev=dev->next) for(i=0, dev=alldevs; (i < numPorts) && (dev!=NULL); i++, dev=dev->next)
{ {
#if 0 // PB
//portInfo[i].portId = i;
//portInfo[i].dev = dev;
//portInfo[i].streamHead = NULL;
//portInfo[i].streamTail = NULL;
#endif
portInfo[i].setId(i); portInfo[i].setId(i);
portInfo[i].setPcapDev(dev); portInfo[i].setPcapDev(dev);
#if 1 #if 1
@ -44,8 +60,17 @@ MyService::MyService(AbstractHost *host)
{ {
LOG(" (%s)\n", dev->description); LOG(" (%s)\n", dev->description);
} }
else #endif
LOG(" (No description available)\n"); #if 0
// FIXME(HI): Testing only!!!!
{
StreamInfo s;
s.d.mutable_stream_id()->set_id(0);
portInfo[i].streamList.append(s);
s.d.mutable_stream_id()->set_id(1);
portInfo[i].streamList.append(s);
}
#endif #endif
} }
@ -61,11 +86,7 @@ _fail:
MyService::~MyService() MyService::~MyService()
{ {
unsigned int i; delete portInfo;
#if 0 // PB?????
for (i = 0; i < numPorts; i++)
DeleteAllStreams(i);
#endif
pcap_freealldevs(alldevs); pcap_freealldevs(alldevs);
} }
@ -75,14 +96,15 @@ void MyService::getPortIdList(
::OstProto::PortIdList* response, ::OstProto::PortIdList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (uint i = 0; i < numPorts; i++) for (uint i = 0; i < numPorts; i++)
response->add_port_id(portInfo[i].d.port_id()); {
::OstProto::PortId *p;
qDebug("Server(%s): portid count = %d", __FUNCTION__, response->port_id_size()); p = response->add_port_id();
p->set_id(portInfo[i].d.port_id().id());
qDebug("Server(%s): %s", __FUNCTION__, response->DebugString().c_str()); }
done->Run(); done->Run();
} }
@ -92,19 +114,19 @@ const ::OstProto::PortIdList* request,
::OstProto::PortConfigList* response, ::OstProto::PortConfigList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
for (int i=0; i < request->port_id_size(); i++) for (int i=0; i < request->port_id_size(); i++)
{ {
unsigned int id; unsigned int idx;
id = request->port_id(i); idx = request->port_id(i).id();
if (id < numPorts) if (idx < numPorts)
{ {
OstProto::PortConfig *p; OstProto::Port *p;
p = response->add_list(); p = response->add_port();
p->CopyFrom(portInfo[request->port_id(i)].d); p->CopyFrom(portInfo[idx].d);
} }
} }
@ -112,34 +134,34 @@ const ::OstProto::PortIdList* request,
} }
void MyService::getStreamIdList(::google::protobuf::RpcController* controller, void MyService::getStreamIdList(::google::protobuf::RpcController* controller,
const ::OstProto::PortIdList* request, const ::OstProto::PortId* request,
::OstProto::StreamIdList* response, ::OstProto::StreamIdList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
unsigned int portIdx;
for (int i = 0; i < request->port_id_size(); i++) qDebug("In %s", __PRETTY_FUNCTION__);
{
unsigned int portId;
portId = request->port_id(i); portIdx = request->id();
if (portId >= numPorts) if (portIdx >= numPorts)
{ {
qDebug("%s: Invalid port id %d", __FUNCTION__, portId); qDebug("%s: Invalid port id %d", __PRETTY_FUNCTION__, portIdx);
continue; // TODO: Partial status of RPC controller->SetFailed("Invalid Port Id");
goto _exit; // TODO(LOW): Partial status of RPC
} }
for (int j = 0; j < portInfo[portId].streamList.size(); j++) response->mutable_port_id()->set_id(portIdx);
for (int j = 0; j < portInfo[portIdx].streamList.size(); j++)
{ {
OstProto::StreamId *s, *q; OstProto::StreamId *s, *q;
q = portInfo[portId].streamList[j].d.mutable_id(); q = portInfo[portIdx].streamList[j].d.mutable_stream_id();
assert(q->port_id() == portId);
s = response->add_id(); s = response->add_stream_id();
s->set_port_id(portId); s->CopyFrom(*q);
s->set_stream_id(q->stream_id());
}
} }
_exit:
done->Run(); done->Run();
} }
@ -148,43 +170,32 @@ const ::OstProto::StreamIdList* request,
::OstProto::StreamConfigList* response, ::OstProto::StreamConfigList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); unsigned int portIdx;
for (int i = 0; i < request->id_size(); i++) qDebug("In %s", __PRETTY_FUNCTION__);
{
unsigned int portId;
unsigned int streamId;
portId = request->id(i).port_id(); portIdx = request->port_id().id();
if (portId >= numPorts) if (portIdx >= numPorts)
{ {
qDebug("%s: Invalid port id %d", __FUNCTION__, portId); controller->SetFailed("invalid portid");
continue; // TODO: Partial status of RPC goto _exit;
} }
streamId = request->id(i).stream_id(); response->mutable_port_id()->set_id(portIdx);
if (streamId >= numPorts) for (int i = 0; i < request->stream_id_size(); i++)
{ {
qDebug("%s: Invalid port id %d", __FUNCTION__, portId); int streamIndex;
continue; // TODO: Partial status of RPC OstProto::Stream *s;
}
for (int j = 0; j < portInfo[portId].streamList.size(); j++) streamIndex = getStreamIndex(portIdx, request->stream_id(i).id());
{ if (streamIndex < 0)
OstProto::Stream *s, *q; continue; // TODO(LOW): Partial status of RPC
#if 0
q = portInfo[portId].streamList[j].d.e_stream();
assert(q->port_id() == portId);
s = response->add_stream(); s = response->add_stream();
s->set_port_id(portId); s->CopyFrom(portInfo[portIdx].streamList[streamIndex].d);
s->set_stream_id(q->stream_id());
#endif
// TODO: more params
} }
}
controller->SetFailed("Not Implemented"); _exit:
done->Run(); done->Run();
} }
@ -193,8 +204,36 @@ const ::OstProto::StreamIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); unsigned int portIdx;
controller->SetFailed("Not Implemented");
qDebug("In %s", __PRETTY_FUNCTION__);
portIdx = request->port_id().id();
if (portIdx >= numPorts)
{
controller->SetFailed("invalid portid");
goto _exit;
}
for (int i = 0; i < request->stream_id_size(); i++)
{
int streamIndex;
StreamInfo s;
// If stream with same id as in request exists already ==> error!!
streamIndex = getStreamIndex(portIdx, request->stream_id(i).id());
if (streamIndex >= 0)
continue; // TODO(LOW): Partial status of RPC
// Append a new "default" stream - actual contents of the new stream is
// expected in a subsequent "modifyStream" request - set the stream id
// now itself however!!!
s.d.mutable_stream_id()->CopyFrom(request->stream_id(i));
portInfo[portIdx].streamList.append(s);
// TODO(LOW): fill-in response "Ack"????
}
_exit:
done->Run(); done->Run();
} }
@ -203,8 +242,31 @@ const ::OstProto::StreamIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); unsigned int portIdx;
controller->SetFailed("Not Implemented");
qDebug("In %s", __PRETTY_FUNCTION__);
portIdx = request->port_id().id();
if (portIdx >= numPorts)
{
controller->SetFailed("invalid portid");
goto _exit;
}
for (int i = 0; i < request->stream_id_size(); i++)
{
int streamIndex;
StreamInfo s;
streamIndex = getStreamIndex(portIdx, request->stream_id(i).id());
if (streamIndex < 0)
continue; // TODO(LOW): Partial status of RPC
portInfo[portIdx].streamList.removeAt(streamIndex);
// TODO(LOW): fill-in response "Ack"????
}
_exit:
done->Run(); done->Run();
} }
@ -213,8 +275,32 @@ const ::OstProto::StreamConfigList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); unsigned int portIdx;
controller->SetFailed("Not Implemented");
qDebug("In %s", __PRETTY_FUNCTION__);
portIdx = request->port_id().id();
if (portIdx >= numPorts)
{
controller->SetFailed("invalid portid");
goto _exit;
}
for (int i = 0; i < request->stream_size(); i++)
{
int streamIndex;
streamIndex = getStreamIndex(portIdx,
request->stream(i).stream_id().id());
if (streamIndex < 0)
continue; // TODO(LOW): Partial status of RPC
portInfo[portIdx].streamList[streamIndex].d.MergeFrom(
request->stream(i));
// TODO(LOW): fill-in response "Ack"????
}
_exit:
done->Run(); done->Run();
} }
@ -223,7 +309,7 @@ const ::OstProto::PortIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -233,7 +319,7 @@ const ::OstProto::PortIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -243,7 +329,7 @@ const ::OstProto::PortIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -253,7 +339,7 @@ const ::OstProto::PortIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -263,7 +349,7 @@ const ::OstProto::PortIdList* request,
::OstProto::CaptureBufferList* response, ::OstProto::CaptureBufferList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -273,7 +359,7 @@ const ::OstProto::PortIdList* request,
::OstProto::PortStatsList* response, ::OstProto::PortStatsList* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }
@ -283,7 +369,7 @@ const ::OstProto::PortIdList* request,
::OstProto::Ack* response, ::OstProto::Ack* response,
::google::protobuf::Closure* done) ::google::protobuf::Closure* done)
{ {
qDebug("In %s", __FUNCTION__); qDebug("In %s", __PRETTY_FUNCTION__);
controller->SetFailed("Not Implemented"); controller->SetFailed("Not Implemented");
done->Run(); done->Run();
} }

View File

@ -12,6 +12,8 @@
#include <pcap.h> #include <pcap.h>
#include <QList> #include <QList>
#include "../rpc/pbhelper.h"
#define MAX_PKT_HDR_SIZE 1536 #define MAX_PKT_HDR_SIZE 1536
#define MAX_STREAM_NAME_SIZE 64 #define MAX_STREAM_NAME_SIZE 64
@ -23,21 +25,7 @@ class StreamInfo
OstProto::Stream d; OstProto::Stream d;
#if 0 // PB StreamInfo() { PbHelper pbh; pbh.ForceSetSingularDefault(&d); }
unsigned int id;
char name[MAX_STREAM_NAME_SIZE];
unsigned char pktHdr[MAX_PKT_HDR_SIZE];
unsigned short hdrLen;
unsigned short pktLen;
unsigned int dataPattern;
unsigned int flags;
#define STREAM_FLAG_MASK_STATUS 0x00000001
#define STREAM_FLAG_VALUE_STATUS_DISABLED 0x00000000
#define STREAM_FLAG_VALUE_STATUS_ENABLED 0x00000001
struct _Stream *next;
#endif
}; };
@ -45,28 +33,23 @@ class PortInfo
{ {
friend class MyService; friend class MyService;
OstProto::PortConfig d; OstProto::Port d;
pcap_if_t *dev; pcap_if_t *dev;
/*! StreamInfo::d::stream_id and index into streamList[] are NOT same! */
QList<StreamInfo> streamList; QList<StreamInfo> streamList;
#if 0 // PB
unsigned int portId; // FIXME:need?
Stream *streamHead;
Stream *streamTail;
#endif
public: public:
// TODO(LOW): Both setId and setPcapDev() should together form the ctor // TODO(LOW): Both setId and setPcapDev() should together form the ctor
void setId(unsigned int id) { d.set_port_id(id); } void setId(unsigned int id) { d.mutable_port_id()->set_id(id); }
void setPcapDev(pcap_if_t *dev) void setPcapDev(pcap_if_t *dev)
{ {
this->dev = dev; this->dev = dev;
d.set_name("eth"); // FIXME: suffix portid d.set_name("eth"); // FIXME(MED): suffix portid
d.set_description(dev->description); d.set_description(dev->description);
d.set_is_enabled(true); // FIXME:check d.set_is_enabled(true); // FIXME(MED):check
d.set_is_oper_up(true); // FIXME:check d.set_is_oper_up(true); // FIXME(MED):check
d.set_is_exclusive_control(false); // FIXME: check d.set_is_exclusive_control(false); // FIXME(MED): check
} }
}; };
@ -75,16 +58,18 @@ class MyService: public OstProto::OstService
AbstractHost *host; AbstractHost *host;
char logStr[1024]; char logStr[1024];
unsigned numPorts; uint numPorts;
/*! PortInfo::d::port_id and index into portInfo[] are same! */
PortInfo *portInfo; PortInfo *portInfo;
pcap_if_t *alldevs; pcap_if_t *alldevs;
int getStreamIndex(unsigned int portIdx,unsigned int streamId);
public: public:
MyService(AbstractHost* host); MyService(AbstractHost* host);
virtual ~MyService(); virtual ~MyService();
//static const ::google::protobuf::ServiceDescriptor* descriptor(); /* Methods provided by the service */
virtual void getPortIdList(::google::protobuf::RpcController* controller, virtual void getPortIdList(::google::protobuf::RpcController* controller,
const ::OstProto::Void* request, const ::OstProto::Void* request,
::OstProto::PortIdList* response, ::OstProto::PortIdList* response,
@ -94,7 +79,7 @@ public:
::OstProto::PortConfigList* response, ::OstProto::PortConfigList* response,
::google::protobuf::Closure* done); ::google::protobuf::Closure* done);
virtual void getStreamIdList(::google::protobuf::RpcController* controller, virtual void getStreamIdList(::google::protobuf::RpcController* controller,
const ::OstProto::PortIdList* request, const ::OstProto::PortId* request,
::OstProto::StreamIdList* response, ::OstProto::StreamIdList* response,
::google::protobuf::Closure* done); ::google::protobuf::Closure* done);
virtual void getStreamConfig(::google::protobuf::RpcController* controller, virtual void getStreamConfig(::google::protobuf::RpcController* controller,

View File

@ -1,5 +1,5 @@
File Not used anymore FIXME(HI): File Not used anymore
#if 0 #if 0
#include "qtglobal" // FIXME: needed only for qdebug #include "qtglobal" // FIXME: needed only for qdebug

View File

@ -1,5 +1,5 @@
File not used anymore FIXME(HI): File not used anymore
#if 0 #if 0