NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
netlink-socket.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2019 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
* @author Davide Pesavento <davide.pesavento@lip6.fr>
22
*/
23
24
#ifndef NDN_NET_NETLINK_SOCKET_HPP
25
#define NDN_NET_NETLINK_SOCKET_HPP
26
27
#include "
ndn-cxx/net/network-monitor.hpp
"
28
#include "
ndn-cxx/util/signal/signal.hpp
"
29
30
#include <boost/asio/generic/raw_protocol.hpp>
31
#include <map>
32
#include <vector>
33
34
#ifndef NDN_CXX_HAVE_NETLINK
35
#error "This file should not be included ..."
36
#endif
37
38
namespace
ndn
{
39
namespace
net
{
40
41
class
NetlinkMessage;
42
43
class
NetlinkSocket
: noncopyable
44
{
45
public
:
46
using
Error
=
NetworkMonitor::Error
;
47
using
MessageCallback
= std::function<void(
const
NetlinkMessage
&)>;
48
49
void
50
joinGroup
(
int
group);
51
52
void
53
registerNotificationCallback
(
MessageCallback
cb);
54
55
protected
:
56
explicit
57
NetlinkSocket
(boost::asio::io_service& io);
58
59
~NetlinkSocket
();
60
61
void
62
open
(
int
protocol);
63
64
void
65
registerRequestCallback
(uint32_t seq,
MessageCallback
cb);
66
67
virtual
std::string
68
nlmsgTypeToString
(uint16_t type)
const
;
69
70
private
:
71
void
72
asyncWait();
73
74
void
75
receiveAndValidate();
76
77
protected
:
78
shared_ptr<boost::asio::generic::raw_protocol::socket>
m_sock
;
79
uint32_t
m_pid
;
80
uint32_t
m_seqNum
;
81
82
private
:
83
std::vector<uint8_t> m_buffer;
84
std::map<uint32_t, MessageCallback> m_pendingRequests;
85
};
86
87
class
RtnlSocket
final :
public
NetlinkSocket
88
{
89
public
:
90
explicit
91
RtnlSocket
(boost::asio::io_service& io);
92
93
void
94
open
();
95
96
void
97
sendDumpRequest
(uint16_t nlmsgType,
98
const
void
* payload,
size_t
payloadLen,
99
MessageCallback
cb);
100
101
protected
:
102
std::string
103
nlmsgTypeToString
(uint16_t type)
const
final
;
104
};
105
106
class
GenlSocket
;
107
108
class
GenlFamilyResolver
: noncopyable
109
{
110
public
:
111
GenlFamilyResolver
(std::string familyName,
GenlSocket
& socket);
112
113
util::Signal<GenlFamilyResolver, uint16_t>
onResolved
;
114
util::Signal<GenlFamilyResolver>
onError
;
115
116
private
:
117
void
118
asyncResolve();
119
120
void
121
handleResolve(
const
NetlinkMessage
& nlmsg);
122
123
private
:
124
GenlSocket
& m_sock;
125
std::string m_family;
126
};
127
128
class
GenlSocket
final :
public
NetlinkSocket
129
{
130
public
:
131
explicit
132
GenlSocket
(boost::asio::io_service& io);
133
134
void
135
open
();
136
137
void
138
sendRequest
(
const
std::string& familyName, uint8_t command,
139
const
void
* payload,
size_t
payloadLen,
140
MessageCallback
messageCb, std::function<
void
()> errorCb);
141
142
void
143
sendRequest
(uint16_t familyId, uint8_t command,
144
const
void
* payload,
size_t
payloadLen,
145
MessageCallback
messageCb);
146
147
protected
:
148
std::string
149
nlmsgTypeToString
(uint16_t type)
const
final
;
150
151
private
:
152
std::map<std::string, uint16_t> m_cachedFamilyIds;
153
std::map<std::string, GenlFamilyResolver> m_familyResolvers;
154
};
155
156
}
// namespace net
157
}
// namespace ndn
158
159
#endif // NDN_NET_NETLINK_SOCKET_HPP
ndn::net::NetlinkSocket::m_sock
shared_ptr< boost::asio::generic::raw_protocol::socket > m_sock
netlink socket descriptor
Definition:
netlink-socket.hpp:78
ndn::net::NetlinkSocket::registerRequestCallback
void registerRequestCallback(uint32_t seq, MessageCallback cb)
Definition:
netlink-socket.cpp:194
ndn::net::RtnlSocket
Definition:
netlink-socket.hpp:88
ndn::net::NetlinkSocket::joinGroup
void joinGroup(int group)
Definition:
netlink-socket.cpp:178
ndn::net::RtnlSocket::sendDumpRequest
void sendDumpRequest(uint16_t nlmsgType, const void *payload, size_t payloadLen, MessageCallback cb)
Definition:
netlink-socket.cpp:363
ndn::net::GenlSocket::open
void open()
Definition:
netlink-socket.cpp:426
ndn::net::GenlFamilyResolver::GenlFamilyResolver
GenlFamilyResolver(std::string familyName, GenlSocket &socket)
Definition:
netlink-socket.cpp:510
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition:
signal.hpp:52
ndn::net::GenlSocket::sendRequest
void sendRequest(const std::string &familyName, uint8_t command, const void *payload, size_t payloadLen, MessageCallback messageCb, std::function< void()> errorCb)
Definition:
netlink-socket.cpp:433
ndn::net::NetlinkMessage
Definition:
netlink-message.hpp:140
ndn::net::NetlinkSocket::registerNotificationCallback
void registerNotificationCallback(MessageCallback cb)
Definition:
netlink-socket.cpp:188
ndn::net::GenlSocket
Definition:
netlink-socket.hpp:129
ndn::net::RtnlSocket::open
void open()
Definition:
netlink-socket.cpp:356
ndn::net::NetlinkSocket::open
void open(int protocol)
Definition:
netlink-socket.cpp:105
signal.hpp
ndn::net::NetlinkSocket::nlmsgTypeToString
virtual std::string nlmsgTypeToString(uint16_t type) const
Definition:
netlink-socket.cpp:208
ndn::net::GenlFamilyResolver::onResolved
util::Signal< GenlFamilyResolver, uint16_t > onResolved
Definition:
netlink-socket.hpp:113
ndn::net::NetlinkSocket::m_pid
uint32_t m_pid
port ID of this socket
Definition:
netlink-socket.hpp:79
ndn::net::GenlSocket::nlmsgTypeToString
std::string nlmsgTypeToString(uint16_t type) const final
Definition:
netlink-socket.cpp:599
ndn::net::RtnlSocket::nlmsgTypeToString
std::string nlmsgTypeToString(uint16_t type) const final
Definition:
netlink-socket.cpp:400
ndn::net::NetlinkSocket::~NetlinkSocket
~NetlinkSocket()
Definition:
netlink-socket.cpp:98
ndn::net::NetlinkSocket::m_seqNum
uint32_t m_seqNum
sequence number of the last netlink request sent to the kernel
Definition:
netlink-socket.hpp:80
ndn::net
Definition:
link-type-helper.cpp:30
ndn::net::RtnlSocket::RtnlSocket
RtnlSocket(boost::asio::io_service &io)
Definition:
netlink-socket.cpp:350
network-monitor.hpp
ndn::net::GenlSocket::GenlSocket
GenlSocket(boost::asio::io_service &io)
Definition:
netlink-socket.cpp:419
ndn::net::NetlinkSocket::NetlinkSocket
NetlinkSocket(boost::asio::io_service &io)
Definition:
netlink-socket.cpp:90
ndn::net::NetlinkSocket::MessageCallback
std::function< void(const NetlinkMessage &)> MessageCallback
Definition:
netlink-socket.hpp:47
ndn::net::GenlFamilyResolver::onError
util::Signal< GenlFamilyResolver > onError
Definition:
netlink-socket.hpp:114
ndn::net::NetlinkSocket
Definition:
netlink-socket.hpp:44
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::net::NetworkMonitor::Error
Definition:
network-monitor.hpp:54
ndn::net::GenlFamilyResolver
Definition:
netlink-socket.hpp:109
ndnSIM
ndn-cxx
ndn-cxx
net
impl
netlink-socket.hpp
Generated on Mon Jun 1 2020 22:32:14 for ndnSIM by
1.8.18