NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-network-region-table-helper.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 &region)
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
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
112 {
113  for (auto nodeIt = nodes.begin(); nodeIt != nodes.End(); ++nodeIt) {
114  EmptyNetworkRegionTable(*nodeIt);
115  }
116 }
117 
118 } // namespace ndn
119 } // namespace ns3
Copyright (c) 2011-2015 Regents of the University of California.
static void AddRegionName(Ptr< Node > node, const Name &regionName)
Copyright (c) 2011-2015 Regents of the University of California.
static void RemoveRegionName(Ptr< Node > node, const Name &regionName)
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Implementation network-layer of NDN stack.