Mohammad Sabet | 532990d | 2016-10-17 20:23:56 +0330 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
| 7 | * |
| 8 | * 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. |
| 11 | * |
| 12 | * 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. |
| 15 | * |
| 16 | * 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 | **/ |
| 19 | |
| 20 | #include "ndn-network-region-table-helper.hpp" |
| 21 | #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp" |
| 22 | #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" |
| 23 | |
| 24 | namespace ns3 { |
| 25 | namespace ndn { |
| 26 | |
| 27 | NS_LOG_COMPONENT_DEFINE("ndn.NetworkRegionTableHelper"); |
| 28 | |
| 29 | void |
| 30 | NetworkRegionTableHelper::AddRegionName(Ptr<Node> node, const Name& region) |
| 31 | { |
| 32 | NS_LOG_LOGIC("Node [" << node->GetId() << "]$ RegionName " << region << " is added into NetworkRegionTable "); |
| 33 | |
| 34 | Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>(); |
| 35 | NS_ASSERT_MSG(l3protocol != 0, "Ndn stack should be installed on the node"); |
| 36 | |
| 37 | node->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().insert(region); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | NetworkRegionTableHelper::AddRegionName(NodeContainer& nodes, const ndn::Name& region) |
| 42 | { |
| 43 | for (auto nodeIt = nodes.Begin(); nodeIt != nodes.End(); ++nodeIt) { |
| 44 | AddRegionName(*nodeIt, region); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void |
| 49 | NetworkRegionTableHelper::AddRegionName(Ptr<Node> node, std::initializer_list<Name> regions) |
| 50 | { |
| 51 | for (const auto& region : regions) { |
| 52 | AddRegionName(node, region); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | NetworkRegionTableHelper::AddRegionName(const NodeContainer& nodes, std::initializer_list<Name> regions) |
| 58 | { |
| 59 | for (auto nodeIt = nodes.begin(); nodeIt != nodes.End(); ++nodeIt) { |
| 60 | AddRegionName(*nodeIt, regions); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | NetworkRegionTableHelper::RemoveRegionName(Ptr<Node> node, const Name& region) |
| 66 | { |
| 67 | NS_LOG_LOGIC("Node [" << node->GetId() << "]$ RegionName " << region << " is removed from NetworkRegionTable "); |
| 68 | |
| 69 | Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>(); |
| 70 | NS_ASSERT_MSG(l3protocol != 0, "Ndn stack should be installed on the node"); |
| 71 | |
| 72 | node->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().erase(region); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | NetworkRegionTableHelper::RemoveRegionName(const NodeContainer& nodes, const ndn::Name ®ion) |
| 77 | { |
| 78 | for (auto nodeIt = nodes.begin(); nodeIt != nodes.End(); ++nodeIt) { |
| 79 | RemoveRegionName(*nodeIt, region); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | NetworkRegionTableHelper::RemoveRegionName(Ptr<Node> node, std::initializer_list<Name> regions) |
| 85 | { |
| 86 | for (const auto& region : regions) { |
| 87 | RemoveRegionName(node, region); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | NetworkRegionTableHelper::RemoveRegionName(const NodeContainer& nodes, std::initializer_list<Name> regions) |
| 93 | { |
| 94 | for (auto nodeIt = nodes.begin(); nodeIt != nodes.End(); ++nodeIt) { |
| 95 | RemoveRegionName(*nodeIt, regions); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | NetworkRegionTableHelper::EmptyNetworkRegionTable(Ptr<Node> node) |
| 101 | { |
| 102 | NS_LOG_LOGIC("Node [" << node->GetId() << "]$ NetworkRegionTable is cleared"); |
| 103 | |
| 104 | Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>(); |
| 105 | NS_ASSERT_MSG(l3protocol != 0, "Ndn stack should be installed on the node"); |
| 106 | |
| 107 | node->GetObject<L3Protocol>()->getForwarder()->getNetworkRegionTable().clear(); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | NetworkRegionTableHelper::EmptyNetworkRegionTable(const NodeContainer& nodes) |
| 112 | { |
| 113 | for (auto nodeIt = nodes.begin(); nodeIt != nodes.End(); ++nodeIt) { |
| 114 | EmptyNetworkRegionTable(*nodeIt); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | } // namespace ndn |
| 119 | } // namespace ns3 |