Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [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 | * |
| 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 Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 25 | #ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP |
| 26 | #define NFD_DAEMON_FACE_ETHERNET_FACE_HPP |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 27 | |
| 28 | #include "ethernet.hpp" |
| 29 | #include "face.hpp" |
| 30 | |
Alexander Afanasyev | 885a85b | 2014-04-12 21:01:13 -0700 | [diff] [blame] | 31 | #ifndef HAVE_LIBPCAP |
| 32 | #error "Cannot include this file when libpcap is not available" |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | // forward declarations |
| 36 | struct pcap; |
| 37 | typedef pcap pcap_t; |
| 38 | |
| 39 | namespace nfd { |
| 40 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 41 | class NetworkInterfaceInfo; |
| 42 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 43 | /** |
| 44 | * \brief Implementation of Face abstraction that uses raw |
| 45 | * Ethernet frames as underlying transport mechanism |
| 46 | */ |
| 47 | class EthernetFace : public Face |
| 48 | { |
| 49 | public: |
| 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 Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 59 | const shared_ptr<NetworkInterfaceInfo>& interface, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 60 | 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 | |
| 82 | private: |
| 83 | void |
| 84 | pcapInit(); |
| 85 | |
| 86 | void |
| 87 | setPacketFilter(const char* filterString); |
| 88 | |
| 89 | void |
| 90 | sendPacket(const ndn::Block& block); |
| 91 | |
| 92 | void |
| 93 | handleRead(const boost::system::error_code& error, |
| 94 | size_t nBytesRead); |
| 95 | |
| 96 | void |
| 97 | processErrorCode(const boost::system::error_code& error); |
| 98 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 99 | size_t |
| 100 | getInterfaceMtu() const; |
| 101 | |
| 102 | private: |
| 103 | shared_ptr<boost::asio::posix::stream_descriptor> m_socket; |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 104 | std::string m_interfaceName; |
| 105 | ethernet::Address m_srcAddress; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 106 | ethernet::Address m_destAddress; |
| 107 | size_t m_interfaceMtu; |
| 108 | pcap_t* m_pcap; |
| 109 | }; |
| 110 | |
| 111 | } // namespace nfd |
| 112 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 113 | #endif // NFD_DAEMON_FACE_ETHERNET_FACE_HPP |