use of org.onlab.packet.dhcp.Dhcp6IaPdOption in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method extractPrefix.
/**
* extract from dhcp6 packet Prefix prefix provided by dhcp server.
*
* @param dhcp6 the dhcp6 payload
* @return IpPrefix Prefix Delegation prefix, or null if not exists.
*/
private PdPrefixInfo extractPrefix(DHCP6 dhcp6) {
log.debug("extractPrefix enters {}", dhcp6);
// extract prefix
PdPrefixInfo pdPrefixInfo = new PdPrefixInfo();
Ip6Address prefixAddress = null;
// Extract IPv6 prefix from IA PD option
Optional<Dhcp6IaPdOption> iaPdOption = dhcp6.getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPdOption).map(opt -> (Dhcp6IaPdOption) opt).findFirst();
Optional<Dhcp6IaPrefixOption> iaPrefixOption;
if (iaPdOption.isPresent()) {
log.debug("IA_PD option found {}", iaPdOption);
iaPrefixOption = iaPdOption.get().getOptions().stream().filter(opt -> opt instanceof Dhcp6IaPrefixOption).map(opt -> (Dhcp6IaPrefixOption) opt).findFirst();
} else {
log.debug("IA_PD option NOT found");
iaPrefixOption = Optional.empty();
}
if (iaPrefixOption.isPresent()) {
log.debug("IAPrefix Option within IA_PD option found {}", iaPrefixOption);
prefixAddress = iaPrefixOption.get().getIp6Prefix();
int prefixLen = (int) iaPrefixOption.get().getPrefixLength();
log.debug("Prefix length is {} bits", prefixLen);
pdPrefixInfo.pdPrefix = IpPrefix.valueOf(prefixAddress, prefixLen);
pdPrefixInfo.prefTime = iaPrefixOption.get().getPreferredLifetime();
} else {
log.debug("Can't find IPv6 prefix from DHCPv6 {}", dhcp6);
return null;
}
return pdPrefixInfo;
}
use of org.onlab.packet.dhcp.Dhcp6IaPdOption in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method buildDhcp6Packet.
/**
* Generates DHCP6 REQUEST packet.
*/
private void buildDhcp6Packet(DHCP6 dhcp6, byte msgType, Ip6Address ip6Addr, IpPrefix prefix) {
// build address option
Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
iaAddressOption.setCode(DHCP6.OptionCode.IAADDR.value());
iaAddressOption.setIp6Address(ip6Addr);
iaAddressOption.setPreferredLifetime(3600);
iaAddressOption.setValidLifetime(1200);
iaAddressOption.setLength((short) Dhcp6IaAddressOption.DEFAULT_LEN);
Dhcp6ClientIdOption clientIdOption = new Dhcp6ClientIdOption();
Dhcp6Duid dhcp6Duip = new Dhcp6Duid();
dhcp6Duip.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
// Ethernet
dhcp6Duip.setHardwareType((short) 0x01);
dhcp6Duip.setDuidTime(1234);
dhcp6Duip.setLinkLayerAddress(CLIENT_MAC.toBytes());
clientIdOption.setDuid(dhcp6Duip);
Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
iaNaOption.setCode(DHCP6.OptionCode.IA_NA.value());
iaNaOption.setIaId(0);
iaNaOption.setT1(302400);
iaNaOption.setT2(483840);
List<Dhcp6Option> iaNaSubOptions = new ArrayList<Dhcp6Option>();
iaNaSubOptions.add(iaAddressOption);
iaNaOption.setOptions(iaNaSubOptions);
iaNaOption.setLength((short) (Dhcp6IaNaOption.DEFAULT_LEN + iaAddressOption.getLength()));
// build prefix option
Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
iaPrefixOption.setCode(DHCP6.OptionCode.IAPREFIX.value());
iaPrefixOption.setIp6Prefix(prefix.address().getIp6Address());
iaPrefixOption.setPrefixLength((byte) prefix.prefixLength());
iaPrefixOption.setPreferredLifetime(3601);
iaPrefixOption.setValidLifetime(1201);
iaPrefixOption.setLength((short) Dhcp6IaPrefixOption.DEFAULT_LEN);
Dhcp6IaPdOption iaPdOption = new Dhcp6IaPdOption();
iaPdOption.setCode(DHCP6.OptionCode.IA_PD.value());
iaPdOption.setIaId(0);
iaPdOption.setT1(302401);
iaPdOption.setT2(483841);
List<Dhcp6Option> iaPdSubOptions = new ArrayList<Dhcp6Option>();
iaPdSubOptions.add(iaPrefixOption);
iaPdOption.setOptions(iaPdSubOptions);
iaPdOption.setLength((short) (Dhcp6IaPdOption.DEFAULT_LEN + iaPrefixOption.getLength()));
dhcp6.setMsgType(msgType);
List<Dhcp6Option> dhcp6Options = new ArrayList<Dhcp6Option>();
dhcp6Options.add(iaNaOption);
dhcp6Options.add(clientIdOption);
dhcp6Options.add(iaPdOption);
dhcp6.setOptions(dhcp6Options);
}
Aggregations