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

Change-Id: Ideb0b1a959bd352b0c535b6010bd9326aca184f8
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 fa5be97..7325010 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
@@ -350,9 +350,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);
 
@@ -514,8 +512,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;
@@ -539,8 +536,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);
@@ -748,8 +744,6 @@
         IPv4 ipv4Packet = (IPv4) etherReply.getPayload();
         UDP udpPacket = (UDP) ipv4Packet.getPayload();
         DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
-
-
         Ip4Address clientInterfaceIp =
                 interfaceService.getInterfacesByPort(context.inPacket().receivedFrom())
                         .stream()
@@ -780,9 +774,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();
@@ -793,13 +788,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;
             }
 
@@ -807,11 +803,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()) {
@@ -836,15 +833,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);
 
@@ -894,7 +889,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.
@@ -908,6 +902,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 d8a3b16..afe05f0 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
@@ -1086,6 +1086,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);
@@ -1097,14 +1098,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) {
@@ -1119,6 +1125,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;
@@ -1247,6 +1256,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);
@@ -1558,7 +1570,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;
@@ -1570,7 +1582,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);
@@ -1584,7 +1596,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;