Search in sources :

Example 1 with HostRoutes

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;
}
Also used : ArrayList(java.util.ArrayList) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) HostRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.HostRoutes)

Example 2 with HostRoutes

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());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HostRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.HostRoutes)

Aggregations

HostRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnet.attributes.HostRoutes)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1