コード例 #1
0
 void
 wireDecode(const Block& wire)
 {
   m_statusList.clear();
   
   if (!wire.hasWire())
     std::cerr << "The supplied block does not contain wire format" << std::endl;
   
   if (wire.type() != statusCollector::tlv::CollectorReply)
     std::cerr << "Unexpected TLV type when decoding CollectorReply: " +
       boost::lexical_cast<std::string>(wire.type()) <<std::endl;
   
   wire.parse();
   
   for (Block::element_const_iterator it = wire.elements_begin();
        it != wire.elements_end(); it++)
   {
     if (it->type() == statusCollector::tlv::FaceStatus)
     {
       m_statusList.push_back(FaceStatus(*it));
     }
     else
       std::cerr << "No FaceStatus entry when decoding CollectorReply!!" << std::endl;
   }
 }
コード例 #2
0
  void
  wireDecode(const Block& block)
  {
    if (block.type() != statusCollector::tlv::ScriptPacket)
    {
      std::stringstream error;
      error << "Expected ScriptPacket block, but block is of different type: #" << block.type();
      std::cerr << error.str() << std::endl;
    }
  
    m_block = block;
    m_block.parse();

    Block::element_const_iterator val = m_block.elements_begin();
    Block::element_const_iterator oldVal; 

    while (val != m_block.elements_end())
    {
      oldVal = val;

      if (val != m_block.elements_end() && val->type() == ndn::statusCollector::tlv::ScriptData)
      {
        m_data.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
        ++val;
      }
      if(oldVal == val)
      {
        std::cout << "ERROR!!: About to exit" << std::endl;
        exit(1);
      }
    } 
  }
コード例 #3
0
  void
  decodeFibEntryBlock(const Data& data)
  {
    Block payload = data.getContent();

    m_buffer.appendByteArray(payload.value(), payload.value_size());

    BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
    if (data.getFinalBlockId() != data.getName()[-1])
      {
        return;
      }

    // wrap the FIB Entry blocks in a single Content TLV for easy parsing
    m_buffer.prependVarNumber(m_buffer.size());
    m_buffer.prependVarNumber(ndn::Tlv::Content);

    ndn::Block parser(m_buffer.buf(), m_buffer.size());
    parser.parse();

    BOOST_REQUIRE_EQUAL(parser.elements_size(), m_referenceEntries.size());

    for (Block::element_const_iterator i = parser.elements_begin();
         i != parser.elements_end();
         ++i)
      {
        if (i->type() != ndn::tlv::nfd::FibEntry)
          {
            BOOST_FAIL("expected fib entry, got type #" << i->type());
          }

        validateFibEntry(*i);
      }
    m_finished = true;
  }
コード例 #4
0
  void
  validateFibEntry(const Block& entry)
  {
    entry.parse();

    Block::element_const_iterator i = entry.elements_begin();
    BOOST_REQUIRE(i != entry.elements_end());


    BOOST_REQUIRE(i->type() == ndn::Tlv::Name);
    Name prefix(*i);
    ++i;

    std::set<shared_ptr<fib::Entry> >::const_iterator referenceIter =
      std::find_if(m_referenceEntries.begin(), m_referenceEntries.end(),
                   bind(&FibEnumerationPublisherFixture::entryHasPrefix,
                        this, _1, prefix));

    BOOST_REQUIRE(referenceIter != m_referenceEntries.end());

    const shared_ptr<fib::Entry>& reference = *referenceIter;
    BOOST_REQUIRE_EQUAL(prefix, reference->getPrefix());

    // 0 or more next hop records
    size_t nRecords = 0;
    const fib::NextHopList& referenceNextHops = reference->getNextHops();
    for (; i != entry.elements_end(); ++i)
      {
        const ndn::Block& nextHopRecord = *i;
        BOOST_REQUIRE(nextHopRecord.type() == ndn::tlv::nfd::NextHopRecord);
        nextHopRecord.parse();

        Block::element_const_iterator j = nextHopRecord.elements_begin();

        FaceId faceId =
          checkedReadNonNegativeIntegerType(j,
                                            entry.elements_end(),
                                            ndn::tlv::nfd::FaceId);

        uint64_t cost =
          checkedReadNonNegativeIntegerType(j,
                                            entry.elements_end(),
                                            ndn::tlv::nfd::Cost);

        BOOST_REQUIRE(hasNextHopWithCost(referenceNextHops, faceId, cost));

        BOOST_REQUIRE(j == nextHopRecord.elements_end());
        nRecords++;
      }
    BOOST_REQUIRE_EQUAL(nRecords, referenceNextHops.size());

    BOOST_REQUIRE(i == entry.elements_end());
    m_referenceEntries.erase(referenceIter);
  }
コード例 #5
0
ファイル: default-param.cpp プロジェクト: CSUL/ndn-tools
void
DefaultParam::wireDecode(const Block& wire)
{
  if (!wire.hasWire()) {
    throw Error("The supplied block does not contain wire format");
  }

  m_wire = wire;
  m_wire.parse();

  if (m_wire.type() != tlv::pib::DefaultParam)
    throw Error("Unexpected TLV type when decoding DefaultParam");

  Block::element_const_iterator it = m_wire.elements_begin();

  // the first block must be PibType
  if (it != m_wire.elements_end() && it->type() == tlv::pib::Type) {
    m_targetType = static_cast<pib::Type>(readNonNegativeInteger(*it));
    it++;
  }
  else
    throw Error("DefaultParam requires the first sub-TLV to be PibType");

  // the second block must be PibType
  if (it != m_wire.elements_end() && it->type() == tlv::pib::Type) {
    m_originType = static_cast<pib::Type>(readNonNegativeInteger(*it));
    it++;
  }
  else
    throw Error("DefaultParam requires the second sub-TLV to be PibType");

  switch (m_originType) {
  case TYPE_ID:
  case TYPE_KEY:
  case TYPE_CERT:
    {
      if (it != m_wire.elements_end()) {
        // the third block, if exists, must be Name
        m_originName.wireDecode(*it);
        return;
      }
      else {
        throw Error("DefaultParam requires the third sub-TLV to be Name");
      }
    }
  case TYPE_USER:
    return;
  default:
    throw Error("DefaultParam::wireDecode: unsupported PibType: " +
                boost::lexical_cast<std::string>(m_originType));
  }
}
コード例 #6
0
ファイル: meta-info.cpp プロジェクト: nnaren1902/ndn-cxx
void
MetaInfo::wireDecode(const Block& wire)
{
  m_wire = wire;
  m_wire.parse();

  // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
  //                ContentType?
  //                FreshnessPeriod?
  //                FinalBlockId?
  //                AppMetaInfo*


  Block::element_const_iterator val = m_wire.elements_begin();

  // ContentType
  if (val != m_wire.elements_end() && val->type() == tlv::ContentType) {
    m_type = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    m_type = TYPE_DEFAULT;
  }

  // FreshnessPeriod
  if (val != m_wire.elements_end() && val->type() == tlv::FreshnessPeriod) {
    m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    m_freshnessPeriod = time::milliseconds::min();
  }

  // FinalBlockId
  if (val != m_wire.elements_end() && val->type() == tlv::FinalBlockId) {
    m_finalBlockId = val->blockFromValue();
    if (m_finalBlockId.type() != tlv::NameComponent)
      {
        /// @todo May or may not throw exception later...
        m_finalBlockId.reset();
      }
    ++val;
  }
  else {
    m_finalBlockId.reset();
  }

  // AppMetaInfo (if any)
  for (; val != m_wire.elements().end(); ++val) {
    m_appMetaInfo.push_back(*val);
  }
}
コード例 #7
0
void
Exclude::wireDecode(const Block& wire)
{
  clear();

  if (wire.type() != tlv::Exclude)
    throw tlv::Error("Unexpected TLV type when decoding Exclude");

  m_wire = wire;
  m_wire.parse();

  if (m_wire.elements_size() == 0) {
    throw Error("Exclude element cannot be empty");
  }

  // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+
  // Any     ::= ANY-TYPE TLV-LENGTH(=0)

  Block::element_const_iterator i = m_wire.elements_begin();
  if (i->type() == tlv::Any) {
    appendExclude(name::Component(), true);
    ++i;
  }

  while (i != m_wire.elements_end()) {
    name::Component excludedComponent;
    try {
      excludedComponent = std::move(name::Component(*i));
    }
    catch (const name::Component::Error&) {
      throw Error("Incorrect format of Exclude filter");
    }

    ++i;

    if (i != m_wire.elements_end()) {
      if (i->type() == tlv::Any) {
        appendExclude(excludedComponent, true);
        ++i;
      }
      else {
        appendExclude(excludedComponent, false);
      }
    }
    else {
      appendExclude(excludedComponent, false);
    }
  }
}
コード例 #8
0
void
MulticastDiscovery::onSuccess(Data& data)
{
  const Block& content = data.getContent();
  content.parse();

  // Get Uri
  Block::element_const_iterator blockValue = content.find(tlv::nfd::Uri);
  if (blockValue == content.elements_end()) {
    m_nextStageOnFailure("Incorrect reply to multicast discovery stage");
    return;
  }
  std::string hubUri(reinterpret_cast<const char*>(blockValue->value()), blockValue->value_size());
  this->connectToHub(hubUri);
}
コード例 #9
0
ファイル: exclude.cpp プロジェクト: cawka/ndn-cxx
void
Exclude::wireDecode(const Block& wire)
{
  clear();

  if (wire.type() != tlv::Exclude)
    BOOST_THROW_EXCEPTION(tlv::Error("Unexpected TLV type when decoding Exclude"));

  m_wire = wire;
  m_wire.parse();

  if (m_wire.elements_size() == 0) {
    BOOST_THROW_EXCEPTION(Error("Exclude element cannot be empty"));
  }

  // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (GenericNameComponent (Any)?)+
  // Any     ::= ANY-TYPE TLV-LENGTH(=0)

  Block::element_const_iterator i = m_wire.elements_begin();
  if (i->type() == tlv::Any) {
    this->appendEntry(true, true);
    ++i;
  }

  while (i != m_wire.elements_end()) {
    name::Component component;
    try {
      component = name::Component(*i);
    }
    catch (const name::Component::Error&) {
      BOOST_THROW_EXCEPTION(Error("Incorrect format of Exclude filter"));
    }
    if (!component.isGeneric() && !component.isImplicitSha256Digest()) {
      BOOST_THROW_EXCEPTION(Error("Excluded component must be generic or ImplicitSha256Digest"));
    }
    ++i;

    if (i != m_wire.elements_end() && i->type() == tlv::Any) {
      this->appendEntry(component, true);
      ++i;
    }
    else {
      this->appendEntry(component, false);
    }
  }
}
コード例 #10
0
void
Manifest::decode()
{
    Block content = getContent();
    content.parse();

    // Manifest ::= CONTENT-TLV TLV-LENGTH
    //                Catalogue?
    //                  Name*
    //                KeyValuePair*

    for ( Block::element_const_iterator val = content.elements_begin();
            val != content.elements_end(); ++val)
    {
        if (val->type() == tlv::ManifestCatalogue)
        {
            val->parse();
            for ( Block::element_const_iterator catalogueNameElem = val->elements_begin();
                    catalogueNameElem != val->elements_end(); ++catalogueNameElem)
            {
                if (catalogueNameElem->type() == tlv::Name)
                {
                    Name name(*catalogueNameElem);
                    m_catalogueNames.push_back(name);
                }
            }
        }
        else if (val->type() == tlv::KeyValuePair)
        {
            std::string str((char*)val->value(), val->value_size());

            size_t index = str.find_first_of('=');
            if (index == std::string::npos || index == 0 || (index == str.size() - 1))
                continue;

            std::string key = str.substr(0, index);
            std::string value = str.substr(index + 1, str.size() - index - 1);
            addKeyValuePair(key, value);
        }
    }
}
コード例 #11
0
ファイル: cache-policy.cpp プロジェクト: cawka/ndn-cxx
void
CachePolicy::wireDecode(const Block& wire)
{
  if (wire.type() != tlv::CachePolicy) {
    BOOST_THROW_EXCEPTION(Error("expecting CachePolicy block"));
  }

  m_wire = wire;
  m_wire.parse();

  Block::element_const_iterator it = m_wire.elements_begin();
  if (it != m_wire.elements_end() && it->type() == tlv::CachePolicyType) {
    m_policy = static_cast<CachePolicyType>(readNonNegativeInteger(*it));
    if (this->getPolicy() == CachePolicyType::NONE) {
      BOOST_THROW_EXCEPTION(Error("unknown CachePolicyType"));
    }
  }
  else {
    BOOST_THROW_EXCEPTION(Error("expecting CachePolicyType block"));
  }
}
コード例 #12
0
void
EndorseExtension::wireDecode(const Block& endorseWire)
{
  m_wire = endorseWire;
  m_wire.parse();

  // EndorseExtension := ENDORSE-EXTENSION-TYPE TLV-LENGTH
  //                       EntryData+
  //
  // EntryData := ENTRYDATA-TYPE TLV-LENGTH
  //                String
  //

  if (m_wire.type() != tlv::EndorseExtension)
    throw Error("Unexpected TLV number when decoding endorse extension packet");

  // EntryData
  Block::element_const_iterator i = m_wire.elements_begin();
  if (i == m_wire.elements_end())
    throw Error("Missing Entry Data");
  if (i->type() != tlv::EntryData)
    throw Error("Expect Entry Data but get TLV Type " + std::to_string(i->type()));

   while (i != m_wire.elements_end() && i->type() == tlv::EntryData) {
     m_entries.push_back(std::string(reinterpret_cast<const char* >(i->value()),
                                     i->value_size()));
     ++i;
  }

  if (i != m_wire.elements_end()) {
    throw Error("Unexpected element");
  }
}
コード例 #13
0
void
StrategyChoice::wireDecode(const Block& block)
{
    if (block.type() != tlv::nfd::StrategyChoice) {
        throw Error("expecting StrategyChoice block");
    }
    m_wire = block;
    m_wire.parse();
    Block::element_const_iterator val = m_wire.elements_begin();

    if (val != m_wire.elements_end() && val->type() == tlv::Name) {
        m_name.wireDecode(*val);
        ++val;
    }
    else {
        throw Error("missing required Name field");
    }

    if (val != m_wire.elements_end() && val->type() == tlv::nfd::Strategy) {
        val->parse();
        if (val->elements().empty()) {
            throw Error("expecting Strategy/Name");
        }
        else {
            m_strategy.wireDecode(*val->elements_begin());
        }
        ++val;
    }
    else {
        throw Error("missing required Strategy field");
    }
}
コード例 #14
0
void
FibEntry::wireDecode(const Block& wire)
{
  m_prefix.clear();
  m_nextHopRecords.clear();

  m_wire = wire;

  if (m_wire.type() != tlv::nfd::FibEntry) {
    std::stringstream error;
    error << "Requested decoding of FibEntry, but Block is of a different type: #"
          << m_wire.type();
    BOOST_THROW_EXCEPTION(Error(error.str()));
  }

  m_wire.parse();

  Block::element_const_iterator val = m_wire.elements_begin();
  if (val == m_wire.elements_end()) {
    BOOST_THROW_EXCEPTION(Error("Unexpected end of FibEntry"));
  }
  else if (val->type() != tlv::Name) {
    std::stringstream error;
    error << "Expected Name, but Block is of a different type: #"
          << val->type();
    BOOST_THROW_EXCEPTION(Error(error.str()));
  }
  m_prefix.wireDecode(*val);
  ++val;

  for (; val != m_wire.elements_end(); ++val) {
    if (val->type() != tlv::nfd::NextHopRecord) {
      std::stringstream error;
      error << "Expected NextHopRecords, but Block is of a different type: #"
            << val->type();
      BOOST_THROW_EXCEPTION(Error(error.str()));
    }
    m_nextHopRecords.push_back(NextHopRecord(*val));
  }
}
コード例 #15
0
ファイル: nfd-rib-entry.cpp プロジェクト: WeiqiJust/NDN-total
void
RibEntry::wireDecode(const Block& wire)
{
  m_prefix.clear();
  m_routes.clear();

  m_wire = wire;

  if (m_wire.type() != tlv::nfd::RibEntry) {
    std::stringstream error;
    error << "Expected RibEntry Block, but Block is of a different type: #"
          << m_wire.type();
    throw Error(error.str());
  }

  m_wire.parse();

  Block::element_const_iterator val = m_wire.elements_begin();

  if (val != m_wire.elements_end() && val->type() == tlv::Name) {
    m_prefix.wireDecode(*val);
    ++val;
  }
  else {
    throw Error("Missing required Name field");
  }

  for (; val != m_wire.elements_end(); ++val) {

    if (val->type() == tlv::nfd::Route) {
      m_routes.push_back(Route(*val));
    }
    else {
      std::stringstream error;
      error << "Expected Route Block, but Block is of a different type: #"
            << m_wire.type();
      throw Error(error.str());
    }
  }
}
コード例 #16
0
void
NextHopRecord::wireDecode(const Block& wire)
{
  m_faceId = std::numeric_limits<uint64_t>::max();
  m_cost = 0;

  m_wire = wire;

  if (m_wire.type() != tlv::nfd::NextHopRecord) {
    std::stringstream error;
    error << "Requested decoding of NextHopRecord, but Block is of a different type: #"
          << m_wire.type();
    BOOST_THROW_EXCEPTION(Error(error.str()));
  }
  m_wire.parse();

  Block::element_const_iterator val = m_wire.elements_begin();
  if (val == m_wire.elements_end()) {
    BOOST_THROW_EXCEPTION(Error("Unexpected end of NextHopRecord"));
  }
  else if (val->type() != tlv::nfd::FaceId) {
    std::stringstream error;
    error << "Expected FaceId, but Block is of a different type: #"
          << val->type();
    BOOST_THROW_EXCEPTION(Error(error.str()));
  }
  m_faceId = readNonNegativeInteger(*val);
  ++val;

  if (val == m_wire.elements_end()) {
    BOOST_THROW_EXCEPTION(Error("Unexpected end of NextHopRecord"));
  }
  else if (val->type() != tlv::nfd::Cost) {
    std::stringstream error;
    error << "Expected Cost, but Block is of a different type: #"
          << m_wire.type();
    BOOST_THROW_EXCEPTION(Error(error.str()));
  }
  m_cost = readNonNegativeInteger(*val);
}
コード例 #17
0
void
NackHeader::wireDecode(const Block& wire)
{
  if (wire.type() != tlv::Nack) {
    BOOST_THROW_EXCEPTION(ndn::tlv::Error("expecting Nack block"));
  }

  m_wire = wire;
  m_wire.parse();
  m_reason = NackReason::NONE;

  if (m_wire.elements_size() > 0) {
    Block::element_const_iterator it = m_wire.elements_begin();

    if (it->type() == tlv::NackReason) {
      m_reason = static_cast<NackReason>(readNonNegativeInteger(*it));
    }
    else {
      BOOST_THROW_EXCEPTION(ndn::tlv::Error("expecting NackReason block"));
    }
  }
}
コード例 #18
0
  static void
  decodeRibEntryBlock(const Data& data, const Name& referenceName, const FaceEntry& referenceFace)
  {
    ndn::EncodingBuffer buffer;

    Block payload = data.getContent();

    buffer.appendByteArray(payload.value(), payload.value_size());
    buffer.prependVarNumber(buffer.size());
    buffer.prependVarNumber(ndn::Tlv::Content);

    ndn::Block parser(buffer.buf(), buffer.size());
    parser.parse();

    Block::element_const_iterator i = parser.elements_begin();

    if (i->type() != ndn::tlv::nfd::RibEntry) {
      BOOST_FAIL("expected RibEntry, got type #" << i->type());
    }
    else {
      validateRibEntry(*i, referenceName, referenceFace);
    }
  }
コード例 #19
0
  void
  decodeFaceStatusBlock(const Data& data)
  {
    Block payload = data.getContent();

    m_buffer.appendByteArray(payload.value(), payload.value_size());

    BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment());
    if (data.getFinalBlockId() != data.getName()[-1])
      {
        return;
      }

    // wrap the Face Statuses in a single Content TLV for easy parsing
    m_buffer.prependVarNumber(m_buffer.size());
    m_buffer.prependVarNumber(tlv::Content);

    ndn::Block parser(m_buffer.buf(), m_buffer.size());
    parser.parse();

    BOOST_REQUIRE_EQUAL(parser.elements_size(), m_referenceFaces.size());

    std::list<shared_ptr<Face> >::const_iterator iReference = m_referenceFaces.begin();
    for (Block::element_const_iterator i = parser.elements_begin();
         i != parser.elements_end();
         ++i)
      {
        if (i->type() != ndn::tlv::nfd::FaceStatus)
          {
            BOOST_FAIL("expected face status, got type #" << i->type());
          }
        validateFaceStatus(*i, *iReference);
        ++iReference;
      }
    m_finished = true;
  }
コード例 #20
0
void
FaceQueryFilter::wireDecode(const Block& block)
{
  //all fields are optional
  if (block.type() != tlv::nfd::FaceQueryFilter) {
    BOOST_THROW_EXCEPTION(Error("expecting FaceQueryFilter block"));
  }

  m_wire = block;
  m_wire.parse();
  Block::element_const_iterator val = m_wire.elements_begin();

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
    m_faceId = readNonNegativeInteger(*val);
    m_hasFaceId = true;
    ++val;
  }
  else {
    m_hasFaceId = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::UriScheme) {
    m_uriScheme.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    m_hasUriScheme = true;
    ++val;
  }
  else {
    m_hasUriScheme = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
    m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    m_hasRemoteUri = true;
    ++val;
  }
  else {
    m_hasRemoteUri = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
    m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    m_hasLocalUri = true;
    ++val;
  }
  else {
    m_hasLocalUri = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
    m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val));
    m_hasFaceScope = true;
    ++val;
  }
  else {
    m_hasFaceScope = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
    m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val));
    m_hasFacePersistency = true;
    ++val;
  }
  else {
    m_hasFacePersistency = false;
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
    m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val));
    m_hasLinkType = true;
    ++val;
  }
  else {
    m_hasLinkType = false;
  }

}
コード例 #21
0
void
FaceStatus::wireDecode(const Block& block)
{
  if (block.type() != tlv::nfd::FaceStatus) {
    BOOST_THROW_EXCEPTION(Error("expecting FaceStatus block"));
  }
  m_wire = block;
  m_wire.parse();
  Block::element_const_iterator val = m_wire.elements_begin();

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
    m_faceId = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required FaceId field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
    m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required Uri field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
    m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required LocalUri field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::ExpirationPeriod) {
    m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
    m_hasExpirationPeriod = true;
    ++val;
  }
  else {
    m_hasExpirationPeriod = false;
    // ExpirationPeriod is optional
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
    m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required FaceScope field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
    m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required FacePersistency field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
    m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required LinkType field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
    m_nInInterests = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NInInterests field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) {
    m_nInDatas = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NInDatas field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
    m_nInNacks = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
    m_nOutInterests = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) {
    m_nOutDatas = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
    m_nOutNacks = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInBytes) {
    m_nInBytes = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NInBytes field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutBytes) {
    m_nOutBytes = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required NOutBytes field"));
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
    m_flags = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    BOOST_THROW_EXCEPTION(Error("missing required Flags field"));
  }
}
コード例 #22
0
  void
  wireDecode(const Block& wire)
  {
    m_tx = 0;
    m_rx = 0;
    m_faceId = 0;
    m_linkIp.empty();
    m_timestamp.empty();
    
    
    if (wire.type() != statusCollector::tlv::FaceStatus)
    {
      std::stringstream error;
      error << "Expected FaceStatus Block, but Block is of a different type: #" << wire.type();
      std::cerr << error.str() << std::endl;
    }
    
    m_wire = wire;
    m_wire.parse();
    
    Block::element_const_iterator val = m_wire.elements_begin();
    Block::element_const_iterator oldVal;
    while (val != m_wire.elements_end())
    {
      oldVal = val;

     // std::cout << "Block is of type: #" << m_wire.type() << std::endl;
      if (val != m_wire.elements_end() && val->type() == ndn::statusCollector::tlv::RX)
      {
        m_rx = readNonNegativeInteger(*val);
        ++val;
      }
      if (val != m_wire.elements_end() && val->type() == ndn::statusCollector::tlv::TX)
      {
        m_tx = readNonNegativeInteger(*val);
        ++val;
      }
      
      if (val != m_wire.elements_end() && val->type() == ndn::statusCollector::tlv::FaceId)
      {
        m_faceId = readNonNegativeInteger(*val);
        ++val;
      }
      
      if (val != m_wire.elements_end() && val->type() == ndn::statusCollector::tlv::LinkIp)
      {
        m_linkIp.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
        ++val;
      }
      
      if (val != m_wire.elements_end() && val->type() == ndn::statusCollector::tlv::CurrentTime)
      {
        m_timestamp.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
        ++val;
      }
      
      if(oldVal == val)
      {
        std::cout << "ERROR!!: About to exit" << std::endl;
        exit(1);
      }
    }
  }
コード例 #23
0
ファイル: nfd-rib-entry.cpp プロジェクト: WeiqiJust/NDN-total
void
Route::wireDecode(const Block& wire)
{
  m_faceId = 0;
  m_origin = 0;
  m_cost = 0;
  m_flags = 0;
  m_expirationPeriod = time::milliseconds::min();

  m_wire = wire;

  if (m_wire.type() != tlv::nfd::Route) {
    std::stringstream error;
    error << "Expected Route Block, but Block is of a different type: #"
          << m_wire.type();
    throw Error(error.str());
  }

  m_wire.parse();

  Block::element_const_iterator val = m_wire.elements_begin();

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
    m_faceId = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    throw Error("Missing required FaceId field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Origin) {
    m_origin = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    throw Error("Missing required Origin field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Cost) {
    m_cost = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    throw Error("Missing required Cost field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
    m_flags = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    throw Error("Missing required Flags field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::ExpirationPeriod) {
    m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
    m_hasInfiniteExpirationPeriod = false;
  }
  else {
    m_expirationPeriod = INFINITE_EXPIRATION_PERIOD;
    m_hasInfiniteExpirationPeriod = true;
  }
}
コード例 #24
0
void
Schedule::wireDecode(const Block& wire)
{
  if (wire.type() != tlv::Schedule)
    BOOST_THROW_EXCEPTION(tlv::Error("Unexpected TLV type when decoding RepetitiveInterval"));

  m_wire = wire;
  m_wire.parse();

  if (m_wire.elements_size() != 2)
    BOOST_THROW_EXCEPTION(tlv::Error("RepetitiveInterval tlv does not have two sub-TLVs"));

  Block::element_const_iterator it = m_wire.elements_begin();

  if (it != m_wire.elements_end() && it->type() == tlv::WhiteIntervalList) {
    it->parse();
    Block::element_const_iterator tempIt = it->elements_begin();
    while (tempIt != it->elements_end() && tempIt->type() == tlv::RepetitiveInterval) {
      m_whiteIntervalList.insert(RepetitiveInterval(*tempIt));
      tempIt++;
    }
    it++;
  }

  if (it != m_wire.elements_end() && it->type() == tlv::BlackIntervalList) {
    it->parse();
    Block::element_const_iterator tempIt = it->elements_begin();
    while (tempIt != it->elements_end() && tempIt->type() == tlv::RepetitiveInterval) {
      m_blackIntervalList.insert(RepetitiveInterval(*tempIt));
      tempIt++;
    }
    it++;
  }
}
コード例 #25
0
void
ChatroomInfo::wireDecode(const Block& chatroomWire)
{
  m_wire = chatroomWire;
  m_wire.parse();

  m_participants.clear();

  // ChatroomInfo := CHATROOM-INFO-TYPE TLV-LENGTH
  //                   ChatroomName
  //                   TrustModel
  //                   ChatroomPrefix
  //                   ManagerPrefix
  //                   Participants
  //
  // ChatroomName := CHATROOM-NAME-TYPE TLV-LENGTH
  //                   NameComponent
  //
  // TrustModel := TRUST-MODEL-TYPE TLV-LENGTH
  //                 nonNegativeInteger
  //
  // ChatroomPrefix := CHATROOM-PREFIX-TYPE TLV-LENGTH
  //                     Name
  //
  // ManagerPrefix := MANAGER-PREFIX-TYPE TLV-LENGTH
  //                    Name
  //
  // Participants := PARTICIPANTS-TYPE TLV-LENGTH
  //                   Name+

  if (m_wire.type() != tlv::ChatroomInfo)
    throw Error("Unexpected TLV number when decoding chatroom packet");

  // Chatroom Info
  Block::element_const_iterator i = m_wire.elements_begin();
  if (i == m_wire.elements_end())
    throw Error("Missing Chatroom Name");
  if (i->type() != tlv::ChatroomName)
    throw Error("Expect Chatroom Name but get TLV Type " + std::to_string(i->type()));
  m_chatroomName.wireDecode(i->blockFromValue());
  ++i;

  // Trust Model
  if (i == m_wire.elements_end())
    throw Error("Missing Trust Model");
  if (i->type() != tlv::TrustModel)
    throw Error("Expect Trust Model but get TLV Type " + std::to_string(i->type()));
  m_trustModel =
      static_cast<TrustModel>(readNonNegativeInteger(*i));
  ++i;

  // Chatroom Sync Prefix
  if (i == m_wire.elements_end())
    throw Error("Missing Chatroom Prefix");
  if (i->type() != tlv::ChatroomPrefix)
    throw Error("Expect Chatroom Prefix but get TLV Type " + std::to_string(i->type()));
  m_syncPrefix.wireDecode(i->blockFromValue());
  ++i;

  // Manager Prefix
  if (i == m_wire.elements_end())
    throw Error("Missing Manager Prefix");
  if (i->type() != tlv::ManagerPrefix)
    throw Error("Expect Manager Prefix but get TLV Type " + std::to_string(i->type()));
  m_manager.wireDecode(i->blockFromValue());
  ++i;

  // Participants
  if (i == m_wire.elements_end())
    throw Error("Missing Participant");
  if (i->type() != tlv::Participants)
    throw Error("Expect Participant but get TLV Type " + std::to_string(i->type()));

  Block temp = *i;
  temp.parse();

  Block::element_const_iterator j = temp.elements_begin();

  while (j != temp.elements_end() && j->type() == tlv::Name) {
    m_participants.push_back(Name(*j));
    ++j;
  }
  if (j != temp.elements_end())
    throw Error("Unexpected element");

  if (m_participants.empty())
    throw Error("No participant in the chatroom");

  ++i;

  if (i != m_wire.elements_end()) {
    throw Error("Unexpected element");
  }
}
void
FaceEventNotification::wireDecode(const Block& block)
{
  if (block.type() != tlv::nfd::FaceEventNotification) {
    throw Error("expecting FaceEventNotification block");
  }
  m_wire = block;
  m_wire.parse();
  Block::element_const_iterator val = m_wire.elements_begin();

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceEventKind) {
    m_kind = static_cast<FaceEventKind>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    throw Error("missing required FaceEventKind field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
    m_faceId = readNonNegativeInteger(*val);
    ++val;
  }
  else {
    throw Error("missing required FaceId field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
    m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    ++val;
  }
  else {
    throw Error("missing required Uri field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
    m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
    ++val;
  }
  else {
    throw Error("missing required LocalUri field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
    m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    throw Error("missing required FaceScope field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
    m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    throw Error("missing required FacePersistency field");
  }

  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
    m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val));
    ++val;
  }
  else {
    throw Error("missing required LinkType field");
  }
}
コード例 #27
0
void
ControlParameters::wireDecode(const Block& block)
{
  if (block.type() != tlv::nfd::ControlParameters) {
    throw Error("expecting TLV-TYPE ControlParameters");
  }
  m_wire = block;
  m_wire.parse();
  Block::element_const_iterator val;

  val = m_wire.find(tlv::Name);
  m_hasFields[CONTROL_PARAMETER_NAME] = val != m_wire.elements_end();
  if (this->hasName()) {
    m_name.wireDecode(*val);
  }

  val = m_wire.find(tlv::nfd::FaceId);
  m_hasFields[CONTROL_PARAMETER_FACE_ID] = val != m_wire.elements_end();
  if (this->hasFaceId()) {
    m_faceId = static_cast<uint64_t>(readNonNegativeInteger(*val));
  }

  val = m_wire.find(tlv::nfd::Uri);
  m_hasFields[CONTROL_PARAMETER_URI] = val != m_wire.elements_end();
  if (this->hasUri()) {
    m_uri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
  }

  val = m_wire.find(tlv::nfd::LocalControlFeature);
  m_hasFields[CONTROL_PARAMETER_LOCAL_CONTROL_FEATURE] = val != m_wire.elements_end();
  if (this->hasLocalControlFeature()) {
    m_localControlFeature = static_cast<LocalControlFeature>(readNonNegativeInteger(*val));
  }

  val = m_wire.find(tlv::nfd::Origin);
  m_hasFields[CONTROL_PARAMETER_ORIGIN] = val != m_wire.elements_end();
  if (this->hasOrigin()) {
    m_origin = static_cast<uint64_t>(readNonNegativeInteger(*val));
  }

  val = m_wire.find(tlv::nfd::Cost);
  m_hasFields[CONTROL_PARAMETER_COST] = val != m_wire.elements_end();
  if (this->hasCost()) {
    m_cost = static_cast<uint64_t>(readNonNegativeInteger(*val));
  }

  val = m_wire.find(tlv::nfd::Flags);
  m_hasFields[CONTROL_PARAMETER_FLAGS] = val != m_wire.elements_end();
  if (this->hasFlags()) {
    m_flags = static_cast<uint64_t>(readNonNegativeInteger(*val));
  }

  val = m_wire.find(tlv::nfd::Strategy);
  m_hasFields[CONTROL_PARAMETER_STRATEGY] = val != m_wire.elements_end();
  if (this->hasStrategy()) {
    val->parse();
    if (val->elements().empty()) {
      throw Error("expecting Strategy/Name");
    }
    else {
      m_strategy.wireDecode(*val->elements_begin());
    }
  }

  val = m_wire.find(tlv::nfd::ExpirationPeriod);
  m_hasFields[CONTROL_PARAMETER_EXPIRATION_PERIOD] = val != m_wire.elements_end();
  if (this->hasExpirationPeriod()) {
    m_expirationPeriod = time::milliseconds(readNonNegativeInteger(*val));
  }
}