NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
unix-transport.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2017 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*/
21
22
#include "
unix-transport.hpp
"
23
#include "
stream-transport-impl.hpp
"
24
25
#include "../face.hpp"
26
#include "
net/face-uri.hpp
"
27
#include "
util/logger.hpp
"
28
29
NDN_LOG_INIT
(
ndn
.
UnixTransport
);
30
// DEBUG level: connect, close, pause, resume.
31
32
namespace
ndn
{
33
34
UnixTransport::UnixTransport
(
const
std::string& unixSocket)
35
: m_unixSocket(unixSocket)
36
{
37
}
38
39
UnixTransport::~UnixTransport
() =
default
;
40
41
std::string
42
UnixTransport::getSocketNameFromUri(
const
std::string& uriString)
43
{
44
// Assume the default nfd.sock location.
45
std::string path =
"/var/run/nfd.sock"
;
46
47
if
(uriString.empty()) {
48
return
path;
49
}
50
51
try
{
52
const
FaceUri
uri(uriString);
53
54
if
(uri.
getScheme
() !=
"unix"
) {
55
BOOST_THROW_EXCEPTION(
Error
(
"Cannot create UnixTransport from \""
+
56
uri.
getScheme
() +
"\" URI"
));
57
}
58
59
if
(!uri.
getPath
().empty()) {
60
path = uri.
getPath
();
61
}
62
}
63
catch
(
const
FaceUri::Error
& error) {
64
BOOST_THROW_EXCEPTION(
Error
(error.what()));
65
}
66
67
return
path;
68
}
69
70
shared_ptr<UnixTransport>
71
UnixTransport::create
(
const
std::string& uri)
72
{
73
return
make_shared<UnixTransport>(getSocketNameFromUri(uri));
74
}
75
76
void
77
UnixTransport::connect
(boost::asio::io_service& ioService,
78
const
ReceiveCallback
& receiveCallback)
79
{
80
NDN_LOG_DEBUG
(
"connect path="
<< m_unixSocket);
81
82
if
(m_impl ==
nullptr
) {
83
Transport::connect
(ioService, receiveCallback);
84
85
m_impl = make_shared<Impl>(ref(*
this
), ref(ioService));
86
}
87
88
m_impl->connect(boost::asio::local::stream_protocol::endpoint(m_unixSocket));
89
}
90
91
void
92
UnixTransport::send
(
const
Block
& wire)
93
{
94
BOOST_ASSERT(m_impl !=
nullptr
);
95
m_impl->send(wire);
96
}
97
98
void
99
UnixTransport::send
(
const
Block
& header,
const
Block
& payload)
100
{
101
BOOST_ASSERT(m_impl !=
nullptr
);
102
m_impl->send(header, payload);
103
}
104
105
void
106
UnixTransport::close
()
107
{
108
BOOST_ASSERT(m_impl !=
nullptr
);
109
NDN_LOG_DEBUG
(
"close"
);
110
m_impl->close();
111
m_impl.reset();
112
}
113
114
void
115
UnixTransport::pause
()
116
{
117
if
(m_impl !=
nullptr
) {
118
NDN_LOG_DEBUG
(
"pause"
);
119
m_impl->pause();
120
}
121
}
122
123
void
124
UnixTransport::resume
()
125
{
126
BOOST_ASSERT(m_impl !=
nullptr
);
127
NDN_LOG_DEBUG
(
"resume"
);
128
m_impl->resume();
129
}
130
131
}
// namespace ndn
ndn::UnixTransport
a transport using Unix stream socket
Definition:
unix-transport.hpp:43
ndn::Transport::Error
Definition:
transport.hpp:43
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
unix-transport.hpp
ndn::UnixTransport::send
void send(const Block &wire) override
send a TLV block through the transport
Definition:
unix-transport.cpp:92
ndn::UnixTransport::create
static shared_ptr< UnixTransport > create(const std::string &uri)
Create transport with parameters defined in URI.
Definition:
unix-transport.cpp:71
NDN_LOG_INIT
#define NDN_LOG_INIT(name)
declare a log module
Definition:
logger.hpp:32
ndn::UnixTransport::pause
void pause() override
pause the transport
Definition:
unix-transport.cpp:115
NDN_LOG_DEBUG
#define NDN_LOG_DEBUG(expression)
Definition:
logger.hpp:35
ndn::UnixTransport::resume
void resume() override
resume the transport
Definition:
unix-transport.cpp:124
ndn::UnixTransport::~UnixTransport
~UnixTransport() override
ndn::UnixTransport::close
void close() override
Close the connection.
Definition:
unix-transport.cpp:106
stream-transport-impl.hpp
ndn::FaceUri::Error
Definition:
face-uri.hpp:46
ndn::FaceUri
represents the underlying protocol and address used by a Face
Definition:
face-uri.hpp:43
ndn::FaceUri::getScheme
const std::string & getScheme() const
get scheme (protocol)
Definition:
face-uri.hpp:112
ndn::UnixTransport::connect
void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback) override
asynchronously open the connection
Definition:
unix-transport.cpp:77
ndn::UnixTransport::UnixTransport
UnixTransport(const std::string &unixSocket)
Definition:
unix-transport.cpp:34
logger.hpp
face-uri.hpp
ndn::Transport::ReceiveCallback
function< void(const Block &wire)> ReceiveCallback
Definition:
transport.hpp:52
ndn::Transport::connect
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback)
asynchronously open the connection
Definition:
transport.cpp:44
ndn::FaceUri::getPath
const std::string & getPath() const
get path
Definition:
face-uri.hpp:133
ndnSIM
ndn-cxx
src
transport
unix-transport.cpp
Generated on Thu Nov 2 2017 03:30:29 for ndnSIM by
1.8.11