EMANE  1.2.1
profilemanager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2009-2010 - 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 "profilemanager.h"
35 #include "filterreader.h"
36 
38  EMANE::PlatformServiceProvider * pPlatformService):
39  id_{id},
40  pPlatformService_{pPlatformService}
41 {}
42 
43 
45 {}
46 
47 std::pair<EMANE::Events::CommEffect,bool>
49  size_t len,
50  EMANE::NEMId src) const
51 {
52  // check commeffect filter rules
53  for(const auto & filter : filters_)
54  {
55  if(filter.match(buf, len) == 1)
56  {
57  return std::make_pair(filter.getEffect(),true);
58  }
59  }
60 
61  // search for profile data based on NEM src id
62  const auto itr = profileDataMap_.find(src);
63 
64  if(itr != profileDataMap_.end())
65  {
66  return std::make_pair(itr->second,true);
67  }
68  else
69  {
70  return std::make_pair(Events::CommEffect{0,{},{},0,0,0,0},false);
71  }
72 }
73 
74 
75 
77 {
78  try
79  {
80  filters_ = FilterReader::load(pzFileName);
81  }
82  catch(...)
83  {
84  return -1;
85  }
86 
87  return 0;
88 }
89 
91 {
92  // load entries
93  for(const auto & effect : effects)
94  {
95  if(effect.getNEMId() != 0)
96  {
97  // action insert or add
98  std::string sAction;
99 
100  // try to insert profile data entry
101  auto result =
102  profileDataMap_.insert(std::make_pair(effect.getNEMId(), effect));
103 
104  if(result.second == true)
105  {
106  // new entry
107  sAction = "added";
108  }
109  else
110  {
111  // entry exists
112  sAction = "updated";
113 
114  // update profile data
115  result.first->second = effect;
116  }
117 
118  LOGGER_STANDARD_LOGGING(pPlatformService_->logService(),
119  DEBUG_LEVEL,
120  "SHIMI %03hu ProfileManager::%s: %s entry src: %03hu latency: %lf,"
121  " jitter: %lf, loss: %.2f%%, dups: %.2f%%, ucbitrate %ju, bcbitrate %ju",
122  id_,
123  __func__,
124  sAction.c_str(),
125  effect.getNEMId(),
126  std::chrono::duration_cast<DoubleSeconds>(effect.getLatency()).count(),
127  std::chrono::duration_cast<DoubleSeconds>(effect.getJitter()).count(),
128  effect.getProbabilityLoss(),
129  effect.getProbabilityDuplicate(),
130  effect.getUnicastBitRate(),
131  effect.getBroadcastBitRate());
132  }
133  }
134 
135  return 0;
136 }
ProfileManager(NEMId id, PlatformServiceProvider *pPlatformService)
std::pair< Events::CommEffect, bool > getProfileData(const void *buf, size_t len, NEMId id) const
The PlatformServiceProvider interface provides access to emulator services.
static Filters load(const char *pzFileName)
std::list< CommEffect > CommEffects
Definition: commeffect.h:131
std::chrono::duration< double > DoubleSeconds
Definition: types.h:47
std::uint16_t NEMId
Definition: types.h:52
A CommEffect entry holds the NEM Id of a transmitter and the link effects to apply to received transm...
Definition: commeffect.h:52
virtual LogServiceProvider & logService()=0
union EtherAddr src
Definition: netutils.h:391
#define LOGGER_STANDARD_LOGGING(logger, level, fmt, args...)