blob: dad2180da68a4e331381796de009023f865546a4 [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 Afanasyev2b4c9472012-08-09 15:00:38 -070046class GlobalRouter : public Object
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070047{
48public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070049 /**
50 * @brief Graph edge
51 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070052 typedef boost::tuple< Ptr< GlobalRouter >, Ptr< Face >, Ptr< GlobalRouter > > Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070053 /**
54 * @brief List of graph edges
55 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070056 typedef std::list< Incidency > IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070057 /**
58 * @brief List of locally exported prefixes
59 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070060 typedef std::list< Ptr<Name> > LocalPrefixList;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070061
62 /**
63 * \brief Interface ID
64 *
65 * \return interface ID
66 */
67 static TypeId
68 GetTypeId ();
69
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070070 /**
71 * @brief Default constructor
72 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 GlobalRouter ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070074
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070075 /**
76 * @brief Get numeric ID of the node (internally assigned)
77 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070078 uint32_t
79 GetId () const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070080
81 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082 * @brief Helper function to get smart pointer to ndn::L3Protocol object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070083 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070084 Ptr<L3Protocol>
85 GetL3Protocol () const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070086
87 /**
88 * @brief Add new locally exported prefix
89 * @param prefix Prefix
90 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070091 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070092 AddLocalPrefix (Ptr< Name > prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070093
94 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070095 * @brief Add edge to the node
96 * @param face Face of the edge
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097 * @param ndn GlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070098 */
99 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700100 AddIncidency (Ptr< Face > face, Ptr< GlobalRouter > ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700101
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700102 /**
103 * @brief Get list of edges that are connected to this node
104 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700105 IncidencyList &
106 GetIncidencies ();
107
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700108 /**
109 * @brief Get list of locally exported prefixes
110 */
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700111 const LocalPrefixList &
112 GetLocalPrefixes () const;
113
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700114 // ??
115protected:
116 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700117 NotifyNewAggregate (); ///< @brief Notify when the object is aggregated to another object (e.g., Node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700118
119private:
120 uint32_t m_id;
121
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 Afanasyev2b4c9472012-08-09 15:00:38 -0700130operator == (const GlobalRouter::Incidency &a,
131 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700132{
133 return a.get<0> () == b.get<0> () &&
134 a.get<1> () == b.get<1> () &&
135 a.get<2> () == b.get<2> ();
136}
137
138inline bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700139operator != (const GlobalRouter::Incidency &a,
140 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700141{
142 return ! (a == b);
143}
144
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145} // namespace ndn
146} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700147
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700148#endif // NDN_GLOBAL_ROUTER_H