blob: 4a7c7779376cf50e3eb73c904feeadb3680f91eb [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev98256102011-08-14 01:00:02 -07002/*
3 * Copyright (c) 2005,2006,2007 INRIA
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 *
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev98256102011-08-14 01:00:02 -070020 *
21 */
22
23#include "ccnx-local-face.h"
24
Alexander Afanasyev98256102011-08-14 01:00:02 -070025#include "ns3/log.h"
26#include "ns3/packet.h"
27#include "ns3/node.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070028#include "ns3/assert.h"
29
30#include "ns3/ccnx-header-helper.h"
31#include "ccnx-interest-header.h"
32#include "ccnx-content-object-header.h"
Alexander Afanasyev98256102011-08-14 01:00:02 -070033
34NS_LOG_COMPONENT_DEFINE ("CcnxLocalFace");
35
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -070036namespace ns3
37{
Alexander Afanasyev98256102011-08-14 01:00:02 -070038
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080039CcnxLocalFace::CcnxLocalFace (Ptr<CcnxApp> app)
40 : CcnxFace (app->GetObject<Node> ())
41 , m_app (app)
Alexander Afanasyev98256102011-08-14 01:00:02 -070042{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043 NS_LOG_FUNCTION (this << app);
44
45 NS_ASSERT (app != 0);
Alexander Afanasyev98256102011-08-14 01:00:02 -070046}
47
48CcnxLocalFace::~CcnxLocalFace ()
49{
50 NS_LOG_FUNCTION_NOARGS ();
51}
52
53void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070054CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler)
Alexander Afanasyev98256102011-08-14 01:00:02 -070055{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056 NS_LOG_FUNCTION (this << handler);
Alexander Afanasyev98256102011-08-14 01:00:02 -070057
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080058 CcnxFace::RegisterProtocolHandler (handler);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070059
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060 app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070061}
Ilya Moiseenkoacac1ea2011-10-28 13:16:53 -070062
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070063void
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080064CcnxLocalFace::SendImpl (Ptr<Packet> p)
Alexander Afanasyev98256102011-08-14 01:00:02 -070065{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080066 NS_LOG_FUNCTION (this << p);
Alexander Afanasyev98256102011-08-14 01:00:02 -070067
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070068 try
69 {
70 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
71 switch (type)
72 {
73 case CcnxHeaderHelper::INTEREST:
74 if (!m_onInterest.IsNull ())
75 {
76 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
77 p->RemoveHeader (*header);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080078 app->OnInterest (header);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070079 }
80 break;
81 case CcnxHeaderHelper::CONTENT_OBJECT:
82 if (!m_onContentObject.IsNull ())
83 {
84 static CcnxContentObjectTail tail;
85 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
86 p->RemoveHeader (*header);
87 p->RemoveTrailer (tail);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080088 app->OnContentObject (header, p/*payload*/);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070089 }
90 break;
91 }
92 }
93 catch (CcnxUnknownHeaderException)
94 {
95 NS_LOG_ERROR ("Unknown header type");
96 }
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -070097}
Alexander Afanasyev98256102011-08-14 01:00:02 -070098
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070099std::ostream& CcnxLocalFace::Print (std::ostream& os) const
100{
101 os << "dev=local(" << GetId() << ")";
Alexander Afanasyev98256102011-08-14 01:00:02 -0700102 return os;
103}
104
105}; // namespace ns3
106