blob: ba7990d1cde8513beeada052538dda4b42e66e4f [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"
Alexander Afanasyev82d5ffe2014-12-30 23:55:38 -080025#include "ns3/ndnSIM/model/ndn-face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070026
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070027#include "ns3/object.h"
28#include "ns3/ptr.h"
29
30#include <list>
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080031#include <tuple>
Alexander Afanasyevad3757f2012-04-17 10:27:59 -070032
33namespace ns3 {
34
35class Channel;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070036
37namespace ndn {
38
39class L3Protocol;
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 */
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080050 typedef std::tuple<Ptr<GlobalRouter>, shared_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
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070098 AddIncidency(shared_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.,
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800116 /// Node)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117
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{
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -0800131 return std::get<0>(a) == std::get<0>(b) && std::get<1>(a) == std::get<1>(b)
132 && std::get<2>(a) == std::get<2>(b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700133}
134
135inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800136operator!=(const GlobalRouter::Incidency& a, const GlobalRouter::Incidency& b)
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700137{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 return !(a == b);
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700139}
140
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700141} // namespace ndn
142} // namespace ns3
Alexander Afanasyevad3757f2012-04-17 10:27:59 -0700143
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700144#endif // NDN_GLOBAL_ROUTER_H