blob: f680db7e34cbc9877ea9f0df8dd62261fe4bc82a [file] [log] [blame]
Alexander Afanasyevad3757f2012-04-17 10:27:59 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 UCLA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef NDN_GLOBAL_ROUTER_H
22#define NDN_GLOBAL_ROUTER_H
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070023
24#include "ns3/object.h"
25#include "ns3/ptr.h"
26
27#include <list>
28#include <boost/tuple/tuple.hpp>
29
30namespace ns3 {
31
32class Channel;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070033
34namespace ndn {
35
36class L3Protocol;
37class Face;
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070038class Name;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070039
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070040typedef Name NameComponents;
41
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070042/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070043 * @ingroup ndn
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070044 * @brief Class representing global router interface for ndnSIM
45 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046class GlobalRouter : public Object {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070047public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070048 /**
49 * @brief Graph edge
50 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 typedef boost::tuple<Ptr<GlobalRouter>, Ptr<Face>, Ptr<GlobalRouter>> Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070052 /**
53 * @brief List of graph edges
54 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 typedef std::list<Incidency> IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070056 /**
57 * @brief List of locally exported prefixes
58 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 typedef std::list<Ptr<Name>> LocalPrefixList;
60
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070061 /**
62 * \brief Interface ID
63 *
64 * \return interface ID
65 */
66 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 GetTypeId();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070068
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070069 /**
70 * @brief Default constructor
71 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 GlobalRouter();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070073
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070074 /**
75 * @brief Get numeric ID of the node (internally assigned)
76 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070077 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 GetId() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070079
80 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081 * @brief Helper function to get smart pointer to ndn::L3Protocol object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070082 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 Ptr<L3Protocol>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 GetL3Protocol() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070085
86 /**
87 * @brief Add new locally exported prefix
88 * @param prefix Prefix
89 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070090 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 AddLocalPrefix(Ptr<Name> prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070092
93 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070094 * @brief Add edge to the node
95 * @param face Face of the edge
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070096 * @param ndn GlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070097 */
98 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 AddIncidency(Ptr<Face> face, Ptr<GlobalRouter> ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700100
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700101 /**
102 * @brief Get list of edges that are connected to this node
103 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 IncidencyList&
105 GetIncidencies();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700106
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700107 /**
108 * @brief Get list of locally exported prefixes
109 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 const LocalPrefixList&
111 GetLocalPrefixes() const;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700112
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700113 // ??
114protected:
115 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 NotifyNewAggregate(); ///< @brief Notify when the object is aggregated to another object (e.g.,
117 /// Node)
118
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700119private:
120 uint32_t m_id;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800121
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700122 Ptr<L3Protocol> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700123 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700124 IncidencyList m_incidencies;
125
126 static uint32_t m_idCounter;
127};
128
129inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800130operator==(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700131{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 return a.get<0>() == b.get<0>() && a.get<1>() == b.get<1>() && a.get<2>() == b.get<2>();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700133}
134
135inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800136operator!=(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700137{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 return !(a == b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700139}
140
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700141} // namespace ndn
142} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700143
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700144#endif // NDN_GLOBAL_ROUTER_H