Commit f24c97d0 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Merged trac3927 (default in option-def)

parents 4f44fea7 82912d2f
......@@ -1160,14 +1160,14 @@ It is merely echoed by the server
should be left blank. Note that the above set of comments define the
format of the new option and do not set its values.
</para>
<note>
<para>
In the current release the default values are not propagated to the
parser when the new configuration is being set. Therefore, all
parameters must be specified at all times, even if their values are
left blank.
</para>
</note>
<para>The <command>name</command>, <command>code</command> and
<command>type</command> parameters are required, all others are
optional. The <command>array</command> default value is
<command>false</command>. The <command>record-types</command>
and <command>encapsulate</command> default values are blank
(i.e. ""). The default <command>space</command> is "dhcp4".
</para>
<para>Once the new option format is defined, its value is set
in the same way as for a standard option. For example the following
......
......@@ -1024,6 +1024,15 @@ temporarily override a list of interface names and listen on all interfaces.
set of comments define the format of the new option and do not set its
values.
</para>
<para>The <command>name</command>, <command>code</command> and
<command>type</command> parameters are required, all others are
optional. The <command>array</command> default value is
<command>false</command>. The <command>record-types</command>
and <command>encapsulate</command> default values are blank
(i.e. ""). The default <command>space</command> is "dhcp6".
</para>
<para>Once the new option format is defined, its value is set
in the same way as for a standard option. For example the following
commands set a global value that applies to all subnets.
......@@ -1061,7 +1070,7 @@ temporarily override a list of interface names and listen on all interfaces.
"space": "dhcp6",
"type": "record",
"array": false,
"record-types": "ipv4-address, uint16, boolean, string",
"record-types": "ipv6-address, uint16, boolean, string",
"encapsulate": ""</userinput>
}, ...
],
......
......@@ -416,8 +416,8 @@ namespace dhcp {
/// @return parser for specified global DHCPv4 parameter
/// @throw NotImplemented if trying to create a parser for unknown
/// config element
DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
ConstElementPtr element) {
DhcpConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id,
ConstElementPtr element) {
DhcpConfigParser* parser = NULL;
if ((config_id.compare("valid-lifetime") == 0) ||
(config_id.compare("renew-timer") == 0) ||
......
......@@ -1330,10 +1330,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1372,10 +1369,8 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"record\","
" \"array\": False,"
" \"record-types\": \"uint16, ipv4-address, ipv6-address, string\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1422,19 +1417,13 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" },"
" {"
" \"name\": \"foo-2\","
" \"code\": 101,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1488,19 +1477,13 @@ TEST_F(Dhcp4ParserTest, optionDefDuplicate) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" },"
" {"
" \"name\": \"foo-2\","
" \"code\": 100,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1529,9 +1512,7 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": True,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1571,8 +1552,6 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"sub-opts-space\""
" } ]"
......@@ -1613,10 +1592,7 @@ TEST_F(Dhcp4ParserTest, optionDefInvalidName) {
" \"name\": \"invalid%name\","
" \"code\": 100,"
" \"type\": \"string\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1640,10 +1616,7 @@ TEST_F(Dhcp4ParserTest, optionDefInvalidType) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"sting\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1667,10 +1640,8 @@ TEST_F(Dhcp4ParserTest, optionDefInvalidRecordType) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"record\","
" \"array\": False,"
" \"record-types\": \"uint32,uint8,sting\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1694,8 +1665,6 @@ TEST_F(Dhcp4ParserTest, optionDefInvalidEncapsulatedSpace) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"invalid%space%name\""
" } ]"
......@@ -1724,7 +1693,6 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulatedSpaceAndArray) {
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": True,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"valid-space-name\""
" } ]"
......@@ -1750,8 +1718,6 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulateOwnSpace) {
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"isc\""
" } ]"
......@@ -1781,10 +1747,7 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
" \"name\": \"foo\","
" \"code\": 109,"
" \"type\": \"string\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"dhcp4\","
" \"encapsulate\": \"\""
" \"space\": \"dhcp4\""
" } ]"
"}";
ElementPtr json = Element::fromJSON(config);
......@@ -1818,10 +1781,7 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
" \"name\": \"routers\","
" \"code\": 3,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"dhcp4\","
" \"encapsulate\": \"\""
" \"space\": \"dhcp4\""
" } ]"
"}";
json = Element::fromJSON(config);
......@@ -1843,10 +1803,7 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
" \"name\": \"nis-server-addr\","
" \"code\": 65,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"dhcp4\","
" \"encapsulate\": \"\""
" \"space\": \"dhcp4\""
" } ]"
"}";
json = Element::fromJSON(config);
......@@ -1879,15 +1836,11 @@ TEST_F(Dhcp4ParserTest, optionDataDefaults) {
"\"renew-timer\": 1000,"
"\"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"ABCDEF0105\","
" \"csv-format\": False"
" },"
" {"
" \"name\": \"default-ip-ttl\","
" \"space\": \"dhcp4\","
" \"code\": 23,"
" \"data\": \"01\","
" \"csv-format\": False"
" } ],"
......@@ -1952,26 +1905,19 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
"\"renew-timer\": 1000,"
"\"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"ABCDEF0105\","
" \"csv-format\": False"
" },"
" {"
" \"name\": \"foo\","
" \"space\": \"isc\","
" \"code\": 56,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 56,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ],"
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
......@@ -2033,34 +1979,24 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
"\"option-data\": [ {"
" \"name\": \"foo\","
" \"space\": \"isc\","
" \"code\": 1,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" },"
" {"
" \"name\": \"foo2\","
" \"space\": \"isc\","
" \"code\": 2,"
" \"data\": \"192.168.2.1\","
" \"csv-format\": True"
" \"data\": \"192.168.2.1\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 1,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" },"
" {"
" \"name\": \"foo2\","
" \"code\": 2,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ]"
"}";
......@@ -2084,31 +2020,22 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
"\"renew-timer\": 1000,"
"\"option-data\": [ {"
" \"name\": \"base-option\","
" \"space\": \"dhcp4\","
" \"code\": 222,"
" \"data\": \"11\","
" \"csv-format\": True"
" \"data\": \"11\""
" },"
" {"
" \"name\": \"foo\","
" \"space\": \"isc\","
" \"code\": 1,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" },"
" {"
" \"name\": \"foo2\","
" \"space\": \"isc\","
" \"code\": 2,"
" \"data\": \"192.168.2.1\","
" \"csv-format\": True"
" \"data\": \"192.168.2.1\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"base-option\","
" \"code\": 222,"
" \"type\": \"uint8\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"dhcp4\","
" \"encapsulate\": \"isc\""
"},"
......@@ -2116,19 +2043,13 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
" \"name\": \"foo\","
" \"code\": 1,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" },"
" {"
" \"name\": \"foo2\","
" \"code\": 2,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ],"
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
......@@ -2180,8 +2101,6 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
"\"renew-timer\": 1000, "
"\"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"AB\","
" \"csv-format\": False"
" } ],"
......@@ -2190,15 +2109,11 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
" \"subnet\": \"192.0.2.0/24\", "
" \"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"ABCDEF0105\","
" \"csv-format\": False"
" },"
" {"
" \"name\": \"default-ip-ttl\","
" \"space\": \"dhcp4\","
" \"code\": 23,"
" \"data\": \"01\","
" \"csv-format\": False"
" } ]"
......@@ -2337,8 +2252,6 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
" \"subnet\": \"192.0.2.0/24\", "
" \"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"0102030405060708090A\","
" \"csv-format\": False"
" } ]"
......@@ -2348,8 +2261,6 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
" \"subnet\": \"192.0.3.0/24\", "
" \"option-data\": [ {"
" \"name\": \"default-ip-ttl\","
" \"space\": \"dhcp4\","
" \"code\": 23,"
" \"data\": \"FF\","
" \"csv-format\": False"
" } ]"
......@@ -2610,34 +2521,24 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
"\"option-data\": [ {"
" \"name\": \"foo\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"code\": 1,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" },"
" {"
" \"name\": \"foo2\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"code\": 2,"
" \"data\": \"192.168.2.1\","
" \"csv-format\": True"
" \"data\": \"192.168.2.1\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 1,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"encapsulate\": \"\""
" \"space\": \"vendor-encapsulated-options-space\""
" },"
" {"
" \"name\": \"foo2\","
" \"code\": 2,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"encapsulate\": \"\""
" \"space\": \"vendor-encapsulated-options-space\""
" } ]"
"}";
......@@ -2665,17 +2566,12 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
"\"renew-timer\": 1000,"
"\"option-data\": [ {"
" \"name\": \"vendor-encapsulated-options\","
" \"space\": \"dhcp4\","
" \"code\": 43,"
" \"data\": \"\","
" \"csv-format\": False"
" },"
" {"
" \"name\": \"foo\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"code\": 1,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" },"
" {"
" \"name\": \"foo2\","
......@@ -2688,19 +2584,13 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
" \"name\": \"foo\","
" \"code\": 1,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"encapsulate\": \"\""
" \"space\": \"vendor-encapsulated-options-space\""
" },"
" {"
" \"name\": \"foo2\","
" \"code\": 2,"
" \"type\": \"ipv4-address\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"vendor-encapsulated-options-space\","
" \"encapsulate\": \"\""
" \"space\": \"vendor-encapsulated-options-space\""
" } ],"
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
......@@ -2834,17 +2724,13 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
" \"name\": \"foo\","
" \"space\": \"vendor-4491\","
" \"code\": 100,"
" \"data\": \"this is a string vendor-opt\","
" \"csv-format\": True"
" \"data\": \"this is a string vendor-opt\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 100,"
" \"type\": \"string\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"vendor-4491\","
" \"encapsulate\": \"\""
" \"space\": \"vendor-4491\""
" } ],"
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
......@@ -2911,26 +2797,19 @@ buildHooksLibrariesConfig(const std::vector<std::string>& libraries) {
"\"renew-timer\": 1000,"
"\"option-data\": [ {"
" \"name\": \"dhcp-message\","
" \"space\": \"dhcp4\","
" \"code\": 56,"
" \"data\": \"ABCDEF0105\","
" \"csv-format\": False"
" },"
" {"
" \"name\": \"foo\","
" \"space\": \"isc\","
" \"code\": 56,"
" \"data\": \"1234\","
" \"csv-format\": True"
" \"data\": \"1234\""
" } ],"
"\"option-def\": [ {"
" \"name\": \"foo\","
" \"code\": 56,"
" \"type\": \"uint32\","
" \"array\": False,"
" \"record-types\": \"\","
" \"space\": \"isc\","
" \"encapsulate\": \"\""
" \"space\": \"isc\""
" } ],"
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
......
......@@ -53,10 +53,7 @@ const char* DECLINE_CONFIGS[] = {
" \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
" \"option-data\": [ {"
" \"name\": \"routers\","
" \"code\": 3,"
" \"data\": \"10.0.0.200,10.0.0.201\","
" \"csv-format\": true,"
" \"space\": \"dhcp4\""
" \"data\": \"10.0.0.200,10.0.0.201\""
" } ]"
" } ]"
"}"
......
......@@ -77,31 +77,19 @@ const char* DORA_CONFIGS[] = {
" \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
" \"option-data\": [ {"
" \"name\": \"routers\","
" \"code\": 3,"
" \"data\": \"10.0.0.200,10.0.0.201\","
" \"csv-format\": true,"
" \"space\": \"dhcp4\""
" \"data\": \"10.0.0.200,10.0.0.201\""
" },"
" {"
" \"name\": \"domain-name-servers\","
" \"code\": 6,"
" \"data\": \"10.0.0.202,10.0.0.203\","
" \"csv-format\": true,"
" \"space\": \"dhcp4\""
" \"data\": \"10.0.0.202,10.0.0.203\""
" },"
" {"
" \"name\": \"log-servers\","
" \"code\": 7,"
" \"data\": \"10.0.0.200,10.0.0.201\","
" \"csv-format\": true,"
" \"space\": \"dhcp4\""
" \"data\": \"10.0.0.200,10.0.0.201\""
" },"
" {"
" \"name\": \"cookie-servers\","
" \"code\": 8,"
" \"data\": \"10.0.0.202,10.0.0.203\","
" \"csv-format\": true,"
" \"space\": \"dhcp4\""
" \"data\": \"10.0.0.202,10.0.0.203\""