Exemplo n.º 1
0
void
Nlsrc::onControlResponse(const std::string& info, const ndn::Data& data)
{
    if (data.getMetaInfo().getType() == ndn::tlv::ContentType_Nack) {
        std::cerr << "ERROR: Run-time advertise/withdraw disabled" << std::endl;
        return;
    }

    ndn::nfd::ControlResponse response;

    try {
        response.wireDecode(data.getContent().blockFromValue());
    }
    catch (const std::exception& e) {
        std::cerr << "ERROR: Control response decoding error" << std::endl;
        return;
    }

    uint32_t code = response.getCode();

    if (code != RESPONSE_CODE_SUCCESS) {
        std::cerr << "Name prefix update error (code: " << code << ")" << std::endl;
        return;
    }

    std::cout << "Applied Name prefix update successfully: " << info << std::endl;
}
void
EdgeStrategy::toNack( ndn::Data& data, const ndn::Interest& interest )
{
    // ensure that denied data doesn't leave the network
    data.setContent( ndn::Block() );
    data.wireEncode();
    
    // do whatever a normal router would do
    RouterStrategy::toNack( data, interest );
}
void
EdgeStrategy::toPreserve( ndn::Data& data,
                          const ndn::Interest& interest )
{
    if( data.getContentType() == ndn::tlv::ContentType_Nack )
    {
        data.setContent( ndn::Block() );
        data.wireEncode();
    }
}
 void
 onData( ndn::Face &face,
         const ndn::Interest& interest,
         ndn::Data& data,
         int globalReference,
         int localReference,
         int patternId,
         boost::posix_time::ptime sentTime )
 {
   double roundTripTime;
   int receivedContentLength;
   std::string receivedContent;
   std::string logLine;
   logLine = "";
   logLine += "Data Received      - PatternType="+toString(patternId+1);
   logLine += ", GlobalID="+toString(globalReference);
   logLine += ", LocalID="+toString(localReference);
   logLine += ", Name="+interest.getName().toUri();
   boost::posix_time::time_duration roundTripDuration;
   totalInterestReceived_++;
   trafficPattern_[patternId].totalInterestReceived++;
   if (trafficPattern_[patternId].expectedContent != "")
   {
     receivedContent = (char*)(data.getContent().value());
     receivedContentLength = data.getContent().value_size();
     receivedContent = receivedContent.substr(0, receivedContentLength);
     if (receivedContent != trafficPattern_[patternId].expectedContent)
     {
       contentInconsistencies_++;
       trafficPattern_[patternId].contentInconsistencies++;
       logLine += ", IsConsistent=No";
     }
     else
       logLine += ", IsConsistent=Yes";
   }
   else
     logLine += ", IsConsistent=NotChecked";
   m_logger.log(logLine, true, false);
   roundTripDuration = boost::posix_time::microsec_clock::local_time() - sentTime;
   roundTripTime = roundTripDuration.total_microseconds()/1000.0;
   if (minimumInterestRoundTripTime_ > roundTripTime)
     minimumInterestRoundTripTime_ = roundTripTime;
   if (maximumInterestRoundTripTime_ < roundTripTime)
     maximumInterestRoundTripTime_ = roundTripTime;
   if (trafficPattern_[patternId].minimumInterestRoundTripTime > roundTripTime)
     trafficPattern_[patternId].minimumInterestRoundTripTime = roundTripTime;
   if (trafficPattern_[patternId].maximumInterestRoundTripTime < roundTripTime)
     trafficPattern_[patternId].maximumInterestRoundTripTime = roundTripTime;
   totalInterestRoundTripTime_ += roundTripTime;
   trafficPattern_[patternId].totalInterestRoundTripTime += roundTripTime;
   if (totalInterestSent_ == interestCount_)
     signalHandler();
 }
Exemplo n.º 5
0
  // This is the first function that incoming Hello data will
  // see. This checks if the data appears to be signed, and passes it
  // on to validate the content of the data.
void
HelloProtocol::onContent(const ndn::Interest& interest, const ndn::Data& data)
{
  _LOG_DEBUG("Received data for INFO(name): " << data.getName());
  if (data.getSignature().hasKeyLocator()) {
    if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) {
      _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName());
    }
  }
  m_nlsr.getValidator().validate(data,
                                 ndn::bind(&HelloProtocol::onContentValidated, this, _1),
                                 ndn::bind(&HelloProtocol::onContentValidationFailed,
                                           this, _1, _2));
}
void
SimpleDataRetrieval::onData(const ndn::Interest& interest, ndn::Data& data)
{
  if (m_isRunning == false)
    return;

  ConsumerDataCallback onDataEnteredContext = EMPTY_CALLBACK;
  m_context->getContextOption(DATA_ENTER_CNTX, onDataEnteredContext);
  if (onDataEnteredContext != EMPTY_CALLBACK)
  {
    onDataEnteredContext(*dynamic_cast<Consumer*>(m_context), data);
  }
  
  ConsumerInterestCallback onInterestSatisfied = EMPTY_CALLBACK;
  m_context->getContextOption(INTEREST_SATISFIED, onInterestSatisfied);
  if (onInterestSatisfied != EMPTY_CALLBACK)
  {
    onInterestSatisfied(*dynamic_cast<Consumer*>(m_context), const_cast<Interest&>(interest));
  }
  
  ConsumerDataVerificationCallback onDataToVerify = EMPTY_CALLBACK;
  m_context->getContextOption(DATA_TO_VERIFY, onDataToVerify);
  if (onDataToVerify != EMPTY_CALLBACK)
  {
    if (onDataToVerify(*dynamic_cast<Consumer*>(m_context), data) == true) // runs verification routine
    {
      const Block content = data.getContent();
      
      ConsumerContentCallback onPayload = EMPTY_CALLBACK;
      m_context->getContextOption(CONTENT_RETRIEVED, onPayload);
      if (onPayload != EMPTY_CALLBACK)
      {
        onPayload(*dynamic_cast<Consumer*>(m_context), content.value(), content.value_size());
      }
    }
  }
  else
  {
    const Block content = data.getContent();
      
    ConsumerContentCallback onPayload = EMPTY_CALLBACK;
    m_context->getContextOption(CONTENT_RETRIEVED, onPayload);
    if (onPayload != EMPTY_CALLBACK)
    {
      onPayload(*dynamic_cast<Consumer*>(m_context), content.value(), content.value_size());
    }
  }
  
  m_isRunning = false;
}
Exemplo n.º 7
0
 void
 onData(const ndn::Interest& interest, ndn::Data& data)
 {
   m_isDataReceived = true;
   if (m_isPayloadOnlySet)
     {
       const ndn::Block& block = data.getContent();
       std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
     }
   else
     {
       const ndn::Block& block = data.wireEncode();
       std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
     }
 }
bool
EdgeStrategy::filterOutgoingData
( const nfd::Face& face,
  const ndn::Interest& interest,
  ndn::Data& data,
  ns3::Time& delay )
{
    auto in_face = getFaceTable().get( data.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !face.isEdge();
    
    // if the data is coming from and leaving to
    // the same network  then we don't need to do
    // anything special
    if( coming_from_network == going_to_network )
    {
        return RouterStrategy::filterOutgoingData
               ( face, interest, data, delay ); 
    }
    
    // if the data is coming into the network then
    // we just change its current network
    if( going_to_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::EXIT_NETWORK );
        tracers::edge->data_entered( data );
        data.setCurrentNetwork( ndn::RouteTracker::INTERNET_NETWORK );
        return RouterStrategy::filterOutgoingData
               ( face, interest, data, delay ); 
    }
    
    // if the data is leaving the network then we change
    // its current network
    if( coming_from_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        tracers::edge->data_left( data );
        data.setCurrentNetwork( ndn::RouteTracker::ENTRY_NETWORK );
        return RouterStrategy::filterOutgoingData
               ( face, interest, data, delay );
    }
    
    // this should never happen
    BOOST_ASSERT( false );
    return true;
}
void
EdgeStrategy::onDataDenied
( const ndn::Data& data,
  const ndn::Interest& interest,
  ns3::Time& delay,
  const std::string& why )
{
    // if the denied data isn't leaving the network
    // then we just do the normal router stuff
    auto in_face = getFaceTable().get( data.getIncomingFaceId() );
    auto out_face = getFaceTable().get( interest.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !out_face->isEdge();
    
    if( coming_from_network == going_to_network )
    {
        RouterStrategy::onDataDenied( data, interest, delay, why );
        return;
    }
    
    if( going_to_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        RouterStrategy::onDataDenied( data, interest, delay, why );
        return;
    }
    
    // if the data is denied then we add the
    // tag used to retrieve it to the negative
    // cache; however we only want to do this
    // when the data is leaving the internet
    // and going into the client network
    // and the data's access level > 0
    BOOST_ASSERT( data.getCurrentNetwork()
                == ndn::RouteTracker::ENTRY_NETWORK );
    if( data.getAccessLevel() > 0 )
    {
        BOOST_ASSERT( interest.hasAuthTag() );
        tracers::edge->bloom_insert
        ( interest.getAuthTag(), s_edge_bloom_delay );
        delay += s_edge_bloom_delay;
        m_negative_cache.insert( interest.getAuthTag() );
    }

    // do whatever a normal router would do
    RouterStrategy::onDataDenied( data, interest, delay, why );
}
Exemplo n.º 10
0
 virtual ndn::shared_ptr<const ndn::Data>
 preCertificateValidation(const ndn::Data& data)
 {
   ndn::shared_ptr<ndn::Data> internalData = ndn::make_shared<ndn::Data>();
   internalData->wireDecode(data.getContent().blockFromValue());
   return internalData;
 }
Exemplo n.º 11
0
void PutDataToFile(ndn::Data data){
	const ndn::Block& block = data.getContent();
	size_t fileSize = block.value_size();
	std::cout << fileSize << std::endl;
	std::ofstream fout;
	fout.open("/home/hult/dataPacketFile");
 	fout.write((char*)(reinterpret_cast<const uint8_t*>(block.value())), block.value_size());
	fout.close();
}
void
EdgeStrategy::onDataSatisfied
( const ndn::Data& data,
  const ndn::Interest& interest,
  ns3::Time& delay )
{
    // if the satisfied data isn't leaving the network
    // then we just do the normal router stuff
    auto in_face = getFaceTable().get( data.getIncomingFaceId() );
    auto out_face = getFaceTable().get( interest.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !out_face->isEdge();
    
    if( coming_from_network == going_to_network )
    {
        RouterStrategy::onDataSatisfied( data, interest, delay );
        return;
    }
    
    if( going_to_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        RouterStrategy::onDataSatisfied( data, interest, delay );
        return;
    }
    
    // if the data is satisfied then we add it to
    // the positive cache if it isn't marked with
    // the no recache flag and if its access level > 0
    BOOST_ASSERT( data.getCurrentNetwork()
                == ndn::RouteTracker::ENTRY_NETWORK );
    if( !data.getNoReCacheFlag()
      && data.getAccessLevel() > 0 )
    {
        BOOST_ASSERT( interest.hasAuthTag() );
        tracers::edge->bloom_insert
        ( interest.getAuthTag(), s_edge_bloom_delay );
        delay += s_edge_bloom_delay;
        m_positive_cache.insert( interest.getAuthTag() );
    }
    
    RouterStrategy::onDataSatisfied( data, interest, delay );
}
Exemplo n.º 13
0
  void
  validate(const ndn::Data& data)
  {
    BOOST_CHECK_EQUAL(data.getFreshnessPeriod(), m_expectedFreshnessPeriod);

    ndn::Block payload = data.getContent();

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

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

    // wrap data in a single Content TLV for easy parsing
    m_buffer.prependVarNumber(m_buffer.size());
    m_buffer.prependVarNumber(ndn::tlv::Content);

    BOOST_TEST_CHECKPOINT("creating parser");
    ndn::Block parser(m_buffer.buf(), m_buffer.size());
    BOOST_TEST_CHECKPOINT("parsing aggregated response");
    parser.parse();

    BOOST_REQUIRE_EQUAL(parser.elements_size(), m_publisher.getLimit());

    uint64_t expectedNo = m_publisher.getLimit() - 1;
    for (ndn::Block::element_const_iterator i = parser.elements_begin();
         i != parser.elements_end();
         ++i)
      {
        uint64_t number = readNonNegativeInteger(*i);
        BOOST_REQUIRE_EQUAL(number, expectedNo);
        --expectedNo;
      }
  }
Exemplo n.º 14
0
  virtual void
  onData(const ndn::Interest& interest, const ndn::Data& data)
  {
    int dollarfound=0;
    int hashfound=0; 
    int i=0;
    cout << data.getName().size() << endl;
    int comp_size=data.getName().size();
    string last_comp=data.getName().get(comp_size-1).toUri();
    string check=UriDecode(last_comp);
    cout<<check<<endl;
    cout<<"Last component is "<<last_comp<<endl;
    std::size_t found = check.find("#");
    if (found!=std::string::npos)
    {
       hashfound=1;
    }
    found = check.find("$");
    if (found!=std::string::npos)
    {
       dollarfound=1;
    }
    printf("DollarFound:%d and HashFound:%d\n",dollarfound,hashfound); 
    std::cout << "Received Data " << data << std::endl;

    const ndn::Block& payload = data.getContent();

    std:: cout << "payload: ";
    std::cout.write(reinterpret_cast<const char*>(payload.value()), payload.value_size());
    std:: cout << std::endl;
 
    if(dollarfound==1)
    {
      printf("Inside Dollar Found\n");      
      const char *sending=reinterpret_cast<const char*>(payload.value()); 
      string received=string(sending);
      int  max_seg_consumer=stoi(received);
      printf("Maximum Number of Segments is =%d\n",max_seg_consumer);
      //Write code to express interest for the 0th segment   
      string seg_req_0=UriDecode(data.getName().toUri());
      seg_req_0.pop_back();
      seg_req_0.append(to_string(max_seg_consumer));
      seg_req_0.append("/#0");
      printf("String for 0th segment is :");    
      cout<<seg_req_0<<endl;
      char str_send[2][1000];
      memset(&str_send,0,sizeof(str_send));
      strcpy(str_send[0], seg_req_0.c_str());
      cout<<"String being sent in $ is:"<<str_send[0]<<endl;
      const ndn::Name name1(str_send[0]);
      ndn::Interest request(name1);
      m_face.expressInterest(request,
                           bind(&Consumer::onData, this, _1, _2),
                           bind(&Consumer::onTimeout, this, _1));
//    m_face.processEvents();
}
    if(hashfound==1){
    printf("Inside Hash Fund\n");
    //Write code to print to the file and ask the next segment
    string filename;
    for(i=0;i<comp_size-2;i++)
   {
        string mid=data.getName().get(i).toUri();
        string checking=UriDecode(mid);
        filename = filename + '_' +mid;
   }
   char node_name[node_size];
   gethostname(node_name,node_size);
   string node_n=string(node_name);
   node_n.append("-");
   node_n=node_n + filename;
   cout<<node_n<<endl;

   FILE *fp1=fopen(node_n.c_str(),"a");
   fseek(fp1, 0L, SEEK_END);
   int start_ind=0;
   start_ind=stoi(check.substr(1));
    const char *sending=reinterpret_cast<const char*>(payload.value());
    int start1=start_ind*MAX_SEG;
    fseek(fp1,start1,SEEK_SET);
    int just_checking=0;
    if (!(just_checking=fwrite(sending,1,(int)payload.value_size(),fp1))) {
    fprintf(stderr, "Failure");
    //perror(???)  I sometimes see code that says perror here and I don't know 
    //exactly what this does.
}
    printf("Just checking.......%d\n",just_checking);
    //fwrite(sending,1,(int)payload.value_size(),fp1);

//    fwrite(sending,1,payload.value_size(),fp1);
    fclose(fp1);
  /* int start_ind=stoi(check.substr(1));
   std::ofstream ofs;
   ofs.open (node_n, std::ofstream::out | std::ofstream::app);
   ofs.write(reinterpret_cast<const char*>(payload.value()), payload.value_size());
   ofs.close();*/
    start_ind++;
 //   printf("Maximum segment count inside the hash function before the condition is:%d and value of start is: %d\n",max_seg_consumer,start_ind);
   int max_seg_consumer=stoi(UriDecode(data.getName().get(comp_size-2).toUri())); 
   if(start_ind<max_seg_consumer)
    {
      printf("Inside the if consition for max segments\n"); 
      string seg_req=UriDecode(data.getName().toUri());
      size_t found = seg_req.find_last_of("#");
      seg_req=seg_req.substr(0,found+1);
      seg_req.append(to_string(start_ind));
      char str_send[5][1000];
      memset(&str_send,0,sizeof(str_send));
      strcpy(str_send[0], seg_req.c_str());
      cout<<"String that is being sent in ####"<<str_send<<endl;
      const ndn::Name name1(str_send[0]);
      ndn::Interest request(name1);
      m_face.expressInterest(request,
                           bind(&Consumer::onData, this, _1, _2),
                           bind(&Consumer::onTimeout, this, _1));
    }
    else
   {
       char buf[16];
       snprintf(buf, 16, "%lu", time(NULL)); 
       strcat(timer,"\n");
       char tab2[100];
       memset(&tab2,0,sizeof(tab2));
       strcpy(tab2, node_n.c_str());
       strcat(timer,tab2);
       strcat(timer," End: ");
       strcat(timer,buf);
       strcat(timer,"\n");
       FILE *fp3;
       fp3=fopen("logs_shivani.txt","a"); 
       fwrite(timer,1,sizeof(timer),fp3);
       fclose(fp3);
       memset(&timer,0,sizeof(timer));
    }
    
 }

 }
Exemplo n.º 15
0
void putDataToBuffer(ndn::Data dataPacket, char *buffer){
	const ndn::Block& block = dataPacket.getContent();
	memcpy(buffer, (char*)(reinterpret_cast<const uint8_t*>(block.value())), block.value_size());
}
 void
 onReadData(const ndn::Interest& interest, ndn::Data& data)
 {
   int rc = memcmp(data.getContent().value(), content, sizeof(content));
   BOOST_CHECK_EQUAL(rc, 0);
 }
Exemplo n.º 17
0
  void
  onData(const ndn::Interest& interest, ndn::Data& data, std::string linkPrefix)
  {
    std::cout << "Data received for: " << interest.getName() << std::endl;
    CollectorData reply;

    reply.wireDecode(data.getContent().blockFromValue());

    if(reply.m_statusList.empty())
    {
      std::cerr << "received data is empty!!" << std::endl;
    }

    // get the list of the remote links requested for this prefix
    std::unordered_map<std::string,std::list<ndn::NdnMapServer::linkPair>>::const_iterator got = m_linksList.find(linkPrefix);

    if(got == m_linksList.end())
    {
      std::cerr << "failed to recognize the prefix: " << linkPrefix << std::endl;
    }
    else
    {
      std::list<ndn::NdnMapServer::linkPair> prefixList = got->second;

      for (unsigned i=0; i< reply.m_statusList.size(); i++)
      {
        int LinkId = 0;
        std::cout << "Reply: " << reply.m_statusList.at(i);

        // get the link id of the current IP
        for (auto pair = prefixList.cbegin(); pair != prefixList.cend(); ++pair)
        {
          if((*pair).linkIp == reply.m_statusList[i].getLinkIp())
          {
            if (DEBUG)
              std::cout << " Link ID for " << linkPrefix << " and " << reply.m_statusList[i].getLinkIp() << " is " << (*pair).linkId << std::endl;

            LinkId = (*pair).linkId;
          }
        }

        std::string cmdStr("http://");
        cmdStr += m_mapServerAddr;
        cmdStr += "/bw/";
        cmdStr += std::to_string(LinkId);
        cmdStr += "/" + reply.m_statusList[i].getTimestamp() + "/";
        cmdStr += std::to_string(reply.m_statusList[i].getTx() * 8) + "/";
        cmdStr += std::to_string(reply.m_statusList[i].getRx() * 8);

        if (DEBUG)
          std::cout << "cmd to pass to curl: " << cmdStr << std::endl;

        int status;
        // check for zombies
        waitpid(-1, &status, WNOHANG);
        int pid;
        if ((pid = fork()) < 0)
          printf("for failed for curl %s\n", cmdStr.c_str());
        else
        {
          if (pid == 0)
            execl("/usr/bin/curl","curl", "-s", "-L", cmdStr.c_str(), NULL);
        }
        // check for zombies again
        waitpid(-1, &status, WNOHANG);

      }
      reply.m_statusList.clear();
    }
  }