Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame^] | 6 | |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 7 | #include "face-status-publisher.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame^] | 8 | #include "core/logger.hpp" |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 9 | |
| 10 | namespace nfd { |
| 11 | |
| 12 | NFD_LOG_INIT("FaceStatusPublisher"); |
| 13 | |
| 14 | |
| 15 | FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable, |
| 16 | shared_ptr<AppFace> face, |
| 17 | const Name& prefix) |
| 18 | : SegmentPublisher(face, prefix) |
| 19 | , m_faceTable(faceTable) |
| 20 | { |
| 21 | |
| 22 | } |
| 23 | |
| 24 | |
| 25 | FaceStatusPublisher::~FaceStatusPublisher() |
| 26 | { |
| 27 | |
| 28 | } |
| 29 | |
| 30 | size_t |
| 31 | FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer) |
| 32 | { |
| 33 | size_t totalLength = 0; |
| 34 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 35 | for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin(); |
| 36 | i != m_faceTable.rend(); |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 37 | ++i) |
| 38 | { |
| 39 | const shared_ptr<Face>& face = *i; |
| 40 | const FaceCounters& counters = face->getCounters(); |
| 41 | const std::string uri = face->getUri().toString(); |
| 42 | |
| 43 | size_t statusLength = 0; |
| 44 | |
| 45 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
Junxiao Shi | 2d2cde1 | 2014-03-31 00:32:42 -0700 | [diff] [blame] | 46 | ndn::tlv::nfd::NOutDatas, |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 47 | counters.getOutData()); |
| 48 | |
| 49 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
Junxiao Shi | 2d2cde1 | 2014-03-31 00:32:42 -0700 | [diff] [blame] | 50 | ndn::tlv::nfd::NOutInterests, |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 51 | counters.getOutInterest()); |
| 52 | |
| 53 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
Junxiao Shi | 2d2cde1 | 2014-03-31 00:32:42 -0700 | [diff] [blame] | 54 | ndn::tlv::nfd::NInDatas, |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 55 | counters.getInData()); |
| 56 | |
| 57 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
Junxiao Shi | 2d2cde1 | 2014-03-31 00:32:42 -0700 | [diff] [blame] | 58 | ndn::tlv::nfd::NInInterests, |
Steve DiBenedetto | 9f6c364 | 2014-03-10 17:02:27 -0600 | [diff] [blame] | 59 | counters.getInInterest()); |
| 60 | |
| 61 | statusLength += prependByteArrayBlock(outBuffer, |
| 62 | ndn::tlv::nfd::Uri, |
| 63 | reinterpret_cast<const uint8_t*>(uri.c_str()), |
| 64 | uri.size()); |
| 65 | |
| 66 | statusLength += prependNonNegativeIntegerBlock(outBuffer, |
| 67 | ndn::tlv::nfd::FaceId, |
| 68 | face->getId()); |
| 69 | |
| 70 | statusLength += outBuffer.prependVarNumber(statusLength); |
| 71 | statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus); |
| 72 | |
| 73 | totalLength += statusLength; |
| 74 | } |
| 75 | return totalLength; |
| 76 | } |
| 77 | |
| 78 | } // namespace nfd |