EMANE  1.2.1
r2riselfmetriccontrolmessage.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::R2RISelfMetricControlMessage::Implementation
38 {
39 public:
40 
41  Implementation():
42  u64BroadcastDataRatebps_{},
43  u64MaxDataRatebps_{},
44  reportInteral_{Microseconds::zero()}{}
45 
46  Implementation(std::uint64_t u64BroadcastDataRatebps,
47  std::uint64_t u64MaxDataRatebps,
48  const Microseconds & reportInteral):
49  u64BroadcastDataRatebps_{u64BroadcastDataRatebps},
50  u64MaxDataRatebps_{u64MaxDataRatebps},
51  reportInteral_{reportInteral}{}
52 
53  std::uint64_t getBroadcastDataRatebps() const
54  {
55  return u64BroadcastDataRatebps_;
56  }
57 
58  std::uint64_t getMaxDataRatebps() const
59  {
60  return u64MaxDataRatebps_;
61  }
62 
63  const Microseconds & getReportInterval() const
64  {
65  return reportInteral_;
66  }
67 
68 private:
69  const std::uint64_t u64BroadcastDataRatebps_;
70  const std::uint64_t u64MaxDataRatebps_;
71  const Microseconds reportInteral_;
72 };
73 
74 EMANE::Controls::R2RISelfMetricControlMessage::
75 R2RISelfMetricControlMessage(const R2RISelfMetricControlMessage & msg):
76  ControlMessage{IDENTIFIER},
77  pImpl_{new Implementation{*msg.pImpl_}}
78 {}
79 
80 EMANE::Controls::R2RISelfMetricControlMessage::
81 R2RISelfMetricControlMessage(std::uint64_t u64BroadcastDataRatebps,
82  std::uint64_t u64MaxDataRatebps,
83  const Microseconds & tvReportInteral):
84  ControlMessage{IDENTIFIER},
85  pImpl_{new Implementation{u64BroadcastDataRatebps,u64MaxDataRatebps,tvReportInteral}}{}
86 
88 {}
89 
91 {
92  return pImpl_->getBroadcastDataRatebps();
93 }
94 
96 {
97  return pImpl_->getMaxDataRatebps();
98 }
99 
101 {
102  return pImpl_->getReportInterval();
103 }
104 
106 EMANE::Controls::R2RISelfMetricControlMessage::create(std::uint64_t u64BroadcastDataRatebps,
107  std::uint64_t u64MaxDataRatebps,
108  const Microseconds & reportInteral)
109 {
110  return new R2RISelfMetricControlMessage{u64BroadcastDataRatebps,
111  u64MaxDataRatebps,
112  reportInteral};
113 }
114 
116 {
117  Serialization serialization;
118 
119  EMANEMessage::RadioToRouterSelfMetric msg;
120 
121  msg.set_broadcastdataratebps(pImpl_->getBroadcastDataRatebps());
122  msg.set_maxdataratebps(pImpl_->getMaxDataRatebps());
123  msg.set_reportinterval(std::chrono::duration_cast<DoubleSeconds>(pImpl_->getReportInterval()).count());
124 
125  if(!msg.SerializeToString(&serialization))
126  {
127  throw SerializationException("unable to serialize R2RISelfMetricControlMessage");
128  }
129 
130  return serialization;
131 }
132 
135 {
136  EMANEMessage::RadioToRouterSelfMetric msg;
137 
138  if(!msg.ParseFromString(serialization))
139  {
140  throw SerializationException("unable to deserialize : R2RISelfMetricControlMessage");
141  }
142 
143  return new R2RISelfMetricControlMessage{msg.broadcastdataratebps(),
144  msg.maxdataratebps(),
145  std::chrono::duration_cast<Microseconds>(DoubleSeconds{msg.reportinterval()})};
146 
147 }
148 
151 {
152  return new R2RISelfMetricControlMessage{*this};
153 }
std::string Serialization
Definition: serializable.h:42
SerializationException is thrown when an exception occurs during serialization or deserialization of ...
R2RISelfMetricControlMessage * clone() const override
std::chrono::microseconds Microseconds
Definition: types.h:45
std::chrono::duration< double > DoubleSeconds
Definition: types.h:47
static R2RISelfMetricControlMessage * create(const Serialization &serialization)
R2RI Self Metric Control Message is sent to an NEM&#39;s transport layer to specify the parameters necess...
ControlMessage(ControlMessageId id)