EMANE  1.2.1
nemlayerstack.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "nemlayerstack.h"
35 
37 
39 
40 
42  DownstreamTransport * pDownstreamTransport)
43 {
44  UpstreamTransport * pCurrentUpstreamTransport = pUpstreamTransport;
45 
46  for(auto & pNEMLayer : nemLayers_)
47  {
48  pCurrentUpstreamTransport->setDownstreamTransport(pNEMLayer.get());
49 
50  pNEMLayer->setUpstreamTransport(pCurrentUpstreamTransport);
51 
52  pCurrentUpstreamTransport = pNEMLayer.get();
53  }
54 
55  pCurrentUpstreamTransport->setDownstreamTransport(pDownstreamTransport);
56 
57  pDownstreamTransport->setUpstreamTransport(pCurrentUpstreamTransport);
58 }
59 
60 
61 /*
62  * NEMNetworkAdapter (connectLayers UpstreamTransport * param)
63  * ... --
64  * MAC |
65  * ... | - stack addLayer, bottom of stack pushed first.
66  * ... | where, ... can be 0 or more shims
67  * PHY |
68  * ... --
69  * NEMOTAAdapter (connectLayers DownstreamTransport * param)
70  */
71 void EMANE::NEMLayerStack::addLayer(std::unique_ptr<NEMLayer> & pNEMLayer)
72 {
73  nemLayers_.push_back(std::move(pNEMLayer));
74 }
75 
76 
77 // NEMLayers initialized individually by the builder
79 {}
80 
81 // NEMLayers initialized individually by the builder
83 {}
84 
86 {
87  std::for_each(nemLayers_.begin(),
88  nemLayers_.end(),
89  std::bind(&Component::start,std::placeholders::_1));
90 }
91 
93 {
94  std::for_each(nemLayers_.begin(),
95  nemLayers_.end(),
96  std::bind(&Component::postStart,std::placeholders::_1));
97 }
98 
100 {
101  std::for_each(nemLayers_.begin(),
102  nemLayers_.end(),
103  std::bind(&Component::stop,std::placeholders::_1));
104 }
105 
107  throw()
108 {
109  std::for_each(nemLayers_.begin(),
110  nemLayers_.end(),
111  std::bind(&Component::destroy,std::placeholders::_1));
112 }
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
void initialize(Registrar &registrar) override
void start() override
void destroy() override
void connectLayers(UpstreamTransport *pUpstreamTransport, DownstreamTransport *pDownstreamTransport)
virtual void postStart()
Definition: component.h:119
virtual void stop()=0
void stop() override
void configure(const ConfigurationUpdate &items) override
virtual void setUpstreamTransport(UpstreamTransport *pUpstreamTransport)
virtual void setDownstreamTransport(DownstreamTransport *pDownstreamTransport)
void postStart() override
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
UpstreamTransport allows for processing upstream data and control messages. Upstream packets and cont...
void addLayer(std::unique_ptr< NEMLayer > &pNEMLayer)
virtual void destroy()=0
virtual void start()=0
DownstreamTransport allows for processing downstream data and control messages.