Skip to content

Commit

Permalink
#73: Update unit test case for complex option defs in config
Browse files Browse the repository at this point in the history
  • Loading branch information
agrabil committed Dec 12, 2022
1 parent afc0360 commit e5cf4c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;

import com.jagornet.dhcp.core.message.DhcpV4Message;
import com.jagornet.dhcp.core.message.DhcpV6Message;
import com.jagornet.dhcp.core.option.base.DhcpOption;
import com.jagornet.dhcp.core.option.generic.GenericIpAddressListOption;
import com.jagornet.dhcp.core.option.generic.GenericIpAddressOption;
import com.jagornet.dhcp.core.option.v4.DhcpV4SubnetMaskOption;
import com.jagornet.dhcp.core.option.v6.DhcpV6DnsServersOption;
Expand Down Expand Up @@ -206,23 +208,41 @@ public void testGlobalOptionDefs() throws Exception {
DhcpV4Message v4RequestMsg = new DhcpV4Message(localAddress, remoteAddress);
Map<Integer, DhcpOption> v4map = serverConfig.effectiveV4AddrOptions(v4RequestMsg);
assertNotNull(v4map);
assertEquals(2, v4map.size());
assertEquals(3, v4map.size());
DhcpOption v4SubnetMaskOption = v4map.get(1);
assertNotNull(v4SubnetMaskOption);
assertTrue(v4SubnetMaskOption instanceof DhcpV4SubnetMaskOption);
DhcpOption v4OtherOption = v4map.get(184);
assertNotNull(v4OtherOption);
assertTrue(v4OtherOption instanceof GenericIpAddressOption);
DhcpOption v4OtherOption184 = v4map.get(184);
assertNotNull(v4OtherOption184);
assertTrue(v4OtherOption184 instanceof GenericIpAddressOption);
assertEquals("1.2.3.4", ((GenericIpAddressOption)v4OtherOption184).getIpAddress());
DhcpOption v4OtherOption185 = v4map.get(185);
assertNotNull(v4OtherOption185);
assertTrue(v4OtherOption185 instanceof GenericIpAddressListOption);
List<String> option185ips = ((GenericIpAddressListOption)v4OtherOption185).getIpAddressList();
assertNotNull(option185ips);
assertEquals(2, option185ips.size());
assertEquals("1.1.1.1", option185ips.get(0));
assertEquals("2.2.2.2", option185ips.get(1));

DhcpV6Message v6RequestMsg = new DhcpV6Message(localAddress, remoteAddress);
Map<Integer, DhcpOption> v6map = serverConfig.effectiveMsgOptions(v6RequestMsg);
assertNotNull(v6map);
assertEquals(2, v6map.size());
assertEquals(3, v6map.size());
DhcpOption v6DnsServersOption = v6map.get(23);
assertNotNull(v6DnsServersOption);
assertTrue(v6DnsServersOption instanceof DhcpV6DnsServersOption);
DhcpOption v6OtherOption = v6map.get(186);
assertNotNull(v6OtherOption);
assertTrue(v6OtherOption instanceof GenericIpAddressOption);
DhcpOption v6OtherOption186 = v6map.get(186);
assertNotNull(v6OtherOption186);
assertTrue(v6OtherOption186 instanceof GenericIpAddressOption);
assertEquals("fd00::0006", ((GenericIpAddressOption)v6OtherOption186).getIpAddress());
DhcpOption v6OtherOption187 = v6map.get(187);
assertNotNull(v6OtherOption187);
assertTrue(v6OtherOption187 instanceof GenericIpAddressListOption);
List<String> option187ips = ((GenericIpAddressListOption)v6OtherOption187).getIpAddressList();
assertNotNull(option187ips);
assertEquals(2, option187ips.size());
assertEquals("fd00::0001", option187ips.get(0));
assertEquals("fd00::0002", option187ips.get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,30 @@
<ipAddress>1.2.3.4</ipAddress>
</ipAddressOption>
</optionDefList>
<optionDefList code="185" name="Option185" v4="true">
<ipAddressListOption>
<ipAddressList>1.1.1.1</ipAddressList>
<ipAddressList>2.2.2.2</ipAddressList>
</ipAddressListOption>
</optionDefList>
</v4OtherOptions>
</v4ConfigOptions>
<v6MsgConfigOptions>
<v6DnsServersOption>
<ipAddressList>3ffe::0001</ipAddressList>
</v6DnsServersOption>
<v6OtherOptions>
<optionDefList code="186" name="Option184">
<optionDefList code="186" name="Option186">
<ipAddressOption>
<ipAddress>fd00::0006</ipAddress>
</ipAddressOption>
</optionDefList>
<optionDefList code="187" name="Option187">
<ipAddressListOption>
<ipAddressList>fd00::0001</ipAddressList>
<ipAddressList>fd00::0002</ipAddressList>
</ipAddressListOption>
</optionDefList>
</v6OtherOptions>
</v6MsgConfigOptions>
</dhc:dhcpServerConfig>

0 comments on commit e5cf4c4

Please sign in to comment.