config_parser_unittest.cc 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184
  1. // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <arpa/inet.h>
  16. #include <gtest/gtest.h>
  17. #include <config/ccsession.h>
  18. #include <dhcp4/dhcp4_srv.h>
  19. #include <dhcp4/config_parser.h>
  20. #include <dhcp/option4_addrlst.h>
  21. #include <dhcp/option_custom.h>
  22. #include <dhcp/option_int.h>
  23. #include <dhcpsrv/subnet.h>
  24. #include <dhcpsrv/cfgmgr.h>
  25. #include <hooks/hooks_manager.h>
  26. #include "marker_file.h"
  27. #include "test_libraries.h"
  28. #include <boost/foreach.hpp>
  29. #include <boost/scoped_ptr.hpp>
  30. #include <iostream>
  31. #include <fstream>
  32. #include <sstream>
  33. #include <limits.h>
  34. using namespace isc;
  35. using namespace isc::asiolink;
  36. using namespace isc::config;
  37. using namespace isc::data;
  38. using namespace isc::dhcp;
  39. using namespace isc::dhcp::test;
  40. using namespace isc::hooks;
  41. using namespace std;
  42. namespace {
  43. class Dhcp4ParserTest : public ::testing::Test {
  44. public:
  45. Dhcp4ParserTest()
  46. :rcode_(-1) {
  47. // Open port 0 means to not do anything at all. We don't want to
  48. // deal with sockets here, just check if configuration handling
  49. // is sane.
  50. srv_.reset(new Dhcpv4Srv(0));
  51. CfgMgr::instance().deleteActiveIfaces();
  52. }
  53. // Check that no hooks libraries are loaded. This is a pre-condition for
  54. // a number of tests, so is checked in one place. As this uses an
  55. // ASSERT call - and it is not clear from the documentation that Gtest
  56. // predicates can be used in a constructor - the check is placed in SetUp.
  57. void SetUp() {
  58. std::vector<std::string> libraries = HooksManager::getLibraryNames();
  59. ASSERT_TRUE(libraries.empty());
  60. }
  61. // Checks if global parameter of name have expected_value
  62. void checkGlobalUint32(string name, uint32_t expected_value) {
  63. const Uint32StoragePtr uint32_defaults =
  64. globalContext()->uint32_values_;
  65. try {
  66. uint32_t actual_value = uint32_defaults->getParam(name);
  67. EXPECT_EQ(expected_value, actual_value);
  68. } catch (DhcpConfigError) {
  69. ADD_FAILURE() << "Expected uint32 with name " << name
  70. << " not found";
  71. }
  72. }
  73. // Checks if the result of DHCP server configuration has
  74. // expected code (0 for success, other for failures).
  75. // Also stores result in rcode_ and comment_.
  76. void checkResult(ConstElementPtr status, int expected_code) {
  77. ASSERT_TRUE(status);
  78. comment_ = parseAnswer(rcode_, status);
  79. EXPECT_EQ(expected_code, rcode_);
  80. }
  81. ~Dhcp4ParserTest() {
  82. resetConfiguration();
  83. // ... and delete the hooks library marker files if present
  84. unlink(LOAD_MARKER_FILE);
  85. unlink(UNLOAD_MARKER_FILE);
  86. };
  87. /// @brief Create the simple configuration with single option.
  88. ///
  89. /// This function allows to set one of the parameters that configure
  90. /// option value. These parameters are: "name", "code", "data",
  91. /// "csv-format" and "space".
  92. ///
  93. /// @param param_value string holding option parameter value to be
  94. /// injected into the configuration string.
  95. /// @param parameter name of the parameter to be configured with
  96. /// param value.
  97. /// @return configuration string containing custom values of parameters
  98. /// describing an option.
  99. std::string createConfigWithOption(const std::string& param_value,
  100. const std::string& parameter) {
  101. std::map<std::string, std::string> params;
  102. if (parameter == "name") {
  103. params["name"] = param_value;
  104. params["space"] = "dhcp4";
  105. params["code"] = "56";
  106. params["data"] = "AB CDEF0105";
  107. params["csv-format"] = "False";
  108. } else if (parameter == "space") {
  109. params["name"] = "dhcp-message";
  110. params["space"] = param_value;
  111. params["code"] = "56";
  112. params["data"] = "AB CDEF0105";
  113. params["csv-format"] = "False";
  114. } else if (parameter == "code") {
  115. params["name"] = "dhcp-message";
  116. params["space"] = "dhcp4";
  117. params["code"] = param_value;
  118. params["data"] = "AB CDEF0105";
  119. params["csv-format"] = "False";
  120. } else if (parameter == "data") {
  121. params["name"] = "dhcp-message";
  122. params["space"] = "dhcp4";
  123. params["code"] = "56";
  124. params["data"] = param_value;
  125. params["csv-format"] = "False";
  126. } else if (parameter == "csv-format") {
  127. params["name"] = "dhcp-message";
  128. params["space"] = "dhcp4";
  129. params["code"] = "56";
  130. params["data"] = "AB CDEF0105";
  131. params["csv-format"] = param_value;
  132. }
  133. return (createConfigWithOption(params));
  134. }
  135. /// @brief Create simple configuration with single option.
  136. ///
  137. /// This function creates a configuration for a single option with
  138. /// custom values for all parameters that describe the option.
  139. ///
  140. /// @params params map holding parameters and their values.
  141. /// @return configuration string containing custom values of parameters
  142. /// describing an option.
  143. std::string createConfigWithOption(const std::map<std::string, std::string>& params) {
  144. std::ostringstream stream;
  145. stream << "{ \"interfaces\": [ \"*\" ],"
  146. "\"rebind-timer\": 2000, "
  147. "\"renew-timer\": 1000, "
  148. "\"subnet4\": [ { "
  149. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  150. " \"subnet\": \"192.0.2.0/24\", "
  151. " \"option-data\": [ {";
  152. bool first = true;
  153. typedef std::pair<std::string, std::string> ParamPair;
  154. BOOST_FOREACH(ParamPair param, params) {
  155. if (!first) {
  156. stream << ", ";
  157. } else {
  158. // cppcheck-suppress unreadVariable
  159. first = false;
  160. }
  161. if (param.first == "name") {
  162. stream << "\"name\": \"" << param.second << "\"";
  163. } else if (param.first == "space") {
  164. stream << "\"space\": \"" << param.second << "\"";
  165. } else if (param.first == "code") {
  166. stream << "\"code\": " << param.second << "";
  167. } else if (param.first == "data") {
  168. stream << "\"data\": \"" << param.second << "\"";
  169. } else if (param.first == "csv-format") {
  170. stream << "\"csv-format\": " << param.second;
  171. }
  172. }
  173. stream <<
  174. " } ]"
  175. " } ],"
  176. "\"valid-lifetime\": 4000 }";
  177. return (stream.str());
  178. }
  179. /// @brief Test invalid option parameter value.
  180. ///
  181. /// This test function constructs the simple configuration
  182. /// string and injects invalid option configuration into it.
  183. /// It expects that parser will fail with provided option code.
  184. ///
  185. /// @param param_value string holding invalid option parameter value
  186. /// to be injected into configuration string.
  187. /// @param parameter name of the parameter to be configured with
  188. /// param_value (can be any of "name", "code", "data")
  189. void testInvalidOptionParam(const std::string& param_value,
  190. const std::string& parameter) {
  191. ConstElementPtr x;
  192. std::string config = createConfigWithOption(param_value, parameter);
  193. ElementPtr json = Element::fromJSON(config);
  194. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  195. ASSERT_TRUE(x);
  196. comment_ = parseAnswer(rcode_, x);
  197. ASSERT_EQ(1, rcode_);
  198. }
  199. /// @brief Test option against given code and data.
  200. ///
  201. /// @param option_desc option descriptor that carries the option to
  202. /// be tested.
  203. /// @param expected_code expected code of the option.
  204. /// @param expected_data expected data in the option.
  205. /// @param expected_data_len length of the reference data.
  206. /// @param extra_data if true extra data is allowed in an option
  207. /// after tested data.
  208. void testOption(const Subnet::OptionDescriptor& option_desc,
  209. uint16_t expected_code, const uint8_t* expected_data,
  210. size_t expected_data_len,
  211. bool extra_data = false) {
  212. // Check if option descriptor contains valid option pointer.
  213. ASSERT_TRUE(option_desc.option);
  214. // Verify option type.
  215. EXPECT_EQ(expected_code, option_desc.option->getType());
  216. // We may have many different option types being created. Some of them
  217. // have dedicated classes derived from Option class. In such case if
  218. // we want to verify the option contents against expected_data we have
  219. // to prepare raw buffer with the contents of the option. The easiest
  220. // way is to call pack() which will prepare on-wire data.
  221. util::OutputBuffer buf(option_desc.option->getData().size());
  222. option_desc.option->pack(buf);
  223. if (extra_data) {
  224. // The length of the buffer must be at least equal to size of the
  225. // reference data but it can sometimes be greater than that. This is
  226. // because some options carry suboptions that increase the overall
  227. // length.
  228. ASSERT_GE(buf.getLength() - option_desc.option->getHeaderLen(),
  229. expected_data_len);
  230. } else {
  231. ASSERT_EQ(buf.getLength() - option_desc.option->getHeaderLen(),
  232. expected_data_len);
  233. }
  234. // Verify that the data is correct. Do not verify suboptions and a header.
  235. const uint8_t* data = static_cast<const uint8_t*>(buf.getData());
  236. EXPECT_EQ(0, memcmp(expected_data, data + option_desc.option->getHeaderLen(),
  237. expected_data_len));
  238. }
  239. /// @brief Parse and Execute configuration
  240. ///
  241. /// Parses a configuration and executes a configuration of the server.
  242. /// If the operation fails, the current test will register a failure.
  243. ///
  244. /// @param config Configuration to parse
  245. /// @param operation Operation being performed. In the case of an error,
  246. /// the error text will include the string "unable to <operation>.".
  247. ///
  248. /// @return true if the configuration succeeded, false if not. In the
  249. /// latter case, a failure will have been added to the current test.
  250. bool
  251. executeConfiguration(const std::string& config, const char* operation) {
  252. ConstElementPtr status;
  253. try {
  254. ElementPtr json = Element::fromJSON(config);
  255. status = configureDhcp4Server(*srv_, json);
  256. } catch (const std::exception& ex) {
  257. ADD_FAILURE() << "Unable to " << operation << ". "
  258. << "The following configuration was used: " << std::endl
  259. << config << std::endl
  260. << " and the following error message was returned:"
  261. << ex.what() << std::endl;
  262. return (false);
  263. }
  264. // The status object must not be NULL
  265. if (!status) {
  266. ADD_FAILURE() << "Unable to " << operation << ". "
  267. << "The configuration function returned a null pointer.";
  268. return (false);
  269. }
  270. // Store the answer if we need it.
  271. // Returned value should be 0 (configuration success)
  272. comment_ = parseAnswer(rcode_, status);
  273. if (rcode_ != 0) {
  274. string reason = "";
  275. if (comment_) {
  276. reason = string(" (") + comment_->stringValue() + string(")");
  277. }
  278. ADD_FAILURE() << "Unable to " << operation << ". "
  279. << "The configuration function returned error code "
  280. << rcode_ << reason;
  281. return (false);
  282. }
  283. return (true);
  284. }
  285. /// @brief Reset configuration database.
  286. ///
  287. /// This function resets configuration data base by
  288. /// removing all subnets and option-data. Reset must
  289. /// be performed after each test to make sure that
  290. /// contents of the database do not affect result of
  291. /// subsequent tests.
  292. void resetConfiguration() {
  293. string config = "{ \"interfaces\": [ \"*\" ],"
  294. "\"hooks-libraries\": [ ], "
  295. "\"rebind-timer\": 2000, "
  296. "\"renew-timer\": 1000, "
  297. "\"valid-lifetime\": 4000, "
  298. "\"subnet4\": [ ], "
  299. "\"option-def\": [ ], "
  300. "\"option-data\": [ ] }";
  301. static_cast<void>(executeConfiguration(config,
  302. "reset configuration database"));
  303. }
  304. boost::scoped_ptr<Dhcpv4Srv> srv_; // DHCP4 server under test
  305. int rcode_; // Return code from element parsing
  306. ConstElementPtr comment_; // Reason for parse fail
  307. };
  308. // Goal of this test is a verification if a very simple config update
  309. // with just a bumped version number. That's the simplest possible
  310. // config update.
  311. TEST_F(Dhcp4ParserTest, version) {
  312. ConstElementPtr x;
  313. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_,
  314. Element::fromJSON("{\"version\": 0}")));
  315. // returned value must be 0 (configuration accepted)
  316. checkResult(x, 0);
  317. }
  318. /// The goal of this test is to verify that the code accepts only
  319. /// valid commands and malformed or unsupported parameters are rejected.
  320. TEST_F(Dhcp4ParserTest, bogusCommand) {
  321. ConstElementPtr x;
  322. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_,
  323. Element::fromJSON("{\"bogus\": 5}")));
  324. // returned value must be 1 (configuration parse error)
  325. checkResult(x, 1);
  326. }
  327. /// The goal of this test is to verify if wrongly defined subnet will
  328. /// be rejected. Properly defined subnet must include at least one
  329. /// pool definition.
  330. TEST_F(Dhcp4ParserTest, emptySubnet) {
  331. ConstElementPtr status;
  332. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
  333. Element::fromJSON("{ \"interfaces\": [ \"*\" ],"
  334. "\"rebind-timer\": 2000, "
  335. "\"renew-timer\": 1000, "
  336. "\"subnet4\": [ ], "
  337. "\"valid-lifetime\": 4000 }")));
  338. // returned value should be 0 (success)
  339. checkResult(status, 0);
  340. checkGlobalUint32("rebind-timer", 2000);
  341. checkGlobalUint32("renew-timer", 1000);
  342. checkGlobalUint32("valid-lifetime", 4000);
  343. }
  344. /// The goal of this test is to verify if defined subnet uses global
  345. /// parameter timer definitions.
  346. TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
  347. ConstElementPtr status;
  348. string config = "{ \"interfaces\": [ \"*\" ],"
  349. "\"rebind-timer\": 2000, "
  350. "\"renew-timer\": 1000, "
  351. "\"subnet4\": [ { "
  352. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  353. " \"subnet\": \"192.0.2.0/24\" } ],"
  354. "\"valid-lifetime\": 4000 }";
  355. ElementPtr json = Element::fromJSON(config);
  356. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  357. // check if returned status is OK
  358. checkResult(status, 0);
  359. // Now check if the configuration was indeed handled and we have
  360. // expected pool configured.
  361. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  362. ASSERT_TRUE(subnet);
  363. EXPECT_EQ(1000, subnet->getT1());
  364. EXPECT_EQ(2000, subnet->getT2());
  365. EXPECT_EQ(4000, subnet->getValid());
  366. }
  367. // Checks if the next-server defined as global parameter is taken into
  368. // consideration.
  369. TEST_F(Dhcp4ParserTest, nextServerGlobal) {
  370. ConstElementPtr status;
  371. string config = "{ \"interfaces\": [ \"*\" ],"
  372. "\"rebind-timer\": 2000, "
  373. "\"renew-timer\": 1000, "
  374. "\"next-server\": \"1.2.3.4\", "
  375. "\"subnet4\": [ { "
  376. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  377. " \"subnet\": \"192.0.2.0/24\" } ],"
  378. "\"valid-lifetime\": 4000 }";
  379. ElementPtr json = Element::fromJSON(config);
  380. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  381. // check if returned status is OK
  382. checkResult(status, 0);
  383. // Now check if the configuration was indeed handled and we have
  384. // expected pool configured.
  385. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  386. ASSERT_TRUE(subnet);
  387. EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
  388. }
  389. // Checks if the next-server defined as subnet parameter is taken into
  390. // consideration.
  391. TEST_F(Dhcp4ParserTest, nextServerSubnet) {
  392. ConstElementPtr status;
  393. string config = "{ \"interfaces\": [ \"*\" ],"
  394. "\"rebind-timer\": 2000, "
  395. "\"renew-timer\": 1000, "
  396. "\"subnet4\": [ { "
  397. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  398. " \"next-server\": \"1.2.3.4\", "
  399. " \"subnet\": \"192.0.2.0/24\" } ],"
  400. "\"valid-lifetime\": 4000 }";
  401. ElementPtr json = Element::fromJSON(config);
  402. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  403. // check if returned status is OK
  404. checkResult(status, 0);
  405. // Now check if the configuration was indeed handled and we have
  406. // expected pool configured.
  407. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  408. ASSERT_TRUE(subnet);
  409. EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
  410. }
  411. // Test checks several negative scenarios for next-server configuration: bogus
  412. // address, IPv6 adddress and empty string.
  413. TEST_F(Dhcp4ParserTest, nextServerNegative) {
  414. ConstElementPtr status;
  415. // Config with junk instead of next-server address
  416. string config_bogus1 = "{ \"interfaces\": [ \"*\" ],"
  417. "\"rebind-timer\": 2000, "
  418. "\"renew-timer\": 1000, "
  419. "\"subnet4\": [ { "
  420. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  421. " \"rebind-timer\": 2000, "
  422. " \"renew-timer\": 1000, "
  423. " \"next-server\": \"a.b.c.d\", "
  424. " \"subnet\": \"192.0.2.0/24\" } ],"
  425. "\"valid-lifetime\": 4000 }";
  426. // Config with IPv6 next server address
  427. string config_bogus2 = "{ \"interfaces\": [ \"*\" ],"
  428. "\"rebind-timer\": 2000, "
  429. "\"renew-timer\": 1000, "
  430. "\"subnet4\": [ { "
  431. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  432. " \"rebind-timer\": 2000, "
  433. " \"renew-timer\": 1000, "
  434. " \"next-server\": \"2001:db8::1\", "
  435. " \"subnet\": \"192.0.2.0/24\" } ],"
  436. "\"valid-lifetime\": 4000 }";
  437. // Config with empty next server address
  438. string config_bogus3 = "{ \"interfaces\": [ \"*\" ],"
  439. "\"rebind-timer\": 2000, "
  440. "\"renew-timer\": 1000, "
  441. "\"subnet4\": [ { "
  442. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  443. " \"rebind-timer\": 2000, "
  444. " \"renew-timer\": 1000, "
  445. " \"next-server\": \"\", "
  446. " \"subnet\": \"192.0.2.0/24\" } ],"
  447. "\"valid-lifetime\": 4000 }";
  448. ElementPtr json1 = Element::fromJSON(config_bogus1);
  449. ElementPtr json2 = Element::fromJSON(config_bogus2);
  450. ElementPtr json3 = Element::fromJSON(config_bogus3);
  451. // check if returned status is always a failure
  452. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json1));
  453. checkResult(status, 1);
  454. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json2));
  455. checkResult(status, 1);
  456. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json3));
  457. checkResult(status, 0);
  458. }
  459. // Checks if the next-server defined as global value is overridden by subnet
  460. // specific value.
  461. TEST_F(Dhcp4ParserTest, nextServerOverride) {
  462. ConstElementPtr status;
  463. string config = "{ \"interfaces\": [ \"*\" ],"
  464. "\"rebind-timer\": 2000, "
  465. "\"renew-timer\": 1000, "
  466. "\"next-server\": \"192.0.0.1\", "
  467. "\"subnet4\": [ { "
  468. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  469. " \"next-server\": \"1.2.3.4\", "
  470. " \"subnet\": \"192.0.2.0/24\" } ],"
  471. "\"valid-lifetime\": 4000 }";
  472. ElementPtr json = Element::fromJSON(config);
  473. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  474. // check if returned status is OK
  475. checkResult(status, 0);
  476. // Now check if the configuration was indeed handled and we have
  477. // expected pool configured.
  478. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  479. ASSERT_TRUE(subnet);
  480. EXPECT_EQ("1.2.3.4", subnet->getSiaddr().toText());
  481. }
  482. // Check whether it is possible to configure echo-client-id
  483. TEST_F(Dhcp4ParserTest, echoClientId) {
  484. ConstElementPtr status;
  485. string config_false = "{ \"interfaces\": [ \"*\" ],"
  486. "\"rebind-timer\": 2000, "
  487. "\"renew-timer\": 1000, "
  488. "\"echo-client-id\": false,"
  489. "\"subnet4\": [ { "
  490. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  491. " \"subnet\": \"192.0.2.0/24\" } ],"
  492. "\"valid-lifetime\": 4000 }";
  493. string config_true = "{ \"interfaces\": [ \"*\" ],"
  494. "\"rebind-timer\": 2000, "
  495. "\"renew-timer\": 1000, "
  496. "\"echo-client-id\": true,"
  497. "\"subnet4\": [ { "
  498. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  499. " \"subnet\": \"192.0.2.0/24\" } ],"
  500. "\"valid-lifetime\": 4000 }";
  501. ElementPtr json_false = Element::fromJSON(config_false);
  502. ElementPtr json_true = Element::fromJSON(config_true);
  503. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json_false));
  504. EXPECT_FALSE(CfgMgr::instance().echoClientId());
  505. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json_true));
  506. EXPECT_TRUE(CfgMgr::instance().echoClientId());
  507. // In any case revert back to the default value (true)
  508. CfgMgr::instance().echoClientId(true);
  509. }
  510. // This test checks if it is possible to override global values
  511. // on a per subnet basis.
  512. TEST_F(Dhcp4ParserTest, subnetLocal) {
  513. ConstElementPtr status;
  514. string config = "{ \"interfaces\": [ \"*\" ],"
  515. "\"rebind-timer\": 2000, "
  516. "\"renew-timer\": 1000, "
  517. "\"subnet4\": [ { "
  518. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  519. " \"renew-timer\": 1, "
  520. " \"rebind-timer\": 2, "
  521. " \"valid-lifetime\": 4,"
  522. " \"subnet\": \"192.0.2.0/24\" } ],"
  523. "\"valid-lifetime\": 4000 }";
  524. ElementPtr json = Element::fromJSON(config);
  525. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  526. // returned value should be 0 (configuration success)
  527. checkResult(status, 0);
  528. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  529. ASSERT_TRUE(subnet);
  530. EXPECT_EQ(1, subnet->getT1());
  531. EXPECT_EQ(2, subnet->getT2());
  532. EXPECT_EQ(4, subnet->getValid());
  533. }
  534. // Test verifies that a subnet with pool values that do not belong to that
  535. // pool are rejected.
  536. TEST_F(Dhcp4ParserTest, poolOutOfSubnet) {
  537. ConstElementPtr status;
  538. string config = "{ \"interfaces\": [ \"*\" ],"
  539. "\"rebind-timer\": 2000, "
  540. "\"renew-timer\": 1000, "
  541. "\"subnet4\": [ { "
  542. " \"pool\": [ \"192.0.4.0/28\" ],"
  543. " \"subnet\": \"192.0.2.0/24\" } ],"
  544. "\"valid-lifetime\": 4000 }";
  545. ElementPtr json = Element::fromJSON(config);
  546. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  547. // returned value must be 1 (values error)
  548. // as the pool does not belong to that subnet
  549. checkResult(status, 1);
  550. }
  551. // Goal of this test is to verify if pools can be defined
  552. // using prefix/length notation. There is no separate test for min-max
  553. // notation as it was tested in several previous tests.
  554. TEST_F(Dhcp4ParserTest, poolPrefixLen) {
  555. ConstElementPtr status;
  556. string config = "{ \"interfaces\": [ \"*\" ],"
  557. "\"rebind-timer\": 2000, "
  558. "\"renew-timer\": 1000, "
  559. "\"subnet4\": [ { "
  560. " \"pool\": [ \"192.0.2.128/28\" ],"
  561. " \"subnet\": \"192.0.2.0/24\" } ],"
  562. "\"valid-lifetime\": 4000 }";
  563. ElementPtr json = Element::fromJSON(config);
  564. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  565. // returned value must be 0 (configuration accepted)
  566. checkResult(status, 0);
  567. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  568. ASSERT_TRUE(subnet);
  569. EXPECT_EQ(1000, subnet->getT1());
  570. EXPECT_EQ(2000, subnet->getT2());
  571. EXPECT_EQ(4000, subnet->getValid());
  572. }
  573. // The goal of this test is to check whether an option definition
  574. // that defines an option carrying an IPv4 address can be created.
  575. TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
  576. // Configuration string.
  577. std::string config =
  578. "{ \"option-def\": [ {"
  579. " \"name\": \"foo\","
  580. " \"code\": 100,"
  581. " \"type\": \"ipv4-address\","
  582. " \"array\": False,"
  583. " \"record-types\": \"\","
  584. " \"space\": \"isc\","
  585. " \"encapsulate\": \"\""
  586. " } ]"
  587. "}";
  588. ElementPtr json = Element::fromJSON(config);
  589. // Make sure that the particular option definition does not exist.
  590. OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
  591. ASSERT_FALSE(def);
  592. // Use the configuration string to create new option definition.
  593. ConstElementPtr status;
  594. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  595. ASSERT_TRUE(status);
  596. checkResult(status, 0);
  597. // The option definition should now be available in the CfgMgr.
  598. def = CfgMgr::instance().getOptionDef("isc", 100);
  599. ASSERT_TRUE(def);
  600. // Verify that the option definition data is valid.
  601. EXPECT_EQ("foo", def->getName());
  602. EXPECT_EQ(100, def->getCode());
  603. EXPECT_FALSE(def->getArrayType());
  604. EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def->getType());
  605. EXPECT_TRUE(def->getEncapsulatedSpace().empty());
  606. }
  607. // The goal of this test is to check whether an option definition
  608. // that defines an option carrying a record of data fields can
  609. // be created.
  610. TEST_F(Dhcp4ParserTest, optionDefRecord) {
  611. // Configuration string.
  612. std::string config =
  613. "{ \"option-def\": [ {"
  614. " \"name\": \"foo\","
  615. " \"code\": 100,"
  616. " \"type\": \"record\","
  617. " \"array\": False,"
  618. " \"record-types\": \"uint16, ipv4-address, ipv6-address, string\","
  619. " \"space\": \"isc\","
  620. " \"encapsulate\": \"\""
  621. " } ]"
  622. "}";
  623. ElementPtr json = Element::fromJSON(config);
  624. // Make sure that the particular option definition does not exist.
  625. OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
  626. ASSERT_FALSE(def);
  627. // Use the configuration string to create new option definition.
  628. ConstElementPtr status;
  629. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  630. ASSERT_TRUE(status);
  631. checkResult(status, 0);
  632. // The option definition should now be available in the CfgMgr.
  633. def = CfgMgr::instance().getOptionDef("isc", 100);
  634. ASSERT_TRUE(def);
  635. // Check the option data.
  636. EXPECT_EQ("foo", def->getName());
  637. EXPECT_EQ(100, def->getCode());
  638. EXPECT_EQ(OPT_RECORD_TYPE, def->getType());
  639. EXPECT_FALSE(def->getArrayType());
  640. EXPECT_TRUE(def->getEncapsulatedSpace().empty());
  641. // The option comprises the record of data fields. Verify that all
  642. // fields are present and they are of the expected types.
  643. const OptionDefinition::RecordFieldsCollection& record_fields =
  644. def->getRecordFields();
  645. ASSERT_EQ(4, record_fields.size());
  646. EXPECT_EQ(OPT_UINT16_TYPE, record_fields[0]);
  647. EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, record_fields[1]);
  648. EXPECT_EQ(OPT_IPV6_ADDRESS_TYPE, record_fields[2]);
  649. EXPECT_EQ(OPT_STRING_TYPE, record_fields[3]);
  650. }
  651. // The goal of this test is to verify that multiple option definitions
  652. // can be created.
  653. TEST_F(Dhcp4ParserTest, optionDefMultiple) {
  654. // Configuration string.
  655. std::string config =
  656. "{ \"option-def\": [ {"
  657. " \"name\": \"foo\","
  658. " \"code\": 100,"
  659. " \"type\": \"uint32\","
  660. " \"array\": False,"
  661. " \"record-types\": \"\","
  662. " \"space\": \"isc\","
  663. " \"encapsulate\": \"\""
  664. " },"
  665. " {"
  666. " \"name\": \"foo-2\","
  667. " \"code\": 101,"
  668. " \"type\": \"ipv4-address\","
  669. " \"array\": False,"
  670. " \"record-types\": \"\","
  671. " \"space\": \"isc\","
  672. " \"encapsulate\": \"\""
  673. " } ]"
  674. "}";
  675. ElementPtr json = Element::fromJSON(config);
  676. // Make sure that the option definitions do not exist yet.
  677. ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
  678. ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 101));
  679. // Use the configuration string to create new option definitions.
  680. ConstElementPtr status;
  681. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  682. ASSERT_TRUE(status);
  683. checkResult(status, 0);
  684. // Check the first definition we have created.
  685. OptionDefinitionPtr def1 = CfgMgr::instance().getOptionDef("isc", 100);
  686. ASSERT_TRUE(def1);
  687. // Check the option data.
  688. EXPECT_EQ("foo", def1->getName());
  689. EXPECT_EQ(100, def1->getCode());
  690. EXPECT_EQ(OPT_UINT32_TYPE, def1->getType());
  691. EXPECT_FALSE(def1->getArrayType());
  692. EXPECT_TRUE(def1->getEncapsulatedSpace().empty());
  693. // Check the second option definition we have created.
  694. OptionDefinitionPtr def2 = CfgMgr::instance().getOptionDef("isc", 101);
  695. ASSERT_TRUE(def2);
  696. // Check the option data.
  697. EXPECT_EQ("foo-2", def2->getName());
  698. EXPECT_EQ(101, def2->getCode());
  699. EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def2->getType());
  700. EXPECT_FALSE(def2->getArrayType());
  701. EXPECT_TRUE(def2->getEncapsulatedSpace().empty());
  702. }
  703. // The goal of this test is to verify that the duplicated option
  704. // definition is not accepted.
  705. TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
  706. // Configuration string. Both option definitions have
  707. // the same code and belong to the same option space.
  708. // This configuration should not be accepted.
  709. std::string config =
  710. "{ \"option-def\": [ {"
  711. " \"name\": \"foo\","
  712. " \"code\": 100,"
  713. " \"type\": \"uint32\","
  714. " \"array\": False,"
  715. " \"record-types\": \"\","
  716. " \"space\": \"isc\","
  717. " \"encapsulate\": \"\""
  718. " },"
  719. " {"
  720. " \"name\": \"foo-2\","
  721. " \"code\": 100,"
  722. " \"type\": \"ipv4-address\","
  723. " \"array\": False,"
  724. " \"record-types\": \"\","
  725. " \"space\": \"isc\","
  726. " \"encapsulate\": \"\""
  727. " } ]"
  728. "}";
  729. ElementPtr json = Element::fromJSON(config);
  730. // Make sure that the option definition does not exist yet.
  731. ASSERT_FALSE(CfgMgr::instance().getOptionDef("isc", 100));
  732. // Use the configuration string to create new option definitions.
  733. ConstElementPtr status;
  734. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  735. ASSERT_TRUE(status);
  736. checkResult(status, 1);
  737. }
  738. // The goal of this test is to verify that the option definition
  739. // comprising an array of uint32 values can be created.
  740. TEST_F(Dhcp4ParserTest, optionDefArray) {
  741. // Configuration string. Created option definition should
  742. // comprise an array of uint32 values.
  743. std::string config =
  744. "{ \"option-def\": [ {"
  745. " \"name\": \"foo\","
  746. " \"code\": 100,"
  747. " \"type\": \"uint32\","
  748. " \"array\": True,"
  749. " \"record-types\": \"\","
  750. " \"space\": \"isc\","
  751. " \"encapsulate\": \"\""
  752. " } ]"
  753. "}";
  754. ElementPtr json = Element::fromJSON(config);
  755. // Make sure that the particular option definition does not exist.
  756. OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
  757. ASSERT_FALSE(def);
  758. // Use the configuration string to create new option definition.
  759. ConstElementPtr status;
  760. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  761. ASSERT_TRUE(status);
  762. checkResult(status, 0);
  763. // The option definition should now be available in the CfgMgr.
  764. def = CfgMgr::instance().getOptionDef("isc", 100);
  765. ASSERT_TRUE(def);
  766. // Check the option data.
  767. EXPECT_EQ("foo", def->getName());
  768. EXPECT_EQ(100, def->getCode());
  769. EXPECT_EQ(OPT_UINT32_TYPE, def->getType());
  770. EXPECT_TRUE(def->getArrayType());
  771. EXPECT_TRUE(def->getEncapsulatedSpace().empty());
  772. }
  773. // The purpose of this test to verify that encapsulated option
  774. // space name may be specified.
  775. TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
  776. // Configuration string. Included the encapsulated
  777. // option space name.
  778. std::string config =
  779. "{ \"option-def\": [ {"
  780. " \"name\": \"foo\","
  781. " \"code\": 100,"
  782. " \"type\": \"uint32\","
  783. " \"array\": False,"
  784. " \"record-types\": \"\","
  785. " \"space\": \"isc\","
  786. " \"encapsulate\": \"sub-opts-space\""
  787. " } ]"
  788. "}";
  789. ElementPtr json = Element::fromJSON(config);
  790. // Make sure that the particular option definition does not exist.
  791. OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("isc", 100);
  792. ASSERT_FALSE(def);
  793. // Use the configuration string to create new option definition.
  794. ConstElementPtr status;
  795. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  796. ASSERT_TRUE(status);
  797. checkResult(status, 0);
  798. // The option definition should now be available in the CfgMgr.
  799. def = CfgMgr::instance().getOptionDef("isc", 100);
  800. ASSERT_TRUE(def);
  801. // Check the option data.
  802. EXPECT_EQ("foo", def->getName());
  803. EXPECT_EQ(100, def->getCode());
  804. EXPECT_EQ(OPT_UINT32_TYPE, def->getType());
  805. EXPECT_FALSE(def->getArrayType());
  806. EXPECT_EQ("sub-opts-space", def->getEncapsulatedSpace());
  807. }
  808. /// The purpose of this test is to verify that the option definition
  809. /// with invalid name is not accepted.
  810. TEST_F(Dhcp4ParserTest, optionDefInvalidName) {
  811. // Configuration string. The option name is invalid as it
  812. // contains the % character.
  813. std::string config =
  814. "{ \"option-def\": [ {"
  815. " \"name\": \"invalid%name\","
  816. " \"code\": 100,"
  817. " \"type\": \"string\","
  818. " \"array\": False,"
  819. " \"record-types\": \"\","
  820. " \"space\": \"isc\","
  821. " \"encapsulate\": \"\""
  822. " } ]"
  823. "}";
  824. ElementPtr json = Element::fromJSON(config);
  825. // Use the configuration string to create new option definition.
  826. ConstElementPtr status;
  827. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  828. ASSERT_TRUE(status);
  829. // Expecting parsing error (error code 1).
  830. checkResult(status, 1);
  831. }
  832. /// The purpose of this test is to verify that the option definition
  833. /// with invalid type is not accepted.
  834. TEST_F(Dhcp4ParserTest, optionDefInvalidType) {
  835. // Configuration string. The option type is invalid. It is
  836. // "sting" instead of "string".
  837. std::string config =
  838. "{ \"option-def\": [ {"
  839. " \"name\": \"foo\","
  840. " \"code\": 100,"
  841. " \"type\": \"sting\","
  842. " \"array\": False,"
  843. " \"record-types\": \"\","
  844. " \"space\": \"isc\","
  845. " \"encapsulate\": \"\""
  846. " } ]"
  847. "}";
  848. ElementPtr json = Element::fromJSON(config);
  849. // Use the configuration string to create new option definition.
  850. ConstElementPtr status;
  851. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  852. ASSERT_TRUE(status);
  853. // Expecting parsing error (error code 1).
  854. checkResult(status, 1);
  855. }
  856. /// The purpose of this test is to verify that the option definition
  857. /// with invalid type is not accepted.
  858. TEST_F(Dhcp4ParserTest, optionDefInvalidRecordType) {
  859. // Configuration string. The third of the record fields
  860. // is invalid. It is "sting" instead of "string".
  861. std::string config =
  862. "{ \"option-def\": [ {"
  863. " \"name\": \"foo\","
  864. " \"code\": 100,"
  865. " \"type\": \"record\","
  866. " \"array\": False,"
  867. " \"record-types\": \"uint32,uint8,sting\","
  868. " \"space\": \"isc\","
  869. " \"encapsulate\": \"\""
  870. " } ]"
  871. "}";
  872. ElementPtr json = Element::fromJSON(config);
  873. // Use the configuration string to create new option definition.
  874. ConstElementPtr status;
  875. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  876. ASSERT_TRUE(status);
  877. // Expecting parsing error (error code 1).
  878. checkResult(status, 1);
  879. }
  880. /// The goal of this test is to verify that the invalid encapsulated
  881. /// option space name is not accepted.
  882. TEST_F(Dhcp4ParserTest, optionDefInvalidEncapsulatedSpace) {
  883. // Configuration string. The encapsulated option space
  884. // name is invalid (% character is not allowed).
  885. std::string config =
  886. "{ \"option-def\": [ {"
  887. " \"name\": \"foo\","
  888. " \"code\": 100,"
  889. " \"type\": \"uint32\","
  890. " \"array\": False,"
  891. " \"record-types\": \"\","
  892. " \"space\": \"isc\","
  893. " \"encapsulate\": \"invalid%space%name\""
  894. " } ]"
  895. "}";
  896. ElementPtr json = Element::fromJSON(config);
  897. // Use the configuration string to create new option definition.
  898. ConstElementPtr status;
  899. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  900. ASSERT_TRUE(status);
  901. // Expecting parsing error (error code 1).
  902. checkResult(status, 1);
  903. }
  904. /// The goal of this test is to verify that the encapsulated
  905. /// option space name can't be specified for the option that
  906. /// comprises an array of data fields.
  907. TEST_F(Dhcp4ParserTest, optionDefEncapsulatedSpaceAndArray) {
  908. // Configuration string. The encapsulated option space
  909. // name is set to non-empty value and the array flag
  910. // is set.
  911. std::string config =
  912. "{ \"option-def\": [ {"
  913. " \"name\": \"foo\","
  914. " \"code\": 100,"
  915. " \"type\": \"uint32\","
  916. " \"array\": True,"
  917. " \"record-types\": \"\","
  918. " \"space\": \"isc\","
  919. " \"encapsulate\": \"valid-space-name\""
  920. " } ]"
  921. "}";
  922. ElementPtr json = Element::fromJSON(config);
  923. // Use the configuration string to create new option definition.
  924. ConstElementPtr status;
  925. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  926. ASSERT_TRUE(status);
  927. // Expecting parsing error (error code 1).
  928. checkResult(status, 1);
  929. }
  930. /// The goal of this test is to verify that the option may not
  931. /// encapsulate option space it belongs to.
  932. TEST_F(Dhcp4ParserTest, optionDefEncapsulateOwnSpace) {
  933. // Configuration string. Option is set to encapsulate
  934. // option space it belongs to.
  935. std::string config =
  936. "{ \"option-def\": [ {"
  937. " \"name\": \"foo\","
  938. " \"code\": 100,"
  939. " \"type\": \"uint32\","
  940. " \"array\": False,"
  941. " \"record-types\": \"\","
  942. " \"space\": \"isc\","
  943. " \"encapsulate\": \"isc\""
  944. " } ]"
  945. "}";
  946. ElementPtr json = Element::fromJSON(config);
  947. // Use the configuration string to create new option definition.
  948. ConstElementPtr status;
  949. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  950. ASSERT_TRUE(status);
  951. // Expecting parsing error (error code 1).
  952. checkResult(status, 1);
  953. }
  954. /// The purpose of this test is to verify that it is not allowed
  955. /// to override the standard option (that belongs to dhcp4 option
  956. /// space) and that it is allowed to define option in the dhcp4
  957. /// option space that has a code which is not used by any of the
  958. /// standard options.
  959. TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
  960. // Configuration string. The option code 109 is unassigned
  961. // so it can be used for a custom option definition in
  962. // dhcp4 option space.
  963. std::string config =
  964. "{ \"option-def\": [ {"
  965. " \"name\": \"foo\","
  966. " \"code\": 109,"
  967. " \"type\": \"string\","
  968. " \"array\": False,"
  969. " \"record-types\": \"\","
  970. " \"space\": \"dhcp4\","
  971. " \"encapsulate\": \"\""
  972. " } ]"
  973. "}";
  974. ElementPtr json = Element::fromJSON(config);
  975. OptionDefinitionPtr def = CfgMgr::instance().getOptionDef("dhcp4", 109);
  976. ASSERT_FALSE(def);
  977. // Use the configuration string to create new option definition.
  978. ConstElementPtr status;
  979. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  980. ASSERT_TRUE(status);
  981. checkResult(status, 0);
  982. // The option definition should now be available in the CfgMgr.
  983. def = CfgMgr::instance().getOptionDef("dhcp4", 109);
  984. ASSERT_TRUE(def);
  985. // Check the option data.
  986. EXPECT_EQ("foo", def->getName());
  987. EXPECT_EQ(109, def->getCode());
  988. EXPECT_EQ(OPT_STRING_TYPE, def->getType());
  989. EXPECT_FALSE(def->getArrayType());
  990. // The combination of option space and code is
  991. // invalid. The 'dhcp4' option space groups
  992. // standard options and the code 100 is reserved
  993. // for one of them.
  994. config =
  995. "{ \"option-def\": [ {"
  996. " \"name\": \"foo\","
  997. " \"code\": 100,"
  998. " \"type\": \"string\","
  999. " \"array\": False,"
  1000. " \"record-types\": \"\","
  1001. " \"space\": \"dhcp4\","
  1002. " \"encapsulate\": \"\""
  1003. " } ]"
  1004. "}";
  1005. json = Element::fromJSON(config);
  1006. // Use the configuration string to create new option definition.
  1007. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1008. ASSERT_TRUE(status);
  1009. // Expecting parsing error (error code 1).
  1010. checkResult(status, 1);
  1011. }
  1012. // Goal of this test is to verify that global option
  1013. // data is configured for the subnet if the subnet
  1014. // configuration does not include options configuration.
  1015. TEST_F(Dhcp4ParserTest, optionDataDefaults) {
  1016. ConstElementPtr x;
  1017. string config = "{ \"interfaces\": [ \"*\" ],"
  1018. "\"rebind-timer\": 2000,"
  1019. "\"renew-timer\": 1000,"
  1020. "\"option-data\": [ {"
  1021. " \"name\": \"dhcp-message\","
  1022. " \"space\": \"dhcp4\","
  1023. " \"code\": 56,"
  1024. " \"data\": \"AB CDEF0105\","
  1025. " \"csv-format\": False"
  1026. " },"
  1027. " {"
  1028. " \"name\": \"default-ip-ttl\","
  1029. " \"space\": \"dhcp4\","
  1030. " \"code\": 23,"
  1031. " \"data\": \"01\","
  1032. " \"csv-format\": False"
  1033. " } ],"
  1034. "\"subnet4\": [ { "
  1035. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1036. " \"subnet\": \"192.0.2.0/24\""
  1037. " } ],"
  1038. "\"valid-lifetime\": 4000 }";
  1039. ElementPtr json = Element::fromJSON(config);
  1040. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  1041. ASSERT_TRUE(x);
  1042. comment_ = parseAnswer(rcode_, x);
  1043. ASSERT_EQ(0, rcode_);
  1044. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  1045. ASSERT_TRUE(subnet);
  1046. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
  1047. ASSERT_EQ(2, options->size());
  1048. // Get the search index. Index #1 is to search using option code.
  1049. const Subnet::OptionContainerTypeIndex& idx = options->get<1>();
  1050. // Get the options for specified index. Expecting one option to be
  1051. // returned but in theory we may have multiple options with the same
  1052. // code so we get the range.
  1053. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1054. Subnet::OptionContainerTypeIndex::const_iterator> range =
  1055. idx.equal_range(56);
  1056. // Expect single option with the code equal to 56.
  1057. ASSERT_EQ(1, std::distance(range.first, range.second));
  1058. const uint8_t foo_expected[] = {
  1059. 0xAB, 0xCD, 0xEF, 0x01, 0x05
  1060. };
  1061. // Check if option is valid in terms of code and carried data.
  1062. testOption(*range.first, 56, foo_expected, sizeof(foo_expected));
  1063. range = idx.equal_range(23);
  1064. ASSERT_EQ(1, std::distance(range.first, range.second));
  1065. // Do another round of testing with second option.
  1066. const uint8_t foo2_expected[] = {
  1067. 0x01
  1068. };
  1069. testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected));
  1070. }
  1071. /// The goal of this test is to verify that two options having the same
  1072. /// option code can be added to different option spaces.
  1073. TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
  1074. // This configuration string is to configure two options
  1075. // sharing the code 56 and having different definitions
  1076. // and belonging to the different option spaces.
  1077. // The option definition must be provided for the
  1078. // option that belongs to the 'isc' option space.
  1079. // The definition is not required for the option that
  1080. // belongs to the 'dhcp4' option space as it is the
  1081. // standard option.
  1082. string config = "{ \"interfaces\": [ \"*\" ],"
  1083. "\"rebind-timer\": 2000,"
  1084. "\"renew-timer\": 1000,"
  1085. "\"option-data\": [ {"
  1086. " \"name\": \"dhcp-message\","
  1087. " \"space\": \"dhcp4\","
  1088. " \"code\": 56,"
  1089. " \"data\": \"AB CDEF0105\","
  1090. " \"csv-format\": False"
  1091. " },"
  1092. " {"
  1093. " \"name\": \"foo\","
  1094. " \"space\": \"isc\","
  1095. " \"code\": 56,"
  1096. " \"data\": \"1234\","
  1097. " \"csv-format\": True"
  1098. " } ],"
  1099. "\"option-def\": [ {"
  1100. " \"name\": \"foo\","
  1101. " \"code\": 56,"
  1102. " \"type\": \"uint32\","
  1103. " \"array\": False,"
  1104. " \"record-types\": \"\","
  1105. " \"space\": \"isc\","
  1106. " \"encapsulate\": \"\""
  1107. " } ],"
  1108. "\"subnet4\": [ { "
  1109. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1110. " \"subnet\": \"192.0.2.0/24\""
  1111. " } ]"
  1112. "}";
  1113. ConstElementPtr status;
  1114. ElementPtr json = Element::fromJSON(config);
  1115. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1116. ASSERT_TRUE(status);
  1117. checkResult(status, 0);
  1118. // Options should be now available for the subnet.
  1119. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.200"));
  1120. ASSERT_TRUE(subnet);
  1121. // Try to get the option from the space dhcp4.
  1122. Subnet::OptionDescriptor desc1 = subnet->getOptionDescriptor("dhcp4", 56);
  1123. ASSERT_TRUE(desc1.option);
  1124. EXPECT_EQ(56, desc1.option->getType());
  1125. // Try to get the option from the space isc.
  1126. Subnet::OptionDescriptor desc2 = subnet->getOptionDescriptor("isc", 56);
  1127. ASSERT_TRUE(desc2.option);
  1128. EXPECT_EQ(56, desc1.option->getType());
  1129. // Try to get the non-existing option from the non-existing
  1130. // option space and expect that option is not returned.
  1131. Subnet::OptionDescriptor desc3 = subnet->getOptionDescriptor("non-existing", 56);
  1132. ASSERT_FALSE(desc3.option);
  1133. }
  1134. // The goal of this test is to verify that it is possible to
  1135. // encapsulate option space containing some options with
  1136. // another option. In this test we create base option that
  1137. // encapsulates option space 'isc' that comprises two other
  1138. // options. Also, for all options their definitions are
  1139. // created.
  1140. TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
  1141. // @todo DHCP configurations has many dependencies between
  1142. // parameters. First of all, configuration for subnet is
  1143. // inherited from the global values. Thus subnet has to be
  1144. // configured when all global values have been configured.
  1145. // Also, an option can encapsulate another option only
  1146. // if the latter has been configured. For this reason in this
  1147. // test we created two-stage configuration where first we
  1148. // created options that belong to encapsulated option space.
  1149. // In the second stage we add the base option. Also, the Subnet
  1150. // object is configured in the second stage so it is created
  1151. // at the very end (when all other parameters are configured).
  1152. // Starting stage 1. Configure sub-options and their definitions.
  1153. string config = "{ \"interfaces\": [ \"*\" ],"
  1154. "\"rebind-timer\": 2000,"
  1155. "\"renew-timer\": 1000,"
  1156. "\"option-data\": [ {"
  1157. " \"name\": \"foo\","
  1158. " \"space\": \"isc\","
  1159. " \"code\": 1,"
  1160. " \"data\": \"1234\","
  1161. " \"csv-format\": True"
  1162. " },"
  1163. " {"
  1164. " \"name\": \"foo2\","
  1165. " \"space\": \"isc\","
  1166. " \"code\": 2,"
  1167. " \"data\": \"192.168.2.1\","
  1168. " \"csv-format\": True"
  1169. " } ],"
  1170. "\"option-def\": [ {"
  1171. " \"name\": \"foo\","
  1172. " \"code\": 1,"
  1173. " \"type\": \"uint32\","
  1174. " \"array\": False,"
  1175. " \"record-types\": \"\","
  1176. " \"space\": \"isc\","
  1177. " \"encapsulate\": \"\""
  1178. " },"
  1179. " {"
  1180. " \"name\": \"foo2\","
  1181. " \"code\": 2,"
  1182. " \"type\": \"ipv4-address\","
  1183. " \"array\": False,"
  1184. " \"record-types\": \"\","
  1185. " \"space\": \"isc\","
  1186. " \"encapsulate\": \"\""
  1187. " } ]"
  1188. "}";
  1189. ConstElementPtr status;
  1190. ElementPtr json = Element::fromJSON(config);
  1191. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1192. ASSERT_TRUE(status);
  1193. checkResult(status, 0);
  1194. // Stage 2. Configure base option and a subnet. Please note that
  1195. // the configuration from the stage 2 is repeated because BIND
  1196. // configuration manager sends whole configuration for the lists
  1197. // where at least one element is being modified or added.
  1198. config = "{ \"interfaces\": [ \"*\" ],"
  1199. "\"rebind-timer\": 2000,"
  1200. "\"renew-timer\": 1000,"
  1201. "\"option-data\": [ {"
  1202. " \"name\": \"base-option\","
  1203. " \"space\": \"dhcp4\","
  1204. " \"code\": 222,"
  1205. " \"data\": \"11\","
  1206. " \"csv-format\": True"
  1207. " },"
  1208. " {"
  1209. " \"name\": \"foo\","
  1210. " \"space\": \"isc\","
  1211. " \"code\": 1,"
  1212. " \"data\": \"1234\","
  1213. " \"csv-format\": True"
  1214. " },"
  1215. " {"
  1216. " \"name\": \"foo2\","
  1217. " \"space\": \"isc\","
  1218. " \"code\": 2,"
  1219. " \"data\": \"192.168.2.1\","
  1220. " \"csv-format\": True"
  1221. " } ],"
  1222. "\"option-def\": [ {"
  1223. " \"name\": \"base-option\","
  1224. " \"code\": 222,"
  1225. " \"type\": \"uint8\","
  1226. " \"array\": False,"
  1227. " \"record-types\": \"\","
  1228. " \"space\": \"dhcp4\","
  1229. " \"encapsulate\": \"isc\""
  1230. "},"
  1231. "{"
  1232. " \"name\": \"foo\","
  1233. " \"code\": 1,"
  1234. " \"type\": \"uint32\","
  1235. " \"array\": False,"
  1236. " \"record-types\": \"\","
  1237. " \"space\": \"isc\","
  1238. " \"encapsulate\": \"\""
  1239. " },"
  1240. " {"
  1241. " \"name\": \"foo2\","
  1242. " \"code\": 2,"
  1243. " \"type\": \"ipv4-address\","
  1244. " \"array\": False,"
  1245. " \"record-types\": \"\","
  1246. " \"space\": \"isc\","
  1247. " \"encapsulate\": \"\""
  1248. " } ],"
  1249. "\"subnet4\": [ { "
  1250. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1251. " \"subnet\": \"192.0.2.0/24\""
  1252. " } ]"
  1253. "}";
  1254. json = Element::fromJSON(config);
  1255. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1256. ASSERT_TRUE(status);
  1257. checkResult(status, 0);
  1258. // Get the subnet.
  1259. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
  1260. ASSERT_TRUE(subnet);
  1261. // We should have one option available.
  1262. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
  1263. ASSERT_TRUE(options);
  1264. ASSERT_EQ(1, options->size());
  1265. // Get the option.
  1266. Subnet::OptionDescriptor desc = subnet->getOptionDescriptor("dhcp4", 222);
  1267. EXPECT_TRUE(desc.option);
  1268. EXPECT_EQ(222, desc.option->getType());
  1269. // This opton should comprise two sub-options.
  1270. // One of them is 'foo' with code 1.
  1271. OptionPtr option_foo = desc.option->getOption(1);
  1272. ASSERT_TRUE(option_foo);
  1273. EXPECT_EQ(1, option_foo->getType());
  1274. // ...another one 'foo2' with code 2.
  1275. OptionPtr option_foo2 = desc.option->getOption(2);
  1276. ASSERT_TRUE(option_foo2);
  1277. EXPECT_EQ(2, option_foo2->getType());
  1278. }
  1279. // Goal of this test is to verify options configuration
  1280. // for a single subnet. In particular this test checks
  1281. // that local options configuration overrides global
  1282. // option setting.
  1283. TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
  1284. ConstElementPtr x;
  1285. string config = "{ \"interfaces\": [ \"*\" ],"
  1286. "\"rebind-timer\": 2000, "
  1287. "\"renew-timer\": 1000, "
  1288. "\"option-data\": [ {"
  1289. " \"name\": \"dhcp-message\","
  1290. " \"space\": \"dhcp4\","
  1291. " \"code\": 56,"
  1292. " \"data\": \"AB\","
  1293. " \"csv-format\": False"
  1294. " } ],"
  1295. "\"subnet4\": [ { "
  1296. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1297. " \"subnet\": \"192.0.2.0/24\", "
  1298. " \"option-data\": [ {"
  1299. " \"name\": \"dhcp-message\","
  1300. " \"space\": \"dhcp4\","
  1301. " \"code\": 56,"
  1302. " \"data\": \"AB CDEF0105\","
  1303. " \"csv-format\": False"
  1304. " },"
  1305. " {"
  1306. " \"name\": \"default-ip-ttl\","
  1307. " \"space\": \"dhcp4\","
  1308. " \"code\": 23,"
  1309. " \"data\": \"01\","
  1310. " \"csv-format\": False"
  1311. " } ]"
  1312. " } ],"
  1313. "\"valid-lifetime\": 4000 }";
  1314. ElementPtr json = Element::fromJSON(config);
  1315. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  1316. ASSERT_TRUE(x);
  1317. comment_ = parseAnswer(rcode_, x);
  1318. ASSERT_EQ(0, rcode_);
  1319. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.24"));
  1320. ASSERT_TRUE(subnet);
  1321. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
  1322. ASSERT_EQ(2, options->size());
  1323. // Get the search index. Index #1 is to search using option code.
  1324. const Subnet::OptionContainerTypeIndex& idx = options->get<1>();
  1325. // Get the options for specified index. Expecting one option to be
  1326. // returned but in theory we may have multiple options with the same
  1327. // code so we get the range.
  1328. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1329. Subnet::OptionContainerTypeIndex::const_iterator> range =
  1330. idx.equal_range(56);
  1331. // Expect single option with the code equal to 100.
  1332. ASSERT_EQ(1, std::distance(range.first, range.second));
  1333. const uint8_t foo_expected[] = {
  1334. 0xAB, 0xCD, 0xEF, 0x01, 0x05
  1335. };
  1336. // Check if option is valid in terms of code and carried data.
  1337. testOption(*range.first, 56, foo_expected, sizeof(foo_expected));
  1338. range = idx.equal_range(23);
  1339. ASSERT_EQ(1, std::distance(range.first, range.second));
  1340. // Do another round of testing with second option.
  1341. const uint8_t foo2_expected[] = {
  1342. 0x01
  1343. };
  1344. testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected));
  1345. }
  1346. // Goal of this test is to verify options configuration
  1347. // for multiple subnets.
  1348. TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
  1349. ConstElementPtr x;
  1350. string config = "{ \"interfaces\": [ \"*\" ],"
  1351. "\"rebind-timer\": 2000, "
  1352. "\"renew-timer\": 1000, "
  1353. "\"subnet4\": [ { "
  1354. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1355. " \"subnet\": \"192.0.2.0/24\", "
  1356. " \"option-data\": [ {"
  1357. " \"name\": \"dhcp-message\","
  1358. " \"space\": \"dhcp4\","
  1359. " \"code\": 56,"
  1360. " \"data\": \"0102030405060708090A\","
  1361. " \"csv-format\": False"
  1362. " } ]"
  1363. " },"
  1364. " {"
  1365. " \"pool\": [ \"192.0.3.101 - 192.0.3.150\" ],"
  1366. " \"subnet\": \"192.0.3.0/24\", "
  1367. " \"option-data\": [ {"
  1368. " \"name\": \"default-ip-ttl\","
  1369. " \"space\": \"dhcp4\","
  1370. " \"code\": 23,"
  1371. " \"data\": \"FF\","
  1372. " \"csv-format\": False"
  1373. " } ]"
  1374. " } ],"
  1375. "\"valid-lifetime\": 4000 }";
  1376. ElementPtr json = Element::fromJSON(config);
  1377. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  1378. ASSERT_TRUE(x);
  1379. comment_ = parseAnswer(rcode_, x);
  1380. ASSERT_EQ(0, rcode_);
  1381. Subnet4Ptr subnet1 = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.100"));
  1382. ASSERT_TRUE(subnet1);
  1383. Subnet::OptionContainerPtr options1 = subnet1->getOptionDescriptors("dhcp4");
  1384. ASSERT_EQ(1, options1->size());
  1385. // Get the search index. Index #1 is to search using option code.
  1386. const Subnet::OptionContainerTypeIndex& idx1 = options1->get<1>();
  1387. // Get the options for specified index. Expecting one option to be
  1388. // returned but in theory we may have multiple options with the same
  1389. // code so we get the range.
  1390. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1391. Subnet::OptionContainerTypeIndex::const_iterator> range1 =
  1392. idx1.equal_range(56);
  1393. // Expect single option with the code equal to 56.
  1394. ASSERT_EQ(1, std::distance(range1.first, range1.second));
  1395. const uint8_t foo_expected[] = {
  1396. 0x01, 0x02, 0x03, 0x04, 0x05,
  1397. 0x06, 0x07, 0x08, 0x09, 0x0A
  1398. };
  1399. // Check if option is valid in terms of code and carried data.
  1400. testOption(*range1.first, 56, foo_expected, sizeof(foo_expected));
  1401. // Test another subnet in the same way.
  1402. Subnet4Ptr subnet2 = CfgMgr::instance().getSubnet4(IOAddress("192.0.3.102"));
  1403. ASSERT_TRUE(subnet2);
  1404. Subnet::OptionContainerPtr options2 = subnet2->getOptionDescriptors("dhcp4");
  1405. ASSERT_EQ(1, options2->size());
  1406. const Subnet::OptionContainerTypeIndex& idx2 = options2->get<1>();
  1407. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1408. Subnet::OptionContainerTypeIndex::const_iterator> range2 =
  1409. idx2.equal_range(23);
  1410. ASSERT_EQ(1, std::distance(range2.first, range2.second));
  1411. const uint8_t foo2_expected[] = { 0xFF };
  1412. testOption(*range2.first, 23, foo2_expected, sizeof(foo2_expected));
  1413. }
  1414. // Verify that empty option name is rejected in the configuration.
  1415. TEST_F(Dhcp4ParserTest, optionNameEmpty) {
  1416. // Empty option names not allowed.
  1417. testInvalidOptionParam("", "name");
  1418. }
  1419. // Verify that empty option name with spaces is rejected
  1420. // in the configuration.
  1421. TEST_F(Dhcp4ParserTest, optionNameSpaces) {
  1422. // Spaces in option names not allowed.
  1423. testInvalidOptionParam("option foo", "name");
  1424. }
  1425. // Verify that negative option code is rejected in the configuration.
  1426. TEST_F(Dhcp4ParserTest, optionCodeNegative) {
  1427. // Check negative option code -4. This should fail too.
  1428. testInvalidOptionParam("-4", "code");
  1429. }
  1430. // Verify that out of bounds option code is rejected in the configuration.
  1431. TEST_F(Dhcp4ParserTest, optionCodeNonUint8) {
  1432. // The valid option codes are uint16_t values so passing
  1433. // uint16_t maximum value incremented by 1 should result
  1434. // in failure.
  1435. testInvalidOptionParam("257", "code");
  1436. }
  1437. // Verify that zero option code is rejected in the configuration.
  1438. TEST_F(Dhcp4ParserTest, optionCodeZero) {
  1439. // Option code 0 is reserved and should not be accepted
  1440. // by configuration parser.
  1441. testInvalidOptionParam("0", "code");
  1442. }
  1443. // Verify that option data which contains non hexadecimal characters
  1444. // is rejected by the configuration.
  1445. TEST_F(Dhcp4ParserTest, optionDataInvalidChar) {
  1446. // Option code 0 is reserved and should not be accepted
  1447. // by configuration parser.
  1448. testInvalidOptionParam("01020R", "data");
  1449. }
  1450. // Verify that option data containing '0x' prefix is rejected
  1451. // by the configuration.
  1452. TEST_F(Dhcp4ParserTest, optionDataUnexpectedPrefix) {
  1453. // Option code 0 is reserved and should not be accepted
  1454. // by configuration parser.
  1455. testInvalidOptionParam("0x0102", "data");
  1456. }
  1457. // Verify that option data consisting od an odd number of
  1458. // hexadecimal digits is rejected in the configuration.
  1459. TEST_F(Dhcp4ParserTest, optionDataOddLength) {
  1460. // Option code 0 is reserved and should not be accepted
  1461. // by configuration parser.
  1462. testInvalidOptionParam("123", "data");
  1463. }
  1464. // Verify that either lower or upper case characters are allowed
  1465. // to specify the option data.
  1466. TEST_F(Dhcp4ParserTest, optionDataLowerCase) {
  1467. ConstElementPtr x;
  1468. std::string config = createConfigWithOption("0a0b0C0D", "data");
  1469. ElementPtr json = Element::fromJSON(config);
  1470. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  1471. ASSERT_TRUE(x);
  1472. comment_ = parseAnswer(rcode_, x);
  1473. ASSERT_EQ(0, rcode_);
  1474. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
  1475. ASSERT_TRUE(subnet);
  1476. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
  1477. ASSERT_EQ(1, options->size());
  1478. // Get the search index. Index #1 is to search using option code.
  1479. const Subnet::OptionContainerTypeIndex& idx = options->get<1>();
  1480. // Get the options for specified index. Expecting one option to be
  1481. // returned but in theory we may have multiple options with the same
  1482. // code so we get the range.
  1483. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1484. Subnet::OptionContainerTypeIndex::const_iterator> range =
  1485. idx.equal_range(56);
  1486. // Expect single option with the code equal to 100.
  1487. ASSERT_EQ(1, std::distance(range.first, range.second));
  1488. const uint8_t foo_expected[] = {
  1489. 0x0A, 0x0B, 0x0C, 0x0D
  1490. };
  1491. // Check if option is valid in terms of code and carried data.
  1492. testOption(*range.first, 56, foo_expected, sizeof(foo_expected));
  1493. }
  1494. // Verify that specific option object is returned for standard
  1495. // option which has dedicated option class derived from Option.
  1496. TEST_F(Dhcp4ParserTest, stdOptionData) {
  1497. ConstElementPtr x;
  1498. std::map<std::string, std::string> params;
  1499. params["name"] = "nis-servers";
  1500. params["space"] = "dhcp4";
  1501. // Option code 41 means nis-servers.
  1502. params["code"] = "41";
  1503. // Specify option values in a CSV (user friendly) format.
  1504. params["data"] = "192.0.2.10, 192.0.2.1, 192.0.2.3";
  1505. params["csv-format"] = "True";
  1506. std::string config = createConfigWithOption(params);
  1507. ElementPtr json = Element::fromJSON(config);
  1508. EXPECT_NO_THROW(x = configureDhcp4Server(*srv_, json));
  1509. ASSERT_TRUE(x);
  1510. comment_ = parseAnswer(rcode_, x);
  1511. ASSERT_EQ(0, rcode_);
  1512. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
  1513. ASSERT_TRUE(subnet);
  1514. Subnet::OptionContainerPtr options =
  1515. subnet->getOptionDescriptors("dhcp4");
  1516. ASSERT_TRUE(options);
  1517. ASSERT_EQ(1, options->size());
  1518. // Get the search index. Index #1 is to search using option code.
  1519. const Subnet::OptionContainerTypeIndex& idx = options->get<1>();
  1520. // Get the options for specified index. Expecting one option to be
  1521. // returned but in theory we may have multiple options with the same
  1522. // code so we get the range.
  1523. std::pair<Subnet::OptionContainerTypeIndex::const_iterator,
  1524. Subnet::OptionContainerTypeIndex::const_iterator> range =
  1525. idx.equal_range(DHO_NIS_SERVERS);
  1526. // Expect single option with the code equal to NIS_SERVERS option code.
  1527. ASSERT_EQ(1, std::distance(range.first, range.second));
  1528. // The actual pointer to the option is held in the option field
  1529. // in the structure returned.
  1530. OptionPtr option = range.first->option;
  1531. ASSERT_TRUE(option);
  1532. // Option object returned for here is expected to be Option6IA
  1533. // which is derived from Option. This class is dedicated to
  1534. // represent standard option IA_NA.
  1535. boost::shared_ptr<Option4AddrLst> option_addrs =
  1536. boost::dynamic_pointer_cast<Option4AddrLst>(option);
  1537. // If cast is unsuccessful than option returned was of a
  1538. // different type than Option6IA. This is wrong.
  1539. ASSERT_TRUE(option_addrs);
  1540. // Get addresses from the option.
  1541. Option4AddrLst::AddressContainer addrs = option_addrs->getAddresses();
  1542. // Verify that the addresses have been configured correctly.
  1543. ASSERT_EQ(3, addrs.size());
  1544. EXPECT_EQ("192.0.2.10", addrs[0].toText());
  1545. EXPECT_EQ("192.0.2.1", addrs[1].toText());
  1546. EXPECT_EQ("192.0.2.3", addrs[2].toText());
  1547. }
  1548. /// This test checks if Uint32Parser can really parse the whole range
  1549. /// and properly err of out of range values. As we can't call Uint32Parser
  1550. /// directly, we are exploiting the fact that it is used to parse global
  1551. /// parameter renew-timer and the results are stored in uint32_defaults.
  1552. /// We get the uint32_defaults using a getUint32Defaults functions which
  1553. /// is defined only to access the values from this test.
  1554. TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser) {
  1555. ConstElementPtr status;
  1556. // CASE 1: 0 - minimum value, should work
  1557. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
  1558. Element::fromJSON("{\"version\": 0,"
  1559. "\"renew-timer\": 0}")));
  1560. // returned value must be ok (0 is a proper value)
  1561. checkResult(status, 0);
  1562. checkGlobalUint32("renew-timer", 0);
  1563. // CASE 2: 4294967295U (UINT_MAX) should work as well
  1564. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
  1565. Element::fromJSON("{\"version\": 0,"
  1566. "\"renew-timer\": 4294967295}")));
  1567. // returned value must be ok (0 is a proper value)
  1568. checkResult(status, 0);
  1569. checkGlobalUint32("renew-timer", 4294967295U);
  1570. // CASE 3: 4294967296U (UINT_MAX + 1) should not work
  1571. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
  1572. Element::fromJSON("{\"version\": 0,"
  1573. "\"renew-timer\": 4294967296}")));
  1574. // returned value must be rejected (1 configuration error)
  1575. checkResult(status, 1);
  1576. // CASE 4: -1 (UINT_MIN -1 ) should not work
  1577. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_,
  1578. Element::fromJSON("{\"version\": 0,"
  1579. "\"renew-timer\": -1}")));
  1580. // returned value must be rejected (1 configuration error)
  1581. checkResult(status, 1);
  1582. }
  1583. // The goal of this test is to verify that the standard option can
  1584. // be configured to encapsulate multiple other options.
  1585. TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
  1586. // The configuration is two stage process in this test.
  1587. // In the first stahe we create definitions of suboptions
  1588. // that we will add to the base option.
  1589. // Let's create some dummy options: foo and foo2.
  1590. string config = "{ \"interfaces\": [ \"*\" ],"
  1591. "\"rebind-timer\": 2000,"
  1592. "\"renew-timer\": 1000,"
  1593. "\"option-data\": [ {"
  1594. " \"name\": \"foo\","
  1595. " \"space\": \"vendor-encapsulated-options-space\","
  1596. " \"code\": 1,"
  1597. " \"data\": \"1234\","
  1598. " \"csv-format\": True"
  1599. " },"
  1600. " {"
  1601. " \"name\": \"foo2\","
  1602. " \"space\": \"vendor-encapsulated-options-space\","
  1603. " \"code\": 2,"
  1604. " \"data\": \"192.168.2.1\","
  1605. " \"csv-format\": True"
  1606. " } ],"
  1607. "\"option-def\": [ {"
  1608. " \"name\": \"foo\","
  1609. " \"code\": 1,"
  1610. " \"type\": \"uint32\","
  1611. " \"array\": False,"
  1612. " \"record-types\": \"\","
  1613. " \"space\": \"vendor-encapsulated-options-space\","
  1614. " \"encapsulate\": \"\""
  1615. " },"
  1616. " {"
  1617. " \"name\": \"foo2\","
  1618. " \"code\": 2,"
  1619. " \"type\": \"ipv4-address\","
  1620. " \"array\": False,"
  1621. " \"record-types\": \"\","
  1622. " \"space\": \"vendor-encapsulated-options-space\","
  1623. " \"encapsulate\": \"\""
  1624. " } ]"
  1625. "}";
  1626. ConstElementPtr status;
  1627. ElementPtr json = Element::fromJSON(config);
  1628. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1629. ASSERT_TRUE(status);
  1630. checkResult(status, 0);
  1631. // Once the definitions have been added we can configure the
  1632. // standard option #17. This option comprises an enterprise
  1633. // number and sub options. By convention (introduced in
  1634. // std_option_defs.h) option named 'vendor-opts'
  1635. // encapsulates the option space named 'vendor-opts-space'.
  1636. // We add our dummy options to this option space and thus
  1637. // they should be included as sub-options in the 'vendor-opts'
  1638. // option.
  1639. config = "{ \"interfaces\": [ \"*\" ],"
  1640. "\"rebind-timer\": 2000,"
  1641. "\"renew-timer\": 1000,"
  1642. "\"option-data\": [ {"
  1643. " \"name\": \"vendor-encapsulated-options\","
  1644. " \"space\": \"dhcp4\","
  1645. " \"code\": 43,"
  1646. " \"data\": \"\","
  1647. " \"csv-format\": False"
  1648. " },"
  1649. " {"
  1650. " \"name\": \"foo\","
  1651. " \"space\": \"vendor-encapsulated-options-space\","
  1652. " \"code\": 1,"
  1653. " \"data\": \"1234\","
  1654. " \"csv-format\": True"
  1655. " },"
  1656. " {"
  1657. " \"name\": \"foo2\","
  1658. " \"space\": \"vendor-encapsulated-options-space\","
  1659. " \"code\": 2,"
  1660. " \"data\": \"192.168.2.1\","
  1661. " \"csv-format\": True"
  1662. " } ],"
  1663. "\"option-def\": [ {"
  1664. " \"name\": \"foo\","
  1665. " \"code\": 1,"
  1666. " \"type\": \"uint32\","
  1667. " \"array\": False,"
  1668. " \"record-types\": \"\","
  1669. " \"space\": \"vendor-encapsulated-options-space\","
  1670. " \"encapsulate\": \"\""
  1671. " },"
  1672. " {"
  1673. " \"name\": \"foo2\","
  1674. " \"code\": 2,"
  1675. " \"type\": \"ipv4-address\","
  1676. " \"array\": False,"
  1677. " \"record-types\": \"\","
  1678. " \"space\": \"vendor-encapsulated-options-space\","
  1679. " \"encapsulate\": \"\""
  1680. " } ],"
  1681. "\"subnet4\": [ { "
  1682. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1683. " \"subnet\": \"192.0.2.0/24\""
  1684. " } ]"
  1685. "}";
  1686. json = Element::fromJSON(config);
  1687. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1688. ASSERT_TRUE(status);
  1689. checkResult(status, 0);
  1690. // Get the subnet.
  1691. Subnet4Ptr subnet = CfgMgr::instance().getSubnet4(IOAddress("192.0.2.5"));
  1692. ASSERT_TRUE(subnet);
  1693. // We should have one option available.
  1694. Subnet::OptionContainerPtr options = subnet->getOptionDescriptors("dhcp4");
  1695. ASSERT_TRUE(options);
  1696. ASSERT_EQ(1, options->size());
  1697. // Get the option.
  1698. Subnet::OptionDescriptor desc =
  1699. subnet->getOptionDescriptor("dhcp4", DHO_VENDOR_ENCAPSULATED_OPTIONS);
  1700. EXPECT_TRUE(desc.option);
  1701. EXPECT_EQ(DHO_VENDOR_ENCAPSULATED_OPTIONS, desc.option->getType());
  1702. // Option with the code 1 should be added as a sub-option.
  1703. OptionPtr option_foo = desc.option->getOption(1);
  1704. ASSERT_TRUE(option_foo);
  1705. EXPECT_EQ(1, option_foo->getType());
  1706. // This option comprises a single uint32_t value thus it is
  1707. // represented by OptionInt<uint32_t> class. Let's get the
  1708. // object of this type.
  1709. boost::shared_ptr<OptionInt<uint32_t> > option_foo_uint32 =
  1710. boost::dynamic_pointer_cast<OptionInt<uint32_t> >(option_foo);
  1711. ASSERT_TRUE(option_foo_uint32);
  1712. // Validate the value according to the configuration.
  1713. EXPECT_EQ(1234, option_foo_uint32->getValue());
  1714. // Option with the code 2 should be added as a sub-option.
  1715. OptionPtr option_foo2 = desc.option->getOption(2);
  1716. ASSERT_TRUE(option_foo2);
  1717. EXPECT_EQ(2, option_foo2->getType());
  1718. // This option comprises the IPV4 address. Such option is
  1719. // represented by OptionCustom object.
  1720. OptionCustomPtr option_foo2_v4 =
  1721. boost::dynamic_pointer_cast<OptionCustom>(option_foo2);
  1722. ASSERT_TRUE(option_foo2_v4);
  1723. // Get the IP address carried by this option and validate it.
  1724. EXPECT_EQ("192.168.2.1", option_foo2_v4->readAddress().toText());
  1725. // Option with the code 3 should not be added.
  1726. EXPECT_FALSE(desc.option->getOption(3));
  1727. }
  1728. // Tests of the hooks libraries configuration. All tests have the pre-
  1729. // condition (checked in the test fixture's SetUp() method) that no hooks
  1730. // libraries are loaded at the start of the tests.
  1731. // Helper function to return a configuration containing an arbitrary number
  1732. // of hooks libraries.
  1733. std::string
  1734. buildHooksLibrariesConfig(const std::vector<std::string>& libraries) {
  1735. const string quote("\"");
  1736. // Create the first part of the configuration string.
  1737. string config =
  1738. "{ \"interfaces\": [ \"*\" ],"
  1739. "\"hooks-libraries\": [";
  1740. // Append the libraries (separated by commas if needed)
  1741. for (int i = 0; i < libraries.size(); ++i) {
  1742. if (i > 0) {
  1743. config += string(", ");
  1744. }
  1745. config += (quote + libraries[i] + quote);
  1746. }
  1747. // Append the remainder of the configuration.
  1748. config += string(
  1749. "],"
  1750. "\"rebind-timer\": 2000,"
  1751. "\"renew-timer\": 1000,"
  1752. "\"option-data\": [ {"
  1753. " \"name\": \"dhcp-message\","
  1754. " \"space\": \"dhcp4\","
  1755. " \"code\": 56,"
  1756. " \"data\": \"AB CDEF0105\","
  1757. " \"csv-format\": False"
  1758. " },"
  1759. " {"
  1760. " \"name\": \"foo\","
  1761. " \"space\": \"isc\","
  1762. " \"code\": 56,"
  1763. " \"data\": \"1234\","
  1764. " \"csv-format\": True"
  1765. " } ],"
  1766. "\"option-def\": [ {"
  1767. " \"name\": \"foo\","
  1768. " \"code\": 56,"
  1769. " \"type\": \"uint32\","
  1770. " \"array\": False,"
  1771. " \"record-types\": \"\","
  1772. " \"space\": \"isc\","
  1773. " \"encapsulate\": \"\""
  1774. " } ],"
  1775. "\"subnet4\": [ { "
  1776. " \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
  1777. " \"subnet\": \"192.0.2.0/24\""
  1778. " } ]"
  1779. "}");
  1780. return (config);
  1781. }
  1782. // Convenience function for creating hooks library configuration with one or
  1783. // two character string constants.
  1784. std::string
  1785. buildHooksLibrariesConfig(const char* library1 = NULL,
  1786. const char* library2 = NULL) {
  1787. std::vector<std::string> libraries;
  1788. if (library1 != NULL) {
  1789. libraries.push_back(string(library1));
  1790. if (library2 != NULL) {
  1791. libraries.push_back(string(library2));
  1792. }
  1793. }
  1794. return (buildHooksLibrariesConfig(libraries));
  1795. }
  1796. // The goal of this test is to verify the configuration of hooks libraries if
  1797. // none are specified.
  1798. TEST_F(Dhcp4ParserTest, NoHooksLibraries) {
  1799. // Parse a configuration containing no names.
  1800. string config = buildHooksLibrariesConfig();
  1801. if (!executeConfiguration(config,
  1802. "set configuration with no hooks libraries")) {
  1803. FAIL() << "Unable to execute configuration";
  1804. } else {
  1805. // No libraries should be loaded at the end of the test.
  1806. std::vector<std::string> libraries = HooksManager::getLibraryNames();
  1807. EXPECT_TRUE(libraries.empty());
  1808. }
  1809. }
  1810. // Verify parsing fails with one library that will fail validation.
  1811. TEST_F(Dhcp4ParserTest, InvalidLibrary) {
  1812. // Parse a configuration containing a failing library.
  1813. string config = buildHooksLibrariesConfig(NOT_PRESENT_LIBRARY);
  1814. ConstElementPtr status;
  1815. ElementPtr json = Element::fromJSON(config);
  1816. ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1817. // The status object must not be NULL
  1818. ASSERT_TRUE(status);
  1819. // Returned value should not be 0
  1820. comment_ = parseAnswer(rcode_, status);
  1821. EXPECT_NE(0, rcode_);
  1822. }
  1823. // Verify the configuration of hooks libraries with two being specified.
  1824. TEST_F(Dhcp4ParserTest, LibrariesSpecified) {
  1825. // Marker files should not be present.
  1826. EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE));
  1827. EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE));
  1828. // Set up the configuration with two libraries and load them.
  1829. string config = buildHooksLibrariesConfig(CALLOUT_LIBRARY_1,
  1830. CALLOUT_LIBRARY_2);
  1831. ASSERT_TRUE(executeConfiguration(config,
  1832. "load two valid libraries"));
  1833. // Expect two libraries to be loaded in the correct order (load marker file
  1834. // is present, no unload marker file).
  1835. std::vector<std::string> libraries = HooksManager::getLibraryNames();
  1836. ASSERT_EQ(2, libraries.size());
  1837. EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"));
  1838. EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE));
  1839. // Unload the libraries. The load file should not have changed, but
  1840. // the unload one should indicate the unload() functions have been run.
  1841. config = buildHooksLibrariesConfig();
  1842. ASSERT_TRUE(executeConfiguration(config, "unloading libraries"));
  1843. EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"));
  1844. EXPECT_TRUE(checkMarkerFile(UNLOAD_MARKER_FILE, "21"));
  1845. // Expect the hooks system to say that none are loaded.
  1846. libraries = HooksManager::getLibraryNames();
  1847. EXPECT_TRUE(libraries.empty());
  1848. }
  1849. // This test verifies that it is possible to select subset of interfaces
  1850. // on which server should listen.
  1851. TEST_F(Dhcp4ParserTest, selectedInterfaces) {
  1852. ConstElementPtr x;
  1853. string config = "{ \"interfaces\": [ \"eth0\", \"eth1\" ],"
  1854. "\"rebind-timer\": 2000, "
  1855. "\"renew-timer\": 1000, "
  1856. "\"valid-lifetime\": 4000 }";
  1857. ElementPtr json = Element::fromJSON(config);
  1858. ConstElementPtr status;
  1859. // Make sure the config manager is clean and there is no hanging
  1860. // interface configuration.
  1861. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth0"));
  1862. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth1"));
  1863. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth2"));
  1864. // Apply configuration.
  1865. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1866. ASSERT_TRUE(status);
  1867. checkResult(status, 0);
  1868. // eth0 and eth1 were explicitly selected. eth2 was not.
  1869. EXPECT_TRUE(CfgMgr::instance().isActiveIface("eth0"));
  1870. EXPECT_TRUE(CfgMgr::instance().isActiveIface("eth1"));
  1871. EXPECT_FALSE(CfgMgr::instance().isActiveIface("eth2"));
  1872. }
  1873. // This test verifies that it is possible to configure the server in such a way
  1874. // that it listens on all interfaces.
  1875. TEST_F(Dhcp4ParserTest, allInterfaces) {
  1876. ConstElementPtr x;
  1877. // This configuration specifies two interfaces on which server should listen
  1878. // but it also includes asterisk. The asterisk switches server into the
  1879. // mode when it listens on all interfaces regardless of what interface names
  1880. // were specified in the "interfaces" parameter.
  1881. string config = "{ \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ],"
  1882. "\"rebind-timer\": 2000, "
  1883. "\"renew-timer\": 1000, "
  1884. "\"valid-lifetime\": 4000 }";
  1885. ElementPtr json = Element::fromJSON(config);
  1886. ConstElementPtr status;
  1887. // Make sure there is no old configuration.
  1888. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth0"));
  1889. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth1"));
  1890. ASSERT_FALSE(CfgMgr::instance().isActiveIface("eth2"));
  1891. // Apply configuration.
  1892. EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
  1893. ASSERT_TRUE(status);
  1894. checkResult(status, 0);
  1895. // All interfaces should be now active.
  1896. EXPECT_TRUE(CfgMgr::instance().isActiveIface("eth0"));
  1897. EXPECT_TRUE(CfgMgr::instance().isActiveIface("eth1"));
  1898. EXPECT_TRUE(CfgMgr::instance().isActiveIface("eth2"));
  1899. }
  1900. }