blob: 0f8ef27a1be367bf71989e3614d4ba52dd1ed3b7 [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"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080031#include "ns3/ccnx-app.h"
32
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070033#include "ccnx-interest-header.h"
34#include "ccnx-content-object-header.h"
Alexander Afanasyev98256102011-08-14 01:00:02 -070035
36NS_LOG_COMPONENT_DEFINE ("CcnxLocalFace");
37
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -070038namespace ns3
39{
Alexander Afanasyev98256102011-08-14 01:00:02 -070040
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080041CcnxLocalFace::CcnxLocalFace (Ptr<CcnxApp> app)
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080042 : CcnxFace (app->GetNode ())
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043 , m_app (app)
Alexander Afanasyev98256102011-08-14 01:00:02 -070044{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080045 NS_LOG_FUNCTION (this << app);
46
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080047 NS_ASSERT (m_app != 0);
Alexander Afanasyev98256102011-08-14 01:00:02 -070048}
49
50CcnxLocalFace::~CcnxLocalFace ()
51{
52 NS_LOG_FUNCTION_NOARGS ();
53}
54
55void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070056CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler)
Alexander Afanasyev98256102011-08-14 01:00:02 -070057{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080058 NS_LOG_FUNCTION (this);
Alexander Afanasyev98256102011-08-14 01:00:02 -070059
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060 CcnxFace::RegisterProtocolHandler (handler);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070061
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080062 m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070063}
Ilya Moiseenkoacac1ea2011-10-28 13:16:53 -070064
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070065void
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080066CcnxLocalFace::SendImpl (Ptr<Packet> p)
Alexander Afanasyev98256102011-08-14 01:00:02 -070067{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068 NS_LOG_FUNCTION (this << p);
Alexander Afanasyev98256102011-08-14 01:00:02 -070069
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070070 try
71 {
72 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
73 switch (type)
74 {
75 case CcnxHeaderHelper::INTEREST:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080076 {
77 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
78 p->RemoveHeader (*header);
79
80 if (header->GetNack () > 0)
81 m_app->OnNack (header);
82 else
83 m_app->OnInterest (header);
84
85 break;
86 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070087 case CcnxHeaderHelper::CONTENT_OBJECT:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080088 {
89 static CcnxContentObjectTail tail;
90 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
91 p->RemoveHeader (*header);
92 p->RemoveTrailer (tail);
93 m_app->OnContentObject (header, p/*payload*/);
94
95 break;
96 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070097 }
98 }
99 catch (CcnxUnknownHeaderException)
100 {
101 NS_LOG_ERROR ("Unknown header type");
102 }
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -0700103}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700104
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700105std::ostream& CcnxLocalFace::Print (std::ostream& os) const
106{
107 os << "dev=local(" << GetId() << ")";
Alexander Afanasyev98256102011-08-14 01:00:02 -0700108 return os;
109}
110
111}; // namespace ns3
112