blob: 3589d7b2d0fa2d7de32959138ac80bdbd427775a [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 */
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06006
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06007#include "face-status-publisher.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06008#include "core/logger.hpp"
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -06009
10namespace nfd {
11
12NFD_LOG_INIT("FaceStatusPublisher");
13
14
15FaceStatusPublisher::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
25FaceStatusPublisher::~FaceStatusPublisher()
26{
27
28}
29
30size_t
31FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
32{
33 size_t totalLength = 0;
34
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070035 for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
36 i != m_faceTable.rend();
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060037 ++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 Shi2d2cde12014-03-31 00:32:42 -070046 ndn::tlv::nfd::NOutDatas,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060047 counters.getOutData());
48
49 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070050 ndn::tlv::nfd::NOutInterests,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060051 counters.getOutInterest());
52
53 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070054 ndn::tlv::nfd::NInDatas,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060055 counters.getInData());
56
57 statusLength += prependNonNegativeIntegerBlock(outBuffer,
Junxiao Shi2d2cde12014-03-31 00:32:42 -070058 ndn::tlv::nfd::NInInterests,
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060059 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