blob: a3267bd613ec1ca4cfddb9cf3bb6a741b983d15c [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 Afanasyevcbe92ae2011-12-16 13:06:18 -080041TypeId
42CcnxLocalFace::GetTypeId ()
43{
44 static TypeId tid = TypeId ("ns3::CcnxLocalFace")
45 .SetParent<CcnxFace> ()
46 .SetGroupName ("Ccnx")
47 ;
48 return tid;
49}
50
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080051CcnxLocalFace::CcnxLocalFace (Ptr<CcnxApp> app)
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080052 : CcnxFace (app->GetNode ())
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080053 , m_app (app)
Alexander Afanasyev98256102011-08-14 01:00:02 -070054{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080055 NS_LOG_FUNCTION (this << app);
56
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080057 NS_ASSERT (m_app != 0);
Alexander Afanasyev98256102011-08-14 01:00:02 -070058}
59
60CcnxLocalFace::~CcnxLocalFace ()
61{
62 NS_LOG_FUNCTION_NOARGS ();
63}
64
Alexander Afanasyev07827182011-12-13 01:07:32 -080065CcnxLocalFace::CcnxLocalFace ()
66 : CcnxFace (0)
67{
68}
69
70CcnxLocalFace::CcnxLocalFace (const CcnxLocalFace &)
71 : CcnxFace (0)
72{
73}
74
75CcnxLocalFace& CcnxLocalFace::operator= (const CcnxLocalFace &)
76{
77 return *((CcnxLocalFace*)0);
78}
79
80
Alexander Afanasyev98256102011-08-14 01:00:02 -070081void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070082CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler)
Alexander Afanasyev98256102011-08-14 01:00:02 -070083{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080084 NS_LOG_FUNCTION (this);
Alexander Afanasyev98256102011-08-14 01:00:02 -070085
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080086 CcnxFace::RegisterProtocolHandler (handler);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070087
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080088 m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070089}
Ilya Moiseenkoacac1ea2011-10-28 13:16:53 -070090
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070091void
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092CcnxLocalFace::SendImpl (Ptr<Packet> p)
Alexander Afanasyev98256102011-08-14 01:00:02 -070093{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094 NS_LOG_FUNCTION (this << p);
Alexander Afanasyev98256102011-08-14 01:00:02 -070095
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070096 try
97 {
98 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
99 switch (type)
100 {
101 case CcnxHeaderHelper::INTEREST:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800102 {
103 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
104 p->RemoveHeader (*header);
105
106 if (header->GetNack () > 0)
107 m_app->OnNack (header);
108 else
109 m_app->OnInterest (header);
110
111 break;
112 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700113 case CcnxHeaderHelper::CONTENT_OBJECT:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800114 {
115 static CcnxContentObjectTail tail;
116 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
117 p->RemoveHeader (*header);
118 p->RemoveTrailer (tail);
119 m_app->OnContentObject (header, p/*payload*/);
120
121 break;
122 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700123 }
124 }
125 catch (CcnxUnknownHeaderException)
126 {
127 NS_LOG_ERROR ("Unknown header type");
128 }
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -0700129}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700130
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700131std::ostream& CcnxLocalFace::Print (std::ostream& os) const
132{
133 os << "dev=local(" << GetId() << ")";
Alexander Afanasyev98256102011-08-14 01:00:02 -0700134 return os;
135}
136
137}; // namespace ns3
138