Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 3 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP |
| 27 | #define NFD_DAEMON_FACE_ETHERNET_FACE_HPP |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 28 | |
Davide Pesavento | f0ae442 | 2014-05-05 16:32:12 +0200 | [diff] [blame] | 29 | #include "config.hpp" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 30 | #include "ethernet.hpp" |
| 31 | #include "face.hpp" |
| 32 | |
Alexander Afanasyev | 885a85b | 2014-04-12 21:01:13 -0700 | [diff] [blame] | 33 | #ifndef HAVE_LIBPCAP |
| 34 | #error "Cannot include this file when libpcap is not available" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | // forward declarations |
| 38 | struct pcap; |
| 39 | typedef pcap pcap_t; |
| 40 | |
| 41 | namespace nfd { |
| 42 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 43 | class NetworkInterfaceInfo; |
| 44 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 45 | /** |
| 46 | * \brief Implementation of Face abstraction that uses raw |
| 47 | * Ethernet frames as underlying transport mechanism |
| 48 | */ |
| 49 | class EthernetFace : public Face |
| 50 | { |
| 51 | public: |
| 52 | /** |
| 53 | * \brief EthernetFace-related error |
| 54 | */ |
| 55 | struct Error : public Face::Error |
| 56 | { |
| 57 | Error(const std::string& what) : Face::Error(what) {} |
| 58 | }; |
| 59 | |
| 60 | EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket, |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 61 | const shared_ptr<NetworkInterfaceInfo>& interface, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 62 | const ethernet::Address& address); |
| 63 | |
| 64 | virtual |
| 65 | ~EthernetFace(); |
| 66 | |
| 67 | /// send an Interest |
| 68 | virtual void |
| 69 | sendInterest(const Interest& interest); |
| 70 | |
| 71 | /// send a Data |
| 72 | virtual void |
| 73 | sendData(const Data& data); |
| 74 | |
| 75 | /** |
| 76 | * \brief Close the face |
| 77 | * |
| 78 | * This terminates all communication on the face and cause |
| 79 | * onFail() method event to be invoked |
| 80 | */ |
| 81 | virtual void |
| 82 | close(); |
| 83 | |
| 84 | private: |
| 85 | void |
| 86 | pcapInit(); |
| 87 | |
| 88 | void |
| 89 | setPacketFilter(const char* filterString); |
| 90 | |
| 91 | void |
| 92 | sendPacket(const ndn::Block& block); |
| 93 | |
| 94 | void |
| 95 | handleRead(const boost::system::error_code& error, |
| 96 | size_t nBytesRead); |
| 97 | |
| 98 | void |
| 99 | processErrorCode(const boost::system::error_code& error); |
| 100 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 101 | size_t |
| 102 | getInterfaceMtu() const; |
| 103 | |
| 104 | private: |
| 105 | shared_ptr<boost::asio::posix::stream_descriptor> m_socket; |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 106 | std::string m_interfaceName; |
| 107 | ethernet::Address m_srcAddress; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 108 | ethernet::Address m_destAddress; |
| 109 | size_t m_interfaceMtu; |
| 110 | pcap_t* m_pcap; |
| 111 | }; |
| 112 | |
| 113 | } // namespace nfd |
| 114 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 115 | #endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP |