EMANE  1.2.1
models/mac/tdma/eventscheduler/eventtablepublisher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "eventtablepublisher.h"
34 
36  bHasStructure_{}{}
37 
39 {
40  pScheduleTable_ =
41  statisticRegistrar.registerTable<std::uint32_t>("scheduler.ScheduleInfoTable",
42  {"Index","Frame","Slot","Type","Frequency","Data Rate","Power","Class","Destination"},
44  "Shows the current TDMA schedule.");
45 
46  pStrutureTable_ =
47  statisticRegistrar.registerTable<std::string>("scheduler.StructureInfoTable",
48  {"Name","Value"},
50  "Shows the current TDMA structure: slot size, slot overhead, number of slots"
51  " per frame, number of frames per multiframe and transceiver bandwidth.");
52 }
53 
55 {
56  pStrutureTable_->clear();
57  pScheduleTable_->clear();
58  scheduleIndexSet_.clear();
59  structure_ = {};
60  bHasStructure_ = false;
61 }
62 
64  const Events::SlotStructure & structure)
65 {
66  pScheduleTable_->clear();
67  scheduleIndexSet_.clear();
68  structure_ = structure;
69 
70  auto loadStructureTable =
72 
73  (pStrutureTable_->*loadStructureTable)("bandwidth",{Any{"bandwidth"},Any{structure.getBandwidth()}});
74 
75  (pStrutureTable_->*loadStructureTable)("frames",{Any{"frames"},Any{structure.getFramesPerMultiFrame()}});
76 
77  (pStrutureTable_->*loadStructureTable)("slots",{Any{"slots"},Any{structure.getSlotsPerFrame()}});
78 
79  (pStrutureTable_->*loadStructureTable)("slotduration",{Any{"slotduration"},Any{structure.getSlotDuration().count()}});
80 
81  (pStrutureTable_->*loadStructureTable)("slotoverhead",{Any{"slotoverhead"},Any{structure.getSlotOverhead().count()}});
82 
83  bHasStructure_ = true;
84 
85  update(slotInfos);
86 }
87 
89 {
90  for(const auto & slotInfo : slotInfos)
91  {
92  auto index =
93  slotInfo.getFrameIndex() * structure_.getSlotsPerFrame() + slotInfo.getSlotIndex();
94 
95  std::vector<Any> anys{};
96 
97  switch(slotInfo.getType())
98  {
100  anys = {Any{index},
101  Any{slotInfo.getFrameIndex()},
102  Any{slotInfo.getSlotIndex()},
103  Any{"TX"},
104  Any{slotInfo.getFrequency()},
105  Any{slotInfo.getDataRate()},
106  Any{slotInfo.getPower()},
107  Any{slotInfo.getServiceClass()},
108  Any{slotInfo.getDestination()}};
109  break;
110 
112  anys = {Any{index},
113  Any{slotInfo.getFrameIndex()},
114  Any{slotInfo.getSlotIndex()},
115  Any{"RX"},
116  Any{slotInfo.getFrequency()},
117  Any{""},
118  Any{""},
119  Any{""},
120  Any{""}};
121  break;
122 
124  anys = {Any{index},
125  Any{slotInfo.getFrameIndex()},
126  Any{slotInfo.getSlotIndex()},
127  Any{"IDLE"},
128  Any{""},
129  Any{""},
130  Any{""},
131  Any{""},
132  Any{""}};
133  break;
134  }
135 
136  if(scheduleIndexSet_.count(index))
137  {
138  pScheduleTable_->setRow(index,anys);
139  }
140  else
141  {
142  pScheduleTable_->addRow(index,anys);
143  scheduleIndexSet_.insert(index);
144  }
145  }
146 }
A two dimentional statistic table that holds Any values.
void replace(const Events::SlotInfos &slotInfos, const Events::SlotStructure &structure)
std::uint32_t getFramesPerMultiFrame() const
void setRow(const Key &key, const std::vector< Any > &anys)
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
std::uint64_t getBandwidth() const
StatisticTable< Key, Compare, scolumn > * registerTable(const std::string &sName, const StatisticTableLabels &labels, const StatisticProperties &properties=StatisticProperties::NONE, const std::string &sDescription="")
std::uint32_t getSlotsPerFrame() const
const Microseconds & getSlotOverhead() const
void addRow(const Key &key, const std::vector< Any > &anys={})
std::vector< SlotInfo > SlotInfos
Definition: slotinfo.h:85
The Any class can contain an instance of one of any type in its support type set. ...
Definition: any.h:49
const Microseconds & getSlotDuration() const