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" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 22 | #include "ns3/log.h" |
| 23 | #include "ns3/ccnx-name-components.h" |
| 24 | #include "ns3/names.h" |
| 25 | #include "../apps/ccnx-consumer.h" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 26 | |
| 27 | NS_LOG_COMPONENT_DEFINE ("CcnxConsumerHelper"); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ns3 |
| 30 | { |
| 31 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 32 | CcnxConsumerHelper::CcnxConsumerHelper (const std::string &prefix) |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 33 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 34 | m_factory.SetTypeId ("ns3::CcnxConsumer"); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 35 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 36 | CcnxNameComponentsValue prefixValue; |
| 37 | prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ()); |
| 38 | m_factory.Set ("InterestName", prefixValue); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | CcnxConsumerHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 43 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 44 | m_factory.Set (name, value); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ApplicationContainer |
| 48 | CcnxConsumerHelper::Install (Ptr<Node> node) |
| 49 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 50 | return ApplicationContainer (InstallPriv (node)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ApplicationContainer |
| 54 | CcnxConsumerHelper::Install (std::string nodeName) |
| 55 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 56 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 57 | return ApplicationContainer (InstallPriv (node)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | ApplicationContainer |
| 61 | CcnxConsumerHelper::Install (NodeContainer c) |
| 62 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 63 | ApplicationContainer apps; |
| 64 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 65 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 66 | apps.Add (InstallPriv (*i)); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 69 | return apps; |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | Ptr<Application> |
| 73 | CcnxConsumerHelper::InstallPriv (Ptr<Node> node) |
| 74 | { |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 75 | Ptr<CcnxConsumer> app = m_factory.Create<CcnxConsumer> (); |
| 76 | node->AddApplication (app); |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 77 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 78 | return app; |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 79 | } |
Alexander Afanasyev | 152cf11 | 2011-08-29 17:58:32 -0700 | [diff] [blame] | 80 | } |