blob: efd956fca2bb41b2cec801e1362b8f909b138a05 [file] [log] [blame]
Alexander Afanasyevf4e24522013-06-24 14:11:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 * Alexander Afanasyev
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
22#include "ndn-ip-faces-helper.h"
23#include "ndn-ip-face-stack.h"
24
25#include "ns3/ndn-stack-helper.h"
26#include "ns3/node-container.h"
27#include "ns3/log.h"
28#include "ns3/simulator.h"
29#include "ndn-tcp-face.h"
30
31NS_LOG_COMPONENT_DEFINE ("ndn.IpFacesHelper");
32
33using namespace std;
34
35namespace ns3 {
36namespace ndn {
37
38void
39IpFacesHelper::Install (Ptr<Node> node)
40{
41 Ptr<IpFaceStack> stack = CreateObject<IpFaceStack> ();
42 node->AggregateObject (stack);
43}
44
45void
46IpFacesHelper::Install (const NodeContainer &nodes)
47{
48 for (NodeContainer::Iterator node = nodes.Begin ();
49 node != nodes.End ();
50 node ++)
51 {
52 Install (*node);
53 }
54}
55
56void
57IpFacesHelper::InstallAll ()
58{
59 Install (NodeContainer::GetGlobal ());
60}
61
62
63static void
64CreateTcpFaceStep2 (Ptr<Node> node, Ipv4Address address, const std::string &prefix)
65{
66 Ptr<Face> face = TcpFace::CreateOrGetFace (node, address);
67 ndn::StackHelper::AddRoute (node, prefix, face, 1);
68}
69
70static void
71CreateTcpFaceStep1 (Ptr<Node> node, Ipv4Address address, const std::string &prefix)
72{
73 TcpFace::CreateOrGetFace (node, address);
74
75 Simulator::ScheduleWithContext (node->GetId (), Seconds (1.0), CreateTcpFaceStep2, node, address, prefix);
76}
77
78void
79IpFacesHelper::CreateTcpFace (Ptr<Node> node, Ipv4Address address, const std::string &prefix)
80{
81 Simulator::ScheduleWithContext (node->GetId (), Seconds (1.0), CreateTcpFaceStep1, node, address, prefix);
82}
83
84
85} // namespace ndn
86} // namespace ns3