blob: d277bb82025b0b1949aed70c7c71e7fabbd1b6aa [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;
38class NameComponents;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070039
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070040/**
41 * @brief Class representing global router interface for ndnSIM
42 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043class GlobalRouter : public Object
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070044{
45public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070046 /**
47 * @brief Graph edge
48 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049 typedef boost::tuple< Ptr< GlobalRouter >, Ptr< Face >, Ptr< GlobalRouter > > Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070050 /**
51 * @brief List of graph edges
52 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070053 typedef std::list< Incidency > IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070054 /**
55 * @brief List of locally exported prefixes
56 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 typedef std::list< Ptr<NameComponents> > LocalPrefixList;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070058
59 /**
60 * \brief Interface ID
61 *
62 * \return interface ID
63 */
64 static TypeId
65 GetTypeId ();
66
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070067 /**
68 * @brief Default constructor
69 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070 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
76 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>
82 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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089 AddLocalPrefix (Ptr< NameComponents > 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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097 AddIncidency (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 Afanasyevad3757f2012-04-17 10:27:59 -0700102 IncidencyList &
103 GetIncidencies ();
104
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700105 /**
106 * @brief Get list of locally exported prefixes
107 */
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700108 const LocalPrefixList &
109 GetLocalPrefixes () const;
110
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700111 // ??
112protected:
113 virtual void
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700114 NotifyNewAggregate (); ///< @brief Notify when the object is aggregated to another object (e.g., Node)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700115
116private:
117 uint32_t m_id;
118
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 Ptr<L3Protocol> m_ndn;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700120 LocalPrefixList m_localPrefixes;
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700121 IncidencyList m_incidencies;
122
123 static uint32_t m_idCounter;
124};
125
126inline bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127operator == (const GlobalRouter::Incidency &a,
128 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700129{
130 return a.get<0> () == b.get<0> () &&
131 a.get<1> () == b.get<1> () &&
132 a.get<2> () == b.get<2> ();
133}
134
135inline bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700136operator != (const GlobalRouter::Incidency &a,
137 const GlobalRouter::Incidency &b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700138{
139 return ! (a == b);
140}
141
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142} // namespace ndn
143} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700144
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700145#endif // NDN_GLOBAL_ROUTER_H