mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-04 20:59:05 -04:00
Added Bandwidth Monitoring service to libretroshare to help debug Lag.
- p3bwctrl.h/.cc & rsbwctrlitems.h/.cc - New Interface in pqihandler to extract the data. - New Interface in rsconfig to display in GUI. - Added extra debugging in pqistreamer for catching big outqueues. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5241 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0d3d1ebc18
commit
48a1c66c60
16 changed files with 880 additions and 31 deletions
|
@ -81,6 +81,10 @@ const uint8_t QOS_PRIORITY_RS_VOIP_PING = 9 ;
|
|||
//
|
||||
const uint8_t QOS_PRIORITY_RS_BANLIST_ITEM = 2 ;
|
||||
|
||||
// Bandwidth Control.
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM = 9 ;
|
||||
|
||||
// Dsdv Routing
|
||||
//
|
||||
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
|
||||
|
|
205
libretroshare/src/serialiser/rsbwctrlitems.cc
Normal file
205
libretroshare/src/serialiser/rsbwctrlitems.cc
Normal file
|
@ -0,0 +1,205 @@
|
|||
/*
|
||||
* libretroshare/src/serialiser: rsbwctrlitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsbwctrlitems.h"
|
||||
|
||||
/***
|
||||
#define RSSERIAL_DEBUG 1
|
||||
***/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsBwCtrlAllowedItem::~RsBwCtrlAllowedItem()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void RsBwCtrlAllowedItem::clear()
|
||||
{
|
||||
allowedBw = 0;
|
||||
}
|
||||
|
||||
std::ostream &RsBwCtrlAllowedItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsBwCtrlAllowedItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "AllowedBw: " << allowedBw;
|
||||
out << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsBwCtrlAllowedItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsBwCtrlSerialiser::sizeAllowed(RsBwCtrlAllowedItem * /*item*/)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvUInt32Size();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBwCtrlSerialiser::serialiseAllowed(RsBwCtrlAllowedItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeAllowed(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Header: " << ok << std::endl;
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsBwCtrlAllowedItem *RsBwCtrlSerialiser::deserialiseAllowed(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsBwCtrlAllowedItem *item = new RsBwCtrlAllowedItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
|
||||
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
uint32_t RsBwCtrlSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsBwCtrlAllowedItem *dri;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
|
||||
{
|
||||
return sizeAllowed(dri);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsBwCtrlAllowedItem *dri;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBwCtrlAllowedItem *>(i)))
|
||||
{
|
||||
return serialiseAllowed(dri, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM:
|
||||
return deserialiseAllowed(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
84
libretroshare/src/serialiser/rsbwctrlitems.h
Normal file
84
libretroshare/src/serialiser/rsbwctrlitems.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
#ifndef RS_BANDWIDTH_CONTROL_ITEMS_H
|
||||
#define RS_BANDWIDTH_CONTROL_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbwctrlitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2012 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM 0x01
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
class RsBwCtrlAllowedItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBwCtrlAllowedItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BWCTRL,
|
||||
RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_BWCTRL_ALLOWED_ITEM);
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsBwCtrlAllowedItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class RsBwCtrlSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsBwCtrlSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BWCTRL)
|
||||
{ return; }
|
||||
virtual ~RsBwCtrlSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeAllowed(RsBwCtrlAllowedItem *);
|
||||
virtual bool serialiseAllowed (RsBwCtrlAllowedItem *item, void *data, uint32_t *size);
|
||||
virtual RsBwCtrlAllowedItem *deserialiseAllowed(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_BANDWIDTH_CONTROL_ITEMS_H */
|
||||
|
|
@ -94,6 +94,9 @@ const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf040;
|
|||
/* DSDV Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_DSDV = 0xf050;
|
||||
|
||||
/* Bandwidth Testing at the moment - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_BWCTRL = 0xf060;
|
||||
|
||||
|
||||
/* Games/External Apps - Service Only */
|
||||
const uint16_t RS_SERVICE_TYPE_GAME_LAUNCHER = 0xf200;
|
||||
|
|
|
@ -115,6 +115,7 @@ const uint16_t TLV_TYPE_UINT32_POP = 0x0031;
|
|||
const uint16_t TLV_TYPE_UINT32_AGE = 0x0032;
|
||||
const uint16_t TLV_TYPE_UINT32_OFFSET = 0x0033;
|
||||
const uint16_t TLV_TYPE_UINT32_SERID = 0x0034;
|
||||
const uint16_t TLV_TYPE_UINT32_BW = 0x0035;
|
||||
|
||||
const uint16_t TLV_TYPE_UINT64_SIZE = 0x0040;
|
||||
const uint16_t TLV_TYPE_UINT64_OFFSET = 0x0041;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue