blob: 0c673c3bd07e0269812261b4e19db6a89d822fbe [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * 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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Davide Pesavento44deacc2014-02-19 10:48:07 +010025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP
27#define NFD_DAEMON_FACE_ETHERNET_FACE_HPP
Davide Pesavento44deacc2014-02-19 10:48:07 +010028
Davide Pesaventof0ae4422014-05-05 16:32:12 +020029#include "config.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010030#include "face.hpp"
Junxiao Shia1937bf2014-11-06 11:43:40 -070031#include "core/network-interface.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010032
Alexander Afanasyev885a85b2014-04-12 21:01:13 -070033#ifndef HAVE_LIBPCAP
34#error "Cannot include this file when libpcap is not available"
Davide Pesavento44deacc2014-02-19 10:48:07 +010035#endif
36
37// forward declarations
38struct pcap;
39typedef pcap pcap_t;
40
41namespace nfd {
42
43/**
44 * \brief Implementation of Face abstraction that uses raw
45 * Ethernet frames as underlying transport mechanism
46 */
47class EthernetFace : public Face
48{
49public:
50 /**
51 * \brief EthernetFace-related error
52 */
53 struct Error : public Face::Error
54 {
55 Error(const std::string& what) : Face::Error(what) {}
56 };
57
58 EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
Davide Pesaventob499a602014-11-18 22:36:56 +010059 const NetworkInterfaceInfo& interface,
Davide Pesavento44deacc2014-02-19 10:48:07 +010060 const ethernet::Address& address);
61
62 virtual
63 ~EthernetFace();
64
65 /// send an Interest
66 virtual void
67 sendInterest(const Interest& interest);
68
69 /// send a Data
70 virtual void
71 sendData(const Data& data);
72
73 /**
74 * \brief Close the face
75 *
76 * This terminates all communication on the face and cause
77 * onFail() method event to be invoked
78 */
79 virtual void
80 close();
81
82private:
83 void
84 pcapInit();
85
86 void
87 setPacketFilter(const char* filterString);
88
89 void
Davide Pesavento10783f22014-03-15 04:40:01 +010090 joinMulticastGroup();
91
92 void
Davide Pesavento44deacc2014-02-19 10:48:07 +010093 sendPacket(const ndn::Block& block);
94
95 void
96 handleRead(const boost::system::error_code& error,
97 size_t nBytesRead);
98
99 void
100 processErrorCode(const boost::system::error_code& error);
101
Davide Pesavento44deacc2014-02-19 10:48:07 +0100102 size_t
103 getInterfaceMtu() const;
104
105private:
106 shared_ptr<boost::asio::posix::stream_descriptor> m_socket;
Davide Pesavento10783f22014-03-15 04:40:01 +0100107#if defined(__linux__)
108 int m_interfaceIndex;
109#endif
Davide Pesaventob60cc122014-03-19 19:26:02 +0100110 std::string m_interfaceName;
111 ethernet::Address m_srcAddress;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100112 ethernet::Address m_destAddress;
113 size_t m_interfaceMtu;
114 pcap_t* m_pcap;
115};
116
117} // namespace nfd
118
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700119#endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP