blob: 4713a5b4fedafd2d1c294efa9ebc5cfbead9d068 [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"
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080024#include "ns3/ndnSIM/model/ndn-face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070026#include "ns3/object.h"
27#include "ns3/ptr.h"
28
29#include <list>
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080030#include <tuple>
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070031
32namespace ns3 {
33
34class Channel;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070035
36namespace ndn {
37
38class L3Protocol;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070039
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070040/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080041 * @ingroup ndn-helpers
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070042 * @brief Class representing global router interface for ndnSIM
43 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044class GlobalRouter : public Object {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070045public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070046 /**
47 * @brief Graph edge
48 */
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080049 typedef std::tuple<Ptr<GlobalRouter>, shared_ptr<Face>, Ptr<GlobalRouter>> Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070050 /**
51 * @brief List of graph edges
52 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 typedef std::list<Incidency> IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070054 /**
55 * @brief List of locally exported prefixes
56 */
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070057 typedef std::list<shared_ptr<Name>> LocalPrefixList;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070059 /**
60 * \brief Interface ID
61 *
62 * \return interface ID
63 */
64 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 GetTypeId();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070066
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070067 /**
68 * @brief Default constructor
69 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 GlobalRouter();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070071
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070072 /**
73 * @brief Get numeric ID of the node (internally assigned)
74 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070075 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 GetId() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070077
78 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079 * @brief Helper function to get smart pointer to ndn::L3Protocol object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070080 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081 Ptr<L3Protocol>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 GetL3Protocol() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070083
84 /**
85 * @brief Add new locally exported prefix
86 * @param prefix Prefix
87 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070088 void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070089 AddLocalPrefix(shared_ptr<Name> prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070090
91 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070092 * @brief Add edge to the node
93 * @param face Face of the edge
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 * @param ndn GlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070095 */
96 void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070097 AddIncidency(shared_ptr<Face> face, Ptr<GlobalRouter> ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070098
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070099 /**
100 * @brief Get list of edges that are connected to this node
101 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 IncidencyList&
103 GetIncidencies();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700104
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700105 /**
106 * @brief Get list of locally exported prefixes
107 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 const LocalPrefixList&
109 GetLocalPrefixes() const;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700110
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700111 // ??
112protected:
113 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 NotifyNewAggregate(); ///< @brief Notify when the object is aggregated to another object (e.g.,
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800115 /// Node)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700117private:
118 uint32_t m_id;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700120 Ptr<L3Protocol> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700121 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700122 IncidencyList m_incidencies;
123
124 static uint32_t m_idCounter;
125};
126
127inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128operator==(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700129{
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800130 return std::get<0>(a) == std::get<0>(b) && std::get<1>(a) == std::get<1>(b)
131 && std::get<2>(a) == std::get<2>(b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700132}
133
134inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135operator!=(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700136{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 return !(a == b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700138}
139
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140} // namespace ndn
141} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700142
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700143#endif // NDN_GLOBAL_ROUTER_H