blob: 7b92d1bb67d5d3d8d04aab75e6b6fe9b7118daa5 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-global-router.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080022#include "model/ndn-l3-protocol.hpp"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070023
24#include "ns3/channel.h"
25
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070026namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070027namespace ndn {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070028
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029uint32_t GlobalRouter::m_idCounter = 0;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070030
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080031NS_OBJECT_ENSURE_REGISTERED(GlobalRouter);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070032
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033TypeId
34GlobalRouter::GetTypeId()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070035{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036 static TypeId tid = TypeId("ns3::ndn::GlobalRouter").SetGroupName("Ndn").SetParent<Object>();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070037 return tid;
38}
39
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040GlobalRouter::GlobalRouter()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041{
42 m_id = m_idCounter;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043 m_idCounter++;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044}
45
46void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047GlobalRouter::NotifyNewAggregate()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 if (m_ndn == 0) {
50 m_ndn = GetObject<L3Protocol>();
51 }
52 Object::NotifyNewAggregate();
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070053}
54
55uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056GlobalRouter::GetId() const
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057{
58 return m_id;
59}
60
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061Ptr<L3Protocol>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062GlobalRouter::GetL3Protocol() const
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070063{
64 return m_ndn;
65}
66
67void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070068GlobalRouter::AddLocalPrefix(shared_ptr<Name> prefix)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070069{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 m_localPrefixes.push_back(prefix);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071}
72
73void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070074GlobalRouter::AddIncidency(shared_ptr<Face> face, Ptr<GlobalRouter> gr)
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070075{
Spyridon Mastorakis60f4b992014-11-07 15:51:38 -080076 m_incidencies.push_back(std::make_tuple(this, face, gr));
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070077}
78
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079GlobalRouter::IncidencyList&
80GlobalRouter::GetIncidencies()
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081{
82 return m_incidencies;
83}
84
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085const GlobalRouter::LocalPrefixList&
86GlobalRouter::GetLocalPrefixes() const
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087{
88 return m_localPrefixes;
89}
90
Yuanzhi Gaodd516fe2015-04-23 04:18:24 -070091void
92GlobalRouter::clear()
93{
94 m_idCounter = 0;
95}
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070096
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097} // namespace ndn
98} // namespace ns3