EMANE  1.0.1
models/mac/bypass/maclayer.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-2009 - 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 "maclayer.h"
36 
37 namespace {
38  const std::uint16_t DROP_CODE_REGISTRATION_ID = 1;
39 
40  EMANE::StatisticTableLabels STATISTIC_TABLE_LABELS {"Reg Id"};
41 }
42 
44  PlatformServiceProvider* pPlatformService,
45  RadioServiceProvider * pRadioServiceProvider):
46  MACLayerImplementor{id, pPlatformService, pRadioServiceProvider},
47  u16SequenceNumber_{},
48  commonLayerStatistics_{STATISTIC_TABLE_LABELS}
49 {}
50 
52 {}
53 
55 {
58  "MACI %03hu Models::Bypass::MACLayer::%s",
59  id_,
60  __func__);
61 }
62 
64 {
67  "MACI %03hu Models::Bypass::MACLayer::%s",
68  id_,
69  __func__);
70 
71 }
72 
74  UpstreamPacket & pkt,
75  const ControlMessages &)
76 {
77  TimePoint beginTime{Clock::now()};
78 
79  commonLayerStatistics_.processInbound(pkt);
80 
81  if(hdr.getRegistrationId() != type_)
82  {
84  ERROR_LEVEL,
85  "MACI %03hu Models::Bypass::MACLayer::%s: MAC Registration Id %hu does not match our Id %hu, drop.",
86  id_,
87  __func__,
88  hdr.getRegistrationId(),
89  type_);
90 
91  commonLayerStatistics_.processOutbound(pkt,
92  std::chrono::duration_cast<Microseconds>(Clock::now() - beginTime),
93  DROP_CODE_REGISTRATION_ID);
94 
95  // drop
96  return;
97  }
98 
100  DEBUG_LEVEL,
101  "MACI %03hu Models::Bypass::MACLayer::%s src %hu dst %hu dscp %hhu",
102  id_,
103  __func__,
104  pkt.getPacketInfo().getSource(),
106  pkt.getPacketInfo().getPriority());
107 
108  commonLayerStatistics_.processOutbound(pkt,
109  std::chrono::duration_cast<Microseconds>(Clock::now() - beginTime));
110 
111  // pass the pkt upstream
112  sendUpstreamPacket(pkt);
113 }
114 
115 
117  const ControlMessages &)
118 {
119  TimePoint beginTime{Clock::now()};
120 
121  commonLayerStatistics_.processInbound(pkt);
122 
124  DEBUG_LEVEL,
125  "MACI %03hu Models::Bypass::MACLayer::%s src %hu dst %hu dscp %hhu",
126  id_,
127  __func__,
128  pkt.getPacketInfo().getSource(),
130  pkt.getPacketInfo().getPriority());
131 
132  commonLayerStatistics_.processOutbound(pkt,
133  std::chrono::duration_cast<Microseconds>(Clock::now() - beginTime));
134 
135  // pass the pkt downstream
136  sendDownstreamPacket(CommonMACHeader{type_, u16SequenceNumber_++}, pkt);
137 }
138 
140 {
142  DEBUG_LEVEL,
143  "MACI %03hu Models::Bypass::MACLayer::%s",
144  id_,
145  __func__);
146 
147  commonLayerStatistics_.registerStatistics(registrar.statisticRegistrar());
148 }
149 
151 {
153  DEBUG_LEVEL,
154  "MACI %03hu Models::Bypass::MACLayer::%s",
155  id_,
156  __func__);
157 
158  if(!update.empty())
159  {
160  throw ConfigureException("Models::Bypass::MACLayer: Unexpected configuration items.");
161  }
162 }
163 
165 {
167  DEBUG_LEVEL,
168  "MACI %03hu Models::Bypass::MACLayer::%s",
169  id_,
170  __func__);
171 }
172 
174 {
176  DEBUG_LEVEL,
177  "MACI %03hu Models::Bypass::MACLayer::%s",
178  id_,
179  __func__);
180 }
181 
183  throw()
184 {
186  DEBUG_LEVEL,
187  "MACI %03hu Models::Bypass::MACLayer::%s",
188  id_,
189  __func__);
190 }
191 
193 {
195  DEBUG_LEVEL,
196  "MACI %03hu Models::Bypass::MACLayer::%s",
197  id_,
198  __func__);
199 }
200 
202  const TimePoint &,
203  const void *)
204 {
206  DEBUG_LEVEL,
207  "MACI %03hu Models::Bypass::MACLayer::%s",
208  id_,
209  __func__);
210 }
211 
std::string Serialization
Definition: serializable.h:42
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
#define LOGGER_VERBOSE_LOGGING(logger, level, fmt, args...)
void initialize(EMANE::Registrar &registrar) override
virtual StatisticRegistrar & statisticRegistrar()=0
void processOutbound(const UpstreamPacket &pkt, Microseconds delay, size_t dropCode={})
std::list< const ControlMessage * > ControlMessages
NEMId getSource() const
Definition: packetinfo.inl:64
RegistrationId getRegistrationId() const
Implementation of the bypass MAC layer.
NEMId getDestination() const
Definition: packetinfo.inl:70
Exception thrown when failures in configuration occur.
std::uint16_t EventId
Definition: types.h:53
The PlatformServiceProvider interface provides access to emulator services.
void registerStatistics(StatisticRegistrar &statisticRegistrar)
void processTimedEvent(EMANE::TimerEventId eventId, const EMANE::TimePoint &timePoint, const void *arg)
void processUpstreamPacket(const EMANE::CommonMACHeader &hdr, EMANE::UpstreamPacket &pkt, const EMANE::ControlMessages &msgs)
MACLayer(NEMId id, PlatformServiceProvider *pPlatformService, RadioServiceProvider *pRadioServiceProvider)
constructor
std::vector< std::string > StatisticTableLabels
const PacketInfo & getPacketInfo() const
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
std::uint16_t NEMId
Definition: types.h:52
void processDownstreamControl(const EMANE::ControlMessages &msgs)
PlatformServiceProvider * pPlatformService_
The RadioServiceProvider interface provides access to radio (RF) model specific services.
void sendDownstreamPacket(const CommonMACHeader &hdr, DownstreamPacket &pkt, const ControlMessages &msgs=DownstreamTransport::empty)
void configure(const EMANE::ConfigurationUpdate &update) override
Priority getPriority() const
Definition: packetinfo.inl:76
virtual LogServiceProvider & logService()=0
void processDownstreamPacket(EMANE::DownstreamPacket &pkt, const EMANE::ControlMessages &msgs)
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
void processEvent(const EMANE::EventId &id, const EMANE::Serialization &serialization)
std::size_t TimerEventId
Definition: types.h:54
Clock::time_point TimePoint
Definition: types.h:50
void sendUpstreamPacket(UpstreamPacket &pkt, const ControlMessages &msgs=empty)
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)
DECLARE_MAC_LAYER(EMANE::Models::Bypass::MACLayer)
void processInbound(const UpstreamPacket &pkt)
void processUpstreamControl(const EMANE::ControlMessages &msgs)
Interface used to create a MAC layer plugin implementation.
Definition: maclayerimpl.h:48