blob: 6bc8c7223a1d53815f69edfdf1b8ebe805d3b4ad [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,
44 ndn::tlv::nfd::TotalOutgoingDataCounter,
45 counters.getOutData());
46
47 statusLength += prependNonNegativeIntegerBlock(outBuffer,
48 ndn::tlv::nfd::TotalOutgoingInterestCounter,
49 counters.getOutInterest());
50
51 statusLength += prependNonNegativeIntegerBlock(outBuffer,
52 ndn::tlv::nfd::TotalIncomingDataCounter,
53 counters.getInData());
54
55 statusLength += prependNonNegativeIntegerBlock(outBuffer,
56 ndn::tlv::nfd::TotalIncomingInterestCounter,
57 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