EMANE  1.0.1
transportadapterimpl.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2016 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2011-2012 - 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 "transportadapterimpl.h"
35 #include "logservice.h"
37 
39 #include "emane/startexception.h"
40 
42  TransportAdapter{nemId},
44  id_{nemId}{}
45 
47 
48 void EMANE::Application::TransportAdapterImpl::setTransport(std::unique_ptr<NEMLayer> & pTransport)
49 {
50  pTransport_ = std::move(pTransport);
51  setUpstreamTransport(pTransport_.get());
52  pTransport_->setDownstreamTransport(this);
53 }
54 
56 {
57  auto & configRegistrar = registrar.configurationRegistrar();
58 
59  configRegistrar.registerNonNumeric<INETAddr>("platformendpoint",
61  {},
62  "IPv4 or IPv6 NEM Platform Service endpoint.");
63 
64  configRegistrar.registerNonNumeric<INETAddr>("transportendpoint",
66  {},
67  "IPv4 or IPv6 Transport endpoint.");
68 
69 }
70 
72 {
73  for(const auto & item : update)
74  {
75  if(item.first == "platformendpoint")
76  {
77  platformEndpointAddr_ = item.second[0].asINETAddr();
78 
80  INFO_LEVEL,
81  "TRANS %03hu TransportAdapterImpl::configure platformendpoint: %s",
82  id_,
83  platformEndpointAddr_.str().c_str());
84 
85  }
86  else if(item.first == "transportendpoint")
87  {
88  transportEndpointAddr_ = item.second[0].asINETAddr();
89 
91  INFO_LEVEL,
92  "TRANS %03hu TransportAdapterImpl::configure Transport endpoint: %s",
93  id_,
94  transportEndpointAddr_.str().c_str());
95  }
96  else
97  {
98  throw makeException<ConfigureException>("TransportAdapterImpl: "
99  "Unexpected configuration item %s",
100  item.first.c_str());
101  }
102  }
103 }
104 
106 {
107  if(!pTransport_)
108  {
109  throw makeException<StartException>("TransportAdapterImpl transport not set for NEM %hu",
110  id_);
111  }
112 
113  try
114  {
115  open(transportEndpointAddr_, platformEndpointAddr_);
116  }
118  {
119  throw StartException(exp.what());
120  }
121 
122  pTransport_->start();
123 }
124 
126 {
127  pTransport_->postStart();
128 }
129 
131 {
132  pTransport_->stop();
133 }
134 
136  throw()
137 {
138  pTransport_->destroy();
139 }
140 
142  const EMANE::ControlMessages & msgs)
143 {
145  pkt.getVectorIO(),
146  pkt.length(),
147  msgs);
148 }
149 
150 void
152 {
153  sendControlMessage(msgs);
154 }
155 
156 void EMANE::Application::TransportAdapterImpl::doProcessPacketMessage(const PacketInfo & packetInfo,
157  const void * pPacketData,
158  size_t packetLength,
159  const ControlMessages & msgs)
160 {
161  UpstreamPacket pkt(packetInfo,
162  pPacketData,
163  packetLength);
164 
165  pTransport_->processUpstreamPacket(pkt,msgs);
166 }
167 
168 void EMANE::Application::TransportAdapterImpl::doProcessControlMessage(const ControlMessages & msgs)
169 {
170  pTransport_->processUpstreamControl(msgs);
171 }
A Packet class that allows upstream processing to strip layer headers as the packet travels up the st...
const PacketInfo & getPacketInfo() const
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
virtual ConfigurationRegistrar & configurationRegistrar()=0
std::list< const ControlMessage * > ControlMessages
void sendPacketMessage(const PacketInfo &packetInfo, const void *pPacketData, size_t packetLength, const ControlMessages &msgs)
void registerNonNumeric(const std::string &sName, const ConfigurationProperties &properties=ConfigurationProperties::NONE, const std::initializer_list< T > &values={}, const std::string &sUsage="", std::size_t minOccurs=1, std::size_t maxOccurs=1, const std::string &sRegexPattern={})
void initialize(Registrar &registrar) override
void sendControlMessage(const ControlMessages &msgs)
Store source, destination, creation time and priority information for a packet.
Definition: packetinfo.h:50
void processDownstreamPacket(DownstreamPacket &pkt, const ControlMessages &msgs)
const char * what() const
Definition: exception.h:62
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
std::string str(bool bWithPort=true) const
Definition: inetaddr.cc:409
void configure(const ConfigurationUpdate &update) override
void processDownstreamControl(const ControlMessages &msgs)
void setTransport(std::unique_ptr< NEMLayer > &pTransport) override
void open(const INETAddr &localAddress, const INETAddr &remoteAddress)
std::uint16_t NEMId
Definition: types.h:52
virtual void setUpstreamTransport(UpstreamTransport *pUpstreamTransport)
Transport Adapter interface. A Transport Adapter combines with a Transport to connect with its respec...
Exception thrown by the during BoundaryMessageManagerException to indicate connection failure...
Component start exception is used to indicate an exception during transition to the start state...
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
Utils::VectorIO getVectorIO() const
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
static LogService * instance()
Definition: singleton.h:56