blob: 5a3a8646dc5e04fa3e7be68b5c0ee269bb588f03 [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");
Yukai Tud93c5fc2015-08-25 11:37:16 +080036 parameters.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Junxiao Shibc19b372014-03-23 16:59:25 -070037 Block wire = parameters.wireEncode();
38
39 ControlParameters decoded(wire);
40 BOOST_CHECK_EQUAL(decoded.getUri(), "tcp4://192.0.2.1:6363");
Yukai Tud93c5fc2015-08-25 11:37:16 +080041 BOOST_CHECK_EQUAL(decoded.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070042
Junxiao Shibc19b372014-03-23 16:59:25 -070043 BOOST_CHECK_EQUAL(decoded.hasName(), false);
44 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
45 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070046 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070047 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070048 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070049 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070050 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070051}
52
53BOOST_AUTO_TEST_CASE(FaceLocalControlOptions)
54{
55 ControlParameters parameters;
56 parameters.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
57
58 Block wire = parameters.wireEncode();
59
60 ControlParameters decoded(wire);
61 BOOST_CHECK_EQUAL(decoded.getLocalControlFeature(), LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070062
Junxiao Shibc19b372014-03-23 16:59:25 -070063 BOOST_CHECK_EQUAL(decoded.hasName(), false);
64 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070065 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070066 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
67 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
68 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070069 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070070 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Yukai Tud93c5fc2015-08-25 11:37:16 +080071 BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070072}
73
74BOOST_AUTO_TEST_CASE(FibOptions)
75{
76 ControlParameters parameters;
77 parameters.setName("ndn:/example")
78 .setFaceId(4)
79 .setCost(555);
80
81 Block wire = parameters.wireEncode();
82
83 ControlParameters decoded(wire);
84 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example"));
85 BOOST_CHECK_EQUAL(decoded.getFaceId(), 4);
86 BOOST_CHECK_EQUAL(decoded.getCost(), 555);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070087
Junxiao Shibc19b372014-03-23 16:59:25 -070088 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070089 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
90 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
91 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070092 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -070093 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Yukai Tud93c5fc2015-08-25 11:37:16 +080094 BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -070095}
96
97BOOST_AUTO_TEST_CASE(StrategyChoiceOptions)
98{
99 ControlParameters parameters;
100 parameters.setName("ndn:/")
101 .setStrategy("ndn:/strategy/A");
102
103 Block wire = parameters.wireEncode();
104
105 ControlParameters decoded(wire);
106 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/"));
107 BOOST_CHECK_EQUAL(decoded.getStrategy(), Name("ndn:/strategy/A"));
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700108
Junxiao Shibc19b372014-03-23 16:59:25 -0700109 BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
110 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
111 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700112 BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -0700113 BOOST_CHECK_EQUAL(decoded.hasCost(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700114 BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
115 BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
Yukai Tud93c5fc2015-08-25 11:37:16 +0800116 BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
Junxiao Shi5f6c74f2014-04-18 16:29:44 -0700117}
118
119BOOST_AUTO_TEST_CASE(RibOptions)
120{
121 ControlParameters parameters;
122 parameters.setName("ndn:/example")
123 .setFaceId(4)
124 .setOrigin(128)
125 .setCost(6)
126 .setFlags(0x01)
127 .setExpirationPeriod(time::milliseconds(1800000));
128
129 Block wire = parameters.wireEncode();
130
131 ControlParameters decoded(wire);
132 BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example"));
133 BOOST_CHECK_EQUAL(decoded.getFaceId(), 4);
134 BOOST_CHECK_EQUAL(decoded.getOrigin(), 128);
135 BOOST_CHECK_EQUAL(decoded.getCost(), 6);
136 BOOST_CHECK_EQUAL(decoded.getFlags(), 0x01);
137 BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), time::milliseconds(1800000));
138
139 BOOST_CHECK_EQUAL(decoded.hasUri(), false);
140 BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
141 BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
Yukai Tud93c5fc2015-08-25 11:37:16 +0800142 BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
Junxiao Shibc19b372014-03-23 16:59:25 -0700143}
144
145BOOST_AUTO_TEST_SUITE_END()
146
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800147} // namespace tests
Junxiao Shibc19b372014-03-23 16:59:25 -0700148} // namespace nfd
149} // namespace ndn