blob: fe6f308d9e8fce6d35add1bd521f3436c551141a [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevad3757f2012-04-17 10:27:59 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevad3757f2012-04-17 10:27:59 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070019
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070020#ifndef NDN_GLOBAL_ROUTER_H
21#define NDN_GLOBAL_ROUTER_H
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070025#include "ns3/object.h"
26#include "ns3/ptr.h"
27
28#include <list>
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080029#include <tuple>
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070030
31namespace ns3 {
32
33class Channel;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034
35namespace ndn {
36
37class L3Protocol;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070038
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070039/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080040 * @ingroup ndn-helpers
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070041 * @brief Class representing global router interface for ndnSIM
42 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043class GlobalRouter : public Object {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070044public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070045 /**
46 * @brief Graph edge
47 */
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080048 typedef std::tuple<Ptr<GlobalRouter>, shared_ptr<Face>, Ptr<GlobalRouter>> Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070049 /**
50 * @brief List of graph edges
51 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 typedef std::list<Incidency> IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070053 /**
54 * @brief List of locally exported prefixes
55 */
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070056 typedef std::list<shared_ptr<Name>> LocalPrefixList;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070058 /**
59 * \brief Interface ID
60 *
61 * \return interface ID
62 */
63 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 GetTypeId();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070065
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070066 /**
67 * @brief Default constructor
68 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 GlobalRouter();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070070
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070071 /**
72 * @brief Get numeric ID of the node (internally assigned)
73 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070074 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 GetId() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070076
77 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 * @brief Helper function to get smart pointer to ndn::L3Protocol object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070079 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 Ptr<L3Protocol>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 GetL3Protocol() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070082
83 /**
84 * @brief Add new locally exported prefix
85 * @param prefix Prefix
86 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070087 void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070088 AddLocalPrefix(shared_ptr<Name> prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070089
90 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070091 * @brief Add edge to the node
92 * @param face Face of the edge
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070093 * @param ndn GlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070094 */
95 void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070096 AddIncidency(shared_ptr<Face> face, Ptr<GlobalRouter> ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070097
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070098 /**
99 * @brief Get list of edges that are connected to this node
100 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 IncidencyList&
102 GetIncidencies();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700103
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700104 /**
105 * @brief Get list of locally exported prefixes
106 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 const LocalPrefixList&
108 GetLocalPrefixes() const;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700109
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -0700110 /**
111 * @brief Clear global state
112 */
113 static void
114 clear();
115
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700116protected:
117 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 NotifyNewAggregate(); ///< @brief Notify when the object is aggregated to another object (e.g.,
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800119 /// Node)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700121private:
122 uint32_t m_id;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 Ptr<L3Protocol> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700125 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700126 IncidencyList m_incidencies;
127
128 static uint32_t m_idCounter;
129};
130
131inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132operator==(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700133{
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800134 return std::get<0>(a) == std::get<0>(b) && std::get<1>(a) == std::get<1>(b)
135 && std::get<2>(a) == std::get<2>(b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700136}
137
138inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800139operator!=(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700140{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 return !(a == b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700142}
143
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144} // namespace ndn
145} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700146
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700147#endif // NDN_GLOBAL_ROUTER_H