blob: f1475a3295d9fa1415960adf37e76725695d07ab [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 Afanasyev4aac5572012-08-09 10:49:55 -070033class Ndn;
34class NdnFace;
35class NdnNameComponents;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070036
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070037/**
38 * @brief Class representing global router interface for ndnSIM
39 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040class NdnGlobalRouter : public Object
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070041{
42public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070043 /**
44 * @brief Graph edge
45 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046 typedef boost::tuple< Ptr< NdnGlobalRouter >, Ptr< NdnFace >, Ptr< NdnGlobalRouter > > Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070047 /**
48 * @brief List of graph edges
49 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070050 typedef std::list< Incidency > IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070051 /**
52 * @brief List of locally exported prefixes
53 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054 typedef std::list< Ptr<NdnNameComponents> > LocalPrefixList;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070055
56 /**
57 * \brief Interface ID
58 *
59 * \return interface ID
60 */
61 static TypeId
62 GetTypeId ();
63
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070064 /**
65 * @brief Default constructor
66 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 NdnGlobalRouter ();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070068
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070069 /**
70 * @brief Get numeric ID of the node (internally assigned)
71 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070072 uint32_t
73 GetId () const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070074
75 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070076 * @brief Helper function to get smart pointer to Ndn object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070077 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078 Ptr<Ndn>
79 GetNdn () const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070080
81 /**
82 * @brief Add new locally exported prefix
83 * @param prefix Prefix
84 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070085 void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070086 AddLocalPrefix (Ptr< NdnNameComponents > prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070087
88 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070089 * @brief Add edge to the node
90 * @param face Face of the edge
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070091 * @param ndn NdnGlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070092 */
93 void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070094 AddIncidency (Ptr< NdnFace > face, Ptr< NdnGlobalRouter > ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070095
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070096 /**
97 * @brief Get list of edges that are connected to this node
98 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070099 IncidencyList &
100 GetIncidencies ();
101
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700102 /**
103 * @brief Get list of locally exported prefixes
104 */
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700105 const LocalPrefixList &
106 GetLocalPrefixes () const;
107
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700108 // ??
109protected:
110 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700111 NotifyNewAggregate (); ///< @brief Notify when the object is aggregated to another object (e.g., Node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700112
113private:
114 uint32_t m_id;
115
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700116 Ptr<Ndn> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700117 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700118 IncidencyList m_incidencies;
119
120 static uint32_t m_idCounter;
121};
122
123inline bool
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700124operator == (const NdnGlobalRouter::Incidency &a,
125 const NdnGlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700126{
127 return a.get<0> () == b.get<0> () &&
128 a.get<1> () == b.get<1> () &&
129 a.get<2> () == b.get<2> ();
130}
131
132inline bool
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700133operator != (const NdnGlobalRouter::Incidency &a,
134 const NdnGlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700135{
136 return ! (a == b);
137}
138
139}
140
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700141#endif // NDN_GLOBAL_ROUTER_H