use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.HostRoutes in project netvirt by opendaylight.
the class DhcpPktHandler method getDhcpInfo.
private DhcpInfo getDhcpInfo(Port port, Subnet subnet, String serverIp) {
DhcpInfo dhcpInfo = null;
if (port != null && subnet != null) {
String clientIp = getIpv4Address(port);
List<IpAddress> dnsServers = subnet.getDnsNameservers();
dhcpInfo = new DhcpInfo();
if (isIpv4Address(subnet.getGatewayIp())) {
dhcpInfo.setGatewayIp(subnet.getGatewayIp().getIpv4Address().getValue());
}
if (clientIp != null && serverIp != null) {
List<HostRoutes> subnetHostRoutes = new ArrayList<>(subnet.getHostRoutes().size());
for (HostRoutes hostRoute : subnet.getHostRoutes()) {
if (!String.valueOf(hostRoute.getNexthop().getValue()).equals(clientIp)) {
subnetHostRoutes.add(hostRoute);
}
}
dhcpInfo.setClientIp(clientIp).setServerIp(serverIp).setCidr(String.valueOf(subnet.getCidr().getValue())).setHostRoutes(subnetHostRoutes).setDnsServersIpAddrs(dnsServers);
}
}
return dhcpInfo;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.HostRoutes in project netvirt by opendaylight.
the class DhcpPktHandler method setOptionClasslessRoute.
private void setOptionClasslessRoute(DHCP reply, DhcpInfo dhcpInfo) {
List<HostRoutes> hostRoutes = dhcpInfo.getHostRoutes();
if (hostRoutes == null) {
// we can't set this option, so return
return;
}
ByteArrayOutputStream result = new ByteArrayOutputStream();
for (HostRoutes hostRoute : hostRoutes) {
if (hostRoute.getNexthop().getIpv4Address() == null || hostRoute.getDestination().getIpv4Prefix() == null) {
// we only deal with IPv4 addresses
return;
}
String router = hostRoute.getNexthop().getIpv4Address().getValue();
String dest = hostRoute.getDestination().getIpv4Prefix().getValue();
try {
result.write(convertToClasslessRouteOption(dest, router));
} catch (IOException | NullPointerException e) {
LOG.trace("Exception {}", e.getMessage());
}
}
if (result.size() > 0) {
reply.setOptionBytes(DHCPConstants.OPT_CLASSLESS_ROUTE, result.toByteArray());
}
}
Aggregations