Beispiel #1
0
  @Test
  public void testContentNameByteArrayArray() throws MalformedContentNameStringException {
    byte[][] arr = new byte[4][];
    arr[0] = baseName.getBytes();
    arr[1] = subName1.getBytes();
    arr[2] = document1.getBytes();
    System.out.println("Creating name from byte arrays.");
    ContentName name = new ContentName(3, arr);
    assertNotNull(name);
    System.out.println("Name: " + name);
    assertEquals(
        name,
        ContentName.fromURI(
            ContentName.SEPARATOR
                + baseName
                + ContentName.SEPARATOR
                + subName1
                + ContentName.SEPARATOR
                + document1));

    arr[3] = document3;
    ContentName name2 = new ContentName(arr);
    assertNotNull(name2);
    System.out.println("Name 2: " + name2);
    assertEquals(name2.count(), 4);
    assertEquals(name2.components().size(), 4);
    assert (DataUtils.arrayEquals(name2.component(0), arr[0]));
    assert (DataUtils.arrayEquals(name2.component(1), arr[1]));
    assert (DataUtils.arrayEquals(name2.component(2), arr[2]));
    assert (DataUtils.arrayEquals(name2.component(3), arr[3]));
  }
Beispiel #2
0
  @Test
  public void testGetFirstDigest() {
    Log.info(Log.FAC_TEST, "Starting testGetFirstDigest");

    long received = 0;
    byte[] bytes = new byte[1024];

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e3) {
      Log.warning(Log.FAC_TEST, "failed to get first digest for pipeline test:");
      Assert.fail();
    }
    try {
      istream.close();
    } catch (IOException e2) {
      Log.warning(Log.FAC_TEST, "failed to close stream for pipeline test: " + e2.getMessage());
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "start first segment digest " + DataUtils.printBytes(firstDigest));

    try {
      istream = new CCNInputStream(testName, readHandle);
    } catch (IOException e1) {
      Log.warning(Log.FAC_TEST, "failed to open stream for pipeline test: " + e1.getMessage());
      Assert.fail();
    }

    while (!istream.eof()) {
      try {
        received += istream.read(bytes);
      } catch (IOException e) {
        Log.warning(Log.FAC_TEST, "failed to read segments: " + e.getMessage());
        Assert.fail();
      }
    }
    Assert.assertTrue(received == bytesWritten);
    try {
      Assert.assertTrue(DataUtils.arrayEquals(firstDigest, istream.getFirstDigest()));
    } catch (IOException e) {
      Log.warning(Log.FAC_TEST, "failed to get first digest after reading in pipeline test:");
      Assert.fail();
    }
    Log.info(Log.FAC_TEST, "end first segment digest " + DataUtils.printBytes(firstDigest));

    Log.info(Log.FAC_TEST, "Completed testGetFirstDigest");
  }
Beispiel #3
0
  @Test
  public void testMultilevelString() throws MalformedContentNameStringException {
    // Test multilevel construction with Strings,
    // i.e. methods that take a parent and then additional components
    ContentName parent =
        ContentName.fromURI(ContentName.SEPARATOR + baseName + ContentName.SEPARATOR + subName1);
    assertNotNull(parent);
    assertEquals(parent.count(), 2);
    String childExtension = document1 + ContentName.SEPARATOR + document2;
    String[] childComps = new String[] {document1, document2};
    ContentName child = null;

    // URI case
    // Note: fromURI takes only one additional component, ignores rest
    child = ContentName.fromURI(parent, childExtension);
    System.out.println("Child is (URI): " + child);
    assertNotNull(child);
    assertEquals(child.count(), 3); // lose the last component
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));

    child = ContentName.fromNative(parent, document1);
    System.out.println("Child is (native, one additional comp): " + child);
    assertNotNull(child);
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.count(), 3);
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));

    child = ContentName.fromNative(parent, childComps[0], childComps[1]);
    System.out.println("Child is (native): " + child);
    assertNotNull(child);
    ContentName child2 = ContentName.fromNative(parent, childComps);
    System.out.println("Child2 is (native): " + child2);
    assertNotNull(child2);
    assertEquals(child, child2);
    assertEquals(child2, child);
    assertTrue(parent.isPrefixOf(child));
    assertEquals(child.count(), 4);
    assertEquals(child.cut(document1.getBytes()), parent);
    assertTrue(DataUtils.arrayEquals(child.component(2), document1.getBytes()));
    assertTrue(DataUtils.arrayEquals(child.component(3), document2.getBytes()));
  }
  @Test
  public void testAutomatedDereferenceForStreams() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForStreams");

    Link bigDataLink =
        new Link(
            bigData,
            "big",
            new LinkAuthenticator(new PublisherID(putHandle.keyManager().getDefaultKeyID())));
    LinkObject bigDataLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForStreams", "bigDataLink"),
            bigDataLink,
            SaveType.REPOSITORY,
            putHandle);
    bigDataLinkObject.save();
    TestUtils.checkObject(putHandle, bigDataLinkObject);

    Link twoHopLink = new Link(bigDataLinkObject.getBaseName());
    LinkObject twoHopLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForStreams", "twoHopLink"),
            twoHopLink,
            SaveType.REPOSITORY,
            putHandle);
    twoHopLinkObject.save();
    TestUtils.checkObject(putHandle, twoHopLinkObject);

    CCNReader reader = new CCNReader(putHandle);
    byte[] bigDataReadback =
        reader.getVersionedData(
            bigDataLinkObject.getVersionedName(), null, SystemConfiguration.getDefaultTimeout());
    byte[] bdrdigest = CCNDigestHelper.digest(bigDataReadback);
    Log.info(
        Log.FAC_TEST,
        "Read back big data via link, got "
            + bigDataReadback.length
            + " bytes of an expected "
            + bigDataLength
            + ", digest match? "
            + (0 == DataUtils.compare(bdrdigest, bigValueDigest)));
    Assert.assertEquals(bigDataLength, bigDataReadback.length);
    Assert.assertArrayEquals(bdrdigest, bigValueDigest);

    byte[] bigDataReadback2 =
        reader.getVersionedData(
            twoHopLinkObject.getBaseName(), null, SystemConfiguration.getDefaultTimeout());
    byte[] bdr2digest = CCNDigestHelper.digest(bigDataReadback);
    Log.info(
        Log.FAC_TEST,
        "Read back big data via two links, got "
            + bigDataReadback2.length
            + " bytes of an expected "
            + bigDataLength
            + ", digest match? "
            + (0 == DataUtils.compare(bdr2digest, bigValueDigest)));
    Assert.assertEquals(bigDataLength, bigDataReadback2.length);
    Assert.assertArrayEquals(bdr2digest, bigValueDigest);

    Log.info(Log.FAC_TEST, "Completed testAutomatedDereferenceForStreams");
  }
Beispiel #5
0
  public Interest handleContent(ContentObject result, Interest interest) {
    Log.finest(
        Log.FAC_TEST, "Interests registered: " + _interests.size() + " content object returned");
    // Parameterized behavior that subclasses can override.
    ContentName interestName = null;
    if (_processedObjects.contains(result)) {
      Log.fine(
          Log.FAC_TEST,
          "FLOSSER: Got repeated content for interest: {0} content: {1}",
          interest,
          result.name());
    } else {
      Log.finest(
          Log.FAC_TEST,
          "FLOSSER: Got new content for interest {0} content name: {1}",
          interest,
          result.name());
      processContent(result);
      // update the interest. follow process used by ccnslurp.
      // exclude the next component of this object, and set up a
      // separate interest to explore its children.
      // first, remove the interest from our list as we aren't going to
      // reexpress it in exactly the same way
      synchronized (_interests) {
        for (Entry<ContentName, Interest> entry : _interests.entrySet()) {
          if (entry.getValue().equals(interest)) {
            interestName = entry.getKey();
            _interests.remove(interestName);
            break;
          }
        }
      }

      int prefixCount = interest.name().count();
      // DKS TODO should the count above be count()-1 and this just prefixCount?
      if (prefixCount == result.name().count()) {
        if (null == interest.exclude()) {
          ArrayList<Exclude.Element> excludes = new ArrayList<Exclude.Element>();
          excludes.add(new ExcludeComponent(result.digest()));
          interest.exclude(new Exclude(excludes));
          Log.finest(Log.FAC_TEST, "Creating new exclude filter for interest {0}", interest.name());
        } else {
          if (interest.exclude().match(result.digest())) {
            Log.fine(
                Log.FAC_TEST,
                "We should have already excluded content digest: "
                    + DataUtils.printBytes(result.digest()));
          } else {
            // Has to be in order...
            Log.finest(Log.FAC_TEST, "Adding child component to exclude.");
            interest.exclude().add(new byte[][] {result.digest()});
          }
        }
        Log.finer(
            Log.FAC_TEST,
            "Excluding content digest: "
                + DataUtils.printBytes(result.digest())
                + " onto interest {0} total excluded: "
                + interest.exclude().size(),
            interest.name());
      } else {
        // Add an exclude for the content we just got
        // DKS TODO might need to split to matchedComponents like ccnslurp
        if (null == interest.exclude()) {
          ArrayList<Exclude.Element> excludes = new ArrayList<Exclude.Element>();
          excludes.add(new ExcludeComponent(result.name().component(prefixCount)));
          interest.exclude(new Exclude(excludes));
          Log.finest(Log.FAC_TEST, "Creating new exclude filter for interest {0}", interest.name());
        } else {
          if (interest.exclude().match(result.name().component(prefixCount))) {
            Log.fine(
                Log.FAC_TEST,
                "We should have already excluded child component: {0}",
                ContentName.componentPrintURI(result.name().component(prefixCount)));
          } else {
            // Has to be in order...
            Log.finest(Log.FAC_TEST, "Adding child component to exclude.");
            interest.exclude().add(new byte[][] {result.name().component(prefixCount)});
          }
        }
        Log.finer(
            Log.FAC_TEST,
            "Excluding child "
                + ContentName.componentPrintURI(result.name().component(prefixCount))
                + " total excluded: "
                + interest.exclude().size());

        if (_flossSubNamespaces
            || SegmentationProfile.isNotSegmentMarker(result.name().component(prefixCount))) {
          ContentName newNamespace = null;
          try {
            if (interest.name().count() == result.name().count()) {
              newNamespace = new ContentName(interest.name(), result.digest());
              Log.info(Log.FAC_TEST, "Not adding content exclusion namespace: {0}", newNamespace);
            } else {
              newNamespace =
                  new ContentName(
                      interest.name(), result.name().component(interest.name().count()));
              Log.info(Log.FAC_TEST, "Adding new namespace: {0}", newNamespace);
              handleNamespace(newNamespace, interest.name());
            }
          } catch (IOException ioex) {
            Log.warning("IOException picking up namespace: {0}", newNamespace);
          }
        }
      }
    }
    if (null != interest)
      synchronized (_interests) {
        _interests.put(interest.name(), interest);
      }
    return interest;
  }