Alexander Afanasyev | f4e2452 | 2013-06-24 14:11:57 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
| 31 | NS_LOG_COMPONENT_DEFINE ("ndn.IpFacesHelper"); |
| 32 | |
| 33 | using namespace std; |
| 34 | |
| 35 | namespace ns3 { |
| 36 | namespace ndn { |
| 37 | |
| 38 | void |
| 39 | IpFacesHelper::Install (Ptr<Node> node) |
| 40 | { |
| 41 | Ptr<IpFaceStack> stack = CreateObject<IpFaceStack> (); |
| 42 | node->AggregateObject (stack); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | IpFacesHelper::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 | |
| 56 | void |
| 57 | IpFacesHelper::InstallAll () |
| 58 | { |
| 59 | Install (NodeContainer::GetGlobal ()); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | static void |
| 64 | CreateTcpFaceStep2 (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 | |
| 70 | static void |
| 71 | CreateTcpFaceStep1 (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 | |
| 78 | void |
| 79 | IpFacesHelper::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 |