blob: a6394cebfe768fbe4d42e6c3768914ca49af453f [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- 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
18struct pcap;
19typedef pcap pcap_t;
20
21namespace nfd {
22
23/**
24 * \brief Implementation of Face abstraction that uses raw
25 * Ethernet frames as underlying transport mechanism
26 */
27class EthernetFace : public Face
28{
29public:
30 /**
31 * \brief EthernetFace-related error
32 */
33 struct Error : public Face::Error
34 {
35 Error(const std::string& what) : Face::Error(what) {}
36 };
37
38 EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
39 const ethernet::Endpoint& interface,
40 const ethernet::Address& address);
41
42 virtual
43 ~EthernetFace();
44
45 /// send an Interest
46 virtual void
47 sendInterest(const Interest& interest);
48
49 /// send a Data
50 virtual void
51 sendData(const Data& data);
52
53 /**
54 * \brief Close the face
55 *
56 * This terminates all communication on the face and cause
57 * onFail() method event to be invoked
58 */
59 virtual void
60 close();
61
62private:
63 void
64 pcapInit();
65
66 void
67 setPacketFilter(const char* filterString);
68
69 void
70 sendPacket(const ndn::Block& block);
71
72 void
73 handleRead(const boost::system::error_code& error,
74 size_t nBytesRead);
75
76 void
77 processErrorCode(const boost::system::error_code& error);
78
79 ethernet::Address
80 getInterfaceAddress() const;
81
82 size_t
83 getInterfaceMtu() const;
84
85private:
86 shared_ptr<boost::asio::posix::stream_descriptor> m_socket;
87 ethernet::Endpoint m_interface;
88 ethernet::Address m_sourceAddress;
89 ethernet::Address m_destAddress;
90 size_t m_interfaceMtu;
91 pcap_t* m_pcap;
92};
93
94} // namespace nfd
95
96#endif // NFD_FACE_ETHERNET_FACE_HPP