blob: eeb18ed89a794f305b9476df5cb160febcad07a4 [file] [log] [blame]
Junxiao Shi5ec80222014-03-25 20:08:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "management/nfd-control-command.hpp"
8// Having a separate compilation unit is necessary to ensure .hpp can compile on its own.
9
10#include <boost/test/unit_test.hpp>
11
12namespace ndn {
13namespace nfd {
14
15BOOST_AUTO_TEST_SUITE(NfdControlCommand)
16
17BOOST_AUTO_TEST_CASE(FaceCreate)
18{
19 FaceCreateCommand command;
20 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/create");
21
22 ControlParameters p1;
23 p1.setUri("tcp4://192.0.2.1")
24 .setFaceId(4);
25 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
26 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
27
28 ControlParameters p2;
29 p2.setName("ndn:/example");
30 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
31 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
32
33 ControlParameters p3;
34 p3.setUri("tcp4://192.0.2.1")
35 .setFaceId(0);
36 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
37}
38
39BOOST_AUTO_TEST_CASE(FaceDestroy)
40{
41 FaceDestroyCommand command;
42 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/destroy");
43
44 ControlParameters p1;
45 p1.setUri("tcp4://192.0.2.1")
46 .setFaceId(4);
47 BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
48 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
49
50 ControlParameters p2;
51 p2.setFaceId(0);
52 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
53 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
54
55 ControlParameters p3;
56 p3.setFaceId(6);
57 BOOST_CHECK_NO_THROW(command.validateRequest(p3));
58 BOOST_CHECK_NO_THROW(command.validateResponse(p3));
59}
60
61BOOST_AUTO_TEST_CASE(FaceEnableLocalControl)
62{
63 FaceEnableLocalControlCommand command;
64 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/enable-local-control");
65
66 ControlParameters p1;
67 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
68 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
69 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
70
71 ControlParameters p2;
72 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
73 .setFaceId(9);
74 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
75 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
76}
77
78BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
79{
80 FaceDisableLocalControlCommand command;
81 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control");
82
83 ControlParameters p1;
84 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
85 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
86 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
87
88 ControlParameters p2;
89 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
90 .setFaceId(9);
91 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
92 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
93}
94
95BOOST_AUTO_TEST_CASE(FibAddNextHop)
96{
97 FibAddNextHopCommand command;
98 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop");
99
100 ControlParameters p1;
101 p1.setName("ndn:/")
102 .setFaceId(22);
103 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
104 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
105
106 ControlParameters p2;
107 p2.setName("ndn:/example")
108 .setFaceId(0)
109 .setCost(6);
110 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
111 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
112
113 command.applyDefaultsToRequest(p1);
114 BOOST_REQUIRE(p1.hasCost());
115 BOOST_CHECK_EQUAL(p1.getCost(), 0);
116}
117
118BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
119{
120 FibRemoveNextHopCommand command;
121 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop");
122
123 ControlParameters p1;
124 p1.setName("ndn:/")
125 .setFaceId(22);
126 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
127 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
128
129 ControlParameters p2;
130 p2.setName("ndn:/example")
131 .setFaceId(0);
132 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
133 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
134}
135
136BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
137{
138 StrategyChoiceSetCommand command;
139 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set");
140
141 ControlParameters p1;
142 p1.setName("ndn:/")
143 .setStrategy("ndn:/strategy/P");
144 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
145 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
146
147 ControlParameters p2;
148 p2.setName("ndn:/example");
149 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
150 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
151}
152
153BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
154{
155 StrategyChoiceUnsetCommand command;
156 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset");
157
158 ControlParameters p1;
159 p1.setName("ndn:/example");
160 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
161 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
162
163 ControlParameters p2;
164 p2.setName("ndn:/example")
165 .setStrategy("ndn:/strategy/P");
166 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
167 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
168
169 ControlParameters p3;
170 p3.setName("ndn:/");
171 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
172 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
173}
174
175BOOST_AUTO_TEST_SUITE_END()
176
177} // namespace nfd
178} // namespace ndn