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 "ethernet-transport.hpp"
28 #include "generic-link-service.hpp"
29 
30 namespace nfd {
31 
32 shared_ptr<Face>
34  const ethernet::Address& address)
35 {
36  if (!address.isMulticast())
37  BOOST_THROW_EXCEPTION(Error(address.toString() + " is not a multicast address"));
38 
39  auto face = findMulticastFace(interface.name, address);
40  if (face)
41  return face;
42 
44  opts.allowFragmentation = true;
45  opts.allowReassembly = true;
46 
47  auto linkService = make_unique<face::GenericLinkService>(opts);
48  auto transport = make_unique<face::EthernetTransport>(interface, address);
49  face = make_shared<Face>(std::move(linkService), std::move(transport));
50 
51  auto key = std::make_pair(interface.name, address);
52  m_multicastFaces[key] = face;
53  connectFaceClosedSignal(*face, [this, key] { m_multicastFaces.erase(key); });
54 
55  return face;
56 }
57 
58 void
60  ndn::nfd::FacePersistency persistency,
61  const FaceCreatedCallback& onCreated,
62  const FaceCreationFailedCallback& onConnectFailed)
63 {
64  BOOST_THROW_EXCEPTION(Error("EthernetFactory does not support 'createFace' operation"));
65 }
66 
67 std::vector<shared_ptr<const Channel>>
69 {
70  return {};
71 }
72 
73 shared_ptr<Face>
74 EthernetFactory::findMulticastFace(const std::string& interfaceName,
75  const ethernet::Address& address) const
76 {
77  auto i = m_multicastFaces.find({interfaceName, address});
78  if (i != m_multicastFaces.end())
79  return i->second;
80  else
81  return nullptr;
82 }
83 
84 } // namespace nfd
function< void(const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
represents an Ethernet hardware address
Definition: ethernet.hpp:53
represents the underlying protocol and address used by a Face
Definition: face-uri.hpp:44
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
Definition: channel.cpp:41
contains information about a network interface
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onConnectFailed) 1
Try to create Face using the supplied FaceUri.
virtual std::vector< shared_ptr< const Channel > > getChannels() const 1
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
shared_ptr< Face > createMulticastFace(const NetworkInterfaceInfo &interface, const ethernet::Address &address)
Create an EthernetFace to communicate with the given multicast group.
Options that control the behavior of GenericLinkService.
Exception of EthernetFactory.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
Definition: channel.hpp:38
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
bool allowFragmentation
enables fragmentation