NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
ethernet-factory.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "ethernet-factory.hpp"
27 #include "face/ethernet-face.hpp"
28 
29 #include "core/logger.hpp"
30 #include "core/global-io.hpp"
31 
32 namespace nfd {
33 
34 shared_ptr<EthernetFace>
36  const ethernet::Address &address)
37 {
38  if (!address.isMulticast())
39  BOOST_THROW_EXCEPTION(Error(address.toString() + " is not a multicast address"));
40 
41  shared_ptr<EthernetFace> face = findMulticastFace(interface.name, address);
42  if (face)
43  return face;
44 
45  face = make_shared<EthernetFace>(boost::asio::posix::stream_descriptor(getGlobalIoService()),
46  interface, address);
47 
48  auto key = std::make_pair(interface.name, address);
49  face->onFail.connectSingleShot([this, key] (const std::string& reason) {
50  m_multicastFaces.erase(key);
51  });
52  m_multicastFaces.insert({key, face});
53 
54  return face;
55 }
56 
57 shared_ptr<EthernetFace>
58 EthernetFactory::findMulticastFace(const std::string& interfaceName,
59  const ethernet::Address& address) const
60 {
61  auto it = m_multicastFaces.find({interfaceName, address});
62  if (it != m_multicastFaces.end())
63  return it->second;
64  else
65  return {};
66 }
67 
68 void
70  ndn::nfd::FacePersistency persistency,
71  const FaceCreatedCallback& onCreated,
72  const FaceConnectFailedCallback& onConnectFailed)
73 {
74  BOOST_THROW_EXCEPTION(Error("EthernetFactory does not support 'createFace' operation"));
75 }
76 
77 std::list<shared_ptr<const Channel>>
79 {
80  return {};
81 }
82 
83 } // namespace nfd
function< void(const std::string &reason)> FaceConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
represents an Ethernet hardware address
Definition: ethernet.hpp:53
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
contains information about a network interface
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onCreated, const FaceConnectFailedCallback &onConnectFailed) 1
Try to create Face using the supplied FaceUri.
bool isMulticast() const
True if this is a multicast address.
Definition: ethernet.cpp:60
std::string toString(char sep= ':') const
Converts the address to a human-readable string.
Definition: ethernet.cpp:72
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
shared_ptr< EthernetFace > createMulticastFace(const NetworkInterfaceInfo &interface, const ethernet::Address &address)
Create an EthernetFace to communicate with the given multicast group.
virtual std::list< shared_ptr< const Channel > > getChannels() const
Exception of EthernetFactory.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
boost::asio::io_service & getGlobalIoService()
Definition: global-io.hpp:35