blob: 01dbf5ecf3f57f7472c72b63be50a3b11e3aabfd [file] [log] [blame]
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
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 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Zhenkai Zhu0f054122012-12-25 22:22:50 -080022#ifndef CCNX_TUNNEL_H
23#define CCNX_TUNNEL_H
24
Zhenkai Zhud4924312012-12-28 11:35:12 -080025#include "ccnx-wrapper.h"
26
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080027#define _OVERRIDE
Zhenkai Zhud4924312012-12-28 11:35:12 -080028#ifdef __GNUC__
29#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
30 #undef _OVERRIDE
31 #define _OVERRIDE override
32#endif // __GNUC__ version
33#endif // __GNUC__
34
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080035// Eventually, Sync::CcnxWrapper should be moved to this namespace.
Zhenkai Zhu0f054122012-12-25 22:22:50 -080036// It has nothing to do with Sync.
37namespace Ccnx
38{
39
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080040class CcnxTunnel : public CcnxWrapper
Zhenkai Zhu0f054122012-12-25 22:22:50 -080041{
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080042public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080043 typedef std::multimap<Name, InterestCallback> RegisteredInterestTable;
44 typedef std::multimap<Name, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080045
46
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080047 CcnxTunnel();
Zhenkai Zhu0f054122012-12-25 22:22:50 -080048 virtual ~CcnxTunnel();
49
50 // name is topology-independent
51 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080052 publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080053
Zhenkai Zhuf1185262012-12-29 17:06:00 -080054 int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080055 publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
Zhenkai Zhuf1185262012-12-29 17:06:00 -080056
Zhenkai Zhud4924312012-12-28 11:35:12 -080057 virtual int
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080058 sendInterest (const Name &interest, const Closure &closure, const Selectors &selectors = Selectors());
Zhenkai Zhud4924312012-12-28 11:35:12 -080059
Zhenkai Zhu0f054122012-12-25 22:22:50 -080060
61 // prefix is topology-independent
62 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080063 setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080064
65 // prefix is topology-independent
66 // this clears all entries with key equal to prefix
67 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080068 clearInterestFilter(const Name &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080069
70 // subclass should provide translation service from topology-independent name
71 // to routable name
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080072 virtual Name
73 queryRoutableName(const Name &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080074
75 // subclass should implement the function to store ContentObject with topoloy-independent
76 // name to the permanent storage; default does nothing
77 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080078 storeContentObject(const Name &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080079
80 // should be called when connect to a different network
81 void
82 refreshLocalPrefix();
83
84 static bool
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080085 isPrefix(const Name &prefix, const Name &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080086
Zhenkai Zhu0f054122012-12-25 22:22:50 -080087 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080088 handleTunneledInterest(const Name &tunneldInterest);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080089
Zhenkai Zhud4924312012-12-28 11:35:12 -080090 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080091 handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080092
Zhenkai Zhu90ef9df2013-01-04 22:31:59 -080093private:
94 CcnxTunnel(const CcnxTunnel &other) {}
95
Zhenkai Zhu0f054122012-12-25 22:22:50 -080096protected:
97 // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080098 Name m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080099 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800100 Lock m_ritLock;
101};
102
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800103class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -0800104{
105public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800106 TunnelClosure(const DataCallback &dataCallback, CcnxTunnel &tunnel,
107 const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800108
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800109 TunnelClosure(const Closure &closure, CcnxTunnel &tunnel, const Name &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -0800110
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -0800111 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800112 runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800113
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800114 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800115 runTimeoutCallback(const Name &interest) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800116
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800117 virtual Closure *
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800118 dup() const;
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800119
Zhenkai Zhud4924312012-12-28 11:35:12 -0800120private:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800121 CcnxTunnel &m_tunnel;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800122 Name m_originalInterest;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800123};
124
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800125};
126
127#endif