EMANE  1.2.1
emaneinfo.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater, New
3  * Jersey
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 Adjacent Link 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 
41 
42 #include "emane/exception.h"
43 #include "manifest.h"
44 #include "configurationloader.h"
45 #include "nemmanagerimpl.h"
46 #include "transportmanagerimpl.h"
48 #include "eventagentmanagerimpl.h"
49 #include "registrarproxy.h"
50 #include "buildidservice.h"
51 #include "otamanager.h"
52 #include <sstream>
53 #include <iostream>
54 #include <tuple>
55 #include <uuid.h>
56 #include <getopt.h>
57 
58 void usage();
59 
60 template<typename T>
62 {
63  uuid_t uuid{};
64  uuid_generate(uuid);
65  T * pManager{new T{uuid}};
66  EMANE::BuildId buildId{0};
67  EMANE::RegistrarProxy registrarProxy{buildId};
68  pManager->initialize(registrarProxy);
69  return pManager;
70 }
71 
72 int main(int argc, char * argv[])
73 {
75 
76  try
77  {
78  std::vector<option> options =
79  {
80  {"help",0,nullptr,'h'},
81  {"version",0,nullptr,'v'},
82  {"configuration",0,nullptr,'c'},
83  {"manifest",0,nullptr,'m'},
84  {0, 0,nullptr,0},
85  };
86 
87  int iOption{};
88  int iOptionIndex{};
89  bool bConfiguration{false};
90  bool bShowManifest{false};
91 
92  while((iOption = getopt_long(argc,argv,"hcmv", &options[0],&iOptionIndex)) != -1)
93  {
94  switch(iOption)
95  {
96  case 'h':
97  usage();
98  return EXIT_SUCCESS;
99  break;
100 
101  case 'v':
102  // --version
103  std::cout<<VERSION<<std::endl;
104  return EXIT_SUCCESS;
105 
106  case 'c':
107  // --configuration
108  bConfiguration = true;
109  break;
110 
111  case 'm':
112  bShowManifest = true;
113  break;
114 
115  default:
116  std::cerr<<"Unknown option: -"<<static_cast<char>(iOption)<<std::endl;
117  return EXIT_FAILURE;
118  }
119  }
120 
121  std::string sFileName;
122 
123  if(optind >= argc)
124  {
125  std::cerr<<"Missing plugin"<<std::endl;
126  return EXIT_FAILURE;
127  }
128  else
129  {
130  sFileName = argv[optind];
131  }
132 
134  EMANE::Application::EventGeneratorBuilder eventGeneratorBuilder;
135  EMANE::Application::EventAgentBuilder eventAgentBuilder;
136  EMANE::Application::TransportBuilder transportBuilder;
137 
139  std::string sPluginName;
141 
142  if(bConfiguration)
143  {
144  EMANE::Application::ConfigurationLoader loader(sFileName);
145  sPluginName = loader.getPluginName();
146  request = loader.getConfigurationUpdateRequest();
147  pluginType = loader.getPluginType();
148  }
149  else
150  {
151  sPluginName = sFileName;
152  }
153 
154  std::unique_ptr<EMANE::Component> pComponent;
155  EMANE::BuildId buildId{};
156 
157  if(sPluginName == "nemmanager")
158  {
159  auto pManager = createManager<EMANE::Application::NEMManagerImpl>();
160  buildId = pManager->getBuildId();
161  pComponent.reset(pManager);
163  }
164  else if(sPluginName == "transportmanager")
165  {
166  auto pManager = createManager<EMANE::Application::TransportManagerImpl>();
167  buildId = pManager->getBuildId();
168  pComponent.reset(pManager);
169  }
170  else if(sPluginName == "eventgeneratormanager")
171  {
172  auto pManager = createManager<EMANE::Application::EventGeneratorManagerImpl>();
173  buildId = pManager->getBuildId();
174  pComponent.reset(pManager);
175  }
176  else if(sPluginName == "eventagentmanager")
177  {
178  auto pManager = createManager<EMANE::Application::EventAgentManagerImpl>();
179  buildId = pManager->getBuildId();
180  pComponent.reset(pManager);
181  }
182  else
183  {
184  if(sPluginName == "emanephy" || sPluginName.empty())
185  {
186  sPluginName.clear();
188  }
189 
190 
191  // the nem layer API is all the same, so you can get
192  // away with building a shim if you are accessing
193  // the Component and Buildable API
194  switch(pluginType)
195  {
197  {
198  auto pPlugin = nemBuilder.buildPHYLayer(1,sPluginName,request,!bConfiguration);
199  buildId = pPlugin->getBuildId();
200  pComponent.reset(pPlugin.release());
201  }
202  break;
203 
205  {
206  auto pPlugin = nemBuilder.buildMACLayer(1,sPluginName,request,!bConfiguration);
207  buildId = pPlugin->getBuildId();
208  pComponent.reset(pPlugin.release());
209  }
210  break;
211 
213  {
214  auto pPlugin = nemBuilder.buildShimLayer(1,sPluginName,request,!bConfiguration);
215  buildId = pPlugin->getBuildId();
216  pComponent.reset(pPlugin.release());
217  }
218  break;
219 
221  {
222  auto pPlugin = eventGeneratorBuilder.buildEventGenerator(sPluginName,request,!bConfiguration);
223  buildId = pPlugin->getBuildId();
224  pComponent.reset(pPlugin.release());
225  }
226  break;
227 
229  {
230  auto pPlugin = eventAgentBuilder.buildEventAgent(1,sPluginName,request,!bConfiguration);
231  buildId = pPlugin->getBuildId();
232  pComponent.reset(pPlugin.release());
233  }
234  break;
235 
237  {
238  auto pPlugin = transportBuilder.buildTransport(1,sPluginName,request,!bConfiguration);
239  buildId = pPlugin->getBuildId();
240  pComponent.reset(pPlugin.release());
241  }
242 
243  break;
244  }
245  }
246 
247  if(bShowManifest)
248  {
249  std::cout<<EMANE::Application::manifest(buildId,sFileName);
250  }
251  }
252  catch(const EMANE::Exception & exp)
253  {
254  std::cerr<<exp.what()<<std::endl;
255 
257 
258  return EXIT_FAILURE;
259  }
260  catch(const std::exception & exp)
261  {
262  std::cerr<<exp.what()<<std::endl;
263 
265 
266  return EXIT_FAILURE;
267  }
268 
270 
271  return EXIT_SUCCESS;
272 }
273 
274 void usage()
275 {
276  std::cout<<"usage: emaneinfo [OPTIONS]... <plugin>|'nemmanager'|'transportmanager'|"<<std::endl;
277  std::cout<<" 'eventagentmanager'|'eventgeneratormanager'"<<std::endl;
278  std::cout<<std::endl;
279  std::cout<<" CONFIG_URI URI of XML configuration file."<<std::endl;
280  std::cout<<std::endl;
281  std::cout<<"options:"<<std::endl;
282  std::cout<<" -h, --help Print this message and exit."<<std::endl;
283  std::cout<<" -m, --manifest Print manifest."<<std::endl;
284  std::cout<<" -v, --version Print version and exit."<<std::endl;
285  std::cout<<std::endl;
286 }
std::unique_ptr< NEMLayer > buildTransport(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false) const
std::unique_ptr< NEMLayer > buildMACLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:159
std::string manifest(BuildId buildId, const std::string &sName)
Definition: manifest.cc:42
void usage()
Definition: emaneinfo.cc:274
Exception base class that allows for type and description information.
Definition: exception.h:49
std::unique_ptr< NEMLayer > buildPHYLayer(NEMId id, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
Definition: nembuilder.cc:87
const EMANE::ConfigurationUpdateRequest & getConfigurationUpdateRequest() const
const char * what() const
Definition: exception.h:62
Provides methods for contructing transports and a manager to contain and control them as a a group...
Provides methods for constructing event generators and a manager to contain and control them as a gro...
std::unique_ptr< EventGenerator > buildEventGenerator(const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
int main(int argc, char *argv[])
Definition: emaneinfo.cc:72
T * createManager()
Definition: emaneinfo.cc:61
std::vector< ConfigurationNameStringValues > ConfigurationUpdateRequest
Provides methods for constructing event agents and a manager to contain and control them as a group...
std::unique_ptr< EventAgent > buildEventAgent(EMANE::NEMId nemId, const std::string &sLibraryFile, const ConfigurationUpdateRequest &request, bool bSkipConfigure=false)
static OTAManager * instance()
Definition: singleton.h:56
std::uint32_t BuildId
Definition: types.h:60
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