/// <summary> /// Test that not setting the any properties returns in an (almost) empty Blob /// </summary> /// public void testExceptionsThrown() { ControlParameters controlParameters = new ControlParameters(); Blob encoded = controlParameters.wireEncode(); Assert.AssertEquals(2, encoded.buf().limit()); // only TLV type 104 and length 0 should be set }
/// <summary> /// Test encoding/decoding with no name defined /// </summary> /// /// <exception cref="EncodingException"></exception> public void testEncodeDecodeWithNoName() { ControlParameters controlParameters = new ControlParameters(); controlParameters.setStrategy(new Name( "/localhost/nfd/strategy/broadcast")); controlParameters.setUri("null://"); // encode Blob encoded = controlParameters.wireEncode(); // decode ControlParameters decodedControlParameters = new ControlParameters(); decodedControlParameters.wireDecode(encoded); // compare Assert.AssertEquals(controlParameters.getStrategy().toUri(), decodedControlParameters.getStrategy().toUri()); Assert.AssertEquals(controlParameters.getUri(), decodedControlParameters.getUri()); }
/// <summary> /// Test encoding/decoding /// </summary> /// /// <exception cref="EncodingException"></exception> public void testEncodeDecode() { ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(new Name("/test/control/parameters")); controlParameters.setFaceId(1); // encode Blob encoded = controlParameters.wireEncode(); // decode ControlParameters decodedControlParameters = new ControlParameters(); decodedControlParameters.wireDecode(encoded); // compare Assert.AssertEquals(controlParameters.getName().toUri(), decodedControlParameters.getName().toUri()); Assert.AssertEquals(controlParameters.getFaceId(), decodedControlParameters.getFaceId()); Assert.AssertEquals("decoded forwarding flags childInherit is different", controlParameters.getForwardingFlags().getChildInherit(), decodedControlParameters.getForwardingFlags().getChildInherit()); Assert.AssertEquals("decoded forwarding flags capture is different", controlParameters.getForwardingFlags().getCapture(), decodedControlParameters.getForwardingFlags().getCapture()); }
/// <summary> /// Do the work of registerPrefix to register with NFD. /// </summary> /// /// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param> /// <param name="prefix"></param> /// <param name="onInterest"></param> /// <param name="onRegisterFailed"></param> /// <param name="onRegisterSuccess"></param> /// <param name="flags"></param> /// <param name="commandKeyChain"></param> /// <param name="commandCertificateName"></param> /// <param name="wireFormat_0"></param> /// <param name="face_1"></param> /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception> private void nfdRegisterPrefix(long registeredPrefixId, Name prefix, OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed, OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags, KeyChain commandKeyChain, Name commandCertificateName, WireFormat wireFormat_0, Face face_1) { if (commandKeyChain == null) { throw new Exception( "registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo."); } if (commandCertificateName.size() == 0) { throw new Exception( "registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo."); } ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(prefix); controlParameters.setForwardingFlags(flags); Interest commandInterest = new Interest(); // Determine whether to use remote prefix registration. bool faceIsLocal; try { faceIsLocal = isLocal(); } catch (IOException ex) { logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error attempting to determine if the face is local: {0}", ex); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception); } return; } if (faceIsLocal) { commandInterest.setName(new Name("/localhost/nfd/rib/register")); // The interest is answered by the local host, so set a short timeout. commandInterest.setInterestLifetimeMilliseconds(2000.0d); } else { commandInterest.setName(new Name("/localhop/nfd/rib/register")); // The host is remote, so set a longer timeout. commandInterest.setInterestLifetimeMilliseconds(4000.0d); } // NFD only accepts TlvWireFormat packets. commandInterest.getName().append( controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get())); makeCommandInterest(commandInterest, commandKeyChain, commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get()); // Send the registration interest. Node.RegisterResponse response = new Node.RegisterResponse( new RegisterResponse.Info(prefix, onRegisterFailed, onRegisterSuccess, registeredPrefixId, onInterest, face_1), this); try { expressInterest(getNextEntryId(), commandInterest, response, response, null, wireFormat_0, face_1); } catch (IOException ex_2) { // Can't send the interest. Call onRegisterFailed. logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error sending the register prefix interest to the forwarder: {0}", ex_2); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception_3) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception_3); } } }
/// <summary> /// Do the work of registerPrefix to register with NFD. /// </summary> /// /// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param> /// <param name="prefix"></param> /// <param name="onInterest"></param> /// <param name="onRegisterFailed"></param> /// <param name="onRegisterSuccess"></param> /// <param name="flags"></param> /// <param name="commandKeyChain"></param> /// <param name="commandCertificateName"></param> /// <param name="wireFormat_0"></param> /// <param name="face_1"></param> /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception> private void nfdRegisterPrefix(long registeredPrefixId, Name prefix, OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed, OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags, KeyChain commandKeyChain, Name commandCertificateName, WireFormat wireFormat_0, Face face_1) { if (commandKeyChain == null) throw new Exception( "registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo."); if (commandCertificateName.size() == 0) throw new Exception( "registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo."); ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(prefix); controlParameters.setForwardingFlags(flags); Interest commandInterest = new Interest(); // Determine whether to use remote prefix registration. bool faceIsLocal; try { faceIsLocal = isLocal(); } catch (IOException ex) { logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error attempting to determine if the face is local: {0}", ex); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception); } return; } if (faceIsLocal) { commandInterest.setName(new Name("/localhost/nfd/rib/register")); // The interest is answered by the local host, so set a short timeout. commandInterest.setInterestLifetimeMilliseconds(2000.0d); } else { commandInterest.setName(new Name("/localhop/nfd/rib/register")); // The host is remote, so set a longer timeout. commandInterest.setInterestLifetimeMilliseconds(4000.0d); } // NFD only accepts TlvWireFormat packets. commandInterest.getName().append( controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get())); makeCommandInterest(commandInterest, commandKeyChain, commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get()); // Send the registration interest. Node.RegisterResponse response = new Node.RegisterResponse ( new RegisterResponse.Info(prefix, onRegisterFailed, onRegisterSuccess, registeredPrefixId, onInterest, face_1), this); try { expressInterest(getNextEntryId(), commandInterest, response, response, null, wireFormat_0, face_1); } catch (IOException ex_2) { // Can't send the interest. Call onRegisterFailed. logger_.log( ILOG.J2CsMapping.Util.Logging.Level.INFO, "Register prefix failed: Error sending the register prefix interest to the forwarder: {0}", ex_2); try { onRegisterFailed.onRegisterFailed(prefix); } catch (Exception exception_3) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed", exception_3); } } }