Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ccnx-consumer-helper.h" |
| 22 | #include "ns3/inet-socket-address.h" |
| 23 | #include "ns3/packet-socket-address.h" |
| 24 | #include "ns3/string.h" |
| 25 | #include "ns3/names.h" |
| 26 | |
| 27 | namespace ns3 |
| 28 | { |
| 29 | |
| 30 | CcnxConsumerHelper::CcnxConsumerHelper (Ptr<CcnxNameComponents> interestName) |
| 31 | { |
| 32 | m_factory.SetTypeId ("ns3::CcnxConsumer"); |
Alexander Afanasyev | 152cf11 | 2011-08-29 17:58:32 -0700 | [diff] [blame^] | 33 | m_factory.Set ("InterestName", CcnxNameComponentsValue (*interestName)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void |
| 37 | CcnxConsumerHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 38 | { |
| 39 | m_factory.Set (name, value); |
| 40 | } |
| 41 | |
| 42 | ApplicationContainer |
| 43 | CcnxConsumerHelper::Install (Ptr<Node> node) |
| 44 | { |
| 45 | return ApplicationContainer (InstallPriv (node)); |
| 46 | } |
| 47 | |
| 48 | ApplicationContainer |
| 49 | CcnxConsumerHelper::Install (std::string nodeName) |
| 50 | { |
| 51 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 52 | return ApplicationContainer (InstallPriv (node)); |
| 53 | } |
| 54 | |
| 55 | ApplicationContainer |
| 56 | CcnxConsumerHelper::Install (NodeContainer c) |
| 57 | { |
| 58 | ApplicationContainer apps; |
| 59 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 60 | { |
| 61 | apps.Add (InstallPriv (*i)); |
| 62 | } |
| 63 | |
| 64 | return apps; |
| 65 | } |
| 66 | |
| 67 | Ptr<Application> |
| 68 | CcnxConsumerHelper::InstallPriv (Ptr<Node> node) |
| 69 | { |
| 70 | Ptr<CcnxLocalFace> localFace = CreateObject<CcnxLocalFace> (); |
| 71 | localFace->SetNode(node); |
| 72 | |
| 73 | m_factory.Set ("Face", PointerValue (localFace)); |
| 74 | Ptr<CcnxConsumer> app = m_factory.Create<CcnxConsumer> (); |
| 75 | |
| 76 | localFace->RegisterProtocolHandler (MakeCallback (&CcnxConsumer::HandlePacket, app)); |
| 77 | localFace->SetUp(); |
| 78 | |
| 79 | node->AddApplication (app); |
| 80 | |
| 81 | return app; |
| 82 | } |
Alexander Afanasyev | 152cf11 | 2011-08-29 17:58:32 -0700 | [diff] [blame^] | 83 | } |