blob: ce567752d7c748202fd69793bd33c7950c028d98 [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 Zhu974c5a62012-12-28 14:15:30 -080025#include "ccnx-common.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -080026#include "ccnx-wrapper.h"
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080027#include "ccnx-name.h"
Zhenkai Zhua6472e02013-01-06 14:33:37 -080028#include "ccnx-selectors.h"
Zhenkai Zhud4924312012-12-28 11:35:12 -080029
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080030#define _OVERRIDE
Zhenkai Zhud4924312012-12-28 11:35:12 -080031#ifdef __GNUC__
32#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
33 #undef _OVERRIDE
34 #define _OVERRIDE override
35#endif // __GNUC__ version
36#endif // __GNUC__
37
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080038// Eventually, Sync::CcnxWrapper should be moved to this namespace.
Zhenkai Zhu0f054122012-12-25 22:22:50 -080039// It has nothing to do with Sync.
40namespace Ccnx
41{
42
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080043class CcnxTunnel : public CcnxWrapper
Zhenkai Zhu0f054122012-12-25 22:22:50 -080044{
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080045public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080046 typedef std::multimap<Name, InterestCallback> RegisteredInterestTable;
47 typedef std::multimap<Name, InterestCallback>::iterator RitIter;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080048
49
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080050 CcnxTunnel();
Zhenkai Zhu0f054122012-12-25 22:22:50 -080051 virtual ~CcnxTunnel();
52
53 // name is topology-independent
54 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080055 publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -080056
Zhenkai Zhuf1185262012-12-29 17:06:00 -080057 int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080058 publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
Zhenkai Zhuf1185262012-12-29 17:06:00 -080059
Zhenkai Zhud4924312012-12-28 11:35:12 -080060 virtual int
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -080061 sendInterest (const Name &interest, const Closure &closure, const Selectors &selectors = Selectors());
Zhenkai Zhud4924312012-12-28 11:35:12 -080062
Zhenkai Zhu0f054122012-12-25 22:22:50 -080063
64 // prefix is topology-independent
65 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080066 setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080067
68 // prefix is topology-independent
69 // this clears all entries with key equal to prefix
70 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080071 clearInterestFilter(const Name &prefix) _OVERRIDE;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080072
73 // subclass should provide translation service from topology-independent name
74 // to routable name
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080075 virtual Name
76 queryRoutableName(const Name &name) = 0;
Zhenkai Zhu0f054122012-12-25 22:22:50 -080077
78 // subclass should implement the function to store ContentObject with topoloy-independent
79 // name to the permanent storage; default does nothing
80 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080081 storeContentObject(const Name &name, const Bytes &content) {}
Zhenkai Zhu0f054122012-12-25 22:22:50 -080082
83 // should be called when connect to a different network
84 void
85 refreshLocalPrefix();
86
87 static bool
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080088 isPrefix(const Name &prefix, const Name &name);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080089
Zhenkai Zhu0f054122012-12-25 22:22:50 -080090 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080091 handleTunneledInterest(const Name &tunneldInterest);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080092
Zhenkai Zhud4924312012-12-28 11:35:12 -080093 void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080094 handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
Zhenkai Zhu0f054122012-12-25 22:22:50 -080095
Zhenkai Zhu90ef9df2013-01-04 22:31:59 -080096private:
97 CcnxTunnel(const CcnxTunnel &other) {}
98
Zhenkai Zhu0f054122012-12-25 22:22:50 -080099protected:
100 // 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 -0800101 Name m_localPrefix;
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800102 RegisteredInterestTable m_rit;
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800103 Lock m_ritLock;
104};
105
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800106class TunnelClosure : public Closure
Zhenkai Zhud4924312012-12-28 11:35:12 -0800107{
108public:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800109 TunnelClosure(const DataCallback &dataCallback, CcnxTunnel &tunnel,
110 const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800111
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800112 TunnelClosure(const Closure &closure, CcnxTunnel &tunnel, const Name &originalInterest);
Zhenkai Zhud4924312012-12-28 11:35:12 -0800113
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -0800114 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800115 runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800116
Zhenkai Zhu974c5a62012-12-28 14:15:30 -0800117 virtual TimeoutCallbackReturnValue
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800118 runTimeoutCallback(const Name &interest) _OVERRIDE;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800119
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800120 virtual Closure *
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800121 dup() const;
Zhenkai Zhu19f81de2013-01-04 22:27:47 -0800122
Zhenkai Zhud4924312012-12-28 11:35:12 -0800123private:
Alexander Afanasyevd6c2a902013-01-19 21:24:30 -0800124 CcnxTunnel &m_tunnel;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -0800125 Name m_originalInterest;
Zhenkai Zhud4924312012-12-28 11:35:12 -0800126};
127
Zhenkai Zhu0f054122012-12-25 22:22:50 -0800128};
129
130#endif