blob: 1ef6329e8b62187b3f7c13fc2f0ec0e48f266367 [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/**
43 * @brief Class representing global router interface for ndnSIM
44 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045class GlobalRouter : public Object
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070046{
47public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070048 /**
49 * @brief Graph edge
50 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051 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 Afanasyevad3757f2012-04-17 10:27:59 -070055 typedef std::list< Incidency > IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070056 /**
57 * @brief List of locally exported prefixes
58 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070059 typedef std::list< Ptr<Name> > LocalPrefixList;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070060
61 /**
62 * \brief Interface ID
63 *
64 * \return interface ID
65 */
66 static TypeId
67 GetTypeId ();
68
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070069 /**
70 * @brief Default constructor
71 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070072 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
78 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>
84 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 Afanasyevcfdc14f2013-03-15 14:38:44 -070091 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 Afanasyev2b4c9472012-08-09 15:00:38 -070099 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 Afanasyevad3757f2012-04-17 10:27:59 -0700104 IncidencyList &
105 GetIncidencies ();
106
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700107 /**
108 * @brief Get list of locally exported prefixes
109 */
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700110 const LocalPrefixList &
111 GetLocalPrefixes () const;
112
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700113 // ??
114protected:
115 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700116 NotifyNewAggregate (); ///< @brief Notify when the object is aggregated to another object (e.g., Node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700117
118private:
119 uint32_t m_id;
120
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700121 Ptr<L3Protocol> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700122 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700123 IncidencyList m_incidencies;
124
125 static uint32_t m_idCounter;
126};
127
128inline bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129operator == (const GlobalRouter::Incidency &a,
130 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700131{
132 return a.get<0> () == b.get<0> () &&
133 a.get<1> () == b.get<1> () &&
134 a.get<2> () == b.get<2> ();
135}
136
137inline bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138operator != (const GlobalRouter::Incidency &a,
139 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700140{
141 return ! (a == b);
142}
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