EMANE  1.2.1
nemdirector.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2009-2010 - 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 "configurationparser.h"
35 #include "nemdirector.h"
36 #include <sstream>
37 
39  NEMBuilder &builder):
40  configPlatform_(filename),
41  rNEMBuilder_(builder)
42 {}
43 
44 /*
45  * Destructor
46  */
48 {}
49 
50 std::unique_ptr<EMANE::Application::NEMManager>
52 {
53  NEMs nems;
54 
55  for(const auto & nemConfiguration : configPlatform_.getNEMs())
56  {
57  nems.push_back(createNEM(nemConfiguration));
58  }
59 
60  /* Construct a platform first (initialized) */
61  std::unique_ptr<NEMManager>
62  pPlatform{rNEMBuilder_.buildNEMManager(uuid,
63  nems,
64  configPlatform_.getConfigurationUpdateRequest())};
65 
66 
67  return pPlatform;
68 }
69 
70 std::unique_ptr<EMANE::Application::NEM>
71 EMANE::Application::NEMDirector::createNEM(EMANE::NEMConfiguration *pNEMConfig)
72 {
73  NEMLayers layers;
74  if (pNEMConfig->isValid())
75  {
76  EMANE::LayerConfigurations::const_iterator layerIter =
77  pNEMConfig->getLayers().begin();
78 
79  for ( ; layerIter != pNEMConfig->getLayers().end(); ++layerIter)
80  {
81  if ((*layerIter)->getType() == "phy")
82  {
83  layers.push_back(rNEMBuilder_.buildPHYLayer(
84  pNEMConfig->getNEMId(),
85  (*layerIter)->getLibrary(),
86  (*layerIter)->getConfigurationUpdateRequest()));
87  }
88  else if ((*layerIter)->getType() == "mac")
89  {
90  layers.push_back(rNEMBuilder_.buildMACLayer(
91  pNEMConfig->getNEMId(),
92  (*layerIter)->getLibrary(),
93  (*layerIter)->getConfigurationUpdateRequest()));
94  }
95  else if ((*layerIter)->getType() == "shim")
96  {
97  layers.push_back(rNEMBuilder_.buildShimLayer(
98  pNEMConfig->getNEMId(),
99  (*layerIter)->getLibrary(),
100  (*layerIter)->getConfigurationUpdateRequest()));
101  }
102  else if ((*layerIter)->getType() == "transport" && !pNEMConfig->isExternalTransport())
103  {
104  layers.push_back(rNEMBuilder_.buildTransportLayer(
105  pNEMConfig->getNEMId(),
106  (*layerIter)->getLibrary(),
107  (*layerIter)->getConfigurationUpdateRequest()));
108  }
109  }// end for layers
110  }// end if valid
111  else
112  {
113  std::stringstream excStream;
114  excStream << "NEM "
115  << pNEMConfig->getNEMId()
116  << ")"
117  << " is NOT properly configured!"
118  << std::endl
119  << std::endl
120  << "Possible reason(s):"
121  << std::endl
122  << std::endl
123  << " * "
124  << " NEM XML is missing one of phy|mac|transport."
125  << std::endl
126  << std::ends;
127 
128  throw ConfigureException(excStream.str());
129  }
130 
131  return rNEMBuilder_.buildNEM(pNEMConfig->getNEMId(),
132  layers,
133  pNEMConfig->getConfigurationUpdateRequest(),
134  pNEMConfig->isExternalTransport());
135 }
const NEMConfigurations & getNEMs()
std::list< std::unique_ptr< NEMLayer > > NEMLayers
Definition: nembuilder.h:51
std::unique_ptr< NEMManager > buildNEMManager(const uuid_t &uuid, NEMs &nems, const ConfigurationUpdateRequest &request)
Definition: nembuilder.cc:324
std::unique_ptr< NEMLayer > buildMACLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:159
Exception thrown when failures in configuration occur.
std::unique_ptr< NEMLayer > buildPHYLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:87
NEMDirector(const std::string &filename, NEMBuilder &builder)
Definition: nemdirector.cc:38
std::unique_ptr< NEMManager > construct(const uuid_t &uuid)
Definition: nemdirector.cc:51
const LayerConfigurations & getLayers()
const ConfigurationUpdateRequest getConfigurationUpdateRequest()
std::unique_ptr< NEM > buildNEM(NEMId id, NEMLayers &layers, const ConfigurationUpdateRequest &request, bool bHasExternalTransport)
Definition: nembuilder.cc:281
std::list< std::unique_ptr< NEM > > NEMs
Definition: nembuilder.h:52
std::unique_ptr< NEMLayer > buildTransportLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:355
Contains all configuration associated with an NEM.
Provides methods for constructing an emulator instance from its constituent parts.
Definition: nembuilder.h:60
std::unique_ptr< NEMLayer > buildShimLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:220