face: Implementing Face::getUri() method
Change-Id: I9a9f774b95784e5b7ec75472f1cc6cf64c4e5d7b
Refs: #1319
diff --git a/tests/face/dummy-face.hpp b/tests/face/dummy-face.hpp
index 969053a..e64a162 100644
--- a/tests/face/dummy-face.hpp
+++ b/tests/face/dummy-face.hpp
@@ -20,6 +20,11 @@
class DummyFaceImpl : public FaceBase
{
public:
+ DummyFaceImpl()
+ : FaceBase(FaceUri("dummy://"))
+ {
+ }
+
virtual void
sendInterest(const Interest& interest)
{
diff --git a/tests/face/ethernet.cpp b/tests/face/ethernet.cpp
index 9322d4c..2e731bf 100644
--- a/tests/face/ethernet.cpp
+++ b/tests/face/ethernet.cpp
@@ -75,6 +75,9 @@
BOOST_REQUIRE(static_cast<bool>(face));
BOOST_CHECK_EQUAL(face->isLocal(), false);
+ BOOST_CHECK_EQUAL(face->getUri().toString(),
+ "ether://" + interfaces[0] + "/" +
+ ethernet::getDefaultMulticastAddress().toString(':'));
Interest interest1("ndn:/TpnzGvW9R");
Data data1 ("ndn:/KfczhUqVix");
diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp
index 9223283..47c3b5b 100644
--- a/tests/face/tcp.cpp
+++ b/tests/face/tcp.cpp
@@ -162,20 +162,19 @@
};
-BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
+BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
{
TcpFactory factory;
shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
- shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
+ factory.createChannel("127.0.0.1", "20071");
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
- channel2->connect("127.0.0.1", "20070",
- bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- bind(&EndToEndFixture::channel2_onConnectFailed, this, _1),
- time::seconds(4));
+ factory.createFace(FaceUri("tcp://127.0.0.1:20070"),
+ bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
+ bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
"TcpChannel error: cannot connect or cannot accept connection");
@@ -183,6 +182,74 @@
BOOST_REQUIRE(static_cast<bool>(m_face1));
BOOST_REQUIRE(static_cast<bool>(m_face2));
+ BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "tcp4://127.0.0.1:20070");
+ // face1 has an unknown URI, since the source port is automatically chosen by OS
+
+ BOOST_CHECK_EQUAL(m_face1->isLocal(), true);
+ BOOST_CHECK_EQUAL(m_face2->isLocal(), true);
+
+ BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(m_face1)), true);
+ BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(m_face2)), true);
+
+ // integrated tests needs to check that TcpFace for non-loopback fails these tests...
+
+ Interest interest1("ndn:/TpnzGvW9R");
+ Data data1 ("ndn:/KfczhUqVix");
+ data1.setContent(0, 0);
+ Interest interest2("ndn:/QWiIMfj5sL");
+ Data data2 ("ndn:/XNBV796f");
+ data2.setContent(0, 0);
+
+ ndn::SignatureSha256WithRsa fakeSignature;
+ fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
+
+ // set fake signature on data1 and data2
+ data1.setSignature(fakeSignature);
+ data2.setSignature(fakeSignature);
+
+ m_face1->sendInterest(interest1);
+ m_face1->sendData (data1 );
+ m_face2->sendInterest(interest2);
+ m_face2->sendData (data2 );
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(4, time::seconds(10)) == LimitedIo::EXCEED_OPS,
+ "TcpChannel error: cannot send or receive Interest/Data packets");
+
+
+ BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
+
+ BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
+ BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
+ BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
+ BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
+}
+
+BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture)
+{
+ TcpFactory factory;
+
+ shared_ptr<TcpChannel> channel1 = factory.createChannel("::1", "20070");
+ shared_ptr<TcpChannel> channel2 = factory.createChannel("::1", "20071");
+
+ channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
+ bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
+
+ factory.createFace(FaceUri("tcp://[::1]:20070"),
+ bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
+ bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS,
+ "TcpChannel error: cannot connect or cannot accept connection");
+
+ BOOST_REQUIRE(static_cast<bool>(m_face1));
+ BOOST_REQUIRE(static_cast<bool>(m_face2));
+
+ BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "tcp6://[::1]:20070");
+ // face1 has an unknown URI, since the source port is automatically chosen by OS
+
BOOST_CHECK_EQUAL(m_face1->isLocal(), true);
BOOST_CHECK_EQUAL(m_face2->isLocal(), true);
diff --git a/tests/face/udp.cpp b/tests/face/udp.cpp
index f877e2f..3c86a6d 100644
--- a/tests/face/udp.cpp
+++ b/tests/face/udp.cpp
@@ -320,16 +320,11 @@
};
-BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
+BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
{
UdpFactory factory;
- shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
-
-
- //channel2->connect("127.0.0.1", "20070",
- // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
- // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
+ factory.createChannel("127.0.0.1", "20071");
factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
@@ -340,12 +335,14 @@
"UdpChannel error: cannot connect or cannot accept connection");
BOOST_REQUIRE(static_cast<bool>(m_face2));
+ BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "udp4://127.0.0.1:20070");
+ BOOST_CHECK_EQUAL(m_face2->isLocal(), false);
+ // m_face1 is not created yet
shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
-
Interest interest1("ndn:/TpnzGvW9R");
Data data1 ("ndn:/KfczhUqVix");
data1.setContent(0, 0);
@@ -375,6 +372,8 @@
"UdpChannel error: cannot send or receive Interest/Data packets");
BOOST_REQUIRE(static_cast<bool>(m_face1));
+ BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp4://127.0.0.1:20071");
+ BOOST_CHECK_EQUAL(m_face1->isLocal(), false);
m_face1->sendInterest(interest1);
m_face1->sendData (data1 );
@@ -408,7 +407,95 @@
BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName());
BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName());
+}
+BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture)
+{
+ UdpFactory factory;
+
+ factory.createChannel("::1", "20071");
+
+ factory.createFace(FaceUri("udp://[::1]:20070"),
+ bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
+ bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
+
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
+ "UdpChannel error: cannot connect or cannot accept connection");
+
+ BOOST_REQUIRE(static_cast<bool>(m_face2));
+ BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "udp6://[::1]:20070");
+ BOOST_CHECK_EQUAL(m_face2->isLocal(), false);
+ // m_face1 is not created yet
+
+ shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
+ channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
+ bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
+
+ Interest interest1("ndn:/TpnzGvW9R");
+ Data data1 ("ndn:/KfczhUqVix");
+ data1.setContent(0, 0);
+ Interest interest2("ndn:/QWiIMfj5sL");
+ Data data2 ("ndn:/XNBV796f");
+ data2.setContent(0, 0);
+ Interest interest3("ndn:/QWiIhjgkj5sL");
+ Data data3 ("ndn:/XNBV794f");
+ data3.setContent(0, 0);
+
+
+ ndn::SignatureSha256WithRsa fakeSignature;
+ fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
+ reinterpret_cast<const uint8_t*>(0),
+ 0));
+
+ // set fake signature on data1 and data2
+ data1.setSignature(fakeSignature);
+ data2.setSignature(fakeSignature);
+ data3.setSignature(fakeSignature);
+
+ m_face2->sendInterest(interest2);
+ m_face2->sendData (data2 );
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(3,//2 send + 1 listen return
+ time::seconds(1)) == LimitedIo::EXCEED_OPS,
+ "UdpChannel error: cannot send or receive Interest/Data packets");
+
+ BOOST_REQUIRE(static_cast<bool>(m_face1));
+ BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp6://[::1]:20071");
+ BOOST_CHECK_EQUAL(m_face1->isLocal(), false);
+
+ m_face1->sendInterest(interest1);
+ m_face1->sendData (data1 );
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
+ "UdpChannel error: cannot send or receive Interest/Data packets");
+
+
+ BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
+ BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
+
+ BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
+ BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
+ BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
+ BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
+
+
+
+ //checking if the connection accepting mechanism works properly.
+
+ m_face2->sendData (data3 );
+ m_face2->sendInterest(interest3);
+
+ BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
+ "UdpChannel error: cannot send or receive Interest/Data packets");
+
+ BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2);
+ BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2);
+
+ BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName());
+ BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName());
}
BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
diff --git a/tests/face/unix-stream.cpp b/tests/face/unix-stream.cpp
index 921c1ff..09ee905 100644
--- a/tests/face/unix-stream.cpp
+++ b/tests/face/unix-stream.cpp
@@ -148,6 +148,11 @@
BOOST_REQUIRE(static_cast<bool>(m_face1));
+ std::string face1uri = m_face1->getUri().toString();
+ BOOST_CHECK_EQUAL(face1uri.find("unix:///"), 0); // third '/' is the path separator
+ BOOST_CHECK_EQUAL(face1uri.rfind(CHANNEL_PATH1),
+ face1uri.size() - std::string(CHANNEL_PATH1).size());
+
m_face2 = make_shared<UnixStreamFace>(client);
m_face2->onReceiveInterest +=
bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);