Add Checkstyle to enforce codestyle rules
Rules are based on Sun style with a few minor modifications
Change-Id: If9e772105053c67550e4f206024fea26b65e611b
diff --git a/build.gradle b/build.gradle
index aed58db..88287a6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -7,7 +7,7 @@
}
plugins {
- id "org.sonarqube" version "1.2"
+ id 'org.sonarqube' version '1.2'
id 'net.saliman.cobertura' version '2.3.0'
}
@@ -15,6 +15,7 @@
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'maven-publish'
+apply plugin: 'checkstyle'
group = 'com.intel.jndn.management'
version = '1.0.1-SNAPSHOT'
@@ -49,8 +50,9 @@
}
configurations {
- integrationTestCompile.extendsFrom testCompile
- integrationTestRuntime.extendsFrom testRuntime
+ checkstyleConfig
+ integrationTestCompile.extendsFrom testCompile
+ integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
@@ -59,6 +61,8 @@
testCompile 'junit:junit:4.12'
testCompile 'com.intel.jndn.mock:jndn-mock:1.0.1'
testRuntime 'org.slf4j:slf4j-api:1.7.16'
+
+ checkstyleConfig "com.puppycrawl.tools:checkstyle:6.15"
}
task javadocJar(type: Jar) {
@@ -87,6 +91,19 @@
outputs.upToDateWhen { false }
}
+tasks.withType(Checkstyle) {
+ checkstyleClasspath = project.configurations.checkstyleConfig
+ checkstyleMain {
+ exclude 'com/intel/jndn/management/enums/NfdTlv.java'
+ }
+ checkstyleTest {
+ configFile file('config/checkstyle/checkstyle-test.xml')
+ }
+ checkstyleIntegrationTest {
+ configFile file('config/checkstyle/checkstyle-test.xml')
+ }
+}
+
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
diff --git a/config/checkstyle/checkstyle-test.xml b/config/checkstyle/checkstyle-test.xml
new file mode 100644
index 0000000..aa2a970
--- /dev/null
+++ b/config/checkstyle/checkstyle-test.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+
+<!--
+
+ Checkstyle configuration that checks the sun coding conventions from:
+
+ - the Java Language Specification at
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
+
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
+
+ - the Javadoc guidelines at
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
+
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
+
+ - some best practices
+
+ Checkstyle is very configurable. Be sure to read the documentation at
+ http://checkstyle.sf.net (or in your downloaded distribution).
+
+ Most Checks are configurable, be sure to consult the documentation.
+
+ To completely disable a check, just comment it out or delete it from the file.
+
+ Finally, it is worth reading the documentation.
+
+-->
+
+<module name="Checker">
+ <!--
+ If you set the basedir property below, then all reported file
+ names will be relative to the specified directory. See
+ http://checkstyle.sourceforge.net/5.x/config.html#Checker
+
+ <property name="basedir" value="${basedir}"/>
+ -->
+
+ <property name="fileExtensions" value="java, properties, xml"/>
+
+ <!-- Checks that a package-info.java file exists for each package. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
+ <!--<module name="JavadocPackage"/>-->
+
+ <!-- Checks whether files end with a new line. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
+ <module name="NewlineAtEndOfFile"/>
+
+ <!-- Checks that property files contain the same keys. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
+ <module name="Translation"/>
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="FileLength"/>
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="FileTabCharacter"/>
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="minimum" value="0"/>
+ <property name="maximum" value="0"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+
+ <!-- Checks for Headers -->
+ <!-- See http://checkstyle.sf.net/config_header.html -->
+ <!-- <module name="Header"> -->
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
+ <!-- <property name="fileExtensions" value="java"/> -->
+ <!-- </module> -->
+
+ <module name="TreeWalker">
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <!--<module name="JavadocMethod">-->
+ <!--<property name="excludeScope" value="private"/>-->
+ <!--</module>-->
+ <module name="JavadocType">
+ <property name="excludeScope" value="private"/>
+ </module>
+ <module name="JavadocVariable">
+ <property name="excludeScope" value="private"/>
+ </module>
+ <module name="JavadocStyle"/>
+
+ <!-- Checks for Naming Conventions. -->
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
+ <module name="ConstantName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="MemberName"/>
+ <module name="MethodName"/>
+ <module name="PackageName"/>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="TypeName"/>
+
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.sf.net/config_import.html -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports">
+ <property name="processJavadoc" value="false"/>
+ </module>
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="LineLength">
+ <property name="max" value="120"/>
+ </module>
+ <module name="MethodLength"/>
+ <module name="ParameterNumber"/>
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="EmptyForIteratorPad"/>
+ <module name="GenericWhitespace"/>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="OperatorWrap">
+ <property name="option" value="eol"/>
+ </module>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad"/>
+ <module name="WhitespaceAfter"/>
+ <module name="WhitespaceAround"/>
+
+ <!-- Modifier Checks -->
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
+ <module name="ModifierOrder"/>
+ <module name="RedundantModifier"/>
+
+ <!-- Checks for blocks. You know, those {}'s -->
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
+ <module name="AvoidNestedBlocks"/>
+ <module name="EmptyBlock"/>
+ <module name="LeftCurly"/>
+ <module name="NeedBraces"/>
+ <module name="RightCurly"/>
+
+ <!-- Checks for common coding problems -->
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
+ <module name="AvoidInlineConditionals"/>
+ <module name="EmptyStatement"/>
+ <module name="EqualsHashCode"/>
+ <!-- <module name="HiddenField"/> -->
+ <module name="IllegalInstantiation"/>
+ <module name="InnerAssignment"/>
+ <!--<module name="MagicNumber"/>-->
+ <module name="MissingSwitchDefault"/>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+
+ <!-- Checks for class design -->
+ <!-- See http://checkstyle.sf.net/config_design.html -->
+ <!--<module name="DesignForExtension"/>-->
+ <module name="FinalClass"/>
+ <module name="HideUtilityClassConstructor"/>
+ <module name="InterfaceIsType"/>
+ <module name="VisibilityModifier"/>
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="ArrayTypeStyle"/>
+ <module name="FinalParameters"/>
+ <!--<module name="TodoComment"/>-->
+ <module name="UpperEll"/>
+
+ </module>
+
+</module>
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
new file mode 100644
index 0000000..bed9ee2
--- /dev/null
+++ b/config/checkstyle/checkstyle.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+
+<!--
+
+ Checkstyle configuration that checks the sun coding conventions from:
+
+ - the Java Language Specification at
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
+
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
+
+ - the Javadoc guidelines at
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
+
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
+
+ - some best practices
+
+ Checkstyle is very configurable. Be sure to read the documentation at
+ http://checkstyle.sf.net (or in your downloaded distribution).
+
+ Most Checks are configurable, be sure to consult the documentation.
+
+ To completely disable a check, just comment it out or delete it from the file.
+
+ Finally, it is worth reading the documentation.
+
+-->
+
+<module name="Checker">
+ <!--
+ If you set the basedir property below, then all reported file
+ names will be relative to the specified directory. See
+ http://checkstyle.sourceforge.net/5.x/config.html#Checker
+
+ <property name="basedir" value="${basedir}"/>
+ -->
+
+ <property name="fileExtensions" value="java, properties, xml"/>
+
+ <!-- Checks that a package-info.java file exists for each package. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
+ <module name="JavadocPackage"/>
+
+ <!-- Checks whether files end with a new line. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
+ <module name="NewlineAtEndOfFile"/>
+
+ <!-- Checks that property files contain the same keys. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
+ <module name="Translation"/>
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="FileLength"/>
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="FileTabCharacter"/>
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="minimum" value="0"/>
+ <property name="maximum" value="0"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+
+ <!-- Checks for Headers -->
+ <!-- See http://checkstyle.sf.net/config_header.html -->
+ <!-- <module name="Header"> -->
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
+ <!-- <property name="fileExtensions" value="java"/> -->
+ <!-- </module> -->
+
+ <module name="TreeWalker">
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <module name="JavadocMethod">
+ <property name="excludeScope" value="private"/>
+ </module>
+ <module name="JavadocType">
+ <property name="excludeScope" value="private"/>
+ </module>
+ <module name="JavadocVariable">
+ <property name="excludeScope" value="private"/>
+ </module>
+ <module name="JavadocStyle"/>
+
+ <!-- Checks for Naming Conventions. -->
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
+ <module name="ConstantName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="MemberName"/>
+ <module name="MethodName"/>
+ <module name="PackageName"/>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="TypeName"/>
+
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.sf.net/config_import.html -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports">
+ <property name="processJavadoc" value="false"/>
+ </module>
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="LineLength">
+ <property name="max" value="120"/>
+ </module>
+ <module name="MethodLength"/>
+ <module name="ParameterNumber"/>
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="EmptyForIteratorPad"/>
+ <module name="GenericWhitespace"/>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="OperatorWrap">
+ <property name="option" value="eol"/>
+ </module>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad"/>
+ <module name="WhitespaceAfter"/>
+ <module name="WhitespaceAround"/>
+
+ <!-- Modifier Checks -->
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
+ <module name="ModifierOrder"/>
+ <module name="RedundantModifier"/>
+
+ <!-- Checks for blocks. You know, those {}'s -->
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
+ <module name="AvoidNestedBlocks"/>
+ <module name="EmptyBlock"/>
+ <module name="LeftCurly"/>
+ <module name="NeedBraces"/>
+ <module name="RightCurly"/>
+
+ <!-- Checks for common coding problems -->
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
+ <module name="AvoidInlineConditionals"/>
+ <module name="EmptyStatement"/>
+ <module name="EqualsHashCode"/>
+ <!-- <module name="HiddenField"/> -->
+ <module name="IllegalInstantiation"/>
+ <module name="InnerAssignment"/>
+ <module name="MagicNumber"/>
+ <module name="MissingSwitchDefault"/>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+
+ <!-- Checks for class design -->
+ <!-- See http://checkstyle.sf.net/config_design.html -->
+ <!--<module name="DesignForExtension"/>-->
+ <module name="FinalClass"/>
+ <module name="HideUtilityClassConstructor"/>
+ <module name="InterfaceIsType"/>
+ <module name="VisibilityModifier"/>
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="ArrayTypeStyle"/>
+ <module name="FinalParameters"/>
+ <!--<module name="TodoComment"/>-->
+ <module name="UpperEll"/>
+
+ </module>
+
+</module>
diff --git a/src/main/java/com/intel/jndn/management/ManagementException.java b/src/main/java/com/intel/jndn/management/ManagementException.java
index 89a0b25..8e2edfd 100644
--- a/src/main/java/com/intel/jndn/management/ManagementException.java
+++ b/src/main/java/com/intel/jndn/management/ManagementException.java
@@ -26,23 +26,28 @@
*/
public class ManagementException extends Exception {
/**
- * Constructor from the message
+ * Constructor from the message.
+ * @param message Error message
*/
- public ManagementException(String message) {
+ public ManagementException(final String message) {
super(message);
}
/**
- * Constructor from the message and the cause
+ * Constructor from the message and the cause.
+ * @param message Error message
+ * @param cause Chained exception
*/
- public ManagementException(String message, Throwable cause) {
+ public ManagementException(final String message, final Throwable cause) {
super(message, cause);
}
/**
- * Parse an NFD response to create a ManagementException.
+ * Create exception from NFD's ControlResponse.
+ * @param response ControlResponse from which to use status code and status text
+ * @return new instance of ManagementException
*/
- public static ManagementException fromResponse(ControlResponse response) {
+ public static ManagementException fromResponse(final ControlResponse response) {
String message = "Action failed, forwarder returned: " + response.getStatusCode() + " " + response.getStatusText();
return new ManagementException(message);
}
diff --git a/src/main/java/com/intel/jndn/management/NdnPingClient.java b/src/main/java/com/intel/jndn/management/NdnPingClient.java
index ecdaecc..95dc279 100644
--- a/src/main/java/com/intel/jndn/management/NdnPingClient.java
+++ b/src/main/java/com/intel/jndn/management/NdnPingClient.java
@@ -23,12 +23,15 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-public class NdnPingClient {
+/**
+ * Simplistic checker for live connection to NFD forwarder.
+ */
+public final class NdnPingClient {
public static final long DEFAULT_TIMEOUT = 2000;
private static final Logger LOG = Logger.getLogger(NdnPingClient.class.getName());
/**
- * Prevent creation of NdnPingClient instances
+ * Prevent creation of NdnPingClient instances.
*/
private NdnPingClient() {
}
@@ -42,7 +45,7 @@
* @param face only a localhost Face
* @return true if successful, false otherwise
*/
- public static boolean pingLocal(Face face) {
+ public static boolean pingLocal(final Face face) {
return ping(face, new Name("/localhost/nfd"));
}
@@ -55,7 +58,7 @@
* @param name a known {@link Name} that the remote node will answer to
* @return true if successful, false otherwise
*/
- public static boolean ping(Face face, Name name) {
+ public static boolean ping(final Face face, final Name name) {
// build interest
Interest interest = new Interest(name);
interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
diff --git a/src/main/java/com/intel/jndn/management/Nfdc.java b/src/main/java/com/intel/jndn/management/Nfdc.java
index ca1a52b..807ef90 100644
--- a/src/main/java/com/intel/jndn/management/Nfdc.java
+++ b/src/main/java/com/intel/jndn/management/Nfdc.java
@@ -16,16 +16,24 @@
import com.intel.jndn.management.enums.RouteOrigin;
import com.intel.jndn.management.helpers.FetchHelper;
import com.intel.jndn.management.helpers.StatusDatasetHelper;
-import net.named_data.jndn.*;
import com.intel.jndn.management.types.FaceStatus;
import com.intel.jndn.management.types.FibEntry;
import com.intel.jndn.management.types.ForwarderStatus;
import com.intel.jndn.management.enums.LocalControlHeader;
import com.intel.jndn.management.types.RibEntry;
import com.intel.jndn.management.types.StrategyChoice;
+
import java.io.IOException;
import java.util.List;
+import net.named_data.jndn.ControlResponse;
+import net.named_data.jndn.Data;
+import net.named_data.jndn.Interest;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.KeyLocator;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.ControlParameters;
+import net.named_data.jndn.ForwardingFlags;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.security.SecurityException;
@@ -36,32 +44,31 @@
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
-public class Nfdc {
+public final class Nfdc {
private static final int OK_STATUS = 200;
/////////////////////////////////////////////////////////////////////////////
/**
- * Prevent creation of Nfdc instances
+ * Prevent creation of Nfdc instances.
*/
private Nfdc() {
}
/**
* Retrieve the status of the given forwarder; calls /localhost/nfd/status/general
- * which requires a local Face (all non-local packets are dropped)
+ * which requires a local Face (all non-local packets are dropped).
*
* @param face only a localhost Face
* @return the forwarder status object
- *
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus">ForwarderStatus</a>
* @throws ManagementException if the network request failed or the returned status could not be decoded
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus">ForwarderStatus</a>
*/
- public static ForwarderStatus getForwarderStatus(Face face) throws ManagementException {
+ public static ForwarderStatus getForwarderStatus(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/status/general"));
return new ForwarderStatus(StatusDatasetHelper.combine(segments));
- } catch (IOException|EncodingException e) {
+ } catch (IOException | EncodingException e) {
throw new ManagementException(e.getMessage(), e);
}
}
@@ -69,15 +76,14 @@
/**
* Retrieve a list of faces and their status from the given forwarder; calls
* /localhost/nfd/faces/list which requires a local Face (all non-local
- * packets are dropped)
+ * packets are dropped).
*
* @param face only a localhost Face
* @return a list of face status objects
- *
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">FaceManagement</a>
* @throws ManagementException if the network request failed or if the NFD rejected the request
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">FaceManagement</a>
*/
- public static List<FaceStatus> getFaceList(Face face) throws ManagementException {
+ public static List<FaceStatus> getFaceList(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/faces/list"));
return StatusDatasetHelper.wireDecode(segments, FaceStatus.class);
@@ -93,11 +99,10 @@
*
* @param face only a localhost Face
* @return a list of FIB entries
- *
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
* @throws ManagementException if the network request failed or if the NFD rejected the request
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
*/
- public static List<FibEntry> getFibList(Face face) throws ManagementException {
+ public static List<FibEntry> getFibList(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/fib/list"));
return StatusDatasetHelper.wireDecode(segments, FibEntry.class);
@@ -113,11 +118,10 @@
*
* @param face only a localhost Face
* @return a list of RIB entries, i.e. routes
- *
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
* @throws ManagementException if the network request failed or if the NFD rejected the request
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
*/
- public static List<RibEntry> getRouteList(Face face) throws ManagementException {
+ public static List<RibEntry> getRouteList(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/rib/list"));
return StatusDatasetHelper.wireDecode(segments, RibEntry.class);
@@ -133,12 +137,11 @@
*
* @param face only a localhost Face
* @return a list of strategy choice entries, i.e. routes
- *
+ * @throws ManagementException if the network request failed, the NFD response could not be decoded, or
+ * the NFD rejected the request
* @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice">StrategyChoice</a>
- * @throws ManagementException if the network request failed, the NFD response could not be decoded, or
- * the NFD rejected the request
*/
- public static List<StrategyChoice> getStrategyList(Face face) throws ManagementException {
+ public static List<StrategyChoice> getStrategyList(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/strategy-choice/list"));
return StatusDatasetHelper.wireDecode(segments, StrategyChoice.class);
@@ -155,7 +158,7 @@
* @throws ManagementException if the network request failed, if the NFD rejected the request, or no
* KeyLocator was found
*/
- public static KeyLocator getKeyLocator(Face face) throws ManagementException {
+ public static KeyLocator getKeyLocator(final Face face) throws ManagementException {
try {
List<Data> segments = FetchHelper.getSegmentedData(face, new Name("/localhost/nfd/status/general"));
if (segments.isEmpty() || !KeyLocator.canGetFromSignature(segments.get(0).getSignature())) {
@@ -173,13 +176,13 @@
* command signing has been set up (e.g. forwarder.setCommandSigningInfo()).
*
* @param face only a localhost {@link Face}
- * @param uri a string like "tcp4://host.name.com" (see nfd-status channels
- * for more protocol options)
+ * @param uri a string like "tcp4://host.name.com" (see nfd-status channels
+ * for more protocol options)
* @return the newly created face ID
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static int createFace(Face face, String uri) throws ManagementException {
+ public static int createFace(final Face face, final String uri) throws ManagementException {
Name command = new Name("/localhost/nfd/faces/create");
ControlParameters parameters = new ControlParameters();
parameters.setUri(uri);
@@ -191,8 +194,7 @@
// return
return response.getBodyAsControlParameters().getFaceId();
- }
- catch (IOException|EncodingException e) {
+ } catch (IOException | EncodingException e) {
throw new ManagementException(e.getMessage(), e);
}
}
@@ -202,12 +204,12 @@
* local machine (management requests are to /localhost/...) and that command
* signing has been set up (e.g. forwarder.setCommandSigningInfo()).
*
- * @param face only a localhost {@link Face}
- * @param faceId the ID of the face to destroy
+ * @param face only a localhost {@link Face}
+ * @param faceId the ID of the face to destroy
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static void destroyFace(Face face, int faceId) throws ManagementException {
+ public static void destroyFace(final Face face, final int faceId) throws ManagementException {
Name command = new Name("/localhost/nfd/faces/destroy");
ControlParameters parameters = new ControlParameters();
parameters.setFaceId(faceId);
@@ -215,21 +217,22 @@
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
/**
- * Enable a local control feature on the given forwarder. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature</a>
+ * Enable a local control feature on the given forwarder.
*
- * @param face only a localhost {@link Face}
- * @param header the control feature to enable
+ * @param face only a localhost {@link Face}
+ * @param header the control feature to enable
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">Face Management</a>
*/
- public static void enableLocalControlHeader(Face face, LocalControlHeader header) throws ManagementException {
+ public static void enableLocalControlHeader(final Face face, final LocalControlHeader header) throws
+ ManagementException {
// build command name
Name command = new Name("/localhost/nfd/faces/enable-local-control");
ControlParameters parameters = new ControlParameters();
@@ -238,21 +241,22 @@
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
/**
- * Disable a local control feature on the given forwarder. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature</a>
+ * Disable a local control feature on the given forwarder.
*
- * @param face only a localhost {@link Face}
- * @param header the control feature to disable
+ * @param face only a localhost {@link Face}
+ * @param header the control feature to disable
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">Face Management</a>
*/
- public static void disableLocalControlHeader(Face face, LocalControlHeader header) throws ManagementException {
+ public static void disableLocalControlHeader(final Face face, final LocalControlHeader header) throws
+ ManagementException {
// build command name
Name command = new Name("/localhost/nfd/faces/disable-local-control");
ControlParameters parameters = new ControlParameters();
@@ -261,48 +265,47 @@
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
/**
- * Register a route on the forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
+ * Register a route on the forwarder.
+ * <p/>
+ * 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 face only a localhost {@link Face}
+ * @param face only a localhost {@link Face}
* @param controlParameters the {@link ControlParameters} command options
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc</a>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
- public static void register(Face face, ControlParameters controlParameters) throws ManagementException {
+ public static void register(final Face face, final ControlParameters controlParameters) throws ManagementException {
// build command name
Name command = new Name("/localhost/nfd/rib/register");
command.append(controlParameters.wireEncode());
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
/**
* Register a route on a forwarder; this will create a new face on the
- * forwarder towards the face (e.g., self registration)
+ * forwarder towards the face (e.g., self registration).
*
- * @param face only a localhost {@link Face}
- * @param route the {@link Name} prefix of the route
- * @param cost the numeric cost of forwarding along the route
+ * @param face only a localhost {@link Face}
+ * @param route the {@link Name} prefix of the route
+ * @param cost the numeric cost of forwarding along the route
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static void register(Face face, Name route, int cost) throws ManagementException {
+ public static void register(final Face face, final Name route, final int cost) throws ManagementException {
ForwardingFlags flags = new ForwardingFlags();
flags.setCapture(false);
flags.setChildInherit(true);
@@ -313,22 +316,24 @@
.setOrigin(RouteOrigin.APP.toInteger())
.setForwardingFlags(flags));
}
+
/**
* Register a route on a forwarder; this will create a new face on the
* forwarder to the given URI/route pair. See register(Face,
* ControlParameters) for more detailed documentation.
*
- * @param face only a localhost {@link Face}
- * @param uri the URI (e.g. "tcp4://10.10.2.2:6363") of the remote node; note
- * that this must be one of the canonical forms described in the wiki
- * (http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#TCP) for NFD to
- * accept the registration--otherwise you will see 400 errors
- * @param route the {@link Name} prefix of the route
- * @param cost the numeric cost of forwarding along the route
+ * @param face only a localhost {@link Face}
+ * @param uri the URI (e.g. "tcp4://10.10.2.2:6363") of the remote node; note
+ * that this must be one of the canonical forms described in the wiki
+ * (http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#TCP) for NFD to
+ * accept the registration--otherwise you will see 400 errors
+ * @param route the {@link Name} prefix of the route
+ * @param cost the numeric cost of forwarding along the route
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static void register(Face face, String uri, Name route, int cost) throws ManagementException {
+ public static void register(final Face face, final String uri, final Name route, final int cost) throws
+ ManagementException {
// create the new face
int faceId = createFace(face, uri);
@@ -348,7 +353,8 @@
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static void register(Face forwarder, int faceId, Name route, int cost) throws ManagementException {
+ public static void register(final Face forwarder, final int faceId, final Name route, final int cost) throws
+ ManagementException {
// build command name
ControlParameters parameters = new ControlParameters();
parameters.setName(route);
@@ -365,46 +371,44 @@
}
/**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * 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()).
+ * Unregister a route on a forwarder
+ * <p/>
+ * 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 face only a localhost {@link Face}
+ * @param face only a localhost {@link Face}
* @param controlParameters the {@link ControlParameters} command options
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc</a>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
- public static void unregister(Face face, ControlParameters controlParameters) throws ManagementException {
+ public static void unregister(final Face face, final ControlParameters controlParameters) throws ManagementException {
// build command name
Name command = new Name("/localhost/nfd/rib/unregister");
command.append(controlParameters.wireEncode());
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
/**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
+ * Unregister a route on a forwarder.
+ * <p/>
+ * 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 face only a localhost {@link Face}
- * @param route the {@link Name} prefix of the route
+ * @param face only a localhost {@link Face}
+ * @param route the {@link Name} prefix of the route
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc</a>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
- public static void unregister(Face face, Name route) throws ManagementException {
+ public static void unregister(final Face face, final Name route) throws ManagementException {
// build command name
ControlParameters controlParameters = new ControlParameters();
controlParameters.setName(route);
@@ -415,21 +419,20 @@
/**
* Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
+ * <p/>
+ * 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 face only a localhost {@link Face}
- * @param route the {@link Name} prefix of the route
- * @param faceId the specific ID of the face to remove (more than one face can
- * be registered to a route)
+ * @param face only a localhost {@link Face}
+ * @param route the {@link Name} prefix of the route
+ * @param faceId the specific ID of the face to remove (more than one face can
+ * be registered to a route)
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
+ * @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc</a>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
- public static void unregister(Face face, Name route, int faceId) throws ManagementException {
+ public static void unregister(final Face face, final Name route, final int faceId) throws ManagementException {
// build command name
ControlParameters controlParameters = new ControlParameters();
controlParameters.setName(route);
@@ -441,20 +444,20 @@
/**
* Unregister a route on a forwarder
- *
+ * <p/>
* Ensure the forwarding face is on the local machine (management requests are to /localhost/...) and that command
* signing has been set up using forwarder.setCommandSigningInfo().
*
- * @param face only a localhost {@link Face}
- * @param route the {@link Name} prefix of the route
- * @param uri the URI (e.g. "tcp4://some.host.com") of the remote node (more
- * than one face can be registered to a route)
+ * @param face only a localhost {@link Face}
+ * @param route the {@link Name} prefix of the route
+ * @param uri the URI (e.g. "tcp4://some.host.com") of the remote node (more
+ * than one face can be registered to a route)
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
* @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc command-line usage</a>
* @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RibMgmt</a>
*/
- public static void unregister(Face face, Name route, String uri) throws ManagementException {
+ public static void unregister(final Face face, final Name route, final String uri) throws ManagementException {
int faceId = -1;
for (FaceStatus faceStatus : getFaceList(face)) {
if (faceStatus.getRemoteUri().matches(uri)) {
@@ -473,20 +476,20 @@
/**
* Set a strategy on the forwarder
- *
+ * <p/>
* Ensure the forwarding face is on the local machine (management requests are to /localhost/...) and that command
* signing has been set up using forwarder.setCommandSigningInfo().
*
- * @param face only a localhost {@link Face}
- * @param prefix the {@link Name} prefix
- * @param strategy the {@link Name} of the strategy to set, e.g.
- * /localhost/nfd/strategy/broadcast
+ * @param face only a localhost {@link Face}
+ * @param prefix the {@link Name} prefix
+ * @param strategy the {@link Name} of the strategy to set, e.g.
+ * /localhost/nfd/strategy/broadcast
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
* @see <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">nfdc command-line usage</a>
* @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice">StrategyChoice</a>
*/
- public static void setStrategy(Face face, Name prefix, Name strategy) throws ManagementException {
+ public static void setStrategy(final Face face, final Name prefix, final Name strategy) throws ManagementException {
// build command name
Name command = new Name("/localhost/nfd/strategy-choice/set");
ControlParameters parameters = new ControlParameters();
@@ -496,7 +499,7 @@
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
@@ -508,12 +511,12 @@
* (management requests are to /localhost/...) and that command signing has
* been set up (e.g. forwarder.setCommandSigningInfo()).
*
- * @param face only a localhost {@link Face}
- * @param prefix the {@link Name} prefix
+ * @param face only a localhost {@link Face}
+ * @param prefix the {@link Name} prefix
* @throws ManagementException if the network request failed, the NFD response could not be decoded, or
* the NFD rejected the request
*/
- public static void unsetStrategy(Face face, Name prefix) throws ManagementException {
+ public static void unsetStrategy(final Face face, final Name prefix) throws ManagementException {
// build command name
Name command = new Name("/localhost/nfd/strategy-choice/unset");
ControlParameters parameters = new ControlParameters();
@@ -522,7 +525,7 @@
try {
sendCommand(face, command);
- } catch (IOException|EncodingException|ManagementException e) {
+ } catch (IOException | EncodingException | ManagementException e) {
throw new ManagementException(e.getMessage(), e);
}
}
@@ -536,23 +539,24 @@
*
* @param face only a localhost Face, command signing info must be set
* @param name As described at
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand,">http://redmine.named-data.net/projects/nfd/wiki/ControlCommand,</a>
+ * <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand">ControlCommand</a>,
* the requested interest must have encoded ControlParameters appended to the
* interest name
* @return a {@link ControlResponse}
- * @throws java.io.IOException
- * @throws net.named_data.jndn.encoding.EncodingException
- * @throws ManagementException
+ * @throws IOException if the network request failed
+ * @throws EncodingException if the NFD response could not be decoded
+ * @throws ManagementException if the NFD rejected the request
*/
- private static ControlResponse
- sendCommand(Face face, Name name) throws IOException, EncodingException, ManagementException {
+ private static ControlResponse sendCommand(final Face face, final Name name) throws IOException, EncodingException,
+ ManagementException {
Interest interest = new Interest(name);
// forwarder must have command signing info set
try {
face.makeCommandInterest(interest);
} catch (SecurityException e) {
- throw new IllegalArgumentException("Failed to make command interest; ensure command signing info is set on the face.", e);
+ throw new IllegalArgumentException("Failed to make command interest; ensure command signing info is set on the " +
+ "face.", e);
}
// send command packet
diff --git a/src/main/java/com/intel/jndn/management/enums/FacePersistency.java b/src/main/java/com/intel/jndn/management/enums/FacePersistency.java
index 08630b8..678b1a2 100644
--- a/src/main/java/com/intel/jndn/management/enums/FacePersistency.java
+++ b/src/main/java/com/intel/jndn/management/enums/FacePersistency.java
@@ -14,10 +14,10 @@
package com.intel.jndn.management.enums;
/**
- * Indicate whether the face is persistent; used by FaceStatus
+ * Indicate whether the face is persistent; used by FaceStatus.
*
- * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">FaceMgmt</a>
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">Face Management</a>
*/
public enum FacePersistency {
NONE(-1), // invalid value
@@ -30,16 +30,32 @@
/////////////////////////////////////////////////////////////////////////////
- FacePersistency(int value) {
+ /**
+ * Create enum using NFD's FacePersistency code.
+ *
+ * @param value NFD's FacePersistency code
+ */
+ FacePersistency(final int value) {
this.value = value;
}
+ /**
+ * Convert FacePersistency to the NFD code.
+ *
+ * @return NFD's FacePersistency code
+ */
public final int toInteger() {
return value;
}
+ /**
+ * Convert NFD code to FacePersistency enum.
+ *
+ * @param value NFD's FacePersistency code
+ * @return enum value
+ */
public static FacePersistency
- fromInteger(int value) {
+ fromInteger(final int value) {
switch (value) {
case 0:
return PERSISTENT;
diff --git a/src/main/java/com/intel/jndn/management/enums/FaceScope.java b/src/main/java/com/intel/jndn/management/enums/FaceScope.java
index d32621e..9b6796b 100644
--- a/src/main/java/com/intel/jndn/management/enums/FaceScope.java
+++ b/src/main/java/com/intel/jndn/management/enums/FaceScope.java
@@ -15,10 +15,10 @@
/**
* Indicate whether the face is local for scope control purposes; used by
- * FaceStatus
+ * FaceStatus.
*
- * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">FaceMgmt</a>
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">Face Management</a>
*/
public enum FaceScope {
@@ -31,16 +31,31 @@
/////////////////////////////////////////////////////////////////////////////
- FaceScope(int value) {
+ /**
+ * Create enum using NFD's FaceScope code.
+ *
+ * @param value NFD's FaceScope code
+ */
+ FaceScope(final int value) {
this.value = value;
}
+ /**
+ * Convert FaceScope to the NFD code.
+ *
+ * @return NFD's FaceScope code
+ */
public final int toInteger() {
return value;
}
- public static FaceScope
- fromInteger(int value) {
+ /**
+ * Convert NFD code to FaceScope enum.
+ *
+ * @param value NFD's FaceScope code
+ * @return enum value
+ */
+ public static FaceScope fromInteger(final int value) {
switch (value) {
case 0:
return NON_LOCAL;
diff --git a/src/main/java/com/intel/jndn/management/enums/LinkType.java b/src/main/java/com/intel/jndn/management/enums/LinkType.java
index 99da791..8d4a1c8 100644
--- a/src/main/java/com/intel/jndn/management/enums/LinkType.java
+++ b/src/main/java/com/intel/jndn/management/enums/LinkType.java
@@ -14,37 +14,46 @@
package com.intel.jndn.management.enums;
/**
- * NFD face link type
- * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">FaceMgmt</a>
+ * NFD face link type.
+ *
+ * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">Face Management</a>
*/
public enum LinkType {
- NONE(-1), // invalid value
-
- /**
- * Link is point-to-point
- */
+ NONE(-1),
POINT_TO_POINT(0),
-
- /**
- * Link is multi-access
- */
MULTI_ACCESS(1);
private final int value;
/////////////////////////////////////////////////////////////////////////////
- LinkType(int value) {
+ /**
+ * Create enum using NFD's LinkType code.
+ *
+ * @param value NFD's LinkType code
+ */
+ LinkType(final int value) {
this.value = value;
}
+ /**
+ * Convert LinkType to the NFD code.
+ *
+ * @return NFD's LinkType code
+ */
public final int toInteger() {
return value;
}
+ /**
+ * Convert NFD code to LinkType enum.
+ *
+ * @param value NFD's LinkType code
+ * @return enum value
+ */
public static LinkType
- fromInteger(int value) {
+ fromInteger(final int value) {
switch (value) {
case 0:
return POINT_TO_POINT;
diff --git a/src/main/java/com/intel/jndn/management/enums/LocalControlHeader.java b/src/main/java/com/intel/jndn/management/enums/LocalControlHeader.java
index 86a205d..426be64 100644
--- a/src/main/java/com/intel/jndn/management/enums/LocalControlHeader.java
+++ b/src/main/java/com/intel/jndn/management/enums/LocalControlHeader.java
@@ -14,10 +14,10 @@
package com.intel.jndn.management.enums;
/**
- * Define constants for local control header options. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature</a>
+ * Define constants for local control header options.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">Face Management</a>
*/
public enum LocalControlHeader {
@@ -29,10 +29,20 @@
/////////////////////////////////////////////////////////////////////////////
- LocalControlHeader(int value) {
+ /**
+ * Create enum using NFD's LocalControlHeader code.
+ *
+ * @param value NFD's LocalControlHeader code
+ */
+ LocalControlHeader(final int value) {
this.value = value;
}
+ /**
+ * Convert LocalControlHeader to the NFD code.
+ *
+ * @return NFD's LocalControlHeader code
+ */
public final int toInteger() {
return value;
}
diff --git a/src/main/java/com/intel/jndn/management/enums/NfdTlv.java b/src/main/java/com/intel/jndn/management/enums/NfdTlv.java
index d414ad2..8f7b536 100644
--- a/src/main/java/com/intel/jndn/management/enums/NfdTlv.java
+++ b/src/main/java/com/intel/jndn/management/enums/NfdTlv.java
@@ -15,9 +15,12 @@
package com.intel.jndn.management.enums;
/**
- * NFD Management protocol TLV codes
+ * NFD Management protocol TLV codes.
+ *
+ * @see <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">Face Management</a>
*/
-public class NfdTlv {
+@SuppressWarnings("CheckStyle")
+public final class NfdTlv {
/**
* Prevent creation of NfdTlv instances
*/
@@ -26,61 +29,61 @@
// ControlParameters
// http://redmine.named-data.net/projects/nfd/wiki/ControlCommand
- public static final int ControlParameters = 104;
- public static final int FaceId = 105;
- public static final int Uri = 114;
+ public static final int ControlParameters = 104;
+ public static final int FaceId = 105;
+ public static final int Uri = 114;
public static final int LocalControlFeature = 110;
- public static final int Origin = 111;
- public static final int Cost = 106;
- public static final int Flags = 108;
- public static final int Strategy = 107;
- public static final int ExpirationPeriod = 109;
+ public static final int Origin = 111;
+ public static final int Cost = 106;
+ public static final int Flags = 108;
+ public static final int Strategy = 107;
+ public static final int ExpirationPeriod = 109;
// ControlResponse
// http://redmine.named-data.net/projects/nfd/wiki/ControlCommand
public static final int ControlResponse = 101;
- public static final int StatusCode = 102;
- public static final int StatusText = 103;
+ public static final int StatusCode = 102;
+ public static final int StatusText = 103;
// ForwarderStatus
// http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
- public static final int NfdVersion = 128;
- public static final int StartTimestamp = 129;
- public static final int CurrentTimestamp = 130;
- public static final int NNameTreeEntries = 131;
- public static final int NFibEntries = 132;
- public static final int NPitEntries = 133;
+ public static final int NfdVersion = 128;
+ public static final int StartTimestamp = 129;
+ public static final int CurrentTimestamp = 130;
+ public static final int NNameTreeEntries = 131;
+ public static final int NFibEntries = 132;
+ public static final int NPitEntries = 133;
public static final int NMeasurementsEntries = 134;
- public static final int NCsEntries = 135;
+ public static final int NCsEntries = 135;
// Face Management
// http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
- public static final int FaceStatus = 128;
- public static final int LocalUri = 129;
- public static final int ChannelStatus = 130;
- public static final int UriScheme = 131;
- public static final int FaceScope = 132;
- public static final int FacePersistency = 133;
- public static final int LinkType = 134;
- public static final int FaceQueryFilter = 150;
+ public static final int FaceStatus = 128;
+ public static final int LocalUri = 129;
+ public static final int ChannelStatus = 130;
+ public static final int UriScheme = 131;
+ public static final int FaceScope = 132;
+ public static final int FacePersistency = 133;
+ public static final int LinkType = 134;
+ public static final int FaceQueryFilter = 150;
public static final int FaceEventNotification = 192;
- public static final int FaceEventKind = 193;
+ public static final int FaceEventKind = 193;
// ForwarderStatus and FaceStatus counters
// http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus
// http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt
- public static final int NInInterests = 144;
- public static final int NInDatas = 145;
- public static final int NInNacks = 151;
+ public static final int NInInterests = 144;
+ public static final int NInDatas = 145;
+ public static final int NInNacks = 151;
public static final int NOutInterests = 146;
- public static final int NOutDatas = 147;
- public static final int NOutNacks = 152;
- public static final int NInBytes = 148;
- public static final int NOutBytes = 149;
+ public static final int NOutDatas = 147;
+ public static final int NOutNacks = 152;
+ public static final int NInBytes = 148;
+ public static final int NOutBytes = 149;
// FIB Management
// http://redmine.named-data.net/projects/nfd/wiki/FibMgmt
- public static final int FibEntry = 128;
+ public static final int FibEntry = 128;
public static final int NextHopRecord = 129;
// Strategy Choice Management
@@ -90,5 +93,5 @@
// RIB Management
// http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
public static final int RibEntry = 128;
- public static final int Route = 129;
+ public static final int Route = 129;
}
diff --git a/src/main/java/com/intel/jndn/management/enums/RouteFlags.java b/src/main/java/com/intel/jndn/management/enums/RouteFlags.java
index 334a726..86c41f6 100644
--- a/src/main/java/com/intel/jndn/management/enums/RouteFlags.java
+++ b/src/main/java/com/intel/jndn/management/enums/RouteFlags.java
@@ -14,22 +14,33 @@
package com.intel.jndn.management.enums;
/**
- * NFD route flags
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RibMgmt</a>
+ * NFD route flags.
+ *
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
public enum RouteFlags {
- NONE (0),
- CHILD_INHERIT (1),
- CAPTURE (2);
+ NONE(0),
+ CHILD_INHERIT(1),
+ CAPTURE(2);
private final int value;
/////////////////////////////////////////////////////////////////////////////
- RouteFlags(int value) {
+ /**
+ * Create enum using NFD's RouteFlags code.
+ *
+ * @param value NFD's RouteFlags code
+ */
+ RouteFlags(final int value) {
this.value = value;
}
+ /**
+ * Convert RouteFlags to the NFD code.
+ *
+ * @return NFD's RouteFlags code
+ */
public final int toInteger() {
return value;
}
diff --git a/src/main/java/com/intel/jndn/management/enums/RouteOrigin.java b/src/main/java/com/intel/jndn/management/enums/RouteOrigin.java
index 6156276..20666c0 100644
--- a/src/main/java/com/intel/jndn/management/enums/RouteOrigin.java
+++ b/src/main/java/com/intel/jndn/management/enums/RouteOrigin.java
@@ -14,47 +14,63 @@
package com.intel.jndn.management.enums;
/**
- * NFD route origin
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RibMgmt</a>
+ * NFD route origin.
+ *
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">RIB Management</a>
*/
public enum RouteOrigin {
- UNKNOWN (-1),
- APP (0),
- AUTOREG (64),
- CLIENT (65),
- AUTOCONF (66),
- NLSR (128),
- STATIC (255);
+ UNKNOWN(-1),
+ APP(0),
+ AUTOREG(64),
+ CLIENT(65),
+ AUTOCONF(66),
+ NLSR(128),
+ STATIC(255);
private final int value;
/////////////////////////////////////////////////////////////////////////////
- RouteOrigin(int value) {
+ /**
+ * Create enum using NFD's RouteOrigin code.
+ *
+ * @param value NFD's RouteOrigin code
+ */
+ RouteOrigin(final int value) {
this.value = value;
}
+ /**
+ * Convert RouteOrigin to the NFD code.
+ *
+ * @return NFD's RouteOrigin code
+ */
public final int toInteger() {
return value;
}
+ /**
+ * Convert NFD code to RouteOrigin enum.
+ *
+ * @param value NFD's RouteOrigin code
+ * @return enum value
+ */
public static RouteOrigin
- fromInteger(int value) {
- switch (value) {
- case 0:
- return APP;
- case 64:
- return AUTOREG;
- case 65:
- return CLIENT;
- case 66:
- return AUTOCONF;
- case 128:
- return NLSR;
- case 255:
- return STATIC;
- default:
- return UNKNOWN;
+ fromInteger(final int value) {
+ if (value == APP.toInteger()) {
+ return APP;
+ } else if (value == AUTOREG.toInteger()) {
+ return AUTOREG;
+ } else if (value == CLIENT.toInteger()) {
+ return CLIENT;
+ } else if (value == AUTOCONF.toInteger()) {
+ return AUTOCONF;
+ } else if (value == NLSR.toInteger()) {
+ return NLSR;
+ } else if (value == STATIC.toInteger()) {
+ return STATIC;
+ } else {
+ return UNKNOWN;
}
}
}
diff --git a/src/main/java/com/intel/jndn/management/enums/Strategies.java b/src/main/java/com/intel/jndn/management/enums/Strategies.java
index f1a9908..bfb1fed 100644
--- a/src/main/java/com/intel/jndn/management/enums/Strategies.java
+++ b/src/main/java/com/intel/jndn/management/enums/Strategies.java
@@ -16,15 +16,20 @@
import net.named_data.jndn.Name;
/**
- * A reference list of the strategies available in NFD; should match
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Strategy">
- * http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Strategy</a>
+ * A reference list of the strategies available in NFD.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice#Strategy">Strategies</a>
*/
-public class Strategies {
+public final class Strategies {
public static final Name BEST_ROUTE = new Name("/localhost/nfd/strategy/best-route");
public static final Name BROADCAST = new Name("/localhost/nfd/strategy/broadcast");
public static final Name CLIENT_CONTROL = new Name("/localhost/nfd/strategy/client-control");
public static final Name NCC = new Name("/localhost/nfd/strategy/ncc");
+
+ /**
+ * Prevent instances of Strategies.
+ */
+ private Strategies() {
+ }
}
diff --git a/src/main/java/com/intel/jndn/management/enums/package-info.java b/src/main/java/com/intel/jndn/management/enums/package-info.java
new file mode 100644
index 0000000..2d340a5
--- /dev/null
+++ b/src/main/java/com/intel/jndn/management/enums/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * NFD constants and enumerations.
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/Management">NFD Management</a>
+ */
+package com.intel.jndn.management.enums;
diff --git a/src/main/java/com/intel/jndn/management/helpers/EncodingHelper.java b/src/main/java/com/intel/jndn/management/helpers/EncodingHelper.java
index 66e2c80..3a59a4a 100644
--- a/src/main/java/com/intel/jndn/management/helpers/EncodingHelper.java
+++ b/src/main/java/com/intel/jndn/management/helpers/EncodingHelper.java
@@ -13,9 +13,6 @@
*/
package com.intel.jndn.management.helpers;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-
import net.named_data.jndn.ControlParameters;
import net.named_data.jndn.ForwardingFlags;
import net.named_data.jndn.Name;
@@ -25,6 +22,9 @@
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
/**
* Provide helper methods to cover areas too protected in Tlv0_1_1WireFormat;
* this class can be deprecated if WireFormats allow passing in an existing
@@ -32,7 +32,13 @@
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
-public class EncodingHelper {
+public final class EncodingHelper {
+
+ /**
+ * Prevent instances of EncodingHelper.
+ */
+ private EncodingHelper() {
+ }
/**
* Helper to decode names since Tlv0_1_1WireFormat.java uses its own internal,
@@ -40,9 +46,9 @@
*
* @param input the bytes to decode
* @return a decoded {@link Name}
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public static Name decodeName(ByteBuffer input) throws EncodingException {
+ public static Name decodeName(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
return decodeName(decoder);
}
@@ -53,9 +59,9 @@
*
* @param decoder a current decoder context to use for decoding
* @return a decoded {@link Name}
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public static Name decodeName(TlvDecoder decoder) throws EncodingException {
+ public static Name decodeName(final TlvDecoder decoder) throws EncodingException {
Name name = new Name();
int endOffset = decoder.readNestedTlvsStart(Tlv.Name);
while (decoder.getOffset() < endOffset) {
@@ -73,7 +79,7 @@
* @param name the {@link Name} to encode
* @return an encoded {@link Blob}
*/
- public static Blob encodeName(Name name) {
+ public static Blob encodeName(final Name name) {
TlvEncoder encoder = new TlvEncoder();
encodeName(name, encoder);
return new Blob(encoder.getOutput(), false);
@@ -83,10 +89,10 @@
* Helper to encode names using an existing encoding context; could be merged
* to Tlv0_1_1WireFormat.java.
*
- * @param name the {@link Name} to encode
+ * @param name the {@link Name} to encode
* @param encoder the current {@link TlvEncoder} context to encode with
*/
- public static final void encodeName(Name name, TlvEncoder encoder) {
+ public static void encodeName(final Name name, final TlvEncoder encoder) {
int saveLength = encoder.getLength();
for (int i = name.size() - 1; i >= 0; --i) {
encoder.writeBlobTlv(Tlv.NameComponent, name.get(i).getValue().buf());
@@ -100,9 +106,9 @@
*
* @param input the bytes to decode
* @return a decoded {@link Name}
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public static Name decodeStrategy(ByteBuffer input) throws EncodingException {
+ public static Name decodeStrategy(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
return decodeStrategy(decoder);
}
@@ -113,9 +119,9 @@
*
* @param decoder the current {@link TlvDecoder} context to decode with
* @return a decoded strategy (e.g. {@link Name})
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public static Name decodeStrategy(TlvDecoder decoder) throws EncodingException {
+ public static Name decodeStrategy(final TlvDecoder decoder) throws EncodingException {
int strategyEndOffset = decoder.readNestedTlvsStart(Tlv.ControlParameters_Strategy);
Name strategy = decodeName(decoder);
decoder.finishNestedTlvs(strategyEndOffset);
@@ -129,7 +135,7 @@
* @param strategy the {@link Name} to encode
* @return an encoded {@link Blob}
*/
- public static Blob encodeStrategy(Name strategy) {
+ public static Blob encodeStrategy(final Name strategy) {
TlvEncoder encoder = new TlvEncoder();
encodeName(strategy, encoder);
return new Blob(encoder.getOutput(), false);
@@ -140,53 +146,52 @@
* merged to Tlv0_1_1WireFormat.java.
*
* @param strategy the {@link Name} to encode
- * @param encoder the current {@link TlvEncoder} context to use
+ * @param encoder the current {@link TlvEncoder} context to use
*/
- public static final void encodeStrategy(Name strategy, TlvEncoder encoder) {
+ public static void encodeStrategy(final Name strategy, final TlvEncoder encoder) {
int strategySaveLength = encoder.getLength();
encodeName(strategy, encoder);
encoder.writeTypeAndLength(Tlv.ControlParameters_Strategy,
- encoder.getLength() - strategySaveLength);
+ encoder.getLength() - strategySaveLength);
}
/**
* Helper to encode control parameters using an existing encoding context;
* could be merged to Tlv0_1_1WireFormat.java.
*
- * @param controlParameters
- * @param encoder
+ * @param controlParameters control parameters
+ * @param encoder TlvEncoder instance
*/
- public static final void encodeControlParameters(ControlParameters controlParameters, TlvEncoder encoder) {
+ public static void encodeControlParameters(final ControlParameters controlParameters, final TlvEncoder encoder) {
int saveLength = encoder.getLength();
// Encode backwards.
encoder.writeOptionalNonNegativeIntegerTlvFromDouble(Tlv.ControlParameters_ExpirationPeriod,
- controlParameters.getExpirationPeriod());
+ controlParameters.getExpirationPeriod());
// Encode strategy
if (controlParameters.getStrategy().size() != 0) {
int strategySaveLength = encoder.getLength();
encodeName(controlParameters.getStrategy(), encoder);
encoder.writeTypeAndLength(Tlv.ControlParameters_Strategy,
- encoder.getLength() - strategySaveLength);
+ encoder.getLength() - strategySaveLength);
}
// Encode ForwardingFlags
int flags = controlParameters.getForwardingFlags().getNfdForwardingFlags();
- if (flags != new ForwardingFlags().getNfdForwardingFlags()) // The flags are not the default value.
- {
+ if (flags != new ForwardingFlags().getNfdForwardingFlags()) { // The flags are not the default value.
encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Flags, flags);
}
encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_Cost, controlParameters.getCost());
encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_Origin, controlParameters.getOrigin());
encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_LocalControlFeature,
- controlParameters.getLocalControlFeature());
+ controlParameters.getLocalControlFeature());
// Encode URI
if (!controlParameters.getUri().isEmpty()) {
encoder.writeBlobTlv(Tlv.ControlParameters_Uri,
- new Blob(controlParameters.getUri()).buf());
+ new Blob(controlParameters.getUri()).buf());
}
encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId, controlParameters.getFaceId());
@@ -200,10 +205,13 @@
}
/**
- * Convert ByteBuffer to string, assuming UTF-8 encoding in the buffer
+ * Convert ByteBuffer to string, assuming UTF-8 encoding in the buffer.
+ *
+ * @param buffer buffer to convert
+ * @return String representation of ByteBuffer (UTF-8 encoding)
*/
public static String
- toString(ByteBuffer buffer) {
+ toString(final ByteBuffer buffer) {
byte[] array = new byte[buffer.remaining()];
buffer.get(array);
return new String(array, Charset.forName("UTF-8"));
diff --git a/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java b/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
index 94e6863..7670771 100644
--- a/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
+++ b/src/main/java/com/intel/jndn/management/helpers/FetchHelper.java
@@ -13,7 +13,12 @@
*/
package com.intel.jndn.management.helpers;
-import net.named_data.jndn.*;
+import net.named_data.jndn.Data;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.Interest;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.OnData;
+import net.named_data.jndn.OnTimeout;
import net.named_data.jndn.encoding.EncodingException;
import java.io.IOException;
@@ -22,10 +27,16 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-public class FetchHelper implements OnData, OnTimeout {
+/**
+ * Trival NDN client to fetch one or multiple Data packets.
+ */
+public final class FetchHelper implements OnData, OnTimeout {
public static final long DEFAULT_TIMEOUT = 2000;
private static final Logger LOG = Logger.getLogger(FetchHelper.class.getName());
+ private static final int SLEEP_TIMEOUT = 20;
+ private static final int SEGMENT_NAME_COMPONENT_OFFSET = -1;
+ private static final int VERSION_NAME_COMPONENT_OFFSET = -2;
private State state;
private Face face;
@@ -33,42 +44,44 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Prevent creation of FetchHelper instances: use getData or getSegmentedData
+ * Prevent creation of FetchHelper instances: use getData or getSegmentedData.
*/
- private FetchHelper()
- {
+ private FetchHelper() {
}
/**
- * Private constructor: use getData or getSegmentedData
+ * Private constructor: use getData or getSegmentedData.
*/
- private FetchHelper(Face face)
- {
+ private FetchHelper(final Face face) {
this.face = face;
}
/**
- * Get a single Data packet
- * @param face Face instance
+ * Get a single Data packet.
+ *
+ * @param face Face instance
* @param interest Interest to retrieve Data
* @return Data packet
* @throws IOException if failed to retrieve packet, e.g., timeout occured
*/
public static Data
- getData(Face face, Interest interest) throws IOException {
+ getData(final Face face, final Interest interest) throws IOException {
FetchHelper fetcher = new FetchHelper(face);
return fetcher.getData(interest);
}
/**
- * Get data using the exact name (without implicit digest)
+ * Get data using the exact name (without implicit digest).
+ * <p/>
+ * TODO: Allow authentication of retrieved data packets
+ *
* @param face Face instance
* @param name Exact name of the data packet to retrieve
- *
- * TODO: Allow authentication of retrieved data packets
+ * @return retrieved Data packet
+ * @throws IOException when communication with NFD fails
*/
public static Data
- getData(Face face, Name name) throws IOException {
+ getData(final Face face, final Name name) throws IOException {
FetchHelper fetcher = new FetchHelper(face);
Interest interest = new Interest(name);
@@ -80,18 +93,21 @@
}
/**
- * Get concatenated data from the segmented
- * @param face Face instance
+ * Get concatenated data from the segmented.
+ * <p/>
+ * Note that this method will first send interest with MustBeFresh selector to discover "latest" version of the
+ * stream and then retrieve the rest of the stream
+ * <p/>
+ * TODO: Allow authentication of retrieved data packets
+ *
+ * @param face Face instance
* @param prefix Prefix of the retrieved data. The retrieved data must have version and segment numbers after this
* prefix
- *
- * Note that this method will first send interest with MustBeFresh selector to discover "latest" version of the
- * stream and then retrieve the rest of the stream
- *
- * TODO: Allow authentication of retrieved data packets
+ * @return list of retrieved Data packets
+ * @throws IOException when communication with NFD fails
*/
public static List<Data>
- getSegmentedData(Face face, Name prefix) throws IOException {
+ getSegmentedData(final Face face, final Name prefix) throws IOException {
FetchHelper fetcher = new FetchHelper(face);
Interest interest = new Interest(new Name(prefix));
@@ -104,9 +120,8 @@
Data data = fetcher.getData(interest);
try {
- data.getName().get(-1).toSegment();
- }
- catch (EncodingException e) {
+ data.getName().get(SEGMENT_NAME_COMPONENT_OFFSET).toSegment();
+ } catch (EncodingException e) {
throw new IOException("Retrieved data does not have segment number as the last name component", e);
}
if (data.getName().size() != prefix.size() + 2) {
@@ -116,15 +131,14 @@
long finalBlockId = 0;
try {
finalBlockId = data.getMetaInfo().getFinalBlockId().toSegment();
- }
- catch (EncodingException e) {
+ } catch (EncodingException e) {
throw new IOException("Requested segmented stream is unbounded", e);
}
List<Data> segments = new ArrayList<>();
segments.add(data);
- prefix.append(data.getName().get(-2));
+ prefix.append(data.getName().get(VERSION_NAME_COMPONENT_OFFSET));
for (int i = 0; i < finalBlockId; i++) {
interest = new Interest(new Name(prefix).appendSegment(i));
interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
@@ -140,7 +154,7 @@
/////////////////////////////////////////////////////////////////////////////
- private Data getData(Interest interest) throws IOException {
+ private Data getData(final Interest interest) throws IOException {
this.state = new State();
this.face.expressInterest(interest, this, this);
@@ -151,7 +165,7 @@
LOG.log(Level.INFO, "Decoding error: " + e.getMessage(), e);
}
try {
- Thread.sleep(20);
+ Thread.sleep(SLEEP_TIMEOUT);
} catch (InterruptedException e) {
// ok
}
@@ -165,13 +179,13 @@
}
@Override
- public void onData(Interest interest, Data data) {
+ public void onData(final Interest interest, final Data data) {
state.response = data;
state.isDone = true;
}
@Override
- public void onTimeout(Interest interest) {
+ public void onTimeout(final Interest interest) {
state.nRetries--;
if (state.nRetries > 0) {
try {
@@ -179,8 +193,7 @@
} catch (IOException e) {
LOG.log(Level.INFO, "Error while expressing interest: " + e.toString(), e);
}
- }
- else {
+ } else {
state.isDone = true;
}
}
@@ -188,8 +201,10 @@
/////////////////////////////////////////////////////////////////////////////
private static class State {
- public int nRetries = 3;
- public Data response = null;
- public boolean isDone = false;
+ private static final int DEFAULT_NUMBER_OF_RETRIES = 3;
+
+ private int nRetries = DEFAULT_NUMBER_OF_RETRIES;
+ private Data response = null;
+ private boolean isDone = false;
}
}
diff --git a/src/main/java/com/intel/jndn/management/helpers/StatusDatasetHelper.java b/src/main/java/com/intel/jndn/management/helpers/StatusDatasetHelper.java
index 0db8341..863d918 100644
--- a/src/main/java/com/intel/jndn/management/helpers/StatusDatasetHelper.java
+++ b/src/main/java/com/intel/jndn/management/helpers/StatusDatasetHelper.java
@@ -15,32 +15,36 @@
import com.intel.jndn.management.ManagementException;
import com.intel.jndn.management.types.Decodable;
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
import net.named_data.jndn.Data;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
/**
- * Helper class to handle StatusDatasets, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
+ * Helper class to handle StatusDatasets.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">StatusDataset</a>
*/
-public class StatusDatasetHelper {
-
+public final class StatusDatasetHelper {
/**
- * Prevent instances of StatusDatasetHelper
+ * Prevent instances of StatusDatasetHelper.
*/
private StatusDatasetHelper() {
}
+ /**
+ * Combine payload of Data packet segments into a single buffer.
+ *
+ * @param segments list of Data packets
+ * @return single buffer containing combined payload
+ */
public static ByteBuffer
- combine(List<Data> segments) {
+ combine(final List<Data> segments) {
int size = 0;
for (Data segment : segments) {
size += segment.getContent().size();
@@ -55,11 +59,17 @@
}
/**
- * Decode multiple status entries as part of a StatusDatasetHelper, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
+ * Decode multiple status entries as part of a StatusDatasetHelper.
+ *
+ * @param <T> Class implementing Decodable interface
+ * @param segments list of Data packets
+ * @param type class implementing Decodable interface
+ * @return List decoded status entries
+ * @throws ManagementException when decoding fails
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">StatusDataset</a>
*/
- public static final <T extends Decodable> List<T>
- wireDecode(List<Data> segments, Class<T> type) throws ManagementException {
+ public static <T extends Decodable> List<T>
+ wireDecode(final List<Data> segments, final Class<T> type) throws ManagementException {
Blob payload = new Blob(combine(segments), false);
List<T> entries = new ArrayList<>();
@@ -70,7 +80,7 @@
T entry = type.newInstance();
entry.wireDecode(decoder);
entries.add(entry);
- } catch (IllegalAccessException|InstantiationException|EncodingException e) {
+ } catch (IllegalAccessException | InstantiationException | EncodingException e) {
throw new ManagementException("Failed to read status dataset.", e);
}
}
diff --git a/src/main/java/com/intel/jndn/management/helpers/package-info.java b/src/main/java/com/intel/jndn/management/helpers/package-info.java
new file mode 100644
index 0000000..fcfcb02
--- /dev/null
+++ b/src/main/java/com/intel/jndn/management/helpers/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Various helpers.
+ */
+package com.intel.jndn.management.helpers;
diff --git a/src/main/java/com/intel/jndn/management/package-info.java b/src/main/java/com/intel/jndn/management/package-info.java
new file mode 100644
index 0000000..79be44a
--- /dev/null
+++ b/src/main/java/com/intel/jndn/management/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Classes implementing NFD management protocol.
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/Management">NFD Management</a>
+ */
+package com.intel.jndn.management;
diff --git a/src/main/java/com/intel/jndn/management/types/Decodable.java b/src/main/java/com/intel/jndn/management/types/Decodable.java
index 05797aa..7d5ae11 100644
--- a/src/main/java/com/intel/jndn/management/types/Decodable.java
+++ b/src/main/java/com/intel/jndn/management/types/Decodable.java
@@ -23,5 +23,11 @@
* @author Andrew Brown <andrew.brown@intel.com>
*/
public interface Decodable {
- void wireDecode(TlvDecoder decoder) throws EncodingException;
+ /**
+ * Decode data structure from TLV wire format.
+ *
+ * @param decoder Instance of TlvDecoder
+ * @throws EncodingException when decoding fails
+ */
+ void wireDecode(final TlvDecoder decoder) throws EncodingException;
}
diff --git a/src/main/java/com/intel/jndn/management/types/FaceStatus.java b/src/main/java/com/intel/jndn/management/types/FaceStatus.java
index abceaca..d7550cc 100644
--- a/src/main/java/com/intel/jndn/management/types/FaceStatus.java
+++ b/src/main/java/com/intel/jndn/management/types/FaceStatus.java
@@ -13,22 +13,23 @@
*/
package com.intel.jndn.management.types;
-import java.nio.ByteBuffer;
-import com.intel.jndn.management.enums.NfdTlv;
import com.intel.jndn.management.enums.FacePersistency;
import com.intel.jndn.management.enums.FaceScope;
import com.intel.jndn.management.enums.LinkType;
+import com.intel.jndn.management.enums.NfdTlv;
import com.intel.jndn.management.helpers.EncodingHelper;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+
/**
- * Represent a FaceStatus object from /localhost/nfd/faces/list
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">Face Management</a>
+ * Represent a FaceStatus object from /localhost/nfd/faces/list.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">Face Management</a>
*/
public class FaceStatus implements Decodable {
private int faceId = 0;
@@ -53,25 +54,26 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public FaceStatus() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public FaceStatus(ByteBuffer input) throws EncodingException {
+ public FaceStatus(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
/**
* Encode using a new TLV encoder.
*
- * @return The encoded buffer.
+ * @return The encoded buffer
*/
public final Blob wireEncode() {
TlvEncoder encoder = new TlvEncoder();
@@ -80,9 +82,11 @@
}
/**
- * Encode as part of an existing encode context
+ * Encode as part of an existing encode context.
+ *
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
encoder.writeNonNegativeIntegerTlv(NfdTlv.NOutBytes, outBytes);
encoder.writeNonNegativeIntegerTlv(NfdTlv.NInBytes, inBytes);
@@ -112,18 +116,18 @@
*
* @param input The input buffer to decode. This reads from position() to
* limit(), but does not change the position.
- * @throws net.named_data.jndn.encoding.EncodingException
+ * @throws EncodingException when decoding fails
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context
+ * {@inheritDoc}
*/
@Override
- public void wireDecode(TlvDecoder decoder) throws EncodingException {
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.FaceStatus);
// parse
this.faceId = (int) decoder.readNonNegativeIntegerTlv(NfdTlv.FaceId);
@@ -151,234 +155,279 @@
}
/**
- * Get face ID
+ * @return face ID
*/
public int getFaceId() {
return faceId;
}
/**
- * Set face ID
+ * Set face ID.
+ *
+ * @param faceId face ID
+ * @return this
*/
- public FaceStatus setFaceId(int faceId) {
+ public FaceStatus setFaceId(final int faceId) {
this.faceId = faceId;
return this;
}
/**
- * Get face ID
+ * @return remote face URI
*/
public String getRemoteUri() {
return remoteUri;
}
/**
- * Set URI
+ * Set remote face URI.
+ *
+ * @param uri remote face URI
+ * @return this
*/
- public FaceStatus setRemoteUri(String uri) {
+ public FaceStatus setRemoteUri(final String uri) {
this.remoteUri = uri;
return this;
}
/**
- * Get face ID
+ * @return remote face URI
*/
public String getLocalUri() {
return localUri;
}
/**
- * Set local URI
+ * Set local face URI.
+ *
+ * @param localUri local face URI
+ * @return this
*/
- public FaceStatus setLocalUri(String localUri) {
+ public FaceStatus setLocalUri(final String localUri) {
this.localUri = localUri;
return this;
}
/**
- * Check if Face has expiration period set
+ * Check if Face has expiration period set.
+ * @return true if Face has expiration period set, false otherwise
*/
public boolean hasExpirationPeriod() {
return expirationPeriod > 0;
}
/**
- * Get expiration period
+ * @return expiration period
*/
public int getExpirationPeriod() {
return expirationPeriod;
}
/**
- * Set expiration period
+ * Set expiration period.
+ *
+ * @param expirationPeriod expiration period
+ * @return this
*/
- public FaceStatus setExpirationPeriod(int expirationPeriod) {
+ public FaceStatus setExpirationPeriod(final int expirationPeriod) {
this.expirationPeriod = expirationPeriod;
return this;
}
/**
- * Get face scope value
+ * @return face scope
*/
public FaceScope getFaceScope() {
return faceScope;
}
/**
- * Set face scope value
+ * Set face scope value.
+ *
+ * @param faceScope face scope
+ * @return this
*/
- public FaceStatus setFaceScope(FaceScope faceScope) {
+ public FaceStatus setFaceScope(final FaceScope faceScope) {
this.faceScope = faceScope;
return this;
}
/**
- * Get face persistency value
+ * @return face persistency
*/
public FacePersistency getFacePersistency() {
return facePersistency;
}
/**
- * Set face persistency value
+ * Set face persistency.
+ *
+ * @param facePersistency face persistency
+ * @return this
*/
- public FaceStatus setFacePersistency(FacePersistency facePersistency) {
+ public FaceStatus setFacePersistency(final FacePersistency facePersistency) {
this.facePersistency = facePersistency;
return this;
}
/**
- * Get link type
+ * @return link type
*/
public LinkType getLinkType() {
return linkType;
}
/**
- * Set link type
+ * Set link type.
+ *
+ * @param linkType link type
+ * @return this
*/
- public FaceStatus setLinkType(LinkType linkType) {
+ public FaceStatus setLinkType(final LinkType linkType) {
this.linkType = linkType;
return this;
}
/**
- * Get number of received Interest packets
+ * @return number of received Interest packets
*/
public int getNInInterests() {
return inInterests;
}
/**
- * Set number of received Interest packets
+ * Set number of received Interest packets.
+ *
+ * @param inInterests number of received Interest packets
+ * @return this
*/
- public FaceStatus setNInInterests(int inInterests) {
+ public FaceStatus setNInInterests(final int inInterests) {
this.inInterests = inInterests;
return this;
}
/**
- * Get number of sent Interest packets
+ * @return number of sent Interest packets
*/
public int getNOutInterests() {
return outInterests;
}
/**
- * Set number of sent Interest packets
+ * Set number of sent Interest packets.
+ *
+ * @param outInterests number of sent Interest packets
+ * @return this
*/
- public FaceStatus setNOutInterests(int outInterests) {
+ public FaceStatus setNOutInterests(final int outInterests) {
this.outInterests = outInterests;
return this;
}
/**
- * Get number of received Data packets
+ * @return number of received Data packets
*/
public int getNInDatas() {
return inDatas;
}
/**
- * Set number of received Data packets
+ * Set number of received Data packets.
+ *
+ * @param inDatas number of received Data packets
+ * @return this
*/
- public FaceStatus setNInDatas(int inDatas) {
+ public FaceStatus setNInDatas(final int inDatas) {
this.inDatas = inDatas;
return this;
}
/**
- * Get number of sent Data packets
+ * @return number of sent Data packets
*/
public int getNOutDatas() {
return outDatas;
}
/**
- * Set number of sent Data packets
+ * Set number of sent Data packets.
+ *
+ * @param outDatas number of sent Data packets
+ * @return this
*/
- public FaceStatus setNOutDatas(int outDatas) {
+ public FaceStatus setNOutDatas(final int outDatas) {
this.outDatas = outDatas;
return this;
}
/**
- * Get number of received Data packets
+ * @return number of received Data packets
*/
public int getNInNacks() {
return inNacks;
}
/**
- * Set number of received Data packets
+ * Set number of received Data packets.
+ *
+ * @param inNacks number of received Data packets
+ * @return this
*/
- public FaceStatus setNInNacks(int inNacks) {
+ public FaceStatus setNInNacks(final int inNacks) {
this.inNacks = inNacks;
return this;
}
/**
- * Get number of sent Data packets
+ * @return number of sent Data packets
*/
public int getNOutNacks() {
return outNacks;
}
/**
- * Set number of sent Data packets
+ * Set number of sent Data packets.
+ *
+ * @param outNacks number of sent Data packets
+ * @return this
*/
- public FaceStatus setNOutNacks(int outNacks) {
+ public FaceStatus setNOutNacks(final int outNacks) {
this.outNacks = outNacks;
return this;
}
-
/**
- * Get number of input bytes
+ * @return number of input bytes
*/
public int getNInBytes() {
return inBytes;
}
/**
- * Set number of input bytes
+ * Set number of input bytes.
+ *
+ * @param inBytes number of input bytes
+ * @return this
*/
- public FaceStatus setNInBytes(int inBytes) {
+ public FaceStatus setNInBytes(final int inBytes) {
this.inBytes = inBytes;
return this;
}
/**
- * Get number of output bytes
+ * @return number of output bytes
*/
public int getNOutBytes() {
return outBytes;
}
/**
- * Set number of output bytes
+ * Set number of output bytes.
+ *
+ * @param outBytes number of output bytes
+ * @return this
*/
- public FaceStatus setNOutBytes(int outBytes) {
+ public FaceStatus setNOutBytes(final int outBytes) {
this.outBytes = outBytes;
return this;
}
diff --git a/src/main/java/com/intel/jndn/management/types/FibEntry.java b/src/main/java/com/intel/jndn/management/types/FibEntry.java
index e30e9a9..f43cbf5 100644
--- a/src/main/java/com/intel/jndn/management/types/FibEntry.java
+++ b/src/main/java/com/intel/jndn/management/types/FibEntry.java
@@ -13,24 +13,24 @@
*/
package com.intel.jndn.management.types;
-import com.intel.jndn.management.helpers.EncodingHelper;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
import com.intel.jndn.management.enums.NfdTlv;
+import com.intel.jndn.management.helpers.EncodingHelper;
import net.named_data.jndn.Name;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
/**
- * Represent a FibEntry returned from /localhost/nfd/fib/list
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
+ * Represent a FibEntry returned from /localhost/nfd/fib/list.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
*/
public class FibEntry implements Decodable {
private Name name = new Name();
@@ -39,18 +39,19 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public FibEntry() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public FibEntry(ByteBuffer input) throws EncodingException {
+ public FibEntry(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
@@ -66,9 +67,11 @@
}
/**
- * Encode as part of an existing encode context
+ * Encode as part of an existing encode context.
+ *
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
ListIterator<NextHopRecord> nh = records.listIterator(records.size());
while (nh.hasPrevious()) {
@@ -85,16 +88,16 @@
* limit(), but does not change the position.
* @throws EncodingException For invalid encoding.
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context
+ * {@inheritDoc}
*/
@Override
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.FibEntry);
name = EncodingHelper.decodeName(decoder);
while (decoder.getOffset() < endOffset) {
@@ -106,36 +109,48 @@
}
/**
- * Get name
+ * @return FIB entry name
*/
public Name getPrefix() {
return name;
}
/**
- * Set name
+ * Set FIB entry name.
+ *
+ * @param name New name for the FIB entry
+ * @return this
*/
- public FibEntry setPrefix(Name name) {
+ public FibEntry setPrefix(final Name name) {
this.name = name;
return this;
}
/**
- * Get records
+ * @return List of NextHop records.
*/
public List<NextHopRecord> getNextHopRecords() {
return records;
}
/**
- * Set records
+ * Set NextHop records.
+ *
+ * @param records List of NextHop records. Previously associated records will be replaced.
+ * @return this
*/
- public FibEntry setNextHopRecords(List<NextHopRecord> records) {
+ public FibEntry setNextHopRecords(final List<NextHopRecord> records) {
this.records = records;
return this;
}
- public FibEntry addNextHopRecord(NextHopRecord record) {
+ /**
+ * Add NextHop records.
+ *
+ * @param record NextHopRecord instance
+ * @return this
+ */
+ public FibEntry addNextHopRecord(final NextHopRecord record) {
this.records.add(record);
return this;
}
diff --git a/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java b/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java
index 7ad4712..d0854d7 100644
--- a/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java
+++ b/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java
@@ -13,19 +13,19 @@
*/
package com.intel.jndn.management.types;
-import java.nio.ByteBuffer;
-
import com.intel.jndn.management.enums.NfdTlv;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+
/**
- * Represent a ForwarderStatus object
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus">ForwarderStatus</a>
+ * Represent a ForwarderStatus object.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus">ForwarderStatus</a>
*/
public class ForwarderStatus implements Decodable {
private String nfdVersion = "";
@@ -46,18 +46,19 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public ForwarderStatus() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public ForwarderStatus(ByteBuffer input) throws EncodingException {
+ public ForwarderStatus(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
@@ -74,8 +75,10 @@
/**
* Encode as part of an existing encode context.
+ *
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
encoder.writeNonNegativeIntegerTlv(NfdTlv.NOutNacks, nOutNacks);
encoder.writeNonNegativeIntegerTlv(NfdTlv.NOutDatas, nOutDatas);
encoder.writeNonNegativeIntegerTlv(NfdTlv.NOutInterests, nOutInterests);
@@ -96,19 +99,19 @@
* Decode the input from its TLV format.
*
* @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
+ * limit(), but does not change the position.
* @throws EncodingException For invalid encoding.
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context
+ * {@inheritDoc}
*/
@Override
- public void wireDecode(TlvDecoder decoder) throws EncodingException {
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
this.nfdVersion = new Blob(decoder.readBlobTlv(NfdTlv.NfdVersion), true).toString();
this.startTimestamp = decoder.readNonNegativeIntegerTlv(NfdTlv.StartTimestamp);
this.currentTimestamp = decoder.readNonNegativeIntegerTlv(NfdTlv.CurrentTimestamp);
@@ -125,115 +128,255 @@
this.nOutNacks = decoder.readNonNegativeIntegerTlv(NfdTlv.NOutNacks);
}
+ /**
+ * @return NFD version string
+ */
public String getNfdVersion() {
return nfdVersion;
}
- public void setNfdVersion(String nfdVersion) {
+ /**
+ * Set NFD version string.
+ *
+ * @param nfdVersion NFD version string
+ * @return this
+ */
+ public ForwarderStatus setNfdVersion(final String nfdVersion) {
this.nfdVersion = nfdVersion;
+ return this;
}
+ /**
+ * @return NFD start timestamp (number of seconds since January 1, 1970)
+ */
public long getStartTimestamp() {
return startTimestamp;
}
- public void setStartTimestamp(long startTimestamp) {
+ /**
+ * Set NFD start timestamp (number of seconds since January 1, 1970).
+ *
+ * @param startTimestamp NFD start timestamp (number of seconds since January 1, 1970)
+ * @return this
+ */
+ public ForwarderStatus setStartTimestamp(final long startTimestamp) {
this.startTimestamp = startTimestamp;
+ return this;
}
+ /**
+ * @return NFD current timestamp (number of seconds since January 1, 1970)
+ */
public long getCurrentTimestamp() {
return currentTimestamp;
}
- public void setCurrentTimestamp(long currentTimestamp) {
+ /**
+ * Set NFD current timestamp (number of seconds since January 1, 1970).
+ *
+ * @param currentTimestamp NFD current timestamp (number of seconds since January 1, 1970)
+ * @return this
+ */
+ public ForwarderStatus setCurrentTimestamp(final long currentTimestamp) {
this.currentTimestamp = currentTimestamp;
+ return this;
}
+ /**
+ * @return Number of NameTree entries
+ */
public long getNNameTreeEntries() {
return nNameTreeEntries;
}
- public void setNNameTreeEntries(long nNameTreeEntries) {
+ /**
+ * Set the number of NameTree entries.
+ *
+ * @param nNameTreeEntries the number of NameTree entries.
+ * @return this
+ */
+ public ForwarderStatus setNNameTreeEntries(final long nNameTreeEntries) {
this.nNameTreeEntries = nNameTreeEntries;
+ return this;
}
+ /**
+ * @return Number of FIB entries
+ */
public long getNFibEntries() {
return nFibEntries;
}
- public void setNFibEntries(long nFibEntries) {
+ /**
+ * Set the number of FIB entries.
+ *
+ * @param nFibEntries the number of FIB entries.
+ * @return this
+ */
+ public ForwarderStatus setNFibEntries(final long nFibEntries) {
this.nFibEntries = nFibEntries;
+ return this;
}
+ /**
+ * @return Number of PIT entries
+ */
public long getNPitEntries() {
return nPitEntries;
}
- public void setNPitEntries(long nPitEntries) {
+ /**
+ * Set the number of PIT entries.
+ *
+ * @param nPitEntries the number of PIT entries.
+ * @return this
+ */
+ public ForwarderStatus setNPitEntries(final long nPitEntries) {
this.nPitEntries = nPitEntries;
+ return this;
}
+ /**
+ * @return Number of Measurement entries
+ */
public long getNMeasurementsEntries() {
return nMeasurementEntries;
}
- public void setNMeasurementsEntries(long nMeasurementEntries) {
+ /**
+ * Set the number of Measurement entries.
+ *
+ * @param nMeasurementEntries the number of Measurement entries.
+ * @return this
+ */
+ public ForwarderStatus setNMeasurementsEntries(final long nMeasurementEntries) {
this.nMeasurementEntries = nMeasurementEntries;
+ return this;
}
+ /**
+ * @return Number of CS entries
+ */
public long getNCsEntries() {
return nCsEntries;
}
- public void setNCsEntries(long nCsEntries) {
+ /**
+ * Set the number of CS entries.
+ *
+ * @param nCsEntries the number of CS entries.
+ * @return this
+ */
+ public ForwarderStatus setNCsEntries(final long nCsEntries) {
this.nCsEntries = nCsEntries;
+ return this;
}
+ /**
+ * @return The number of incoming Interests since NFD start
+ */
public long getNInInterests() {
return nInInterests;
}
- public void setNInInterests(long nInInterests) {
+ /**
+ * Set the number of incoming Interests since NFD start.
+ *
+ * @param nInInterests the number of incoming Interests since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNInInterests(final long nInInterests) {
this.nInInterests = nInInterests;
+ return this;
}
+ /**
+ * @return Number of incoming Data since NFD start
+ */
public long getNInDatas() {
return nInDatas;
}
- public void setNInDatas(long nInDatas) {
+ /**
+ * Set the number of incoming Data since NFD start.
+ *
+ * @param nInDatas the number of incoming Interests since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNInDatas(final long nInDatas) {
this.nInDatas = nInDatas;
+ return this;
}
+ /**
+ * @return Number of outgoing Interests since NFD start
+ */
public long getNOutInterests() {
return nOutInterests;
}
- public void setNOutInterests(long nOutInterests) {
+ /**
+ * Set the number of outgoing Interests since NFD start.
+ *
+ * @param nOutInterests the number of outgoing Interests since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNOutInterests(final long nOutInterests) {
this.nOutInterests = nOutInterests;
+ return this;
}
+ /**
+ * @return Number of outgoing Data since NFD start
+ */
public long getNOutDatas() {
return nOutDatas;
}
- public void setNOutDatas(long nOutDatas) {
+ /**
+ * Set the number of outgoing Data since NFD start.
+ *
+ * @param nOutDatas the number of outgoing Data since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNOutDatas(final long nOutDatas) {
this.nOutDatas = nOutDatas;
+ return this;
}
+ /**
+ * @return Number of incoming NACKs since NFD start
+ */
public long getNInNacks() {
return nInNacks;
}
- public void setNInNacks(long nInNacks) {
+ /**
+ * Set the number of incoming NACKs since NFD start.
+ *
+ * @param nInNacks the number of incoming NACKs since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNInNacks(final long nInNacks) {
this.nInNacks = nInNacks;
+ return this;
}
+ /**
+ * @return Number of outgoing NACKs since NFD start
+ */
public long getNOutNacks() {
return nOutNacks;
}
- public void setNOutNacks(long nOutNacks) {
+ /**
+ * Set the number of outgoing NACKs since NFD start.
+ *
+ * @param nOutNacks the number of outgoing NACKs since NFD start
+ * @return this
+ */
+ public ForwarderStatus setNOutNacks(final long nOutNacks) {
this.nOutNacks = nOutNacks;
+ return this;
}
}
diff --git a/src/main/java/com/intel/jndn/management/types/NextHopRecord.java b/src/main/java/com/intel/jndn/management/types/NextHopRecord.java
index 84756e5..8c75edc 100644
--- a/src/main/java/com/intel/jndn/management/types/NextHopRecord.java
+++ b/src/main/java/com/intel/jndn/management/types/NextHopRecord.java
@@ -13,8 +13,6 @@
*/
package com.intel.jndn.management.types;
-import java.nio.ByteBuffer;
-
import com.intel.jndn.management.enums.NfdTlv;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.Tlv;
@@ -22,36 +20,39 @@
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+
/**
- * Represent a NextHopRecord in a FibEntry
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
+ * Represent a NextHopRecord in a FibEntry.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">FIB Dataset</a>
*/
-public class NextHopRecord {
+public class NextHopRecord implements Decodable {
private int faceId;
private int cost;
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public NextHopRecord() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public NextHopRecord(ByteBuffer input) throws EncodingException {
+ public NextHopRecord(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
/**
- * Encode using a new TLV encoder
+ * Encode using a new TLV encoder.
*
* @return The encoded buffer
*/
@@ -62,9 +63,11 @@
}
/**
- * Encode as part of an existing encode context
+ * Encode as part of an existing encode context.
+ *
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Cost, cost);
encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId, faceId);
@@ -75,18 +78,19 @@
* Decode the input from its TLV format.
*
* @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
+ * limit(), but does not change the position.
* @throws EncodingException For invalid encoding.
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context
+ * {@inheritDoc}
*/
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
+ @Override
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.NextHopRecord);
this.faceId = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId);
this.cost = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Cost);
@@ -94,30 +98,38 @@
}
/**
- * Get face ID
+ * @return face ID
*/
public int getFaceId() {
return faceId;
}
/**
- * Set face ID
+ * Set face ID.
+ *
+ * @param faceId face ID
+ * @return this
*/
- public void setFaceId(int faceId) {
+ public NextHopRecord setFaceId(final int faceId) {
this.faceId = faceId;
+ return this;
}
/**
- * Get cost
+ * @return next hop record cost
*/
public int getCost() {
return cost;
}
/**
- * Set cost
+ * Set next hop record cost.
+ *
+ * @param cost next hop record cost
+ * @return this
*/
- public void setCost(int cost) {
+ public NextHopRecord setCost(final int cost) {
this.cost = cost;
+ return this;
}
}
diff --git a/src/main/java/com/intel/jndn/management/types/RibEntry.java b/src/main/java/com/intel/jndn/management/types/RibEntry.java
index a5c0380..2608198 100644
--- a/src/main/java/com/intel/jndn/management/types/RibEntry.java
+++ b/src/main/java/com/intel/jndn/management/types/RibEntry.java
@@ -15,40 +15,41 @@
import com.intel.jndn.management.enums.NfdTlv;
import com.intel.jndn.management.helpers.EncodingHelper;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
import net.named_data.jndn.Name;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
/**
- * Represent a entry in the RIB
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
+ * Represent a entry in the RIB.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
*/
public class RibEntry implements Decodable {
private Name name = new Name();
private List<Route> routes = new ArrayList<>();
/**
- * Default constructor
+ * Default constructor.
*/
public RibEntry() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public RibEntry(ByteBuffer input) throws EncodingException {
+ public RibEntry(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
@@ -65,8 +66,10 @@
/**
* Encode as part of an existing encode context.
+ *
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
ListIterator<Route> route = routes.listIterator(routes.size());
while (route.hasPrevious()) {
@@ -80,19 +83,19 @@
* Decode the input from its TLV format.
*
* @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
+ * limit(), but does not change the position.
* @throws EncodingException For invalid encoding.
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context.
+ * {@inheritDoc}
*/
@Override
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.RibEntry);
name = EncodingHelper.decodeName(decoder);
while (decoder.getOffset() < endOffset) {
@@ -104,50 +107,59 @@
}
/**
- * Get name
+ * @return RIB entry name.
*/
public Name getName() {
return name;
}
/**
- * Set name
+ * Set RIB entry name.
+ *
+ * @param name New name for the RIB entry
+ * @return this
*/
- public void setName(Name name) {
+ public RibEntry setName(final Name name) {
this.name = name;
+ return this;
}
/**
- * Get routes
+ * @return List of associated routes to the RIB entry
*/
public List<Route> getRoutes() {
return routes;
}
/**
- * Add route
+ * Add route.
+ *
+ * @param route Route to add to the RIB entry
+ * @return this
*/
- public RibEntry addRoute(Route route) {
+ public RibEntry addRoute(final Route route) {
getRoutes().add(route);
return this;
}
/**
- * Clear all routes
+ * Clear all routes.
*/
public void clearRoutes() {
getRoutes().clear();
}
/**
- * Set routes
+ * Set routes.
+ *
+ * @param routes List of routes to associate with RIB entry. Will replace previously associated routes.
*/
- public void setRoutes(List<Route> routes) {
+ public void setRoutes(final List<Route> routes) {
this.routes = routes;
}
/**
- * Get human-readable representation of RibEntry
+ * @return Human-readable representation of RibEntry
*/
@Override
public String toString() {
diff --git a/src/main/java/com/intel/jndn/management/types/Route.java b/src/main/java/com/intel/jndn/management/types/Route.java
index 0b9acb4..b134a6f 100644
--- a/src/main/java/com/intel/jndn/management/types/Route.java
+++ b/src/main/java/com/intel/jndn/management/types/Route.java
@@ -13,8 +13,6 @@
*/
package com.intel.jndn.management.types;
-import java.nio.ByteBuffer;
-
import com.intel.jndn.management.enums.NfdTlv;
import com.intel.jndn.management.enums.RouteFlags;
import net.named_data.jndn.encoding.EncodingException;
@@ -22,13 +20,15 @@
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+
/**
- * Represent a Route object from /localhost/nfd/rib/list
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
+ * Represent a Route object from /localhost/nfd/rib/list.
*
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">RIB Dataset</a>
*/
-public class Route {
+public class Route implements Decodable {
public static final int INFINITE_EXPIRATION_PERIOD = -1;
private int faceId = -1;
@@ -40,18 +40,19 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public Route() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public Route(ByteBuffer input) throws EncodingException {
+ public Route(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
@@ -69,9 +70,9 @@
/**
* Encode as part of an existing encode context.
*
- * @param encoder
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
encoder.writeOptionalNonNegativeIntegerTlv(NfdTlv.ExpirationPeriod, expirationPeriod);
encoder.writeNonNegativeIntegerTlv(NfdTlv.Flags, flags);
@@ -86,20 +87,18 @@
*
* @param input The input buffer to decode. This reads from position() to
* limit(), but does not change the position.
- * @throws net.named_data.jndn.encoding.EncodingException
+ * @throws EncodingException when decoding fails
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
+ * {@inheritDoc}
*/
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
+ @Override
+ public final void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.Route);
this.faceId = (int) decoder.readNonNegativeIntegerTlv(NfdTlv.FaceId);
this.origin = (int) decoder.readNonNegativeIntegerTlv(NfdTlv.Origin);
@@ -110,103 +109,144 @@
}
/**
- * Get Face ID
+ * Get Face ID.
+ *
+ * @return Face ID
*/
public int getFaceId() {
return faceId;
}
/**
- * Set Face ID
+ * Set Face ID.
+ *
+ * @param faceId Face ID
+ * @return this
*/
- public Route setFaceId(int faceId) {
+ public Route setFaceId(final int faceId) {
this.faceId = faceId;
return this;
}
/**
- * Get origin
+ * Get route origin.
+ *
+ * @return origin code
+ * @see com.intel.jndn.management.enums.RouteOrigin
*/
public int getOrigin() {
return origin;
}
/**
- * Set origin
+ * Set route origin.
+ *
+ * @param origin Route origin code
+ * @return this
+ * @see com.intel.jndn.management.enums.RouteOrigin
*/
- public Route setOrigin(int origin) {
+ public Route setOrigin(final int origin) {
this.origin = origin;
return this;
}
/**
- * Get cost
+ * Get route cost.
+ *
+ * @return route cost
*/
public int getCost() {
return cost;
}
/**
- * Set cost
+ * Set cost.
+ *
+ * @param cost Route cost
+ * @return this
*/
- public Route setCost(int cost) {
+ public Route setCost(final int cost) {
this.cost = cost;
return this;
}
/**
- * Get flags
+ * Get flags.
+ *
+ * @return route flags
*/
public int getFlags() {
return flags;
}
/**
- * Set flags
+ * Set flags.
+ *
+ * @param flags NFD Route flags
+ * @return this
+ * @see RouteFlags
*/
- public void setFlags(int flags) {
+ public Route setFlags(final int flags) {
this.flags = flags;
+ return this;
}
/**
- * Get expiration period (in milliseconds)
+ * Get expiration period (in milliseconds).
+ *
+ * @return expiration period (in milliseconds)
*/
public int getExpirationPeriod() {
return expirationPeriod;
}
/**
- * Check if route should not expire
+ * Check if route should not expire.
+ *
+ * @return true if route has associated expiration period, false otherwise
*/
public boolean hasInfiniteExpirationPeriod() {
return expirationPeriod < 0;
}
/**
- * Set expiration period
+ * Set expiration period.
*
- * @param expirationPeriod
+ * @param expirationPeriod Expiration period in milliseconds
+ * @return this
*/
- public void setExpirationPeriod(int expirationPeriod) {
+ public Route setExpirationPeriod(final int expirationPeriod) {
this.expirationPeriod = expirationPeriod;
+ return this;
}
/**
- * Get human-readable representation of Route
+ * Get a human-readable representation of the Route.
+ *
+ * @return Human-readable representation of the Route
*/
@Override
public String toString() {
StringBuilder out = new StringBuilder();
out.append("Route(");
- out.append("FaceId: "); out.append(getFaceId()); out.append(", ");
- out.append("Origin: "); out.append(getOrigin()); out.append(", ");
- out.append("Cost: "); out.append(getCost()); out.append(", ");
- out.append("Flags: "); out.append(getFlags()); out.append(", ");
+ out.append("FaceId: ");
+ out.append(getFaceId());
+ out.append(", ");
+ out.append("Origin: ");
+ out.append(getOrigin());
+ out.append(", ");
+ out.append("Cost: ");
+ out.append(getCost());
+ out.append(", ");
+ out.append("Flags: ");
+ out.append(getFlags());
+ out.append(", ");
if (!hasInfiniteExpirationPeriod()) {
- out.append("ExpirationPeriod: "); out.append(getExpirationPeriod()); out.append(" milliseconds");
- }
- else {
+ out.append("ExpirationPeriod: ");
+ out.append(getExpirationPeriod());
+ out.append(" milliseconds");
+ } else {
out.append("ExpirationPeriod: Infinity");
}
out.append(")");
diff --git a/src/main/java/com/intel/jndn/management/types/StrategyChoice.java b/src/main/java/com/intel/jndn/management/types/StrategyChoice.java
index 7e092b2..7c1f8a4 100644
--- a/src/main/java/com/intel/jndn/management/types/StrategyChoice.java
+++ b/src/main/java/com/intel/jndn/management/types/StrategyChoice.java
@@ -13,21 +13,21 @@
*/
package com.intel.jndn.management.types;
-import com.intel.jndn.management.helpers.EncodingHelper;
-import java.nio.ByteBuffer;
-
import com.intel.jndn.management.enums.NfdTlv;
+import com.intel.jndn.management.helpers.EncodingHelper;
import net.named_data.jndn.Name;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.encoding.tlv.TlvDecoder;
import net.named_data.jndn.encoding.tlv.TlvEncoder;
import net.named_data.jndn.util.Blob;
+import java.nio.ByteBuffer;
+
/**
* Represent a strategy choice entry.
- * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice">StrategyChoice</a>
-
+ *
* @author Andrew Brown <andrew.brown@intel.com>
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice">StrategyChoice</a>
*/
public class StrategyChoice implements Decodable {
private Name name;
@@ -36,18 +36,19 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Default constructor
+ * Default constructor.
*/
public StrategyChoice() {
// nothing to do
}
/**
- * Constructor from wire format
+ * Constructor from wire format.
+ *
* @param input wire format
- * @throws EncodingException
+ * @throws EncodingException when decoding fails
*/
- public StrategyChoice(ByteBuffer input) throws EncodingException {
+ public StrategyChoice(final ByteBuffer input) throws EncodingException {
wireDecode(input);
}
@@ -65,9 +66,9 @@
/**
* Encode as part of an existing encode context.
*
- * @param encoder
+ * @param encoder TlvEncoder instance
*/
- public final void wireEncode(TlvEncoder encoder) {
+ public final void wireEncode(final TlvEncoder encoder) {
int saveLength = encoder.getLength();
EncodingHelper.encodeStrategy(strategy, encoder);
EncodingHelper.encodeName(name, encoder);
@@ -78,22 +79,19 @@
* Decode the input from its TLV format.
*
* @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
+ * limit(), but does not change the position.
* @throws EncodingException For invalid encoding.
*/
- public final void wireDecode(ByteBuffer input) throws EncodingException {
+ public final void wireDecode(final ByteBuffer input) throws EncodingException {
TlvDecoder decoder = new TlvDecoder(input);
wireDecode(decoder);
}
/**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
+ * {@inheritDoc}
*/
@Override
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
+ public void wireDecode(final TlvDecoder decoder) throws EncodingException {
int endOffset = decoder.readNestedTlvsStart(NfdTlv.StrategyChoice);
name = EncodingHelper.decodeName(decoder);
strategy = EncodingHelper.decodeStrategy(decoder);
@@ -116,16 +114,18 @@
/**
* @param name the {@link Name} to set
+ * @return this
*/
- public StrategyChoice setName(Name name) {
+ public StrategyChoice setName(final Name name) {
this.name = name;
return this;
}
/**
* @param strategy the {@link Name} to set
+ * @return this
*/
- public StrategyChoice setStrategy(Name strategy) {
+ public StrategyChoice setStrategy(final Name strategy) {
this.strategy = strategy;
return this;
}
diff --git a/src/main/java/com/intel/jndn/management/types/package-info.java b/src/main/java/com/intel/jndn/management/types/package-info.java
new file mode 100644
index 0000000..5a4c84b
--- /dev/null
+++ b/src/main/java/com/intel/jndn/management/types/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * NFD management types.
+ * @see <a href="http://redmine.named-data.net/projects/nfd/wiki/Management">NFD Management</a>
+ */
+package com.intel.jndn.management.types;
diff --git a/src/test/java/com/intel/jndn/management/NdnPingClientIT.java b/src/test/java/com/intel/jndn/management/NdnPingClientIT.java
index b561b6e..e0f9562 100644
--- a/src/test/java/com/intel/jndn/management/NdnPingClientIT.java
+++ b/src/test/java/com/intel/jndn/management/NdnPingClientIT.java
@@ -13,29 +13,17 @@
*/
package com.intel.jndn.management;
-import com.intel.jndn.management.enums.Strategies;
-import com.intel.jndn.management.types.RibEntry;
-import com.intel.jndn.management.types.StrategyChoice;
-import com.intel.jndn.mock.MockKeyChain;
import net.named_data.jndn.Face;
-import net.named_data.jndn.KeyLocator;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.security.KeyChain;
import net.named_data.jndn.security.SecurityException;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
-import java.util.List;
-import java.util.Random;
-import java.util.logging.Logger;
-import static junit.framework.Assert.assertEquals;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
/**
- * Testing basic pining using real NFD instance (NFD must be run locally while executing the test)
+ * Testing basic pining using real NFD instance (NFD must be run locally while executing the test).
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
diff --git a/src/test/java/com/intel/jndn/management/NfdcIT.java b/src/test/java/com/intel/jndn/management/NfdcIT.java
index 8a8a0c3..da341a2 100644
--- a/src/test/java/com/intel/jndn/management/NfdcIT.java
+++ b/src/test/java/com/intel/jndn/management/NfdcIT.java
@@ -13,11 +13,6 @@
*/
package com.intel.jndn.management;
-import java.io.IOException;
-import java.util.List;
-import java.util.Random;
-import java.util.logging.Logger;
-
import com.intel.jndn.management.enums.LocalControlHeader;
import com.intel.jndn.management.enums.Strategies;
import com.intel.jndn.management.types.RibEntry;
@@ -31,13 +26,19 @@
import net.named_data.jndn.security.SecurityException;
import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import static junit.framework.Assert.assertEquals;
-import static org.junit.Assert.*;
+import java.io.IOException;
+import java.util.List;
+import java.util.Random;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/**
- * Testing Nfdc with real NFD instance (NFD must be run locally while executing the test)
+ * Testing Nfdc with real NFD instance (NFD must be run locally while executing the test).
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
@@ -112,7 +113,7 @@
}
/**
- * LocalControlHeader would work only with NFD < 0.3.4, broken otherwise
+ * LocalControlHeader works only with NFD < 0.3.4, broken otherwise.
*/
@Test(expected = ManagementException.class)
public void testLocalControlHeader() throws Exception {
diff --git a/src/test/java/com/intel/jndn/management/TestHelper.java b/src/test/java/com/intel/jndn/management/TestHelper.java
index 09ea326..492d272 100644
--- a/src/test/java/com/intel/jndn/management/TestHelper.java
+++ b/src/test/java/com/intel/jndn/management/TestHelper.java
@@ -16,21 +16,22 @@
import java.nio.ByteBuffer;
/**
- * Helper methods for unit tests
+ * Helper methods for unit tests.
*/
-public class TestHelper {
+public final class TestHelper {
/**
- * Prevent instances of TestHelper
+ * Prevent instances of TestHelper.
*/
private TestHelper() {
}
/**
- * Construct ByteBuffer from int[]
+ * Construct ByteBuffer from int[].
+ *
+ * @param array array to convert
*/
public static ByteBuffer
- bufferFromIntArray(int[] array)
- {
+ bufferFromIntArray(final int[] array) {
ByteBuffer result = ByteBuffer.allocate(array.length);
for (int value : array) {
result.put((byte) (value & 0xFF));
diff --git a/src/test/java/com/intel/jndn/management/types/FaceStatusTest.java b/src/test/java/com/intel/jndn/management/types/FaceStatusTest.java
index b6b959b..6816ebd 100644
--- a/src/test/java/com/intel/jndn/management/types/FaceStatusTest.java
+++ b/src/test/java/com/intel/jndn/management/types/FaceStatusTest.java
@@ -17,26 +17,25 @@
import com.intel.jndn.management.enums.FacePersistency;
import com.intel.jndn.management.enums.FaceScope;
import com.intel.jndn.management.enums.LinkType;
-
-import java.nio.ByteBuffer;
import net.named_data.jndn.util.Blob;
-import static org.junit.Assert.*;
-
import org.junit.Before;
import org.junit.Test;
+import java.nio.ByteBuffer;
+
+import static org.junit.Assert.assertEquals;
+
/**
- * Test whether the decoding for the face management service is working
- * correctly
+ * Test encode/decode of FaceStatus.
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
public class FaceStatusTest {
- ByteBuffer TestFaceStatus;
+ private ByteBuffer testFaceStatusWire;
@Before
public void setUp() throws Exception {
- TestFaceStatus = TestHelper.bufferFromIntArray(new int[] {
+ testFaceStatusWire = TestHelper.bufferFromIntArray(new int[] {
0x80, 0x5e, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70,
0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e,
0x32, 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0x81, 0x16,
@@ -50,9 +49,6 @@
});
}
- /**
- * Test encoding
- */
@Test
public void testEncode() throws Exception {
FaceStatus status = new FaceStatus();
@@ -74,15 +70,12 @@
// encode
Blob encoded = status.wireEncode();
- assertEquals(TestFaceStatus, encoded.buf());
+ assertEquals(testFaceStatusWire, encoded.buf());
}
- /**
- * Test decoding
- */
@Test
public void testDecode() throws Exception {
- FaceStatus status = new FaceStatus(TestFaceStatus);
+ FaceStatus status = new FaceStatus(testFaceStatusWire);
assertEquals(100, status.getFaceId());
assertEquals("tcp4://192.0.2.1:6363", status.getRemoteUri());
diff --git a/src/test/java/com/intel/jndn/management/types/FibEntryTest.java b/src/test/java/com/intel/jndn/management/types/FibEntryTest.java
index d8c19f4..a1080a0 100644
--- a/src/test/java/com/intel/jndn/management/types/FibEntryTest.java
+++ b/src/test/java/com/intel/jndn/management/types/FibEntryTest.java
@@ -14,39 +14,39 @@
package com.intel.jndn.management.types;
import com.intel.jndn.management.TestHelper;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.encoding.EncodingException;
+import org.junit.Before;
+import org.junit.Test;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
+
import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
-
/**
- * Test encode/decode of FibEntry and NextHopRecord
+ * Test encode/decode of FibEntry and NextHopRecord.
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
public class FibEntryTest {
- ByteBuffer TestNextHopRecord;
- ByteBuffer TestFibEntryNoNextHops;
- ByteBuffer TestFibEntry;
+ private ByteBuffer testNextHopRecordWire;
+ private ByteBuffer testFibEntryNoNextHopsWire;
+ private ByteBuffer testFibEntryWire;
@Before
public void setUp() {
- TestNextHopRecord = TestHelper.bufferFromIntArray(new int[] {
+ testNextHopRecordWire = TestHelper.bufferFromIntArray(new int[] {
0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8
});
- TestFibEntryNoNextHops = TestHelper.bufferFromIntArray(new int[] {
+ testFibEntryNoNextHopsWire = TestHelper.bufferFromIntArray(new int[] {
0x80, 0x15, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73,
0x08, 0x02, 0x69, 0x73, 0x08, 0x01, 0x61, 0x08, 0x04, 0x74,
0x65, 0x73, 0x74
});
- TestFibEntry = TestHelper.bufferFromIntArray(new int[] {
+ testFibEntryWire = TestHelper.bufferFromIntArray(new int[] {
0x80, 0x38, 0x07, 0x13, 0x08, 0x04, 0x74, 0x68, 0x69, 0x73, 0x08, 0x02, 0x69, 0x73, 0x08, 0x01,
0x61, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x81, 0x06, 0x69, 0x01, 0x0a, 0x6a, 0x01, 0xc8, 0x81,
0x07, 0x69, 0x01, 0x14, 0x6a, 0x02, 0x01, 0x2c, 0x81, 0x07, 0x69, 0x01, 0x1e, 0x6a, 0x02, 0x01,
@@ -55,51 +55,47 @@
}
@Test
- public void testNextHopRecordEncode()
- {
+ public void testNextHopRecordEncode() {
NextHopRecord record = new NextHopRecord();
record.setFaceId(10);
record.setCost(200);
ByteBuffer wire = record.wireEncode().buf();
- assertEquals(TestNextHopRecord, wire);
+ assertEquals(testNextHopRecordWire, wire);
}
@Test
public void testNextHopRecordDecode() throws EncodingException {
- NextHopRecord record = new NextHopRecord(TestNextHopRecord);
+ NextHopRecord record = new NextHopRecord(testNextHopRecordWire);
assertEquals(10, record.getFaceId());
assertEquals(200, record.getCost());
}
@Test
- public void testFibEntryNoNextHopEncode()
- {
+ public void testFibEntryNoNextHopEncode() {
FibEntry entry = new FibEntry();
entry.setPrefix(new Name("/this/is/a/test"));
ByteBuffer wire = entry.wireEncode().buf();
- assertEquals(TestFibEntryNoNextHops, wire);
+ assertEquals(testFibEntryNoNextHopsWire, wire);
}
@Test
public void testFibEntryNoNextHopsDecode() throws EncodingException {
- FibEntry entry = new FibEntry(TestFibEntryNoNextHops);
+ FibEntry entry = new FibEntry(testFibEntryNoNextHopsWire);
assertEquals("/this/is/a/test", entry.getPrefix().toString());
assertEquals(0, entry.getNextHopRecords().size());
}
@Test
- public void testFibEntryEncode()
- {
+ public void testFibEntryEncode() {
FibEntry entry = new FibEntry();
entry.setPrefix(new Name("/this/is/a/test"));
List<NextHopRecord> records = new ArrayList<>();
- for (int i = 1; i < 4; i++)
- {
+ for (int i = 1; i < 4; i++) {
NextHopRecord record = new NextHopRecord();
record.setFaceId(i * 10);
record.setCost((i * 100) + 100);
@@ -115,12 +111,12 @@
entry.addNextHopRecord(oneMore);
ByteBuffer wire = entry.wireEncode().buf();
- assertEquals(TestFibEntry, wire);
+ assertEquals(testFibEntryWire, wire);
}
@Test
public void testFibEntryDecode() throws EncodingException {
- FibEntry entry = new FibEntry(TestFibEntry);
+ FibEntry entry = new FibEntry(testFibEntryWire);
List<NextHopRecord> records = entry.getNextHopRecords();
diff --git a/src/test/java/com/intel/jndn/management/types/ForwarderStatusTest.java b/src/test/java/com/intel/jndn/management/types/ForwarderStatusTest.java
index 5ff5157..fc2484d 100644
--- a/src/test/java/com/intel/jndn/management/types/ForwarderStatusTest.java
+++ b/src/test/java/com/intel/jndn/management/types/ForwarderStatusTest.java
@@ -27,11 +27,11 @@
* @author Andrew Brown <andrew.brown@intel.com>
*/
public class ForwarderStatusTest {
- ByteBuffer TestForwarderStatus;
+ private ByteBuffer testForwarderStatusWire;
@Before
public void setUp() throws Exception {
- TestForwarderStatus = TestHelper.bufferFromIntArray(new int[] {
+ testForwarderStatusWire = TestHelper.bufferFromIntArray(new int[] {
0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35,
0x2d, 0x67, 0x37, 0x35, 0x61, 0x62, 0x36, 0x62, 0x37, 0x81, 0x08, 0x00,
0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00,
@@ -63,12 +63,12 @@
status.setNOutNacks(4321);
ByteBuffer wire = status.wireEncode().buf();
- assertEquals(TestForwarderStatus, wire);
+ assertEquals(testForwarderStatusWire, wire);
}
@Test
public void testDecode() throws EncodingException {
- ForwarderStatus status = new ForwarderStatus(TestForwarderStatus);
+ ForwarderStatus status = new ForwarderStatus(testForwarderStatusWire);
assertEquals("0.2.0-65-g75ab6b7", status.getNfdVersion());
assertEquals(375193249325L, status.getStartTimestamp());
diff --git a/src/test/java/com/intel/jndn/management/types/RibEntryTest.java b/src/test/java/com/intel/jndn/management/types/RibEntryTest.java
index 82b4d22..bb980ca 100644
--- a/src/test/java/com/intel/jndn/management/types/RibEntryTest.java
+++ b/src/test/java/com/intel/jndn/management/types/RibEntryTest.java
@@ -13,68 +13,69 @@
*/
package com.intel.jndn.management.types;
-import java.nio.ByteBuffer;
-
import com.intel.jndn.management.TestHelper;
import com.intel.jndn.management.enums.RouteFlags;
+import net.named_data.jndn.Name;
+import org.junit.Before;
+import org.junit.Test;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.ListIterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import net.named_data.jndn.Name;
-import org.junit.Before;
-import org.junit.Test;
-
+/**
+ * Test RibEntry and Route encoding/decoding.
+ */
public class RibEntryTest {
- ByteBuffer RouteData;
- ByteBuffer RouteInfiniteExpirationPeriod;
- ByteBuffer RibEntryData;
- ByteBuffer RibEntryInfiniteExpirationPeriod;
- ByteBuffer RibEntryForRootData;
+ private ByteBuffer testRouteDataWire;
+ private ByteBuffer testRouteInfiniteExpirationPeriodWire;
+ private ByteBuffer testRibEntryDataWire;
+ private ByteBuffer testRibEntryInfiniteExpirationPeriodWire;
+ private ByteBuffer testRibEntryForRootDataWire;
@Before
public void setUp() throws Exception {
- RouteData = TestHelper.bufferFromIntArray(new int[] {
- 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
- 0x6d, 0x02, 0x27, 0x10
- });
- RouteInfiniteExpirationPeriod = TestHelper.bufferFromIntArray(new int[] {
- 0x81, 0x0C, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02
- });
- RibEntryData = TestHelper.bufferFromIntArray(new int[] {
- // Header + Name (ndn:/hello/world)
- 0x80, 0x34, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
- 0x08, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64,
- // Route
- 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
- 0x6d, 0x02, 0x27, 0x10,
- // Route
- 0x81, 0x10, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
- 0x6d, 0x02, 0x13, 0x88
- });
- RibEntryInfiniteExpirationPeriod = TestHelper.bufferFromIntArray(new int[] {
- // Header + Name (ndn:/hello/world)
- 0x80, 0x30, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
- 0x08, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64,
- // Route
- 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
- 0x6d, 0x02, 0x27, 0x10,
- // Route with no ExpirationPeriod
- 0x81, 0x0C, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
- });
- RibEntryForRootData = TestHelper.bufferFromIntArray(new int[] {
- // Header + Name (ndn:/)
- 0x80, 0x26, 0x07, 0x00,
- // Route
- 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
- 0x6d, 0x02, 0x27, 0x10,
- // Route
- 0x81, 0x10, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
- 0x6d, 0x02, 0x13, 0x88
- });
+ testRouteDataWire = TestHelper.bufferFromIntArray(new int[]{
+ 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
+ 0x6d, 0x02, 0x27, 0x10
+ });
+ testRouteInfiniteExpirationPeriodWire = TestHelper.bufferFromIntArray(new int[]{
+ 0x81, 0x0C, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02
+ });
+ testRibEntryDataWire = TestHelper.bufferFromIntArray(new int[]{
+ // Header + Name (ndn:/hello/world)
+ 0x80, 0x34, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
+ 0x08, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64,
+ // Route
+ 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
+ 0x6d, 0x02, 0x27, 0x10,
+ // Route
+ 0x81, 0x10, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
+ 0x6d, 0x02, 0x13, 0x88
+ });
+ testRibEntryInfiniteExpirationPeriodWire = TestHelper.bufferFromIntArray(new int[]{
+ // Header + Name (ndn:/hello/world)
+ 0x80, 0x30, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
+ 0x08, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64,
+ // Route
+ 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
+ 0x6d, 0x02, 0x27, 0x10,
+ // Route with no ExpirationPeriod
+ 0x81, 0x0C, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
+ });
+ testRibEntryForRootDataWire = TestHelper.bufferFromIntArray(new int[]{
+ // Header + Name (ndn:/)
+ 0x80, 0x26, 0x07, 0x00,
+ // Route
+ 0x81, 0x10, 0x69, 0x01, 0x01, 0x6f, 0x01, 0x80, 0x6a, 0x01, 0x64, 0x6c, 0x01, 0x02,
+ 0x6d, 0x02, 0x27, 0x10,
+ // Route
+ 0x81, 0x10, 0x69, 0x01, 0x02, 0x6f, 0x01, 0x00, 0x6a, 0x01, 0x20, 0x6c, 0x01, 0x01,
+ 0x6d, 0x02, 0x13, 0x88
+ });
}
@Test
@@ -86,12 +87,12 @@
route.setFlags(RouteFlags.CAPTURE.toInteger());
route.setExpirationPeriod(10000);
- assertEquals(RouteData, route.wireEncode().buf());
+ assertEquals(testRouteDataWire, route.wireEncode().buf());
}
@Test
public void testRouteDecode() throws Exception {
- Route route = new Route(RouteData);
+ Route route = new Route(testRouteDataWire);
assertEquals(route.getFaceId(), 1);
assertEquals(route.getOrigin(), 128);
@@ -110,12 +111,12 @@
route.setFlags(RouteFlags.CAPTURE.toInteger());
route.setExpirationPeriod(Route.INFINITE_EXPIRATION_PERIOD);
- assertEquals(RouteInfiniteExpirationPeriod, route.wireEncode().buf());
+ assertEquals(testRouteInfiniteExpirationPeriodWire, route.wireEncode().buf());
}
@Test
public void testRouteInfiniteExpirationPeriodDecode() throws Exception {
- Route route = new Route(RouteInfiniteExpirationPeriod);
+ Route route = new Route(testRouteInfiniteExpirationPeriodWire);
assertEquals(route.getFaceId(), 1);
assertEquals(route.getOrigin(), 128);
@@ -135,19 +136,19 @@
route.setExpirationPeriod(10000);
assertEquals(route.toString(), "Route(FaceId: 1, Origin: 128, Cost: 100, " +
- "Flags: 2, ExpirationPeriod: 10000 milliseconds)");
+ "Flags: 2, ExpirationPeriod: 10000 milliseconds)");
}
@Test
public void testRibEntryEncode() throws Exception {
RibEntry entry = newRibEntry("/hello/world", 2, false);
- assertEquals(RibEntryData, entry.wireEncode().buf());
+ assertEquals(testRibEntryDataWire, entry.wireEncode().buf());
}
@Test
public void testRibEntryDecode() throws Exception {
- RibEntry entry = new RibEntry(RibEntryData);
+ RibEntry entry = new RibEntry(testRibEntryDataWire);
assertRibEntry(entry, "/hello/world", 2, false);
}
@@ -156,12 +157,12 @@
public void testRibEntryForRootEncode() throws Exception {
RibEntry entry = newRibEntry("/", 2, false);
- assertEquals(RibEntryForRootData, entry.wireEncode().buf());
+ assertEquals(testRibEntryForRootDataWire, entry.wireEncode().buf());
}
@Test
public void testRibEntryForRootDecode() throws Exception {
- RibEntry entry = new RibEntry(RibEntryForRootData);
+ RibEntry entry = new RibEntry(testRibEntryForRootDataWire);
assertRibEntry(entry, "/", 2, false);
}
@@ -169,14 +170,14 @@
@Test
public void testRibEntryInfiniteExpirationPeriodEncode() throws Exception {
RibEntry entry = newRibEntry("/hello/world", 2, true);
- assertEquals(RibEntryInfiniteExpirationPeriod, entry.wireEncode().buf());
+ assertEquals(testRibEntryInfiniteExpirationPeriodWire, entry.wireEncode().buf());
}
@Test
public void testRibEntryInfiniteExpirationPeriodDecode() throws Exception {
RibEntry entry = new RibEntry();
- entry.wireDecode(RibEntryInfiniteExpirationPeriod);
+ entry.wireDecode(testRibEntryInfiniteExpirationPeriodWire);
assertRibEntry(entry, "/hello/world", 2, true);
}
@@ -195,11 +196,11 @@
RibEntry entry = newRibEntry("/hello/world", 2, true);
assertEquals("RibEntry{\n" +
- " Name: /hello/world\n" +
- " Route(FaceId: 1, Origin: 128, Cost: 100, Flags: 2, ExpirationPeriod: 10000 milliseconds)\n" +
- " Route(FaceId: 2, Origin: 0, Cost: 32, Flags: 1, ExpirationPeriod: Infinity)\n" +
- "}",
- entry.toString());
+ " Name: /hello/world\n" +
+ " Route(FaceId: 1, Origin: 128, Cost: 100, Flags: 2, ExpirationPeriod: 10000 milliseconds)\n" +
+ " Route(FaceId: 2, Origin: 0, Cost: 32, Flags: 1, ExpirationPeriod: Infinity)\n" +
+ "}",
+ entry.toString());
}
@Test
@@ -211,17 +212,17 @@
b.setRoutes(a.getRoutes());
assertEquals("RibEntry{\n" +
- " Name: /another/prefix\n" +
- " Route(FaceId: 1, Origin: 128, Cost: 100, Flags: 2, ExpirationPeriod: 10000 milliseconds)\n" +
- " Route(FaceId: 2, Origin: 0, Cost: 32, Flags: 1, ExpirationPeriod: Infinity)\n" +
- "}",
- b.toString());
+ " Name: /another/prefix\n" +
+ " Route(FaceId: 1, Origin: 128, Cost: 100, Flags: 2, ExpirationPeriod: 10000 milliseconds)\n" +
+ " Route(FaceId: 2, Origin: 0, Cost: 32, Flags: 1, ExpirationPeriod: Infinity)\n" +
+ "}",
+ b.toString());
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
- private RibEntry newRibEntry(String name, int nRoutes, boolean isInfiniteSecond) {
+ private RibEntry newRibEntry(final String name, final int nRoutes, final boolean isInfiniteSecond) {
RibEntry entry = new RibEntry();
entry.setName(new Name(name));
@@ -241,8 +242,7 @@
route2.setFlags(RouteFlags.CHILD_INHERIT.toInteger());
if (isInfiniteSecond) {
route2.setExpirationPeriod(Route.INFINITE_EXPIRATION_PERIOD);
- }
- else {
+ } else {
route2.setExpirationPeriod(5000);
}
entry.addRoute(route2);
@@ -251,7 +251,8 @@
return entry;
}
- private void assertRibEntry(RibEntry entry, String name, int nRoutes, boolean isInfiniteSecond) throws Exception {
+ private void assertRibEntry(final RibEntry entry, final String name, final int nRoutes,
+ final boolean isInfiniteSecond) throws Exception {
assertEquals(entry.getName().toUri(), name);
assertEquals(entry.getRoutes().size(), nRoutes);
@@ -278,8 +279,7 @@
if (isInfiniteSecond) {
assertEquals(item.getExpirationPeriod(), Route.INFINITE_EXPIRATION_PERIOD);
assertEquals(item.hasInfiniteExpirationPeriod(), true);
- }
- else {
+ } else {
assertEquals(item.getExpirationPeriod(), 5000);
assertEquals(item.hasInfiniteExpirationPeriod(), false);
}
diff --git a/src/test/java/com/intel/jndn/management/types/StrategyChoiceTest.java b/src/test/java/com/intel/jndn/management/types/StrategyChoiceTest.java
index 077d91c..1940b41 100644
--- a/src/test/java/com/intel/jndn/management/types/StrategyChoiceTest.java
+++ b/src/test/java/com/intel/jndn/management/types/StrategyChoiceTest.java
@@ -24,16 +24,16 @@
import static org.junit.Assert.assertEquals;
/**
- * Test StrategyChoice encoding/decoding
+ * Test StrategyChoice encoding/decoding.
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
public class StrategyChoiceTest {
- ByteBuffer TestStrategyChoice;
+ private ByteBuffer testStrategyChoiceWire;
@Before
public void setUp() throws Exception {
- TestStrategyChoice = TestHelper.bufferFromIntArray(new int[] {
+ testStrategyChoiceWire = TestHelper.bufferFromIntArray(new int[]{
0x80, 0x39, 0x07, 0x0e, 0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x08, 0x05, 0x77,
0x6f, 0x72, 0x6c, 0x64, 0x6b, 0x27, 0x07, 0x25, 0x08, 0x04, 0x73, 0x6f, 0x6d, 0x65,
0x08, 0x03, 0x6e, 0x6f, 0x6e, 0x08, 0x08, 0x65, 0x78, 0x69, 0x73, 0x74, 0x69, 0x6e,
@@ -47,16 +47,15 @@
StrategyChoice strategyChoice = new StrategyChoice();
strategyChoice
.setName(new Name("/hello/world"))
- .setStrategy(new Name("/some/non/existing/strategy/name"))
- ;
+ .setStrategy(new Name("/some/non/existing/strategy/name"));
ByteBuffer wire = strategyChoice.wireEncode().buf();
- assertEquals(TestStrategyChoice, wire);
+ assertEquals(testStrategyChoiceWire, wire);
}
@Test
public void testDecode() throws EncodingException {
- StrategyChoice strategyChoice = new StrategyChoice(TestStrategyChoice);
+ StrategyChoice strategyChoice = new StrategyChoice(testStrategyChoiceWire);
assertEquals("/hello/world", strategyChoice.getName().toUri());
assertEquals("/some/non/existing/strategy/name", strategyChoice.getStrategy().toUri());
}