use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method findServerInfoFromServer.
private DhcpServerInfo findServerInfoFromServer(boolean directConnFlag, ConnectPoint inPort) {
List<DhcpServerInfo> validServerInfoList = findValidServerInfo(directConnFlag);
DhcpServerInfo foundServerInfo = null;
for (DhcpServerInfo serverInfo : validServerInfoList) {
if (inPort.equals(serverInfo.getDhcpServerConnectPoint().get())) {
foundServerInfo = serverInfo;
log.debug("ServerInfo found for Rcv port {} Server Connect Point {} for {}", inPort, serverInfo.getDhcpServerConnectPoint(), directConnFlag ? "direct" : "indirect");
break;
}
}
return foundServerInfo;
}
use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method getHostInfoForServerInfo.
/**
* Checks if serverInfo's host info (mac and vlan) is filled in; if not, fills in.
*
* @param serverInfo server information
* @return newServerInfo if host info can be either found or filled in.
*/
private DhcpServerInfo getHostInfoForServerInfo(DhcpServerInfo serverInfo, List<DhcpServerInfo> sererInfoList) {
DhcpServerInfo newServerInfo = null;
MacAddress dhcpServerConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
VlanId dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
ConnectPoint dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
if (dhcpServerConnectMac != null && dhcpConnectVlan != null) {
newServerInfo = serverInfo;
log.debug("DHCP server {} host info found. ConnectPt{} Mac {} vlan {}", serverInfo.getDhcpServerIp4(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
} else {
log.debug("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp4(), dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
Ip4Address ipToProbe;
if (serverInfo.getDhcpGatewayIp4().isPresent()) {
ipToProbe = serverInfo.getDhcpGatewayIp4().get();
} else {
ipToProbe = serverInfo.getDhcpServerIp4().orElse(null);
}
String hostToProbe = serverInfo.getDhcpGatewayIp6().map(ip -> "gateway").orElse("server");
log.debug("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
hostService.startMonitoringIp(ipToProbe);
Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
if (!hosts.isEmpty()) {
int serverInfoIndex = sererInfoList.indexOf(serverInfo);
Host host = hosts.iterator().next();
serverInfo.setDhcpConnectVlan(host.vlan());
serverInfo.setDhcpConnectMac(host.mac());
// replace the serverInfo in the list
sererInfoList.set(serverInfoIndex, serverInfo);
newServerInfo = serverInfo;
log.warn("Dynamically host found host {}", host);
} else {
log.debug("No host found host ip {} dynamically", ipToProbe);
}
}
return newServerInfo;
}
use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.
the class DhcpRelayWebResource method getDefaultDhcpServers.
/**
* To get the list of default dhcp servers.
*
* @return node type ObjectNode.
*/
private ArrayNode getDefaultDhcpServers() {
ObjectNode node = mapper().createObjectNode();
DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
List<DhcpServerInfo> defaultDhcpServerInfoList = dhcpDelayService.getDefaultDhcpServerInfoList();
ArrayNode defaultDhcpServers = listServers(defaultDhcpServerInfoList);
return defaultDhcpServers;
}
use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.
the class DhcpRelayWebResource method listServers.
/**
* To get the liset of dhcp servers.
*
* @param dhcpServerInfoList type List
* @return servers type ArrayNode.
*/
private ArrayNode listServers(List<DhcpServerInfo> dhcpServerInfoList) {
ArrayNode servers = mapper().createArrayNode();
dhcpServerInfoList.forEach(dhcpServerInfo -> {
ObjectNode serverNode = mapper().createObjectNode();
String connectPoint = dhcpServerInfo.getDhcpServerConnectPoint().map(cp -> cp.toString()).orElse(NA);
String serverMac = dhcpServerInfo.getDhcpConnectMac().map(mac -> mac.toString()).orElse(NA);
String gatewayAddress;
String serverIp;
switch(dhcpServerInfo.getVersion()) {
case DHCP_V4:
gatewayAddress = dhcpServerInfo.getDhcpGatewayIp4().map(gw -> gw.toString()).orElse(null);
serverIp = dhcpServerInfo.getDhcpServerIp4().map(ip -> ip.toString()).orElse(NA);
break;
case DHCP_V6:
gatewayAddress = dhcpServerInfo.getDhcpGatewayIp6().map(gw -> gw.toString()).orElse(null);
serverIp = dhcpServerInfo.getDhcpServerIp6().map(ip -> ip.toString()).orElse(NA);
break;
default:
return;
}
serverNode.put("connectPoint", connectPoint);
if (gatewayAddress != null) {
serverNode.put("server", serverIp.concat(" via ").concat(gatewayAddress));
} else {
serverNode.put("server", serverIp);
}
serverNode.put("mac", serverMac);
servers.add(serverNode);
});
return servers;
}
use of org.onosproject.dhcprelay.api.DhcpServerInfo in project onos by opennetworkinglab.
the class DhcpRelayWebResource method getIndirectDhcpServers.
/**
* To get the list of indirect dhcp servers.
*
* @return node type ObjectNode.
*/
private ArrayNode getIndirectDhcpServers() {
DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
List<DhcpServerInfo> indirectDhcpServerInfoList = dhcpDelayService.getIndirectDhcpServerInfoList();
ArrayNode indirectDhcpServers = listServers(indirectDhcpServerInfoList);
return indirectDhcpServers;
}
Aggregations