Network REWORK: Partial tests for p3ConnectMgr behaviour..

* Added new test harnesses for pqiPersonGrp and pqiconnect.
 * Added 2 p3connmgr tests.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3248 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-07-04 10:38:54 +00:00
parent f4331da483
commit 8745c2fe2e
9 changed files with 1110 additions and 4 deletions

View File

@ -7,12 +7,18 @@ RS_TOP_DIR = ../..
include $(RS_TOP_DIR)/tests/scripts/config.mk include $(RS_TOP_DIR)/tests/scripts/config.mk
############################################################### ###############################################################
TESTOBJ = net_test.o dht_test.o net_test1.o netiface_test.o dht_test.o # Generic Test Harnesses.
TESTOBJ += pkt_test.o testconnect.o pqiarchive_test.o pqiperson_test.o TESTOBJ = conn_harness.o ppg_harness.o
TESTOBJ += net_test.o dht_test.o net_test1.o netiface_test.o dht_test.o
TESTOBJ += pkt_test.o pqiarchive_test.o pqiperson_test.o
TESTOBJ += extaddrfinder_test.o TESTOBJ += extaddrfinder_test.o
TESTOBJ += p3connmgr_reset_test.o p3connmgr_connect_test.o
#conn_test.o #conn_test.o
TESTS = net_test net_test1 netiface_test pqiarchive_test pqiperson_test extaddrfinder_test TESTS = net_test net_test1 netiface_test pqiarchive_test pqiperson_test extaddrfinder_test
TESTS = p3connmgr_reset_test p3connmgr_connect_test
#TESTS = p3connmgr_test1
MANUAL_TESTS = dht_test MANUAL_TESTS = dht_test
#conn_test #conn_test
@ -49,6 +55,18 @@ pqiperson_test: pqiperson_test.o testconnect.o
extaddrfinder_test: extaddrfinder_test.o extaddrfinder_test: extaddrfinder_test.o
$(CC) $(CFLAGS) -o extaddrfinder_test extaddrfinder_test.o $(LIBS) $(CC) $(CFLAGS) -o extaddrfinder_test extaddrfinder_test.o $(LIBS)
p3connmgr_reset_test: p3connmgr_reset_test.o
$(CC) $(CFLAGS) -o p3connmgr_reset_test p3connmgr_reset_test.o $(LIBS)
p3connmgr_connect_test: p3connmgr_connect_test.o conn_harness.o ppg_harness.o
$(CC) $(CFLAGS) -o p3connmgr_connect_test p3connmgr_connect_test.o conn_harness.o ppg_harness.o $(LIBS)
p3connmgr_test1: p3connmgr_test1.o
$(CC) $(CFLAGS) -o p3connmgr_test1 p3connmgr_test1.o $(LIBS)
clobber: remove_extra_files clobber: remove_extra_files

View File

@ -0,0 +1,284 @@
/*
* libretroshare/src/test/pqi testconnect.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2008 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 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".
*
*/
/******
* pqiperson acts as the wrapper for all connection methods to a single peer.
*
* This test creates, a pqiperson and simulates connections, disconnections.
* packets passing through.
*
*/
#include "conn_harness.h"
#include "pqi/pqibin.h"
#include <iostream>
#include <sstream>
/*******************************************************
*
* Test structure
*****************/
/* static test variables */
uint32_t testCounter = 0;
pqiconnect *testConnectPointer[NUM_CONN_MAX];
PQInterface *testConnectParent[NUM_CONN_MAX];
uint32_t testConnectState[NUM_CONN_MAX];
std::list<uint32_t> testConnectTimes[NUM_CONN_MAX];
std::list<struct sockaddr_in> testConnectAddrs[NUM_CONN_MAX];
std::list<uint32_t> testResetState[NUM_CONN_MAX];
std::list<uint32_t> testResetTimes[NUM_CONN_MAX];
uint32_t testConnectAction[NUM_CONN_MAX] = { 0 };
time_t testConnectPeriod[NUM_CONN_MAX] = { 0 };
uint32_t defTestConnectAction = TST_ACTION_FAILED;
uint32_t findWhichConnect(pqiconnect *conn)
{
int i;
for(i = 0; i < NUM_CONN_MAX; i++)
{
if (testConnectPointer[i] == conn)
{
return i;
}
}
// error.
std::cerr << "Connect Missing" << std::endl;
exit(1);
return 0;
}
void addTestConnect(pqiconnect *pqi, PQInterface *parent)
{
testConnectPointer[testCounter] = pqi;
testConnectParent[testCounter] = parent;
testConnectState[testCounter] = 0;
testCounter++;
if (testCounter > NUM_CONN_MAX)
{
std::cerr << "Too Many Connects" << std::endl;
exit(1);
}
}
void resetTestConnects()
{
testCounter = 0;
int i;
for(i = 0; i < NUM_CONN_MAX; i++)
{
testConnectAddrs[i].clear();
testConnectTimes[i].clear();
testResetState[i].clear();
testResetTimes[i].clear();
}
}
/* setup callback actions */
void setDefaultTestConnectAction(uint32_t action)
{
defTestConnectAction = action;
}
void forceConnect(uint32_t idx)
{
/* flag as con */
}
testConnect::testConnect(RsSerialiser *rss, NetBinInterface *ni_in)
:pqiconnect(rss, ni_in)
{
}
testConnect::~testConnect()
{
return;
}
/* dummyConnect */
int testConnect::connect(struct sockaddr_in raddr)
{
int cidx = findWhichConnect(this);
time_t now = time(NULL);
testConnectState[cidx] |= TST_STATE_CONNECT;
testConnectTimes[cidx].push_back(now);
testConnectAddrs[cidx].push_back(raddr);
testConnectAction[cidx] = defTestConnectAction;
std::cerr << "testConnect[" << cidx << "].connect() called";
std::cerr << std::endl;
return 0;
}
int testConnect::listen()
{
int cidx = findWhichConnect(this);
testConnectState[cidx] |= TST_STATE_LISTEN;
std::cerr << "testConnect[" << cidx << "].listen() called";
std::cerr << std::endl;
return 1;
}
int testConnect::stoplistening()
{
int cidx = findWhichConnect(this);
testConnectState[cidx] &= ~TST_STATE_LISTEN;
std::cerr << "testConnect[" << cidx << "].stoplistening() called";
std::cerr << std::endl;
return 1;
}
int testConnect::reset()
{
int cidx = findWhichConnect(this);
time_t now = time(NULL);
// reset everything except listening.
testResetState[cidx].push_back(testConnectState[cidx]);
testResetTimes[cidx].push_back(now);
testConnectState[cidx] &= TST_STATE_LISTEN;
std::cerr << "testConnect[" << cidx << "].reset() called";
std::cerr << std::endl;
return 1;
}
// leave this as is virtual int disconnect() { return ni -> reset(); }
bool testConnect::connect_parameter(uint32_t type, uint32_t value)
{
int cidx = findWhichConnect(this);
//testConnectState[cidx] |= TST_STATE_LISTEN;
std::cerr << "testConnect[" << cidx << "].connect_parameter() called";
std::cerr << std::endl;
/* sum up PERIOD and DELAY */
if (type == NET_PARAM_CONNECT_DELAY)
{
std::cerr << "PARAMETER: DELAY: " << value;
std::cerr << std::endl;
//testConnectPeriod[cidx] = value;
}
else if (type == NET_PARAM_CONNECT_PERIOD)
{
std::cerr << "PARAMETER: PERIOD: " << value;
std::cerr << std::endl;
//testConnectPeriod[cidx] += value;
}
else if (type == NET_PARAM_CONNECT_TIMEOUT)
{
std::cerr << "PARAMETER: TIMEOUT: " << value;
std::cerr << std::endl;
testConnectPeriod[cidx] = value;
//testConnectPeriod[cidx] += value;
}
std::cerr << "total testConnectPeriod: " << testConnectPeriod[cidx];
std::cerr << std::endl;
return true;
}
int testConnect::getConnectAddress(struct sockaddr_in &raddr)
{
int cidx = findWhichConnect(this);
if (testConnectAddrs[cidx].size() > 0)
{
raddr = testConnectAddrs[cidx].back();
return 1;
}
std::cerr << "testConnect[" << cidx << "].getConnectAddress() called";
std::cerr << std::endl;
return 0;
}
int testConnect::tick()
{
int cidx = findWhichConnect(this);
std::cerr << "testConnect[" << cidx << "].tick()";
std::cerr << std::endl;
if (testConnectState[cidx] & TST_STATE_CONNECT)
{
time_t now = time(NULL);
time_t cTime = testConnectTimes[cidx].back();
if (now - cTime > testConnectPeriod[cidx])
{
std::cerr << "testConnect[" << cidx << "].tick() reached ConnectPeriod";
std::cerr << " age: " << now - cTime << " period: " << testConnectPeriod[cidx];
std::cerr << std::endl;
PQInterface *connParent = testConnectParent[cidx];
testConnectState[cidx] &= ~TST_STATE_CONNECT;
/* do callback now */
if (testConnectAction[cidx] == TST_ACTION_SUCCESS)
{
std::cerr << "testConnect[" << cidx << "].tick() CONNECTED callback";
std::cerr << std::endl;
testConnectState[cidx] &= ~TST_STATE_CONNECTED;
/* do callback */
connParent -> notifyEvent(this->ni, NET_CONNECT_SUCCESS);
}
else if (testConnectAction[cidx] == TST_ACTION_FAILED)
{
std::cerr << "testConnect[" << cidx << "].tick() FAILED callback";
std::cerr << std::endl;
/* do callback */
connParent -> notifyEvent(this->ni, NET_CONNECT_FAILED);
}
else
{
std::cerr << "testConnect[" << cidx << "].tick() no callback (BAD)";
std::cerr << std::endl;
}
}
}
return 0;
}

View File

@ -0,0 +1,87 @@
#ifndef TEST_PQICONNECT_H
#define TEST_PQICONNECT_H
/*
* libretroshare/src/test/pqi testconnect.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2010 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 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 "pqi/pqiperson.h"
//#include "pqi/pqibin.h"
#include "util/rsnet.h"
/*******************************************************
*
* Test structure
*****************/
#define NUM_CONN_MAX 50
#define TST_STATE_CONNECT 0x0001
#define TST_STATE_LISTEN 0x0002
#define TST_STATE_CONNECTED 0x0004
#define TST_ACTION_NONE 0x0000
#define TST_ACTION_FAILED 0x0001
#define TST_ACTION_SUCCESS 0x0002
/* static test variables */
extern uint32_t testCounter;
extern pqiconnect *testConnectPointer[NUM_CONN_MAX];
extern uint32_t testConnectState[NUM_CONN_MAX];
extern std::list<uint32_t> testConnectTimes[NUM_CONN_MAX];
extern std::list<struct sockaddr_in> testConnectAddrs[NUM_CONN_MAX];
extern std::list<uint32_t> testResetState[NUM_CONN_MAX];
extern std::list<uint32_t> testResetTimes[NUM_CONN_MAX];
uint32_t findWhichConnect(pqiconnect *conn);
void addTestConnect(pqiconnect *pqi, PQInterface *parent);
void resetTestConnects();
void setDefaultTestConnectAction(uint32_t action);
class testConnect: public pqiconnect
{
public:
testConnect(RsSerialiser *rss, NetBinInterface *ni_in);
virtual ~testConnect();
/* dummyConnect */
virtual int tick();
virtual int connect(struct sockaddr_in raddr);
virtual int listen();
virtual int stoplistening();
virtual int reset();
virtual bool connect_parameter(uint32_t type, uint32_t value);
virtual int getConnectAddress(struct sockaddr_in &raddr);
}; // end of testConnect.
pqiperson *createTestPerson(std::string id, pqipersongrp *ppg);
#endif

View File

@ -0,0 +1,195 @@
/*
* libretroshare/src/test/pqi p3connmgr_test.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2008 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 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".
*
*/
/******
* p3connmgr test module.
*
* create a p3connmgr and run the following tests.
* 1) UDP test
* 2) UPNP test
* 3) ExtAddr test.
* 4) full reset in between.
*
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "ppg_harness.h"
#include "conn_harness.h"
#include "pqi/p3connmgr.h"
#include "pqi/authssltest.h"
#include "pqi/authgpgtest.h"
#include "pqi/p3dhtmgr.h"
#include "upnp/upnphandler.h"
#include "util/rsnet.h"
#include <iostream>
#include <sstream>
#include "util/utest.h"
INITTEST();
/* generic startup test */
#define MAX_TIME_SHORT_TEST 10
#define MAX_TIME_BASIC_TEST 60
int run_connect_test(time_t timeout);
/*******************************************************
*
* Test structure
*****************/
#define FLAG_UPNP 1
#define FLAG_UDP 2
#define FLAG_DHT 4
#define FLAG_EXT 8
p3ConnectMgr *mConnMgr;
pqiNetAssistFirewall *mUpnpMgr = NULL;
p3DhtMgr *mDhtMgr = NULL;
void createP3ConnMgr(std::string id, uint32_t testFlags)
{
/* now add test children */
{
std::cerr << "createP3ConnMgr()";
std::cerr << std::endl;
}
mConnMgr = new p3ConnectMgr();
mDhtMgr = NULL; //new p3DhtMgr();
/* setup status */
//mConnMgr->setStatus(UPNP);
}
/* ACTUAL TEST */
int main(int argc, char **argv)
{
/* test p3connmgr net stuff */
std::cerr << "p3connmgr_net_connect_test" << std::endl;
// setup test authssl.
setAuthGPG(new AuthGPGtest());
setAuthSSL(new AuthSSLtest());
createP3ConnMgr("abcd", 0);
pqiNetStatus status;
setupPqiPersonGrpTH();
/* install ppg as a monitor */
mConnMgr->addMonitor(mPqiPersonGrpTH);
std::string peer1_gpgid = "PEERID0001_GPG__";
std::string peer1_sslid = "PEERID0001_SSL__";
/* first test, add a single peer (no Addresses) */
mConnMgr->addFriend(peer1_sslid, peer1_gpgid);
run_connect_test(MAX_TIME_SHORT_TEST);
mConnMgr->getNetStatus(status);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
// Check that there have been... 1 reset / 0 connects / 1 listen
// per connect.
REPORT("p3connmgr_connect_test() SINGLE PEER - NO Addresses");
/* second test, add addresses for peer */
time_t now = time(NULL);
pqiIpAddrSet peer1_tst2_addrs;
pqiIpAddress paddr;
inet_aton("192.168.1.1", &(paddr.mAddr.sin_addr));
paddr.mAddr.sin_port = htons(6411);
paddr.mSeenTime = now - 10;
peer1_tst2_addrs.mLocal.updateIpAddressList(paddr);
inet_aton("192.168.1.2", &(paddr.mAddr.sin_addr));
paddr.mAddr.sin_port = htons(6422);
paddr.mSeenTime = now - 20;
peer1_tst2_addrs.mLocal.updateIpAddressList(paddr);
inet_aton("23.56.25.1", &(paddr.mAddr.sin_addr));
paddr.mAddr.sin_port = htons(6511);
paddr.mSeenTime = now - 30;
peer1_tst2_addrs.mExt.updateIpAddressList(paddr);
inet_aton("23.56.25.2", &(paddr.mAddr.sin_addr));
paddr.mAddr.sin_port = htons(6522);
paddr.mSeenTime = now - 40;
peer1_tst2_addrs.mExt.updateIpAddressList(paddr);
mConnMgr->updateAddressList(peer1_sslid, peer1_tst2_addrs);
mConnMgr->retryConnect(peer1_sslid);
run_connect_test(MAX_TIME_BASIC_TEST);
// Check that there have been:
// 0 Listens / 0 resets.
// 0 connect attempts on UDP
// 4 connect attempts on TCP
// 0 connect attempts on TUNNEL
REPORT("p3connmgr_connect_test() SINGLE PEER - 4 Addresses");
/* third test, add an second peer with addresses */
/* fourth test, setup default action as connect */
setDefaultTestConnectAction(TST_ACTION_SUCCESS);
}
/* Generic restart test */
int run_connect_test(time_t timeout)
{
/* tick */
time_t start = time(NULL);
bool extAddr = false;
while ((start > time(NULL) - timeout) && (!extAddr))
{
mConnMgr->tick();
tickPqiPersonGrpTH();
sleep(1);
}
return 1;
}

View File

@ -0,0 +1,320 @@
/*
* libretroshare/src/test/pqi p3connmgr_test.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2008 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 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".
*
*/
/******
* p3connmgr test module.
*
* create a p3connmgr and run the following tests.
* 1) UDP test
* 2) UPNP test
* 3) ExtAddr test.
* 4) full reset in between.
*
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "pqi/p3connmgr.h"
#include "pqi/authssltest.h"
#include "pqi/authgpgtest.h"
#include "pqi/p3dhtmgr.h"
#include "upnp/upnphandler.h"
#include "util/rsnet.h"
#include <iostream>
#include <sstream>
#include "util/utest.h"
INITTEST();
/* generic startup test */
#define MAX_TIME_BASIC_TEST 40
#define MAX_TIME_UPNP_TEST 700 /* seems to take a while */
#define RESTART_EXPECT_NO_EXT_ADDR 1
#define RESTART_EXPECT_EXTFINDER_ADDR 2
#define RESTART_EXPECT_UPNP_ADDR 3
#define RESTART_EXPECT_DHT_ADDR 4
int test_p3connmgr_restart_test(uint32_t expectState, time_t timeout);
#define RESET_VIA_LOCAL_ADDR 1
#define RESET_VIA_REMOTE_ADDR 2
int force_reset(uint32_t method);
/*******************************************************
*
* Test structure
*****************/
#define FLAG_UPNP 1
#define FLAG_UDP 2
#define FLAG_DHT 4
#define FLAG_EXT 8
p3ConnectMgr *mConnMgr;
pqiNetAssistFirewall *mUpnpMgr = NULL;
p3DhtMgr *mDhtMgr = NULL;
void createP3ConnMgr(std::string id, uint32_t testFlags)
{
/* now add test children */
{
std::cerr << "createP3ConnMgr()";
std::cerr << std::endl;
}
mConnMgr = new p3ConnectMgr();
mDhtMgr = NULL; //new p3DhtMgr();
/* setup status */
//mConnMgr->setStatus(UPNP);
}
void add_upnp()
{
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
mDhtMgr = NULL; //new p3DhtMgr();
//mConnMgr->addNetAssistConnect(1, mDhtMgr);
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
}
void disableUpnp()
{
//mConnMgr->
}
void enableUpnp()
{
}
void disableExtFinder()
{
//mConnMgr->
mConnMgr->setIPServersEnabled(false);
}
void enableExtFinder()
{
mConnMgr->setIPServersEnabled(true);
}
/* ACTUAL TEST */
int main(int argc, char **argv)
{
/* test p3connmgr net stuff */
std::cerr << "p3connmgr_net_restart_test" << std::endl;
// setup test authssl.
setAuthGPG(new AuthGPGtest());
setAuthSSL(new AuthSSLtest());
createP3ConnMgr("abcd", 0);
pqiNetStatus status;
/* first test, no Upnp / ExtFinder -> expect no Ext Address */
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UDP);
disableExtFinder();
mConnMgr->getNetStatus(status);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_NO_EXT_ADDR, MAX_TIME_BASIC_TEST);
REPORT("test_p3connmgr_restart_test()");
/* second test, add ExtFinder -> expect Ext Address */
enableExtFinder();
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UDP);
force_reset(RESET_VIA_LOCAL_ADDR);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_EXTFINDER_ADDR, MAX_TIME_BASIC_TEST);
/* third test. disable ExtFinder again -> expect No Ext Address */
disableExtFinder();
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UDP);
force_reset(RESET_VIA_LOCAL_ADDR);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_NO_EXT_ADDR, MAX_TIME_BASIC_TEST);
/* fourth test. enable Upnp -> expect Upnp Ext Address */
add_upnp();
enableUpnp();
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UPNP);
force_reset(RESET_VIA_LOCAL_ADDR);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_UPNP_ADDR, MAX_TIME_UPNP_TEST);
/* fifth test. disable Upnp -> expect No Ext Address */
disableUpnp();
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UDP);
force_reset(RESET_VIA_LOCAL_ADDR);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_NO_EXT_ADDR, MAX_TIME_BASIC_TEST);
/* sixth test. enable both Ext and Upnp -> expect UpnP Ext Address (prefered) */
enableExtFinder();
enableUpnp();
mConnMgr->setNetworkMode(AuthSSL::getAuthSSL()->OwnId(), RS_NET_MODE_UPNP);
force_reset(RESET_VIA_LOCAL_ADDR);
CHECK(status.mLocalAddrOk == false);
CHECK(status.mExtAddrOk == false);
test_p3connmgr_restart_test(RESTART_EXPECT_UPNP_ADDR, MAX_TIME_UPNP_TEST);
REPORT("test_p3connmgr_restart_test()");
FINALREPORT("p3connmgr_net_restart_test");
return TESTRESULT();
}
/******************************************************
*
*/
int force_reset(uint32_t method)
{
/* force reset network */
struct sockaddr_in tst_addr;
inet_aton("123.45.2.2", &(tst_addr.sin_addr));
tst_addr.sin_port = ntohs(8461);
mConnMgr->setLocalAddress(AuthSSL::getAuthSSL()->OwnId(), tst_addr);
return 1;
}
/* Generic restart test */
int test_p3connmgr_restart_test(uint32_t expectState, time_t timeout)
{
/* force reset network */
struct sockaddr_in tst_addr;
inet_aton("123.45.2.2", &(tst_addr.sin_addr));
tst_addr.sin_port = ntohs(8461);
mConnMgr->setLocalAddress(AuthSSL::getAuthSSL()->OwnId(), tst_addr);
/* tick */
time_t start = time(NULL);
bool extAddr = false;
while ((start > time(NULL) - timeout) && (!extAddr))
{
mConnMgr->tick();
pqiNetStatus status;
mConnMgr->getNetStatus(status);
std::cerr << "test_p3connmgr_restart_test() Age: " << time(NULL) - start;
std::cerr << " netStatus:";
std::cerr << std::endl;
status.print(std::cerr);
if (status.mExtAddrOk)
{
std::cerr << "test_p3connmgr_restart_test() Got ExtAddr. Finished Restart.";
std::cerr << std::endl;
extAddr = true;
}
sleep(1);
}
std::cerr << "test_p3connmgr_restart_test() Test Mode: " << expectState << " Complete";
std::cerr << std::endl;
pqiNetStatus status;
mConnMgr->getNetStatus(status);
status.print(std::cerr);
if (status.mExtAddrOk)
{
CHECK(isValidNet(&(status.mExtAddr.sin_addr)));
}
CHECK(isValidNet(&(status.mLocalAddr.sin_addr)));
/* check expectState */
switch(expectState)
{
default:
case RESTART_EXPECT_NO_EXT_ADDR:
CHECK(status.mLocalAddrOk == true);
CHECK(status.mExtAddrOk == false);
CHECK(status.mExtAddrStableOk == false);
CHECK(status.mUpnpOk == false);
CHECK(status.mDhtOk == false);
break;
case RESTART_EXPECT_EXTFINDER_ADDR:
CHECK(status.mLocalAddrOk == true);
CHECK(status.mExtAddrOk == true);
CHECK(status.mExtAddrStableOk == false);
CHECK(status.mUpnpOk == false);
break;
case RESTART_EXPECT_UPNP_ADDR:
CHECK(status.mLocalAddrOk == true);
CHECK(status.mExtAddrOk == true);
CHECK(status.mExtAddrStableOk == true);
CHECK(status.mUpnpOk == true);
break;
case RESTART_EXPECT_DHT_ADDR:
CHECK(status.mLocalAddrOk == true);
CHECK(status.mExtAddrOk == false);
CHECK(status.mUpnpOk == false);
CHECK(status.mDhtOk == true);
break;
}
return 1;
}

View File

@ -0,0 +1,141 @@
/*
* libretroshare/src/test/pqi pqiperson_test.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2008 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 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".
*
*/
/******
* pqiperson acts as the wrapper for all connection methods to a single peer.
*
* This test creates, a pqiperson and simulates connections, disconnections.
* packets passing through.
*
*/
#include "conn_harness.h"
#include "ppg_harness.h"
#include "pqi/pqiperson.h"
#include "pqi/pqibin.h"
#include "util/rsnet.h"
#include <iostream>
#include <sstream>
/*******************************************************
*
* Test structure
*****************/
pqiperson *createTestPerson(std::string id, pqipersongrp *ppg);
pqipersongrpTestHarness *mPqiPersonGrpTH = NULL;
void setupPqiPersonGrpTH()
{
mPqiPersonGrpTH = new pqipersongrpTestHarness(NULL, 0);
}
void tickPqiPersonGrpTH()
{
mPqiPersonGrpTH->tick();
}
pqipersongrpTestHarness::pqipersongrpTestHarness(SecurityPolicy *pol, unsigned long flags)
:pqipersongrp(pol, flags)
{
return;
}
/********* FUNCTIONS to OVERLOAD for specialisation ********/
pqilistener *pqipersongrpTestHarness::createListener(struct sockaddr_in laddr)
{
return new pqilistener();
}
pqiperson *pqipersongrpTestHarness::createPerson(std::string id, pqilistener *listener)
{
return createTestPerson(id, this);
}
/********* FUNCTIONS to OVERLOAD for specialisation ********/
pqiperson *createTestPerson(std::string id, pqipersongrp *ppg)
{
/* now add test children */
{
std::cerr << "createTestPerson()";
std::cerr << std::endl;
}
pqiperson *pqip = new pqiperson(id, ppg);
/* construct the serialiser ....
* Needs:
* * FileItem
* * FileData
* * ServiceGeneric
*/
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser());
NetBinDummy *dummy1 = new NetBinDummy(pqip, id, PQI_CONNECT_TCP);
pqiconnect *pqisc = new testConnect(rss, dummy1);
addTestConnect(pqisc, pqip);
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
RsSerialiser *rss2 = new RsSerialiser();
rss2->addSerialType(new RsFileItemSerialiser());
rss2->addSerialType(new RsCacheItemSerialiser());
rss2->addSerialType(new RsServiceSerialiser());
NetBinDummy *dummy2 = new NetBinDummy(pqip, id, PQI_CONNECT_TUNNEL);
pqiconnect *pqicontun = new testConnect(rss2, dummy2);
addTestConnect(pqicontun, pqip);
pqip -> addChildInterface(PQI_CONNECT_TUNNEL, pqicontun);
RsSerialiser *rss3 = new RsSerialiser();
rss3->addSerialType(new RsFileItemSerialiser());
rss3->addSerialType(new RsCacheItemSerialiser());
rss3->addSerialType(new RsServiceSerialiser());
NetBinDummy *dummy3 = new NetBinDummy(pqip, id, PQI_CONNECT_UDP);
pqiconnect *pqiusc = new testConnect(rss3, dummy3);
addTestConnect(pqiusc, pqip);
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
return pqip;
}

View File

@ -0,0 +1,61 @@
#ifndef PPG_HARNESS_TEST_H
#define PPG_HARNESS_TEST_H
/*
* libretroshare/src/test/pqi ppg_harness.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2007-2008 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 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".
*
*/
/******
* test harness for pqipersongrp / pqihandler.
*/
#include "pqi/pqiperson.h"
#include "pqi/pqipersongrp.h"
/*******************************************************
*
* Test structure
*****************/
void setupPqiPersonGrpTH();
void tickPqiPersonGrpTH();
class pqipersongrpTestHarness;
extern pqipersongrpTestHarness *mPqiPersonGrpTH;
class pqipersongrpTestHarness: public pqipersongrp
{
public:
pqipersongrpTestHarness(SecurityPolicy *pol, unsigned long flags);
protected:
/********* FUNCTIONS to OVERLOAD for specialisation ********/
virtual pqilistener *createListener(struct sockaddr_in laddr);
virtual pqiperson *createPerson(std::string id, pqilistener *listener);
/********* FUNCTIONS to OVERLOAD for specialisation ********/
};
#endif

View File

@ -111,7 +111,7 @@ pqiperson *createTestPerson(std::string id, pqipersongrp *ppg)
rss->addSerialType(new RsCacheItemSerialiser()); rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser()); rss->addSerialType(new RsServiceSerialiser());
NetBinDummy *dummy1 = new NetBinDummy(pqip, id, PQI_CONNECT_TUNNEL); NetBinDummy *dummy1 = new NetBinDummy(pqip, id, PQI_CONNECT_TCP);
pqiconnect *pqisc = new testConnect(rss, dummy1); pqiconnect *pqisc = new testConnect(rss, dummy1);
addTestConnect(pqisc); addTestConnect(pqisc);
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc); pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);

View File

@ -141,7 +141,7 @@ pqiperson *createTestPerson(std::string id, pqipersongrp *ppg)
rss->addSerialType(new RsCacheItemSerialiser()); rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser()); rss->addSerialType(new RsServiceSerialiser());
NetBinDummy *dummy1 = new NetBinDummy(pqip, id, PQI_CONNECT_TUNNEL); NetBinDummy *dummy1 = new NetBinDummy(pqip, id, PQI_CONNECT_TCP);
pqiconnect *pqisc = new testConnect(rss, dummy1); pqiconnect *pqisc = new testConnect(rss, dummy1);
addTestConnect(pqisc); addTestConnect(pqisc);
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc); pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);