blob: 157110691a1173e3a710ed656a70d18965f67eb4 [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
Alexander Afanasyev07827182011-12-13 01:07:32 -080055CcnxLocalFace::CcnxLocalFace ()
56 : CcnxFace (0)
57{
58}
59
60CcnxLocalFace::CcnxLocalFace (const CcnxLocalFace &)
61 : CcnxFace (0)
62{
63}
64
65CcnxLocalFace& CcnxLocalFace::operator= (const CcnxLocalFace &)
66{
67 return *((CcnxLocalFace*)0);
68}
69
70
Alexander Afanasyev98256102011-08-14 01:00:02 -070071void
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070072CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler)
Alexander Afanasyev98256102011-08-14 01:00:02 -070073{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080074 NS_LOG_FUNCTION (this);
Alexander Afanasyev98256102011-08-14 01:00:02 -070075
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080076 CcnxFace::RegisterProtocolHandler (handler);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070077
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080078 m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070079}
Ilya Moiseenkoacac1ea2011-10-28 13:16:53 -070080
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070081void
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080082CcnxLocalFace::SendImpl (Ptr<Packet> p)
Alexander Afanasyev98256102011-08-14 01:00:02 -070083{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 NS_LOG_FUNCTION (this << p);
Alexander Afanasyev98256102011-08-14 01:00:02 -070085
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070086 try
87 {
88 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
89 switch (type)
90 {
91 case CcnxHeaderHelper::INTEREST:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080092 {
93 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
94 p->RemoveHeader (*header);
95
96 if (header->GetNack () > 0)
97 m_app->OnNack (header);
98 else
99 m_app->OnInterest (header);
100
101 break;
102 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103 case CcnxHeaderHelper::CONTENT_OBJECT:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800104 {
105 static CcnxContentObjectTail tail;
106 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
107 p->RemoveHeader (*header);
108 p->RemoveTrailer (tail);
109 m_app->OnContentObject (header, p/*payload*/);
110
111 break;
112 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700113 }
114 }
115 catch (CcnxUnknownHeaderException)
116 {
117 NS_LOG_ERROR ("Unknown header type");
118 }
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -0700119}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700121std::ostream& CcnxLocalFace::Print (std::ostream& os) const
122{
123 os << "dev=local(" << GetId() << ")";
Alexander Afanasyev98256102011-08-14 01:00:02 -0700124 return os;
125}
126
127}; // namespace ns3
128