Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_FACE_ETHERNET_FACE_HPP |
| 8 | #define NFD_FACE_ETHERNET_FACE_HPP |
| 9 | |
| 10 | #include "ethernet.hpp" |
| 11 | #include "face.hpp" |
| 12 | |
| 13 | #ifndef HAVE_PCAP |
| 14 | #error "Cannot include this file when pcap is not available" |
| 15 | #endif |
| 16 | |
| 17 | // forward declarations |
| 18 | struct pcap; |
| 19 | typedef pcap pcap_t; |
| 20 | |
| 21 | namespace nfd { |
| 22 | |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 23 | class NetworkInterfaceInfo; |
| 24 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 25 | /** |
| 26 | * \brief Implementation of Face abstraction that uses raw |
| 27 | * Ethernet frames as underlying transport mechanism |
| 28 | */ |
| 29 | class EthernetFace : public Face |
| 30 | { |
| 31 | public: |
| 32 | /** |
| 33 | * \brief EthernetFace-related error |
| 34 | */ |
| 35 | struct Error : public Face::Error |
| 36 | { |
| 37 | Error(const std::string& what) : Face::Error(what) {} |
| 38 | }; |
| 39 | |
| 40 | EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket, |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 41 | const shared_ptr<NetworkInterfaceInfo>& interface, |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 42 | const ethernet::Address& address); |
| 43 | |
| 44 | virtual |
| 45 | ~EthernetFace(); |
| 46 | |
| 47 | /// send an Interest |
| 48 | virtual void |
| 49 | sendInterest(const Interest& interest); |
| 50 | |
| 51 | /// send a Data |
| 52 | virtual void |
| 53 | sendData(const Data& data); |
| 54 | |
| 55 | /** |
| 56 | * \brief Close the face |
| 57 | * |
| 58 | * This terminates all communication on the face and cause |
| 59 | * onFail() method event to be invoked |
| 60 | */ |
| 61 | virtual void |
| 62 | close(); |
| 63 | |
| 64 | private: |
| 65 | void |
| 66 | pcapInit(); |
| 67 | |
| 68 | void |
| 69 | setPacketFilter(const char* filterString); |
| 70 | |
| 71 | void |
| 72 | sendPacket(const ndn::Block& block); |
| 73 | |
| 74 | void |
| 75 | handleRead(const boost::system::error_code& error, |
| 76 | size_t nBytesRead); |
| 77 | |
| 78 | void |
| 79 | processErrorCode(const boost::system::error_code& error); |
| 80 | |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 81 | size_t |
| 82 | getInterfaceMtu() const; |
| 83 | |
| 84 | private: |
| 85 | shared_ptr<boost::asio::posix::stream_descriptor> m_socket; |
Davide Pesavento | b60cc12 | 2014-03-19 19:26:02 +0100 | [diff] [blame] | 86 | std::string m_interfaceName; |
| 87 | ethernet::Address m_srcAddress; |
Davide Pesavento | 44deacc | 2014-02-19 10:48:07 +0100 | [diff] [blame] | 88 | ethernet::Address m_destAddress; |
| 89 | size_t m_interfaceMtu; |
| 90 | pcap_t* m_pcap; |
| 91 | }; |
| 92 | |
| 93 | } // namespace nfd |
| 94 | |
| 95 | #endif // NFD_FACE_ETHERNET_FACE_HPP |