DHCP-Relay : fix logs when one or more DHCP servers are not reachable.

Change-Id: Ideb0b1a959bd352b0c535b6010bd9326aca184f8
(cherry picked from commit 89cf2b51c13a7a1fa86781c3506602386913274f)
diff --git a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
index 31c278a..48a4748 100644
--- a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
+++ b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp4HandlerImpl.java
@@ -349,9 +349,7 @@
                 ipToProbe = newServerInfo.getDhcpServerIp4().orElse(null);
             }
             log.info("Probe_IP {}", ipToProbe);
-            String hostToProbe = newServerInfo.getDhcpGatewayIp4()
-                    .map(ip -> "gateway").orElse("server");
-
+            String hostToProbe = newServerInfo.getDhcpGatewayIp4().map(ip -> "gateway").orElse("server");
             log.debug("Probing to resolve {} IP {}", hostToProbe, ipToProbe);
             hostService.startMonitoringIp(ipToProbe);
 
@@ -513,8 +511,7 @@
         return serverInfos.stream()
                 .findFirst()
                 .map(serverInfo -> {
-                    ConnectPoint dhcpServerConnectPoint =
-                            serverInfo.getDhcpServerConnectPoint().orElse(null);
+                    ConnectPoint dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
                     VlanId dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
                     if (dhcpServerConnectPoint == null || dhcpConnectVlan == null) {
                         return null;
@@ -538,8 +535,7 @@
     private boolean interfaceContainsVlan(Interface iface, VlanId vlanId) {
         if (vlanId.equals(VlanId.NONE)) {
             // untagged packet, check if vlan untagged or vlan native is not NONE
-            return !iface.vlanUntagged().equals(VlanId.NONE) ||
-                    !iface.vlanNative().equals(VlanId.NONE);
+            return !iface.vlanUntagged().equals(VlanId.NONE) || !iface.vlanNative().equals(VlanId.NONE);
         }
         // tagged packet, check if the interface contains the vlan
         return iface.vlanTagged().contains(vlanId);
@@ -747,8 +743,6 @@
         IPv4 ipv4Packet = (IPv4) etherReply.getPayload();
         UDP udpPacket = (UDP) ipv4Packet.getPayload();
         DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
-
-
         Ip4Address clientInterfaceIp =
                 interfaceService.getInterfacesByPort(context.inPacket().receivedFrom())
                         .stream()
@@ -779,9 +773,10 @@
         List<InternalPacket> internalPackets = new ArrayList<>();
         List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
         List<DhcpServerInfo> copyServerInfoList = new ArrayList<DhcpServerInfo>(serverInfoList);
-
+        boolean serverFound = false;
 
         for (DhcpServerInfo serverInfo : copyServerInfoList) {
+
             etherReply = (Ethernet) ethernetPacket.clone();
             ipv4Packet = (IPv4) etherReply.getPayload();
             udpPacket = (UDP) ipv4Packet.getPayload();
@@ -792,13 +787,14 @@
             }
             DhcpServerInfo newServerInfo = getHostInfoForServerInfo(serverInfo, serverInfoList);
             if (newServerInfo == null) {
-                log.warn("Can't get server interface with host info resolved, ignore");
+                log.debug("Can't get server interface with host info resolved, ignore serverInfo {} serverInfoList {}",
+                              serverInfo, serverInfoList);
                 continue;
             }
-
             Interface serverInterface = getServerInterface(newServerInfo);
             if (serverInterface == null) {
-                log.warn("Can't get server interface, ignore");
+                log.debug("Can't get server interface, ignore for serverInfo {}, serverInfoList {}",
+                           serverInfo, serverInfoList);
                 continue;
             }
 
@@ -806,11 +802,12 @@
             MacAddress macFacingServer = serverInterface.mac();
             log.debug("Interfacing server {} Mac : {} ", ipFacingServer, macFacingServer);
             if (ipFacingServer == null || macFacingServer == null) {
-                log.warn("No IP address for server Interface {}", serverInterface);
+                log.debug("No IP address for server Interface {}", serverInterface);
                 continue;
             }
 
-
+            serverFound = true;
+            log.debug("Server Info Found {}", serverInfo.getDhcpConnectMac());
             etherReply.setSourceMACAddress(macFacingServer);
             // set default info and replace with indirect if available later on.
             if (newServerInfo.getDhcpConnectMac().isPresent()) {
@@ -835,15 +832,13 @@
 
                 ipv4Packet.setDestinationAddress(newServerInfo.getDhcpServerIp4().get().toInt());
 
-
                 ConnectPoint inPort = context.inPacket().receivedFrom();
                 VlanId vlanId = VlanId.vlanId(ethernetPacket.getVlanID());
                 // add connected in port and vlan
                 CircuitId cid = new CircuitId(inPort.toString(), vlanId);
                 byte[] circuitId = cid.serialize();
                 DhcpOption circuitIdSubOpt = new DhcpOption();
-                circuitIdSubOpt
-                        .setCode(CIRCUIT_ID.getValue())
+                circuitIdSubOpt.setCode(CIRCUIT_ID.getValue())
                         .setLength((byte) circuitId.length)
                         .setData(circuitId);
 
@@ -893,7 +888,6 @@
 
             // Remove broadcast flag
             dhcpPacket.setFlags((short) 0);
-
             udpPacket.setPayload(dhcpPacket);
             // As a DHCP relay, the source port should be server port( instead
             // of client port.
@@ -907,6 +901,9 @@
 
             internalPackets.add(internalPacket);
         }
+        if (!serverFound) {
+            log.warn("ProcessDhcp4PacketFromClient No Server Found");
+        }
         return internalPackets;
     }
 
@@ -1909,7 +1906,7 @@
             log.debug("DHCP server {} host info found. ConnectPt{}  Mac {} vlan {}", serverInfo.getDhcpServerIp4(),
                     dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
         } else {
-            log.warn("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp4(),
+            log.debug("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp4(),
                     dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
 
             Ip4Address ipToProbe;
@@ -1921,7 +1918,7 @@
             String hostToProbe = serverInfo.getDhcpGatewayIp6()
                     .map(ip -> "gateway").orElse("server");
 
-            log.warn("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
+            log.debug("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
             hostService.startMonitoringIp(ipToProbe);
 
             Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
@@ -1935,7 +1932,7 @@
                 newServerInfo = serverInfo;
                 log.warn("Dynamically host found host {}", host);
             } else {
-                log.warn("No host found host ip {} dynamically", ipToProbe);
+                log.debug("No host found host ip {} dynamically", ipToProbe);
             }
         }
         return newServerInfo;
diff --git a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
index 1aa7931..1099956 100644
--- a/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
+++ b/apps/dhcprelay/app/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
@@ -1083,6 +1083,7 @@
         DHCP6 clientDhcp6 = (DHCP6) clientUdp.getPayload();
 
         boolean directConnFlag = Dhcp6HandlerUtil.directlyConnected(clientDhcp6);
+        boolean serverFound = false;
         List<InternalPacket> internalPackets = new ArrayList<>();
         List<DhcpServerInfo> serverInfoList = findValidServerInfo(directConnFlag);
         List<DhcpServerInfo> copyServerInfoList = new ArrayList<DhcpServerInfo>(serverInfoList);
@@ -1094,14 +1095,19 @@
             }
             DhcpServerInfo newServerInfo = getHostInfoForServerInfo(serverInfo, serverInfoList);
             if (newServerInfo == null) {
-                log.warn("Can't get server interface with host info resolved, ignore");
+                log.debug("Can't get server interface with host info resolved, ignore serverInfo {} serverInfoList {}",
+                            serverInfo, serverInfoList);
                 continue;
             }
             Interface serverInterface = getServerInterface(newServerInfo);
             if (serverInterface == null) {
-                log.warn("Can't get server interface, ignore");
+                log.debug("Can't get server interface, ignore for serverInfo {}, serverInfoList {}",
+                           serverInfo, serverInfoList);
                 continue;
             }
+
+            serverFound = true;
+            log.debug("Server Info Found {}", serverInfo.getDhcpConnectMac());
             Ethernet etherRouted = (Ethernet) clientPacket.clone();
             MacAddress macFacingServer = serverInterface.mac();
             if (macFacingServer == null) {
@@ -1116,6 +1122,9 @@
             internalPackets.add(internalPacket);
             log.debug("Sending LQ to DHCP server {}", newServerInfo.getDhcpServerIp6());
         }
+        if (!serverFound) {
+            log.warn("ProcessDhcp6PacketFromClient No Server Found");
+        }
         log.debug("num of client packets to send is{}", internalPackets.size());
 
         return internalPackets;
@@ -1244,6 +1253,9 @@
         String clientConnectionPointStr = new String(interfaceIdOption.getInPort());
         ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
         VlanId vlanIdInUse = VlanId.vlanId(interfaceIdOption.getVlanId());
+
+        log.debug("processDhcp6PacketFromServer Interface Id Mac {}, port{}, vlan {}",
+                          peerMac, clientConnectionPointStr, vlanIdInUse);
         Interface clientInterface = interfaceService.getInterfacesByPort(clientConnectionPoint)
                 .stream().filter(iface -> Dhcp6HandlerUtil.interfaceContainsVlan(iface, vlanIdInUse))
                 .findFirst().orElse(null);
@@ -1555,7 +1567,7 @@
             log.debug("DHCP server {} host info found. ConnectPt{}  Mac {} vlan {}", serverInfo.getDhcpServerIp6(),
                     dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
         } else {
-            log.warn("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp6(),
+            log.debug("DHCP server {} not resolve yet connectPt {} mac {} vlan {}", serverInfo.getDhcpServerIp6(),
                     dhcpServerConnectPoint, dhcpServerConnectMac, dhcpConnectVlan);
 
             Ip6Address ipToProbe;
@@ -1567,7 +1579,7 @@
             String hostToProbe = serverInfo.getDhcpGatewayIp6()
                     .map(ip -> "gateway").orElse("server");
 
-            log.info("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
+            log.debug("Dynamically probing to resolve {} IP {}", hostToProbe, ipToProbe);
             hostService.startMonitoringIp(ipToProbe);
 
             Set<Host> hosts = hostService.getHostsByIp(ipToProbe);
@@ -1581,7 +1593,7 @@
                 newServerInfo = serverInfo;
                 log.warn("Dynamically host found host {}", host);
             } else {
-                log.warn("No host found host ip {} dynamically", ipToProbe);
+                log.debug("No host found host ip {} dynamically", ipToProbe);
             }
         }
         return newServerInfo;