blob: 9a959e4d2bbdcf6a849f11d35d7945c692bffc94 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shibc19b372014-03-23 16:59:25 -07002/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Junxiao Shibc19b372014-03-23 16:59:25 -070020 */
21
22#include "management/nfd-control-parameters.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070023
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070024#include "boost-test.hpp"
Junxiao Shibc19b372014-03-23 16:59:25 -070025
26namespace ndn {
27namespace nfd {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Junxiao Shibc19b372014-03-23 16:59:25 -070029
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030BOOST_AUTO_TEST_SUITE(ManagementNfdControlParameters)
Junxiao Shibc19b372014-03-23 16:59:25 -070031
32BOOST_AUTO_TEST_CASE(FaceOptions)
33{
34 ControlParameters parameters;
35 parameters.setUri("tcp4://192.0.2.1:6363");
36
37 Block wire = parameters.wireEncode();
38
39 ControlParameters decoded(wire);
40 BOOST_CHECK_EQUAL(decoded.getUri(), "tcp4://192.0.2.1:6363");
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070041
Junxiao Shibc19b372014-03-23 16:59:25 -070042 BOOST_CHECK_EQUAL(decoded.hasName(), false);
43 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
44 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070045 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070046 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070047 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070048 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070049 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070050}
51
52BOOST_AUTO_TEST_CASE(FaceLocalControlOptions)
53{
54 ControlParameters parameters;
55 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
56
57 Block wire = parameters.wireEncode();
58
59 ControlParameters decoded(wire);
60 BOOST_CHECK_EQUAL(decoded.getLocalControlFeature(), LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070061
Junxiao Shibc19b372014-03-23 16:59:25 -070062 BOOST_CHECK_EQUAL(decoded.hasName(), false);
63 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070064 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070065 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
66 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
67 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070068 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070069 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070070}
71
72BOOST_AUTO_TEST_CASE(FibOptions)
73{
74 ControlParameters parameters;
75 parameters.setName("ndn:/example")
76 .setFaceId(4)
77 .setCost(555);
78
79 Block wire = parameters.wireEncode();
80
81 ControlParameters decoded(wire);
82 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example"));
83 BOOST_CHECK_EQUAL(decoded.getFaceId(), 4);
84 BOOST_CHECK_EQUAL(decoded.getCost(), 555);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070085
Junxiao Shibc19b372014-03-23 16:59:25 -070086 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070087 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
88 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
89 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070090 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070091 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070092}
93
94BOOST_AUTO_TEST_CASE(StrategyChoiceOptions)
95{
96 ControlParameters parameters;
97 parameters.setName("ndn:/")
98 .setStrategy("ndn:/strategy/A");
99
100 Block wire = parameters.wireEncode();
101
102 ControlParameters decoded(wire);
103 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/"));
104 BOOST_CHECK_EQUAL(decoded.getStrategy(), Name("ndn:/strategy/A"));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700105
Junxiao Shibc19b372014-03-23 16:59:25 -0700106 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
107 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
108 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700109 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -0700110 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700111 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
112 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
113}
114
115BOOST_AUTO_TEST_CASE(RibOptions)
116{
117 ControlParameters parameters;
118 parameters.setName("ndn:/example")
119 .setFaceId(4)
120 .setOrigin(128)
121 .setCost(6)
122 .setFlags(0x01)
123 .setExpirationPeriod(time::milliseconds(1800000));
124
125 Block wire = parameters.wireEncode();
126
127 ControlParameters decoded(wire);
128 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example"));
129 BOOST_CHECK_EQUAL(decoded.getFaceId(), 4);
130 BOOST_CHECK_EQUAL(decoded.getOrigin(), 128);
131 BOOST_CHECK_EQUAL(decoded.getCost(), 6);
132 BOOST_CHECK_EQUAL(decoded.getFlags(), 0x01);
133 BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), time::milliseconds(1800000));
134
135 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
136 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
137 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -0700138}
139
140BOOST_AUTO_TEST_SUITE_END()
141
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800142} // namespace tests
Junxiao Shibc19b372014-03-23 16:59:25 -0700143} // namespace nfd
144} // namespace ndn