blob: 5add077806eed29e51a7d84dba02d62d3070191e [file] [log] [blame]
Ilya Moiseenkoa1214112011-08-29 13:03:55 -07001/* -*- 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
27namespace ns3
28{
29
30CcnxConsumerHelper::CcnxConsumerHelper (Ptr<CcnxNameComponents> interestName)
31{
32 m_factory.SetTypeId ("ns3::CcnxConsumer");
33 m_factory.Set ("InterestName", PointerValue (interestName));
34}
35
36void
37CcnxConsumerHelper::SetAttribute (std::string name, const AttributeValue &value)
38{
39 m_factory.Set (name, value);
40}
41
42ApplicationContainer
43CcnxConsumerHelper::Install (Ptr<Node> node)
44{
45 return ApplicationContainer (InstallPriv (node));
46}
47
48ApplicationContainer
49CcnxConsumerHelper::Install (std::string nodeName)
50{
51 Ptr<Node> node = Names::Find<Node> (nodeName);
52 return ApplicationContainer (InstallPriv (node));
53}
54
55ApplicationContainer
56CcnxConsumerHelper::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
67Ptr<Application>
68CcnxConsumerHelper::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}
83}