blob: d242ee7ce764d90445fe77c0d5c5317f3a08c318 [file] [log] [blame]
Vince Lehman27f1add2014-10-16 17:14:46 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 **/
21
22#include "tests/test-common.hpp"
23#include "tests/control-commands.hpp"
24#include "tests/dummy-face.hpp"
25
26#include "utility/face-controller.hpp"
27
28#include <ndn-cxx/management/nfd-controller.hpp>
29
30namespace nlsr {
31namespace test {
32
33using ndn::bind;
34using ndn::shared_ptr;
35using ndn::Interest;
36
37class FaceControllerFixture : public BaseFixture
38{
39public:
40 FaceControllerFixture()
41 : face(ndn::makeDummyFace())
42 , interests(face->m_sentInterests)
43 , controller(ndn::ref(*face))
44 , faceManager(g_ioService, controller)
45 {
46 }
47
48 void
49 expectCanonizeSuccess(const std::string& request, const std::string expectedUri)
50 {
51 faceManager.createFace(request, 0, bind(&FaceControllerFixture::onFailure, this, _1, _2));
52 expectedUris.push_back(expectedUri);
53 }
54
55 void
56 expectCanonizeFailure(const std::string& request)
57 {
58 faceManager.createFace(request, 0, bind(&FaceControllerFixture::onFailure, this, _1, _2));
59 }
60
61 void
62 onFailure(uint32_t code, const std::string& reason)
63 {
64 BOOST_CHECK_EQUAL(code, 408);
65 }
66
67public:
68 shared_ptr<ndn::DummyFace> face;
69 std::vector<Interest>& interests;
70 ndn::nfd::Controller controller;
71 util::FaceController faceManager;
72
73 std::list<std::string> expectedUris;
74};
75
76BOOST_FIXTURE_TEST_SUITE(TestFaceController, FaceControllerFixture)
77
78BOOST_AUTO_TEST_CASE(FaceCreateCanonize)
79{
80 expectCanonizeSuccess("udp4://192.0.2.1:6363", "udp4://192.0.2.1:6363");
81 expectCanonizeSuccess("tcp4://192.0.2.1:6363", "tcp4://192.0.2.1:6363");
82
83 expectCanonizeSuccess("udp://192.0.2.1", "udp4://192.0.2.1:6363");
84 expectCanonizeSuccess("udp://203.0.113.1:6363", "udp4://203.0.113.1:6363");
85 expectCanonizeSuccess("udp4://google-public-dns-a.google.com", "udp4://8.8.8.8:6363");
86
87 expectCanonizeSuccess("tcp://192.0.2.1", "tcp4://192.0.2.1:6363");
88 expectCanonizeSuccess("tcp://203.0.113.1:6363", "tcp4://203.0.113.1:6363");
89 expectCanonizeSuccess("tcp4://google-public-dns-a.google.com", "tcp4://8.8.8.8:6363");
90
91 expectCanonizeSuccess("udp6://[2001:4860:4860::8888]:6363", "udp6://[2001:4860:4860::8888]:6363");
92 expectCanonizeSuccess("tcp6://[2001:4860:4860::8888]:6363", "tcp6://[2001:4860:4860::8888]:6363");
93
94 expectCanonizeSuccess("udp://[2001:4860:4860::8888]", "udp6://[2001:4860:4860::8888]:6363");
95 expectCanonizeSuccess("udp://[2001:4860:4860::8888]:6363", "udp6://[2001:4860:4860::8888]:6363");
96 expectCanonizeSuccess("udp6://google-public-dns-a.google.com",
97 "udp6://[2001:4860:4860::8888]:6363");
98
99 expectCanonizeSuccess("tcp://[2001:4860:4860::8888]", "tcp6://[2001:4860:4860::8888]:6363");
100 expectCanonizeSuccess("tcp://[2001:4860:4860::8888]:6363", "tcp6://[2001:4860:4860::8888]:6363");
101 expectCanonizeSuccess("tcp6://google-public-dns-a.google.com",
102 "tcp6://[2001:4860:4860::8888]:6363");
103
104 g_ioService.run();
105 face->processEvents(ndn::time::milliseconds(1));
106
107 BOOST_CHECK_EQUAL(interests.size(), expectedUris.size());
108
109 for (std::vector<ndn::Interest>::iterator it = interests.begin(); it != interests.end(); ++it) {
110
111 ndn::nfd::ControlParameters extractedParameters;
112 ndn::Name::Component verb;
113
114 extractFaceCommandParameters(*it, verb, extractedParameters);
115
116 BOOST_CHECK_EQUAL(verb, ndn::Name::Component("create"));
117
118 std::list<std::string>::iterator uri = std::find(expectedUris.begin(),
119 expectedUris.end(),
120 extractedParameters.getUri());
121
122 BOOST_REQUIRE(uri != expectedUris.end());
123 expectedUris.erase(uri);
124 }
125}
126
127BOOST_AUTO_TEST_CASE(FaceCreateFailure)
128{
129 expectCanonizeFailure("udp4://not-a-valid.uri");
130 expectCanonizeFailure("udp4://256.0.0.1:6363");
131
132 g_ioService.run();
133 face->processEvents(ndn::time::milliseconds(1));
134
135 BOOST_CHECK_EQUAL(interests.size(), 0);
136}
137
138BOOST_AUTO_TEST_SUITE_END()
139
140} //namespace test
141} //namespace nlsr