use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method setDhcpServerConfigs.
public void setDhcpServerConfigs(Collection<DhcpServerConfig> configs, List<DhcpServerInfo> serverInfoList) {
if (configs.size() == 0) {
// no config to update
return;
}
Boolean isConfigValid = false;
for (DhcpServerConfig serverConfig : configs) {
if (serverConfig.getDhcpServerIp4().isPresent()) {
isConfigValid = true;
break;
}
}
if (!isConfigValid) {
log.warn("No IP V4 server address found.");
// No IP V6 address found
return;
}
// if (!serverInfoList.isEmpty()) {
for (DhcpServerInfo oldServerInfo : serverInfoList) {
log.info("In for (DhcpServerInfo oldServerInfo : serverInfoList) {");
// remove old server info
// DhcpServerInfo oldServerInfo = serverInfoList.remove(0);
// stop monitoring gateway or server
oldServerInfo.getDhcpGatewayIp4().ifPresent(gatewayIp -> {
hostService.stopMonitoringIp(gatewayIp);
});
oldServerInfo.getDhcpServerIp4().ifPresent(serverIp -> {
hostService.stopMonitoringIp(serverIp);
cancelDhcpPacket(serverIp);
});
}
// Create new server info according to the config
serverInfoList.clear();
for (DhcpServerConfig serverConfig : configs) {
log.debug("Create new server info according to the config");
DhcpServerInfo newServerInfo = new DhcpServerInfo(serverConfig, DhcpServerInfo.Version.DHCP_V4);
checkState(newServerInfo.getDhcpServerConnectPoint().isPresent(), "Connect point not exists");
checkState(newServerInfo.getDhcpServerIp4().isPresent(), "IP of DHCP server not exists");
log.debug("DHCP server connect point: {}", newServerInfo.getDhcpServerConnectPoint().orElse(null));
log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp4().orElse(null));
Ip4Address serverIp = newServerInfo.getDhcpServerIp4().get();
Ip4Address ipToProbe;
if (newServerInfo.getDhcpGatewayIp4().isPresent()) {
ipToProbe = newServerInfo.getDhcpGatewayIp4().get();
} else {
ipToProbe = newServerInfo.getDhcpServerIp4().orElse(null);
}
log.info("Probe_IP {}", ipToProbe);
String hostToProbe = newServerInfo.getDhcpGatewayIp4().map(ip -> "gateway").orElse("server");
log.debug("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
hostService.startMonitoringIp(ipToProbe);
Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
if (!hosts.isEmpty()) {
Host host = hosts.iterator().next();
newServerInfo.setDhcpConnectVlan(host.vlan());
newServerInfo.setDhcpConnectMac(host.mac());
}
// Add new server info
synchronized (this) {
// serverInfoList.clear();
serverInfoList.add(newServerInfo);
}
requestDhcpPacket(serverIp);
}
}
use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method setDhcpServerConfigs.
public void setDhcpServerConfigs(Collection<DhcpServerConfig> configs, List<DhcpServerInfo> serverInfoList) {
log.debug("config size {}.", configs.size());
if (configs.size() == 0) {
// no config to update
return;
}
// TODO: currently we pick up first DHCP server config.
// Will use other server configs in the future for HA.
Boolean isConfigValid = false;
for (DhcpServerConfig serverConfig : configs) {
if (serverConfig.getDhcpServerIp6().isPresent()) {
isConfigValid = true;
break;
}
}
if (!isConfigValid) {
log.warn("No IP V6 server address found.");
// No IP V6 address found
return;
}
for (DhcpServerInfo oldServerInfo : serverInfoList) {
// stop monitoring gateway or server
oldServerInfo.getDhcpGatewayIp6().ifPresent(gatewayIp -> {
hostService.stopMonitoringIp(gatewayIp);
});
oldServerInfo.getDhcpServerIp6().ifPresent(serverIp -> {
hostService.stopMonitoringIp(serverIp);
cancelDhcpPacket(serverIp);
});
}
serverInfoList.clear();
for (DhcpServerConfig serverConfig : configs) {
// Create new server info according to the config
DhcpServerInfo newServerInfo = new DhcpServerInfo(serverConfig, DhcpServerInfo.Version.DHCP_V6);
checkState(newServerInfo.getDhcpServerConnectPoint().isPresent(), "Connect point not exists");
checkState(newServerInfo.getDhcpServerIp6().isPresent(), "IP of DHCP server not exists");
log.debug("DHCP server connect point: {}", newServerInfo.getDhcpServerConnectPoint().orElse(null));
log.debug("DHCP server IP: {}", newServerInfo.getDhcpServerIp6().orElse(null));
Ip6Address serverIp = newServerInfo.getDhcpServerIp6().get();
Ip6Address ipToProbe;
if (newServerInfo.getDhcpGatewayIp6().isPresent()) {
ipToProbe = newServerInfo.getDhcpGatewayIp6().get();
} else {
ipToProbe = newServerInfo.getDhcpServerIp6().orElse(null);
}
String hostToProbe = newServerInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
log.warn("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
hostService.startMonitoringIp(ipToProbe);
Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
if (!hosts.isEmpty()) {
Host host = hosts.iterator().next();
newServerInfo.setDhcpConnectVlan(host.vlan());
newServerInfo.setDhcpConnectMac(host.mac());
log.warn("Host found host {}", host);
} else {
log.warn("No host found host ip {}", ipToProbe);
}
// Add new server info
synchronized (this) {
serverInfoList.add(newServerInfo);
}
if (!hosts.isEmpty()) {
requestDhcpPacket(serverIp);
}
}
}
use of org.onosproject.dhcprelay.config.DhcpServerConfig in project onos by opennetworkinglab.
the class DhcpRelayManager method getDhcpServerMacAddress.
@Override
public Optional<MacAddress> getDhcpServerMacAddress() {
// TODO: depreated it
DefaultDhcpRelayConfig config = cfgService.getConfig(appId, DefaultDhcpRelayConfig.class);
DhcpServerConfig serverConfig = config.dhcpServerConfigs().get(0);
Ip4Address serverip = serverConfig.getDhcpServerIp4().get();
return hostService.getHostsByIp(serverip).stream().map(Host::mac).findFirst();
}
Aggregations