blob: f742656a8b42dcdc6d4ace6531c898662dbb42ac [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070026#include "ns3/object.h"
27#include "ns3/ptr.h"
28
29#include <list>
30#include <boost/tuple/tuple.hpp>
31
32namespace ns3 {
33
34class Channel;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070035
36namespace ndn {
37
38class L3Protocol;
39class Face;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070040
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070041/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070042 * @ingroup ndn
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070043 * @brief Class representing global router interface for ndnSIM
44 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045class GlobalRouter : public Object {
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070046public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070047 /**
48 * @brief Graph edge
49 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 typedef boost::tuple<Ptr<GlobalRouter>, Ptr<Face>, Ptr<GlobalRouter>> Incidency;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070051 /**
52 * @brief List of graph edges
53 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 typedef std::list<Incidency> IncidencyList;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070055 /**
56 * @brief List of locally exported prefixes
57 */
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070058 typedef std::list<shared_ptr<Name>> LocalPrefixList;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070060 /**
61 * \brief Interface ID
62 *
63 * \return interface ID
64 */
65 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 GetTypeId();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070067
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070068 /**
69 * @brief Default constructor
70 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 GlobalRouter();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070072
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070073 /**
74 * @brief Get numeric ID of the node (internally assigned)
75 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070076 uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 GetId() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070078
79 /**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 * @brief Helper function to get smart pointer to ndn::L3Protocol object (basically, self)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070081 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082 Ptr<L3Protocol>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 GetL3Protocol() const;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070084
85 /**
86 * @brief Add new locally exported prefix
87 * @param prefix Prefix
88 */
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070089 void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070090 AddLocalPrefix(shared_ptr<Name> prefix);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070091
92 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070093 * @brief Add edge to the node
94 * @param face Face of the edge
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 * @param ndn GlobalRouter of another node
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070096 */
97 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 AddIncidency(Ptr<Face> face, Ptr<GlobalRouter> ndn);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070099
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700100 /**
101 * @brief Get list of edges that are connected to this node
102 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 IncidencyList&
104 GetIncidencies();
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700105
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700106 /**
107 * @brief Get list of locally exported prefixes
108 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 const LocalPrefixList&
110 GetLocalPrefixes() const;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700111
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700112 // ??
113protected:
114 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 NotifyNewAggregate(); ///< @brief Notify when the object is aggregated to another object (e.g.,
116 /// Node)
117
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700118private:
119 uint32_t m_id;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120
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 Afanasyevbe55cf62014-12-20 17:51:09 -0800129operator==(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700130{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800131 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 -0700132}
133
134inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135operator!=(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700136{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 return !(a == b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700138}
139
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140} // namespace ndn
141} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700142
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700143#endif // NDN_GLOBAL_ROUTER_H