blob: a1d58847549e16c8e385c732487b64433d08615e [file] [log] [blame]
Alexander Afanasyev2a655f72015-01-26 18:38:33 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shif748a4e2017-07-05 23:41:48 +00002/*
3 * Copyright (c) 2014-2017, Regents of the University of California,
Alexander Afanasyev2a655f72015-01-26 18:38:33 -08004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_TOOLS_NDN_AUTOCONFIG_MULTICAST_DISCOVERY_HPP
27#define NFD_TOOLS_NDN_AUTOCONFIG_MULTICAST_DISCOVERY_HPP
28
Junxiao Shif748a4e2017-07-05 23:41:48 +000029#include "stage.hpp"
Junxiao Shicb766862017-07-07 22:21:04 +000030#include <ndn-cxx/face.hpp>
31#include <ndn-cxx/mgmt/nfd/controller.hpp>
32#include <ndn-cxx/mgmt/nfd/face-status.hpp>
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080033
34namespace ndn {
35namespace tools {
36namespace autoconfig {
37
Junxiao Shia5a3a872017-07-08 12:42:11 +000038/** \brief multicast discovery stage
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080039 *
Junxiao Shia5a3a872017-07-08 12:42:11 +000040 * This stage locates an NDN gateway router, commonly known as a "hub", in the local network by
41 * sending a hub discovery Interest ndn:/localhop/ndn-autoconf/hub via multicast. This class
42 * configures routes and strategy on local NFD, so that this Interest is multicast to all
43 * multi-access faces.
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080044 *
Junxiao Shia5a3a872017-07-08 12:42:11 +000045 * If an NDN gateway router is present in the local network, it should reply with a Data
46 * containing its own FaceUri. The Data payload contains a Uri element, and the value of this
47 * element is an ASCII-encoded string of the router's FaceUri. The router may use
48 * ndn-autoconfig-server program to serve this Data.
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080049 *
Junxiao Shia5a3a872017-07-08 12:42:11 +000050 * Signature on this Data is currently not verified. This stage succeeds when the Data is
51 * successfully decoded.
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080052 */
Junxiao Shif748a4e2017-07-05 23:41:48 +000053class MulticastDiscovery : public Stage
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080054{
55public:
Junxiao Shicb766862017-07-07 22:21:04 +000056 MulticastDiscovery(Face& face, nfd::Controller& controller);
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080057
Junxiao Shicb766862017-07-07 22:21:04 +000058 const std::string&
Junxiao Shia5a3a872017-07-08 12:42:11 +000059 getName() const final
Junxiao Shicb766862017-07-07 22:21:04 +000060 {
61 static const std::string STAGE_NAME("multicast discovery");
62 return STAGE_NAME;
63 }
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080064
65private:
66 void
Junxiao Shia5a3a872017-07-08 12:42:11 +000067 doStart() final;
Junxiao Shia8891112016-12-06 21:11:33 +000068
69 void
Junxiao Shicb766862017-07-07 22:21:04 +000070 registerHubDiscoveryPrefix(const std::vector<nfd::FaceStatus>& dataset);
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080071
72 void
Junxiao Shia5a3a872017-07-08 12:42:11 +000073 afterReg();
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080074
75 void
76 setStrategy();
77
78 void
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080079 requestHubData();
80
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080081private:
Junxiao Shicb766862017-07-07 22:21:04 +000082 Face& m_face;
83 nfd::Controller& m_controller;
Junxiao Shia5a3a872017-07-08 12:42:11 +000084
85 int m_nRegs = 0;
86 int m_nRegSuccess = 0;
87 int m_nRegFailure = 0;
Alexander Afanasyev2a655f72015-01-26 18:38:33 -080088};
89
90} // namespace autoconfig
91} // namespace tools
92} // namespace ndn
93
94#endif // NFD_TOOLS_NDN_AUTOCONFIG_MULTICAST_DISCOVERY_HPP