Beispiel #1
0
 /// <summary>
 /// Set the control response body as a ControlParameters.
 /// </summary>
 ///
 /// <param name="controlParameters">ControlParameters, set to null.</param>
 /// <returns>This ControlResponse so that you can chain calls to update values.</returns>
 public ControlResponse setBodyAsControlParameters(
     ControlParameters controlParameters)
 {
     bodyAsControlParameters_ = (controlParameters == null) ? null
                                 : new ControlParameters(controlParameters);
     return(this);
 }
 /// <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>
 /// Create a new ControlResponse as a deep copy of the given ControlResponse.
 /// </summary>
 ///
 /// <param name="controlResponse">The ControlResponse to copy.</param>
 public ControlResponse(ControlResponse controlResponse)
 {
     this.statusCode_ = -1;
     this.statusText_ = "";
     this.bodyAsControlParameters_ = null;
     statusCode_ = controlResponse.statusCode_;
     statusText_ = controlResponse.statusText_;
     bodyAsControlParameters_ = (controlResponse.bodyAsControlParameters_ == null) ? null
             : new ControlParameters(
                     controlResponse.bodyAsControlParameters_);
 }
 /// <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>
 /// Create a new ControlParameters as a deep copy of the given controlParameters.
 /// </summary>
 ///
 /// <param name="controlParameters">The ControlParameters to copy.</param>
 public ControlParameters(ControlParameters controlParameters)
 {
     this.name_   = null;
     this.faceId_ = -1;
     this.uri_    = "";
     this.localControlFeature_ = -1;
     this.origin_           = -1;
     this.cost_             = -1;
     this.flags_            = new ForwardingFlags();
     this.strategy_         = new Name();
     this.expirationPeriod_ = -1.0d;
     name_ = (controlParameters.name_ == null) ? null : new Name(
         controlParameters.name_);
     faceId_ = controlParameters.faceId_;
     uri_    = controlParameters.uri_;
     localControlFeature_ = controlParameters.localControlFeature_;
     origin_           = controlParameters.origin_;
     cost_             = controlParameters.cost_;
     flags_            = new ForwardingFlags(controlParameters.flags_);
     strategy_         = new Name(controlParameters.strategy_);
     expirationPeriod_ = controlParameters.expirationPeriod_;
 }
Beispiel #7
0
        /// <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>
 /// Create a new ControlParameters as a deep copy of the given controlParameters.
 /// </summary>
 ///
 /// <param name="controlParameters">The ControlParameters to copy.</param>
 public ControlParameters(ControlParameters controlParameters)
 {
     this.name_ = null;
     this.faceId_ = -1;
     this.uri_ = "";
     this.localControlFeature_ = -1;
     this.origin_ = -1;
     this.cost_ = -1;
     this.flags_ = new ForwardingFlags();
     this.strategy_ = new Name();
     this.expirationPeriod_ = -1.0d;
     name_ = (controlParameters.name_ == null) ? null : new Name(
             controlParameters.name_);
     faceId_ = controlParameters.faceId_;
     uri_ = controlParameters.uri_;
     localControlFeature_ = controlParameters.localControlFeature_;
     origin_ = controlParameters.origin_;
     cost_ = controlParameters.cost_;
     flags_ = new ForwardingFlags(controlParameters.flags_);
     strategy_ = new Name(controlParameters.strategy_);
     expirationPeriod_ = controlParameters.expirationPeriod_;
 }
        private static void encodeControlParameters(
				ControlParameters controlParameters, TlvEncoder encoder)
        {
            int saveLength = encoder.getLength();

            // Encode backwards.
            encoder.writeOptionalNonNegativeIntegerTlvFromDouble(
                    net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ExpirationPeriod,
                    controlParameters.getExpirationPeriod());

            // Encode strategy
            if (controlParameters.getStrategy().size() != 0) {
                int strategySaveLength = encoder.getLength();
                encodeName(controlParameters.getStrategy(), new int[1], new int[1],
                        encoder);
                encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy,
                        encoder.getLength() - strategySaveLength);
            }

            // Encode ForwardingFlags
            int flags = controlParameters.getForwardingFlags()
                    .getNfdForwardingFlags();
            if (flags != new ForwardingFlags().getNfdForwardingFlags())
                // The flags are not the default value.
                encoder.writeNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags,
                        flags);

            encoder.writeOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Cost,
                    controlParameters.getCost());
            encoder.writeOptionalNonNegativeIntegerTlv(
                    net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Origin, controlParameters.getOrigin());
            encoder.writeOptionalNonNegativeIntegerTlv(
                    net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_LocalControlFeature,
                    controlParameters.getLocalControlFeature());

            // Encode URI
            if (controlParameters.getUri().Length != 0) {
                encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, new Blob(
                        controlParameters.getUri()).buf());
            }

            encoder.writeOptionalNonNegativeIntegerTlv(
                    net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_FaceId, controlParameters.getFaceId());

            // Encode name
            if (controlParameters.getName() != null) {
                encodeName(controlParameters.getName(), new int[1], new int[1],
                        encoder);
            }

            encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters,
                    encoder.getLength() - saveLength);
        }
        private static void decodeControlParameters(
				ControlParameters controlParameters, TlvDecoder decoder,
				bool copy)
        {
            controlParameters.clear();

            int endOffset = decoder
                    .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters);

            // decode name
            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Name, endOffset)) {
                Name name = new Name();
                decodeName(name, new int[1], new int[1], decoder, copy);
                controlParameters.setName(name);
            }

            // decode face ID
            controlParameters.setFaceId((int) decoder
                    .readOptionalNonNegativeIntegerTlv(
                            net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_FaceId, endOffset));

            // decode URI
            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset)) {
                // Set copy false since we just immediately get the string.
                Blob uri = new Blob(decoder.readOptionalBlobTlv(
                        net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset), false);
                controlParameters.setUri("" + uri);
            }

            // decode integers
            controlParameters.setLocalControlFeature((int) decoder
                    .readOptionalNonNegativeIntegerTlv(
                            net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_LocalControlFeature, endOffset));
            controlParameters.setOrigin((int) decoder
                    .readOptionalNonNegativeIntegerTlv(
                            net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Origin, endOffset));
            controlParameters.setCost((int) decoder
                    .readOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Cost,
                            endOffset));

            // set forwarding flags
            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags, endOffset)) {
                ForwardingFlags flags = new ForwardingFlags();
                flags.setNfdForwardingFlags((int) decoder
                        .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags));
                controlParameters.setForwardingFlags(flags);
            }

            // decode strategy
            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy, endOffset)) {
                int strategyEndOffset = decoder
                        .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy);
                decodeName(controlParameters.getStrategy(), new int[1], new int[1],
                        decoder, copy);
                decoder.finishNestedTlvs(strategyEndOffset);
            }

            // decode expiration period
            controlParameters.setExpirationPeriod(decoder
                    .readOptionalNonNegativeIntegerTlv(
                            net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ExpirationPeriod, endOffset));

            decoder.finishNestedTlvs(endOffset);
        }
        /// <summary>
        /// Decode input as a control parameters in NDN-TLV and set the fields of the
        /// controlParameters object.
        /// </summary>
        ///
        /// <param name="controlParameters"></param>
        /// <param name="input"></param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="EncodingException">For invalid encoding</exception>
        public override void decodeControlParameters(ControlParameters controlParameters,
				ByteBuffer input, bool copy)
        {
            TlvDecoder decoder = new TlvDecoder(input);
            decodeControlParameters(controlParameters, decoder, copy);
        }
Beispiel #12
0
        /// <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>
 /// Encode controlParameters in NDN-TLV and return the encoding.
 /// </summary>
 ///
 /// <param name="controlParameters">The ControlParameters object to encode.</param>
 /// <returns>A Blob containing the encoding.</returns>
 public override Blob encodeControlParameters(ControlParameters controlParameters)
 {
     TlvEncoder encoder = new TlvEncoder(256);
     encodeControlParameters(controlParameters, encoder);
     return new Blob(encoder.getOutput(), false);
 }
Beispiel #14
0
 /// <summary>
 /// Encode controlParameters and return the encoding.
 /// Your derived class should override.
 /// </summary>
 ///
 /// <param name="controlParameters">The ControlParameters object to encode.</param>
 /// <returns>A Blob containing the encoding.</returns>
 /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
 public virtual Blob encodeControlParameters(ControlParameters controlParameters)
 {
     throw new NotSupportedException(
             "encodeControlParameters is not implemented");
 }
 /// <summary>
 /// Create a new ControlResponse where all values are unspecified.
 /// </summary>
 ///
 public ControlResponse()
 {
     this.statusCode_ = -1;
     this.statusText_ = "";
     this.bodyAsControlParameters_ = null;
 }
        /// <summary>
        /// Set the control response body as a ControlParameters.
        /// </summary>
        ///
        /// <param name="controlParameters">ControlParameters, set to null.</param>
        /// <returns>This ControlResponse so that you can chain calls to update values.</returns>
        public ControlResponse setBodyAsControlParameters(
				ControlParameters controlParameters)
        {
            bodyAsControlParameters_ = (controlParameters == null) ? null
                    : new ControlParameters(controlParameters);
            return this;
        }
Beispiel #17
0
        /// <summary>
        /// Decode input as a control parameters and set the fields of the
        /// controlParameters object. Copy from the input when making new Blob values.
        /// Your derived class should override.
        /// </summary>
        ///
        /// <param name="controlParameters"></param>
        /// <param name="input"></param>
        /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void decodeControlParameters(
				ControlParameters controlParameters, ByteBuffer input)
        {
            decodeControlParameters(controlParameters, input, true);
        }
Beispiel #18
0
        /// <summary>
        /// Decode input as a control parameters and set the fields of the
        /// controlParameters object.  Your derived class should override.
        /// </summary>
        ///
        /// <param name="controlParameters"></param>
        /// <param name="input"></param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public virtual void decodeControlParameters(ControlParameters controlParameters,
				ByteBuffer input, bool copy)
        {
            throw new NotSupportedException(
                    "decodeControlParameters is not implemented");
        }