EMANE  1.2.1
r2rineighbormetriccontrolmessage.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014,2016 - Adjacent Link LLC, Bridgewater,
3  * New 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 
35 #include "radiotorouter.pb.h"
36 
37 class EMANE::Controls::R2RINeighborMetricControlMessage::Implementation
38 {
39 public:
40  Implementation(){}
41 
42  Implementation(const R2RINeighborMetrics & neighborMetrics):
43  neighborMetrics_{neighborMetrics}{}
44 
46  {
47  return neighborMetrics_;
48  }
49 
50 private:
51  const R2RINeighborMetrics neighborMetrics_;
52 };
53 
54 EMANE::Controls::R2RINeighborMetricControlMessage::
55 R2RINeighborMetricControlMessage(const R2RINeighborMetricControlMessage & msg):
56  ControlMessage{IDENTIFIER},
57  pImpl_{new Implementation{*msg.pImpl_}}
58 {}
59 
60 
61 EMANE::Controls::R2RINeighborMetricControlMessage::
62 R2RINeighborMetricControlMessage(const R2RINeighborMetrics & neighborMetrics):
63  ControlMessage(IDENTIFIER),
64  pImpl_{new Implementation{neighborMetrics}}{}
65 
66 
68 {}
69 
72 {
73  return pImpl_->getNeighborMetrics();
74 }
75 
78 {
79  return new R2RINeighborMetricControlMessage{neighborMetrics};
80 }
81 
83 {
84  EMANE::Serialization serialization;
85 
86  EMANEMessage::RadioToRouterNeighborMetrics msg;
87 
88  const R2RINeighborMetrics & metrics = pImpl_->getNeighborMetrics();
89 
90  R2RINeighborMetrics::const_iterator iter = metrics.begin();
91 
92  for(;iter != metrics.end(); ++iter)
93  {
94  EMANEMessage::RadioToRouterNeighborMetrics::NeighborMetric * pNeighborMetric =
95  msg.add_metrics();
96 
97  pNeighborMetric->set_neighborid(iter->getId());
98  pNeighborMetric->set_numrxframes(iter->getNumRxFrames());
99  pNeighborMetric->set_numtxframes(iter->getNumTxFrames());
100  pNeighborMetric->set_nummissedframes(iter->getNumMissedFrames());
101  pNeighborMetric->set_bandwidthconsumption
102  (std::chrono::duration_cast<DoubleSeconds>(iter->getBandwidthConsumption()).count());
103 
104  pNeighborMetric->set_sinraverage(iter->getSINRAvgdBm());
105  pNeighborMetric->set_sinrstddev(iter->getSINRStddev());
106  pNeighborMetric->set_noiseflooravg(iter->getNoiseFloorAvgdBm());
107  pNeighborMetric->set_noisefloorstddev(iter->getNoiseFloorStddev());
108  pNeighborMetric->set_rxavgdataratebps(iter->getRxAvgDataRatebps());
109  pNeighborMetric->set_txavgdataratebps(iter->getTxAvgDataRatebps());
110  }
111 
112  if(!msg.SerializeToString(&serialization))
113  {
114  throw SerializationException("unable the serialize RadioToRouterNeighborMetrics");
115  }
116 
117  return serialization;
118 }
119 
122 {
123  EMANEMessage::RadioToRouterNeighborMetrics msg;
124 
125  if(!msg.ParseFromString(serialization))
126  {
127  throw SerializationException("unable to deserialize : R2RINeighborMetricControlMessage");
128  }
129 
130  R2RINeighborMetrics metrics;
131 
132  for(const auto & neighbor : msg.metrics())
133  {
134  metrics.push_back(R2RINeighborMetric{static_cast<std::uint16_t>(neighbor.neighborid()),
135  neighbor.numrxframes(),
136  neighbor.numtxframes(),
137  neighbor.nummissedframes(),
138  std::chrono::duration_cast<Microseconds>(DoubleSeconds{neighbor.bandwidthconsumption()}),
139  neighbor.sinraverage(),
140  neighbor.sinrstddev(),
141  neighbor.noiseflooravg(),
142  neighbor.noisefloorstddev(),
143  neighbor.rxavgdataratebps(),
144  neighbor.txavgdataratebps()});
145  }
146 
147  return new R2RINeighborMetricControlMessage{metrics};
148 }
149 
150 
153 {
154  return new R2RINeighborMetricControlMessage{*this};
155 }
std::string Serialization
Definition: serializable.h:42
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
std::list< R2RINeighborMetric > R2RINeighborMetrics
std::chrono::microseconds Microseconds
Definition: types.h:45
std::chrono::duration< double > DoubleSeconds
Definition: types.h:47
R2RI Neighbor Metric Control Message is sent to an NEM&#39;s transport layer to convey information about ...
R2RI neighbor metrics are used in conjunction with the R2RINeighborMetricControlMessage to inform an ...
static R2RINeighborMetricControlMessage * create(const Serialization &serialization)
R2RINeighborMetricControlMessage * clone() const override
ControlMessage(ControlMessageId id)