Beispiel #1
0
 public void testMissingPreferenceEncoding()
 {
     Link link = new Link();
     try {
         link.wireDecode(new Blob(MissingPreferenceLink, false));
         Assert.Fail("Expected error decoding MissingPreferenceLink");
     } catch (EncodingException ex) {
     }
 }
Beispiel #2
0
        public void testRemoveDelegation()
        {
            Link link = new Link();
            link.setName(new Name("test"));
            link.addDelegation(10, new Name("/test1"));
            link.addDelegation(20, new Name("/test2"));
            link.addDelegation(100, new Name("/test3"));

            link.removeDelegation(new Name("/test2"));
            DelegationSet delegations = link.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test1"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(100, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test3"), delegations.get(i).getName());
                }
            }
        }
Beispiel #3
0
        ////////////////////////////////////
        // Tests from ndn-cxx interest.t.cpp
        ////////////////////////////////////
        public void testInterestLinkObject()
        {
            Link link1 = new Link();
            link1.setName(new Name("test"));
            link1.addDelegation(10, new Name("/test1"));
            link1.addDelegation(20, new Name("/test2"));
            link1.addDelegation(100, new Name("/test3"));

            try {
                keyChain.sign(link1, certificateName);
            } catch (SecurityException ex) {
                Assert.Fail(ex.Message);
            }

            Blob linkEncoding = link1.wireEncode();

            Interest interestA = new Interest();
            Link link2 = null;
            try {
                interestA.setLinkWireEncoding(linkEncoding);
                link2 = interestA.getLink();
            } catch (Exception ex_0) {
                Assert.Fail(ex_0.Message);
            }

            Assert.AssertTrue(link2 != null);
            Name name = link2.getName();
            Assert.AssertEquals(new Name("test"), name);

            DelegationSet delegations = link2.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test1"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(20, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test2"), delegations.get(i).getName());
                }
                if (i == 2) {
                    Assert.AssertEquals(100, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test3"), delegations.get(i).getName());
                }
            }

            interestA.setLinkWireEncoding(new Blob(LINK, false));
            Link link3 = null;
            try {
                link3 = interestA.getLink();
            } catch (Exception ex_1) {
                Assert.Fail(ex_1.Message);
            }
            Assert.AssertEquals(2, link3.getDelegations().size());

            interestA.unsetLink();
            Assert.AssertEquals(false, interestA.hasLink());
        }
Beispiel #4
0
        public void testInterestSelectedDelegation()
        {
            Link link = new Link();
            link.setName(new Name("test"));
            link.addDelegation(10, new Name("/test1"));
            link.addDelegation(20, new Name("/test2"));
            link.addDelegation(100, new Name("/test3"));

            try {
                keyChain.sign(link, certificateName);
            } catch (SecurityException ex) {
                Assert.Fail(ex.Message);
            }

            Blob linkEncoding = link.wireEncode();

            Interest interestA = new Interest();
            interestA.setLinkWireEncoding(linkEncoding);
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() < 0);

            interestA.setSelectedDelegationIndex(link.getDelegations().find(
                    new Name("test2")));
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() >= 0);
            Link link2 = null;
            try {
                link2 = interestA.getLink();
            } catch (Exception ex_0) {
                Assert.Fail(ex_0.Message);
            }
            Assert.AssertEquals(
                    new Name("test2"),
                    link2.getDelegations()
                            .get(interestA.getSelectedDelegationIndex()).getName());

            interestA.setSelectedDelegationIndex(-1);
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() < 0);
        }
Beispiel #5
0
 public void testIncorrectContentType()
 {
     Link link = new Link();
     try {
         link.wireDecode(new Blob(IncorrectContentTypeLink, false));
         Assert.Fail("Expected error decoding IncorrectContentTypeLink");
     } catch (EncodingException ex) {
     }
 }
Beispiel #6
0
        public void testEncodeDecodeInterestWithLink()
        {
            Link link1 = new Link();
            link1.setName(new Name("test"));
            link1.addDelegation(10, new Name("/test1"));
            link1.addDelegation(20, new Name("/test2"));
            link1.addDelegation(100, new Name("/test3"));

            try {
                keyChain.sign(link1, certificateName);
            } catch (SecurityException ex) {
                Assert.Fail(ex.Message);
            }

            Interest interestA = new Interest();
            interestA.setName(new Name("/Test/Encode/Decode/With/Link"));
            interestA.setChildSelector(1);
            interestA.setInterestLifetimeMilliseconds(10000);
            interestA.setLinkWireEncoding(link1.wireEncode());

            Blob interestEncoding = interestA.wireEncode();
            Interest interestB = new Interest();
            try {
                interestB.wireDecode(interestEncoding);
            } catch (EncodingException ex_0) {
                Assert.Fail(ex_0.Message);
            }

            Assert.AssertEquals(interestA.getName(), interestB.getName());

            Link link2 = null;
            try {
                link2 = interestB.getLink();
            } catch (Exception ex_1) {
                Assert.Fail("interestB.getLink(): " + ex_1.Message);
            }

            Assert.AssertTrue("Interest link object not specified", link2 != null);
            DelegationSet delegations = link2.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test1"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(20, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test2"), delegations.get(i).getName());
                }
                if (i == 2) {
                    Assert.AssertEquals(100, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test3"), delegations.get(i).getName());
                }
            }
        }
Beispiel #7
0
        public void testEncodeDecode()
        {
            Link link1 = new Link();
            link1.setName(new Name("test"));
            link1.addDelegation(10, new Name("/test1"));
            link1.addDelegation(20, new Name("/test2"));
            link1.addDelegation(100, new Name("/test3"));

            try {
                keyChain.sign(link1, certificateName);
            } catch (SecurityException ex) {
                Assert.Fail(ex.Message);
            }
            Blob wireEncoding = link1.wireEncode();

            Link link2 = new Link();
            try {
                link2.wireDecode(wireEncoding);
            } catch (EncodingException ex_0) {
                Assert.Fail(ex_0.Message);
            }
            Name name = link2.getName();
            Assert.AssertEquals(new Name("test"), name);

            DelegationSet delegations = link2.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test1"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(20, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test2"), delegations.get(i).getName());
                }
                if (i == 2) {
                    Assert.AssertEquals(100, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("/test3"), delegations.get(i).getName());
                }
            }
        }
Beispiel #8
0
        public void testDecode()
        {
            Link link = new Link();
            try {
                link.wireDecode(new Blob(LinkTest, false));
            } catch (EncodingException ex) {
                Assert.Fail(ex.Message);
            }
            Assert.AssertEquals(new Name("/local/ndn/prefix"), link.getName());

            DelegationSet delegations = link.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("local"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(20, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("ndn"), delegations.get(i).getName());
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Get the link object. If necessary, decode it from the link wire encoding.
        /// </summary>
        ///
        /// <returns>The link object, or null if not specified.</returns>
        /// <exception cref="EncodingException">For error decoding the link wire encoding (ifnecessary).</exception>
        public Link getLink()
        {
            if (link_.get() != null)
                return (Link) link_.get();
            else if (!linkWireEncoding_.isNull()) {
                // Decode the link object from linkWireEncoding_.
                Link link = new Link();
                link.wireDecode(linkWireEncoding_, linkWireEncodingFormat_);
                link_.set(link);

                // Clear linkWireEncoding_ since it is now managed by the link object.
                linkWireEncoding_ = new Blob();
                linkWireEncodingFormat_ = null;

                return link;
            } else
                return null;
        }