NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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  bool wantLocalFieldsEnabled,
62  const FaceCreatedCallback& onCreated,
63  const FaceCreationFailedCallback& onFailure)
64 {
65  onFailure(406, "Unsupported protocol");
66 }
67 
68 std::vector<shared_ptr<const Channel>>
70 {
71  return {};
72 }
73 
74 shared_ptr<Face>
75 EthernetFactory::findMulticastFace(const std::string& interfaceName,
76  const ethernet::Address& address) const
77 {
78  auto i = m_multicastFaces.find({interfaceName, address});
79  if (i != m_multicastFaces.end())
80  return i->second;
81  else
82  return nullptr;
83 }
84 
85 } // namespace nfd
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 std::vector< shared_ptr< const Channel > > getChannels() const override
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
virtual void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
Try to create Face using the supplied FaceUri.
shared_ptr< Face > createMulticastFace(const NetworkInterfaceInfo &interface, const ethernet::Address &address)
Create an EthernetFace to communicate with the given multicast group.
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
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