Add initial integration test
diff --git a/src/main/java/com/intel/jndn/management/NFD.java b/src/main/java/com/intel/jndn/management/NFD.java
index 8f8cdab..e05b2a9 100644
--- a/src/main/java/com/intel/jndn/management/NFD.java
+++ b/src/main/java/com/intel/jndn/management/NFD.java
@@ -14,6 +14,7 @@
import com.intel.jndn.management.types.StatusDataset;
import com.intel.jndn.management.types.ControlResponse;
import com.intel.jndn.management.types.FaceStatus;
+import com.intel.jndn.management.types.FibEntry;
import com.intel.jndn.management.types.RibEntry;
import com.intel.jndn.utils.Client;
import java.io.IOException;
@@ -89,7 +90,7 @@
interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
- // TODO verify that all faces are being returned; right now they don't
+ // TODO verify that all faces are being returned; right now they don't
// match up with the results from nfd-status-http-server but no
// additional segments are present;
// see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
@@ -104,6 +105,36 @@
}
/**
+ * Retrieve a list of FIB entries and their NextHopRecords from the given
+ * forwarder; calls /localhost/nfd/fib/list which requires a local Face (all
+ * non-local packets are dropped).
+ *
+ * @param forwarder Only a localhost Face
+ * @return
+ * @throws Exception
+ */
+ public static List<FibEntry> getFibList(Face forwarder) throws Exception {
+ // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
+ Interest interest = new Interest(new Name("/localhost/nfd/fib/list"));
+ interest.setMustBeFresh(true);
+ interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
+ interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
+
+ // TODO verify that all faces are being returned; right now they don't
+ // match up with the results from nfd-status-http-server but no
+ // additional segments are present;
+ // see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
+ // send packet
+ Data data = Client.getDefault().getSync(forwarder, interest);
+ if (data == null) {
+ throw new Exception("Failed to retrieve list of fib entries from the forwarder.");
+ }
+
+ // parse packet
+ return StatusDataset.wireDecode(data.getContent(), FibEntry.class);
+ }
+
+ /**
* Retrieve a list of routing entries from the RIB; calls
* /localhost/nfd/rib/list which requires a local Face (all non-local packets
* are dropped)
@@ -250,6 +281,31 @@
}
/**
+ * Unregister a route on a forwarder; see
+ * http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
+ * usage and http://redmine.named-data.net/projects/nfd/wiki/RibMgmt for
+ * protocol documentation. Ensure the forwarding face is on the local machine
+ * (management requests are to /localhost/...) and that command signing has
+ * been set up (e.g. forwarder.setCommandSigningInfo()
+ *
+ * @param forwarder
+ * @param route
+ * @return
+ */
+ public static boolean unregister(Face forwarder, Name route) throws Exception{
+ // build command name
+ ControlParameters controlParameters = new ControlParameters();
+ controlParameters.setName(route);
+
+ // build command name
+ Name command = new Name("/localhost/nfd/rib/unregister");
+ command.append(controlParameters.wireEncode());
+
+ // send the interest
+ return sendCommandAndErrorCheck(forwarder, new Interest(command));
+ }
+
+ /**
* Set a strategy on the forwarder; see
* http://named-data.net/doc/NFD/current/manpages/nfdc.html for command-line
* usage and http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice
diff --git a/src/test/java/com/intel/jndn/management/FaceStatusTest.java b/src/test/java/com/intel/jndn/management/FaceStatusTest.java
index e5fbab7..42bba95 100644
--- a/src/test/java/com/intel/jndn/management/FaceStatusTest.java
+++ b/src/test/java/com/intel/jndn/management/FaceStatusTest.java
@@ -14,6 +14,8 @@
import com.intel.jndn.management.types.FaceStatus;
import com.intel.jndn.utils.Client;
import java.util.List;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
import junit.framework.Assert;
import net.named_data.jndn.Data;
import net.named_data.jndn.Face;
@@ -21,8 +23,6 @@
import net.named_data.jndn.Name;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.util.Blob;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -34,7 +34,7 @@
*/
public class FaceStatusTest {
- private static final Logger logger = LogManager.getLogger();
+ private static final Logger logger = Logger.getLogger(FaceStatusTest.class.getName());
/**
* Test encoding/decoding
diff --git a/src/test/java/com/intel/jndn/management/IntegrationSuite.java b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
new file mode 100644
index 0000000..d968df0
--- /dev/null
+++ b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
@@ -0,0 +1,43 @@
+/*
+ * File name: IntegrationSuite.java
+ *
+ * Purpose: Tests to run with a local NFD as part of integration testing; will
+ * not run in the maven test phase, must be run manually.
+ *
+ * © Copyright Intel Corporation. All rights reserved.
+ * Intel Corporation, 2200 Mission College Boulevard,
+ * Santa Clara, CA 95052-8119, USA
+ */
+package com.intel.jndn.management;
+
+import java.util.logging.Logger;
+import junit.framework.Assert;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.Name;
+
+/**
+ * Tests to run with a local NFD as part of integration testing; will not run in
+ * the maven test phase, must be run manually.
+ *
+ * @author Andrew Brown <andrew.brown@intel.com>
+ */
+public class IntegrationSuite {
+
+ private static final Logger logger = Logger.getLogger(IntegrationSuite.class.getName());
+
+ public static void main(String[] args) throws Exception {
+ Face face = new Face();
+ Assert.assertTrue(NFD.pingLocal(face));
+
+ // grab datasets
+ Assert.assertFalse(NFD.getFaceList(face).isEmpty());
+ Assert.assertFalse(NFD.getFibList(face).isEmpty());
+ Assert.assertFalse(NFD.getRouteList(face).isEmpty());
+
+ // create a new route
+ Assert.assertTrue(NFD.register(face, "contentstore://", new Name("/my/cache/route"), 999));
+
+ // remove the route
+ Assert.assertTrue(NFD.unregister(face, new Name("/my/cache/route")));
+ }
+}