blob: 06b205f2dbbf7c8f742381636de9771653efdf5c [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"
Junxiao Shi6e694322014-04-03 10:27:13 -07008#include "face-flags.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -06009#include "core/logger.hpp"
Junxiao Shi6e694322014-04-03 10:27:13 -070010#include <ndn-cpp-dev/management/nfd-face-status.hpp>
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060011
12namespace nfd {
13
14NFD_LOG_INIT("FaceStatusPublisher");
15
16
17FaceStatusPublisher::FaceStatusPublisher(const FaceTable& faceTable,
18 shared_ptr<AppFace> face,
19 const Name& prefix)
20 : SegmentPublisher(face, prefix)
21 , m_faceTable(faceTable)
22{
23
24}
25
26
27FaceStatusPublisher::~FaceStatusPublisher()
28{
29
30}
31
32size_t
33FaceStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
34{
35 size_t totalLength = 0;
36
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070037 for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
Junxiao Shi6e694322014-04-03 10:27:13 -070038 i != m_faceTable.rend(); ++i) {
39 const shared_ptr<Face>& face = *i;
40 const FaceCounters& counters = face->getCounters();
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060041
Junxiao Shi6e694322014-04-03 10:27:13 -070042 ndn::nfd::FaceStatus status;
43 status.setFaceId(face->getId())
44 .setRemoteUri(face->getRemoteUri().toString())
45 .setLocalUri(face->getLocalUri().toString())
46 .setFlags(getFaceFlags(*face))
47 .setNInInterests(counters.getNInInterests())
48 .setNInDatas(counters.getNInDatas())
49 .setNOutInterests(counters.getNOutInterests())
50 .setNOutDatas(counters.getNOutDatas());
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060051
Junxiao Shi6e694322014-04-03 10:27:13 -070052 totalLength += status.wireEncode(outBuffer);
53 }
Steve DiBenedetto9f6c3642014-03-10 17:02:27 -060054 return totalLength;
55}
56
57} // namespace nfd