blob: 89c731e003b3334831907c0eec9fe07a2a87b11a [file] [log] [blame]
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06001/* -*- 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 */
6#include "face-status-publisher.hpp"
7
8namespace nfd {
9
10NFD_LOG_INIT("FaceStatusPublisher");
11
12
13FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable,
14 shared_ptr<AppFace> face,
15 const Name& prefix)
16 : SegmentPublisher(face, prefix)
17 , m_faceTable(faceTable)
18{
19
20}
21
22
23FaceStatusPublisher::~FaceStatusPublisher()
24{
25
26}
27
28size_t
29FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
30{
31 size_t totalLength = 0;
32
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070033 for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
34 i != m_faceTable.rend();
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060035 ++i)
36 {
37 const shared_ptr<Face>& face = *i;
38 const FaceCounters& counters = face->getCounters();
39 const std::string uri = face->getUri().toString();
40
41 size_t statusLength = 0;
42
43 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070044 ndn::tlv::nfd::NOutDatas,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060045 counters.getOutData());
46
47 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070048 ndn::tlv::nfd::NOutInterests,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060049 counters.getOutInterest());
50
51 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070052 ndn::tlv::nfd::NInDatas,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060053 counters.getInData());
54
55 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070056 ndn::tlv::nfd::NInInterests,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060057 counters.getInInterest());
58
59 statusLength += prependByteArrayBlock(outBuffer,
60 ndn::tlv::nfd::Uri,
61 reinterpret_cast<const uint8_t*>(uri.c_str()),
62 uri.size());
63
64 statusLength += prependNonNegativeIntegerBlock(outBuffer,
65 ndn::tlv::nfd::FaceId,
66 face->getId());
67
68 statusLength += outBuffer.prependVarNumber(statusLength);
69 statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus);
70
71 totalLength += statusLength;
72 }
73 return totalLength;
74}
75
76} // namespace nfd