EMANE  1.2.1
otamanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2017 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-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 #ifndef EMANEOTAMANAGER_HEADER_
35 #define EMANEOTAMANAGER_HEADER_
36 
37 #include "otaprovider.h"
38 #include "emane/inetaddr.h"
39 #include "multicastsocket.h"
40 #include "otastatisticpublisher.h"
42 
43 #include "emane/utils/singleton.h"
44 
45 #include <map>
46 #include <queue>
47 #include <atomic>
48 #include <thread>
49 #include <tuple>
50 #include <array>
51 #include <uuid.h>
52 
53 
54 namespace EMANE
55 {
62  class OTAManager : public OTAProvider,
63  public Utils::Singleton<OTAManager>
64  {
65  public:
66  OTAManager();
67 
68  ~OTAManager();
69 
70  void sendOTAPacket(NEMId id,
71  const DownstreamPacket & pkt,
72  const ControlMessages & msgs) const override;
73 
74  void registerOTAUser(NEMId id, OTAUser * pOTAUser) override;
75 
76  void unregisterOTAUser(NEMId id) override;
77 
97  void open(const INETAddr & otaGroupAddress,
98  const std::string & sDevice,
99  bool bLoopback,
100  int iTTL,
101  const uuid_t & uuid,
102  size_t otaMTU,
103  Seconds partCheckThreshold,
104  Seconds partTimeoutThreshold);
105 
106  void setStatPacketCountRowLimit(size_t rows);
107 
108  void setStatEventCountRowLimit(size_t rows);
109 
110  private:
111  typedef std::map<NEMId,OTAUser *> NEMUserMap;
112  std::thread thread_;
113  NEMUserMap nemUserMap_;
114  INETAddr otaGroupAddress_;
115  MulticastSocket mcast_;
116  bool bOpen_;
117  uuid_t uuid_;
118  size_t otaMTU_;
119  Seconds partCheckThreshold_;
120  Seconds partTimeoutThreshold_;
121 
122  mutable OTAStatisticPublisher otaStatisticPublisher_;
123  mutable EventStatisticPublisher eventStatisticPublisher_;
124  mutable std::atomic<std::uint64_t> u64SequenceNumber_;
125 
126  using PartKey = std::tuple<NEMId, // source NEM
127  std::uint64_t>; // sequence number
128 
129  using Parts = std::map<size_t, // offset
130  std::vector<std::uint8_t>>;
131 
132  using PartsData = std::tuple<size_t, // total size in map
133  size_t, // events size bytes
134  size_t, // controls size bytes
135  size_t, // data size bytes
136  Parts, // parts map
137  TimePoint, // last part time
138  std::array<uint8_t,sizeof(uuid_t)>>; // emulator uuid instance
139 
140  using PartStore = std::map<PartKey,PartsData>;
141  PartStore partStore_;
142  TimePoint lastPartCheckTime_;
143 
144 
145  void processOTAMessage();
146 
147  void handleOTAMessage(NEMId source,
148  NEMId destination,
149  const uuid_t & remoteUUID,
150  const TimePoint & now,
151  size_t eventsSize,
152  size_t controlsSize,
153  size_t dataSize,
154  const Utils::VectorIO & vectorIO);
155  };
156 
158 }
159 
160 #endif //EMANEOTAMANAGER_HEADER_
Interface for OTA.
Definition: otaprovider.h:49
void registerOTAUser(NEMId id, OTAUser *pOTAUser) override
Definition: otamanager.cc:409
void sendOTAPacket(NEMId id, const DownstreamPacket &pkt, const ControlMessages &msgs) const override
Definition: otamanager.cc:136
Ensure a class only has one instance, and provide a global point of access to it. ...
Definition: singleton.h:47
std::list< const ControlMessage * > ControlMessages
std::vector< iovec > VectorIO
Definition: vectorio.h:43
std::chrono::seconds Seconds
Definition: types.h:43
Provides OTA access to all platform NEMs and handles intra and inter platform OTA message disseminati...
Definition: otamanager.h:62
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
std::uint16_t NEMId
Definition: types.h:52
void unregisterOTAUser(NEMId id) override
Definition: otamanager.cc:421
void setStatEventCountRowLimit(size_t rows)
Definition: otamanager.cc:131
OTA user interface that allows access to the OTA provider.
Definition: otauser.h:50
Clock::time_point TimePoint
Definition: types.h:50
void setStatPacketCountRowLimit(size_t rows)
Definition: otamanager.cc:126
void open(const INETAddr &otaGroupAddress, const std::string &sDevice, bool bLoopback, int iTTL, const uuid_t &uuid, size_t otaMTU, Seconds partCheckThreshold, Seconds partTimeoutThreshold)
Definition: otamanager.cc:431
Definition: agent.h:43