Cosmetic fixes and logging around Juniper driver
Change-Id: Ief0dba3a1c4cc567cf9fe6fa16b4aeae9488c51e
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
index fc53137..0c2823f 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
@@ -19,7 +19,6 @@
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
-import org.onosproject.drivers.utilities.XmlConfigParser;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
@@ -27,8 +26,8 @@
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfSession;
+import org.slf4j.Logger;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
@@ -37,6 +36,7 @@
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_MAC_ADD_INFO;
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_SYS_INFO;
import static org.onosproject.drivers.juniper.JuniperUtils.requestBuilder;
+import static org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -47,7 +47,7 @@
public class DeviceDiscoveryJuniperImpl extends AbstractHandlerBehaviour
implements DeviceDescriptionDiscovery {
- public final org.slf4j.Logger log = getLogger(getClass());
+ private final Logger log = getLogger(getClass());
@Override
public DeviceDescription discoverDeviceDetails() {
@@ -63,10 +63,12 @@
log.warn("Failed to retrieve device details for {}", devId);
return null;
}
+ log.trace("Device {} system-information {}", devId, sysInfo);
DeviceDescription description =
- JuniperUtils.parseJuniperDescription(devId, XmlConfigParser.
- loadXml(new ByteArrayInputStream(sysInfo.getBytes())), chassis);
- log.debug("Device description {}", description);
+ JuniperUtils.parseJuniperDescription(devId,
+ loadXmlString(sysInfo),
+ chassis);
+ log.debug("Device {} description {}", devId, description);
return description;
}
@@ -82,10 +84,10 @@
log.warn("Failed to retrieve ports for device {}", devId);
return ImmutableList.of();
}
+ log.trace("Device {} interface-information {}", devId, reply);
List<PortDescription> descriptions =
- JuniperUtils.parseJuniperPorts(XmlConfigParser.
- loadXml(new ByteArrayInputStream(reply.getBytes())));
- log.debug("Discovered ports {}", descriptions);
+ JuniperUtils.parseJuniperPorts(loadXmlString(reply));
+ log.debug("Device {} Discovered ports {}", devId, descriptions);
return descriptions;
}
}
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
index 76f5f3b..efd5f50 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/JuniperUtils.java
@@ -33,6 +33,7 @@
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.link.LinkDescription;
+import org.slf4j.Logger;
import java.util.HashSet;
import java.util.List;
@@ -45,6 +46,7 @@
import static org.onosproject.net.Device.Type.ROUTER;
import static org.onosproject.net.Port.Type.COPPER;
import static org.onosproject.net.PortNumber.portNumber;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Utility class for Netconf XML for Juniper.
@@ -52,6 +54,8 @@
*/
public final class JuniperUtils {
+ private static final Logger log = getLogger(JuniperUtils.class);
+
public static final String FAILED_CFG = "Failed to retrieve configuration.";
private static final String RPC_TAG_NETCONF_BASE = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">";
@@ -173,6 +177,9 @@
if (interf.getString(IF_TYPE).contains(ETH) &&
interf.getString(SPEED).contains(MBPS)) {
portDescriptions.add(parseDefaultPort(interf));
+ } else {
+ log.debug("Ignoring default port candidate {}",
+ interf.getString(NAME));
}
} else if (interf.getString(IF_LO_ENCAP) != null &&
!interf.getString(NAME).contains("pfe") &&
@@ -180,6 +187,9 @@
portDescriptions.add(parseLogicalPort(interf));
} else if (interf.getString(NAME).contains("lo")) {
portDescriptions.add(parseLoopback(interf));
+ } else {
+ log.debug("Ignoring unknown port {}",
+ interf.getString(NAME));
}
}
}
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
index 2b99faa..1c9f208 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/LinkDiscoveryJuniperImpl.java
@@ -19,7 +19,6 @@
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import org.onosproject.drivers.utilities.XmlConfigParser;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
@@ -31,7 +30,6 @@
import org.onosproject.netconf.NetconfSession;
import org.slf4j.Logger;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Optional;
@@ -41,6 +39,7 @@
import static org.onosproject.drivers.juniper.JuniperUtils.LinkAbstraction;
import static org.onosproject.drivers.juniper.JuniperUtils.parseJuniperLldp;
import static org.onosproject.drivers.juniper.JuniperUtils.requestBuilder;
+import static org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_LLDP_NBR_INFO;
import static org.slf4j.LoggerFactory.getLogger;
@@ -72,8 +71,7 @@
return ImmutableSet.of();
}
log.debug("Reply from device {} : {}", localDeviceId, reply);
- Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(
- XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
+ Set<LinkAbstraction> linkAbstractions = parseJuniperLldp(loadXmlString(reply));
log.debug("Set of LinkAbstraction discovered {}", linkAbstractions);
DeviceService deviceService = this.handler().get(DeviceService.class);
@@ -126,9 +124,9 @@
JuniperUtils.createBiDirLinkDescription(localDeviceId,
localPort.get(),
- remoteDevice.id(),
- remotePort.get(),
- descriptions);
+ remoteDevice.id(),
+ remotePort.get(),
+ descriptions);
}
return descriptions;
diff --git a/drivers/utilities/src/main/java/org/onosproject/drivers/utilities/XmlConfigParser.java b/drivers/utilities/src/main/java/org/onosproject/drivers/utilities/XmlConfigParser.java
index 7db6e2f..55eecb1 100644
--- a/drivers/utilities/src/main/java/org/onosproject/drivers/utilities/XmlConfigParser.java
+++ b/drivers/utilities/src/main/java/org/onosproject/drivers/utilities/XmlConfigParser.java
@@ -25,8 +25,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -53,6 +55,10 @@
}
}
+ public static HierarchicalConfiguration loadXmlString(String xmlStr) {
+ return loadXml(new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8)));
+ }
+
public static List<ControllerInfo> parseStreamControllers(HierarchicalConfiguration cfg) {
List<ControllerInfo> controllers = new ArrayList<>();
List<HierarchicalConfiguration> fields =
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
index f46c42f..73c6f93 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/NetconfSessionImpl.java
@@ -118,7 +118,7 @@
try {
netconfConnection.connect(null, 1000 * connectTimeout, 1000 * connectTimeout);
} catch (IOException e) {
- throw new NetconfException("Cannot open a connection with device" + deviceInfo, e);
+ throw new NetconfException("Cannot open a connection with device " + deviceInfo, e);
}
boolean isAuthenticated;
try {