blob: e47d35bbce00559422dd0919e55fff6a5efb03be [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/*
Ilya Moiseenko956d0542012-01-02 15:26:40 -08003 * Copyright (c) 2011 University of California, Los Angeles
Alexander Afanasyev98256102011-08-14 01:00:02 -07004 *
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
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070023#include "ccnx-app-face.h"
Alexander Afanasyev98256102011-08-14 01:00:02 -070024
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"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080029#include "ns3/simulator.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070030
31#include "ns3/ccnx-header-helper.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032#include "ns3/ccnx-app.h"
33
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070034#include "ccnx-interest-header.h"
35#include "ccnx-content-object-header.h"
Alexander Afanasyev98256102011-08-14 01:00:02 -070036
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070037NS_LOG_COMPONENT_DEFINE ("CcnxAppFace");
Alexander Afanasyev98256102011-08-14 01:00:02 -070038
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -070039namespace ns3
40{
Alexander Afanasyev98256102011-08-14 01:00:02 -070041
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080042TypeId
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070043CcnxAppFace::GetTypeId ()
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080044{
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070045 static TypeId tid = TypeId ("ns3::CcnxAppFace")
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080046 .SetParent<CcnxFace> ()
47 .SetGroupName ("Ccnx")
48 ;
49 return tid;
50}
51
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070052CcnxAppFace::CcnxAppFace (Ptr<CcnxApp> app)
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080053 : CcnxFace (app->GetNode ())
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080054 , m_app (app)
Alexander Afanasyev98256102011-08-14 01:00:02 -070055{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080056 NS_LOG_FUNCTION (this << app);
57
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080058 NS_ASSERT (m_app != 0);
Alexander Afanasyev98256102011-08-14 01:00:02 -070059}
60
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070061CcnxAppFace::~CcnxAppFace ()
Alexander Afanasyev98256102011-08-14 01:00:02 -070062{
63 NS_LOG_FUNCTION_NOARGS ();
64}
65
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070066CcnxAppFace::CcnxAppFace ()
Alexander Afanasyev07827182011-12-13 01:07:32 -080067 : CcnxFace (0)
68{
69}
70
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070071CcnxAppFace::CcnxAppFace (const CcnxAppFace &)
Alexander Afanasyev07827182011-12-13 01:07:32 -080072 : CcnxFace (0)
73{
74}
75
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070076CcnxAppFace& CcnxAppFace::operator= (const CcnxAppFace &)
Alexander Afanasyev07827182011-12-13 01:07:32 -080077{
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070078 return *((CcnxAppFace*)0);
Alexander Afanasyev07827182011-12-13 01:07:32 -080079}
80
81
Alexander Afanasyev98256102011-08-14 01:00:02 -070082void
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070083CcnxAppFace::RegisterProtocolHandler (ProtocolHandler handler)
Alexander Afanasyev98256102011-08-14 01:00:02 -070084{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080085 NS_LOG_FUNCTION (this);
Alexander Afanasyev98256102011-08-14 01:00:02 -070086
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080087 CcnxFace::RegisterProtocolHandler (handler);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070088
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080089 m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070090}
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080091
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070092void
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -070093CcnxAppFace::SendImpl (Ptr<Packet> p)
Alexander Afanasyev98256102011-08-14 01:00:02 -070094{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080095 NS_LOG_FUNCTION (this << p);
Alexander Afanasyev98256102011-08-14 01:00:02 -070096
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070097 try
98 {
99 CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p);
100 switch (type)
101 {
102 case CcnxHeaderHelper::INTEREST:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800103 {
104 Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> ();
105 p->RemoveHeader (*header);
106
107 if (header->GetNack () > 0)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800108 m_app->OnNack (header, p);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800109 else
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800110 m_app->OnInterest (header, p);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800111
112 break;
113 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700114 case CcnxHeaderHelper::CONTENT_OBJECT:
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800115 {
116 static CcnxContentObjectTail tail;
117 Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> ();
118 p->RemoveHeader (*header);
119 p->RemoveTrailer (tail);
120 m_app->OnContentObject (header, p/*payload*/);
121
122 break;
123 }
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700124 }
125 }
126 catch (CcnxUnknownHeaderException)
127 {
128 NS_LOG_ERROR ("Unknown header type");
129 }
Ilya Moiseenko1cf6b0a2011-08-29 13:02:34 -0700130}
Alexander Afanasyev98256102011-08-14 01:00:02 -0700131
Alexander Afanasyev4a4ea602012-06-06 11:12:45 -0700132std::ostream& CcnxAppFace::Print (std::ostream& os) const
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700133{
134 os << "dev=local(" << GetId() << ")";
Alexander Afanasyev98256102011-08-14 01:00:02 -0700135 return os;
136}
137
138}; // namespace ns3
139