blob: 724d6e5ba978ec2c0b5600607ce09700669ebe6f [file] [log] [blame]
#include "ccnx-tunnel.h"
#include "ccnx-closure.h"
#include "ccnx-name.h"
#include "ccnx-pco.h"
#include <unistd.h>
#include <boost/test/unit_test.hpp>
using namespace Ccnx;
using namespace std;
using namespace boost;
BOOST_AUTO_TEST_SUITE(CcnxTunnelTests)
class DummyTunnel : public CcnxTunnel
{
public:
DummyTunnel();
virtual ~DummyTunnel() {}
virtual Name
queryRoutableName(const Name &name);
void
overridePrefix();
};
DummyTunnel::DummyTunnel() : CcnxTunnel()
{
m_localPrefix = Name("/local");
}
void
DummyTunnel::overridePrefix()
{
CcnxWrapper::setInterestFilter(m_localPrefix, bind(&DummyTunnel::handleTunneledInterest, this, _1));
}
Name
DummyTunnel::queryRoutableName (const Name &name)
{
return Name("/local") + name;
}
CcnxWrapperPtr t1(new DummyTunnel());
CcnxWrapperPtr t2(new DummyTunnel());
CcnxWrapperPtr c1(new CcnxWrapper());
DummyTunnel t3;
// global data callback counter;
int g_dc_i = 0;
int g_dc_o = 0;
int g_ic = 0;
void innerCallback(const Name &name, const Bytes &content)
{
g_dc_i ++;
string str((const char *)&content[0], content.size());
BOOST_CHECK_EQUAL(name, str);
}
void outerCallback(const Name &name, const Bytes &content)
{
g_dc_o ++;
}
void interestCallback(const Name &name)
{
string strName = name.toString();
t3.publishData(name, (const unsigned char *)strName.c_str(), strName.size(), 5);
g_ic++;
}
BOOST_AUTO_TEST_CASE (CcnxTunnelTest)
{
// test publish
string inner = "/hello";
g_dc_o = 0;
t1->publishData(Name(inner), (const unsigned char *)inner.c_str(), inner.size(), 5);
usleep(100000);
c1->sendInterest(Name("/local/hello"), Closure(bind(outerCallback, _1, _2)));
usleep(100000);
// it is indeed published as /local/hello
BOOST_CHECK_EQUAL(g_dc_o, 1);
g_dc_i = 0;
t2->sendInterest(Name(inner), Closure(bind(innerCallback, _1, _2)));
usleep(100000);
BOOST_CHECK_EQUAL(g_dc_i, 1);
}
BOOST_AUTO_TEST_CASE (CcnxTunnelRegister)
{
g_ic = 0;
g_dc_i = 0;
t3.overridePrefix();
t3.setInterestFilter(Name("/t3"), bind(interestCallback, _1));
usleep(100000);
Closure innerClosure (bind(innerCallback, _1, _2));
t1->sendInterest(Name("/t3/hello"), innerClosure);
usleep(100000);
BOOST_CHECK_EQUAL(g_dc_i, 1);
BOOST_CHECK_EQUAL(g_ic, 1);
t3.clearInterestFilter(Name("/t3"));
usleep(100000);
t1->sendInterest(Name("/t3/hello-there"), innerClosure);
usleep(100000);
BOOST_CHECK_EQUAL(g_dc_i, 1);
BOOST_CHECK_EQUAL(g_ic, 1);
}
BOOST_AUTO_TEST_SUITE_END()