Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 2 | /* |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 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 Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 23 | #include "ccnx-app-face.h" |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 25 | #include "ns3/log.h" |
| 26 | #include "ns3/packet.h" |
| 27 | #include "ns3/node.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 28 | #include "ns3/assert.h" |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 29 | #include "ns3/simulator.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include "ns3/ccnx-header-helper.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 32 | #include "ns3/ccnx-app.h" |
| 33 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 34 | #include "ccnx-interest-header.h" |
| 35 | #include "ccnx-content-object-header.h" |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 37 | NS_LOG_COMPONENT_DEFINE ("CcnxAppFace"); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 38 | |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 39 | namespace ns3 |
| 40 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 42 | TypeId |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 43 | CcnxAppFace::GetTypeId () |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 44 | { |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 45 | static TypeId tid = TypeId ("ns3::CcnxAppFace") |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 46 | .SetParent<CcnxFace> () |
| 47 | .SetGroupName ("Ccnx") |
| 48 | ; |
| 49 | return tid; |
| 50 | } |
| 51 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 52 | CcnxAppFace::CcnxAppFace (Ptr<CcnxApp> app) |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 53 | : CcnxFace (app->GetNode ()) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 54 | , m_app (app) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 56 | NS_LOG_FUNCTION (this << app); |
| 57 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 58 | NS_ASSERT (m_app != 0); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 61 | CcnxAppFace::~CcnxAppFace () |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 62 | { |
| 63 | NS_LOG_FUNCTION_NOARGS (); |
| 64 | } |
| 65 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 66 | CcnxAppFace::CcnxAppFace () |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 67 | : CcnxFace (0) |
| 68 | { |
| 69 | } |
| 70 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 71 | CcnxAppFace::CcnxAppFace (const CcnxAppFace &) |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 72 | : CcnxFace (0) |
| 73 | { |
| 74 | } |
| 75 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 76 | CcnxAppFace& CcnxAppFace::operator= (const CcnxAppFace &) |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 77 | { |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 78 | return *((CcnxAppFace*)0); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 82 | void |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 83 | CcnxAppFace::RegisterProtocolHandler (ProtocolHandler handler) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 84 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 85 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 86 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 87 | CcnxFace::RegisterProtocolHandler (handler); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 89 | m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this)); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 90 | } |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 92 | void |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 93 | CcnxAppFace::SendImpl (Ptr<Packet> p) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 94 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 95 | NS_LOG_FUNCTION (this << p); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 97 | try |
| 98 | { |
| 99 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
| 100 | switch (type) |
| 101 | { |
| 102 | case CcnxHeaderHelper::INTEREST: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 103 | { |
| 104 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
| 105 | p->RemoveHeader (*header); |
| 106 | |
| 107 | if (header->GetNack () > 0) |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 108 | m_app->OnNack (header, p); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 109 | else |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 110 | m_app->OnInterest (header, p); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 111 | |
| 112 | break; |
| 113 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 114 | case CcnxHeaderHelper::CONTENT_OBJECT: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 115 | { |
| 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 Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | catch (CcnxUnknownHeaderException) |
| 127 | { |
| 128 | NS_LOG_ERROR ("Unknown header type"); |
| 129 | } |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 130 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 4a4ea60 | 2012-06-06 11:12:45 -0700 | [diff] [blame^] | 132 | std::ostream& CcnxAppFace::Print (std::ostream& os) const |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 133 | { |
| 134 | os << "dev=local(" << GetId() << ")"; |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 135 | return os; |
| 136 | } |
| 137 | |
| 138 | }; // namespace ns3 |
| 139 | |