blob: 5cf1910b49e7b3ac9e5e7666e753ce374cf1be83 [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);
Junxiao Shi6888bc12014-03-29 23:01:41 -070076
77 ControlParameters p3;
78 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
79 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
80 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -070081}
82
83BOOST_AUTO_TEST_CASE(FaceDisableLocalControl)
84{
85 FaceDisableLocalControlCommand command;
86 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/faces/disable-local-control");
87
88 ControlParameters p1;
89 p1.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
90 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
91 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
92
93 ControlParameters p2;
94 p2.setLocalControlFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)
95 .setFaceId(9);
96 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
97 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
Junxiao Shi6888bc12014-03-29 23:01:41 -070098
99 ControlParameters p3;
100 p3.setLocalControlFeature(static_cast<LocalControlFeature>(666));
101 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
102 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
Junxiao Shi5ec80222014-03-25 20:08:05 -0700103}
104
105BOOST_AUTO_TEST_CASE(FibAddNextHop)
106{
107 FibAddNextHopCommand command;
108 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/add-nexthop");
109
110 ControlParameters p1;
111 p1.setName("ndn:/")
112 .setFaceId(22);
113 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
114 BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
115
116 ControlParameters p2;
117 p2.setName("ndn:/example")
118 .setFaceId(0)
119 .setCost(6);
120 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
121 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
122
123 command.applyDefaultsToRequest(p1);
124 BOOST_REQUIRE(p1.hasCost());
125 BOOST_CHECK_EQUAL(p1.getCost(), 0);
126}
127
128BOOST_AUTO_TEST_CASE(FibRemoveNextHop)
129{
130 FibRemoveNextHopCommand command;
131 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/fib/remove-nexthop");
132
133 ControlParameters p1;
134 p1.setName("ndn:/")
135 .setFaceId(22);
136 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
137 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
138
139 ControlParameters p2;
140 p2.setName("ndn:/example")
141 .setFaceId(0);
142 BOOST_CHECK_NO_THROW(command.validateRequest(p2));
143 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
144}
145
146BOOST_AUTO_TEST_CASE(StrategyChoiceSet)
147{
148 StrategyChoiceSetCommand command;
149 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/set");
150
151 ControlParameters p1;
152 p1.setName("ndn:/")
153 .setStrategy("ndn:/strategy/P");
154 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
155 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
156
157 ControlParameters p2;
158 p2.setName("ndn:/example");
159 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
160 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
161}
162
163BOOST_AUTO_TEST_CASE(StrategyChoiceUnset)
164{
165 StrategyChoiceUnsetCommand command;
166 BOOST_CHECK_EQUAL(command.getPrefix(), "ndn:/localhost/nfd/strategy-choice/unset");
167
168 ControlParameters p1;
169 p1.setName("ndn:/example");
170 BOOST_CHECK_NO_THROW(command.validateRequest(p1));
171 BOOST_CHECK_NO_THROW(command.validateResponse(p1));
172
173 ControlParameters p2;
174 p2.setName("ndn:/example")
175 .setStrategy("ndn:/strategy/P");
176 BOOST_CHECK_THROW(command.validateRequest(p2), ControlCommand::ArgumentError);
177 BOOST_CHECK_THROW(command.validateResponse(p2), ControlCommand::ArgumentError);
178
179 ControlParameters p3;
180 p3.setName("ndn:/");
181 BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
182 BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
183}
184
185BOOST_AUTO_TEST_SUITE_END()
186
187} // namespace nfd
188} // namespace ndn