blob: 805c0e095f293fdbaa718ffb2876038ef8889f97 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Davide Pesavento44deacc2014-02-19 10:48:07 +010024
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070025#ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP
26#define NFD_DAEMON_FACE_ETHERNET_FACE_HPP
Davide Pesavento44deacc2014-02-19 10:48:07 +010027
Davide Pesaventof0ae4422014-05-05 16:32:12 +020028#include "config.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010029#include "ethernet.hpp"
30#include "face.hpp"
31
Alexander Afanasyev885a85b2014-04-12 21:01:13 -070032#ifndef HAVE_LIBPCAP
33#error "Cannot include this file when libpcap is not available"
Davide Pesavento44deacc2014-02-19 10:48:07 +010034#endif
35
36// forward declarations
37struct pcap;
38typedef pcap pcap_t;
39
40namespace nfd {
41
Davide Pesaventob60cc122014-03-19 19:26:02 +010042class NetworkInterfaceInfo;
43
Davide Pesavento44deacc2014-02-19 10:48:07 +010044/**
45 * \brief Implementation of Face abstraction that uses raw
46 * Ethernet frames as underlying transport mechanism
47 */
48class EthernetFace : public Face
49{
50public:
51 /**
52 * \brief EthernetFace-related error
53 */
54 struct Error : public Face::Error
55 {
56 Error(const std::string& what) : Face::Error(what) {}
57 };
58
59 EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
Davide Pesaventob60cc122014-03-19 19:26:02 +010060 const shared_ptr<NetworkInterfaceInfo>& interface,
Davide Pesavento44deacc2014-02-19 10:48:07 +010061 const ethernet::Address& address);
62
63 virtual
64 ~EthernetFace();
65
66 /// send an Interest
67 virtual void
68 sendInterest(const Interest& interest);
69
70 /// send a Data
71 virtual void
72 sendData(const Data& data);
73
74 /**
75 * \brief Close the face
76 *
77 * This terminates all communication on the face and cause
78 * onFail() method event to be invoked
79 */
80 virtual void
81 close();
82
83private:
84 void
85 pcapInit();
86
87 void
88 setPacketFilter(const char* filterString);
89
90 void
91 sendPacket(const ndn::Block& block);
92
93 void
94 handleRead(const boost::system::error_code& error,
95 size_t nBytesRead);
96
97 void
98 processErrorCode(const boost::system::error_code& error);
99
Davide Pesavento44deacc2014-02-19 10:48:07 +0100100 size_t
101 getInterfaceMtu() const;
102
103private:
104 shared_ptr<boost::asio::posix::stream_descriptor> m_socket;
Davide Pesaventob60cc122014-03-19 19:26:02 +0100105 std::string m_interfaceName;
106 ethernet::Address m_srcAddress;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100107 ethernet::Address m_destAddress;
108 size_t m_interfaceMtu;
109 pcap_t* m_pcap;
110};
111
112} // namespace nfd
113
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700114#endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP