TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TTIncoming.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "TTIncoming.h"
17 
18 #include <TTEScheduler.h>
20 
21 namespace TTEthernetModel {
22 
23 Define_Module( TTIncoming);
24 
26 {
27  frame = NULL;
28 }
29 
31 {
32  if (frame != NULL)
33  {
34  delete frame;
35  }
36 }
37 
38 void TTIncoming::handleMessage(cMessage *msg)
39 {
40  //Incoming Message
41  if (msg->arrivedOn("in"))
42  {
43  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
44  //get current time in cylce
45  uint32_t currentTicks = tteScheduler->getTicks();
46  //Now check for correct arrival:
47  if (frame != NULL)
48  {
49  emit(ctDroppedSignal, 1);
50  hadError=true;
51  if(ev.isGUI()){
52  ev.printf("Received frame before permanence point of previous frame \n");
53  bubble("Received frame before permanence point of previous frame");
54  getDisplayString().setTagArg("i2", 0, "status/excl3");
55  getDisplayString().setTagArg("tt", 0, "WARNING: Received frame before permanence point of previous frame");
56  getParentModule()->getDisplayString().setTagArg("i2", 0, "status/excl3");
57  getParentModule()->getDisplayString().setTagArg("tt", 0, "Problem with Buffer");
58  }
59  delete msg;
60  }
61  //Check too early
62  else if (currentTicks < (uint32_t) par("receive_window_start").longValue())
63  {
64  emit(ctDroppedSignal, 1);
65  hadError=true;
66  if(ev.isGUI()){
67  ev.printf("Received frame in %s too early! Receive Time was %d Ticks, should have been between %d and %d! \n",
68  getName(), currentTicks, par("receive_window_start").longValue(),
69  par("receive_window_end").longValue());
70  bubble("Frame to early");
71  getDisplayString().setTagArg("i2", 0, "status/excl3");
72  getDisplayString().setTagArg("tt", 0, "WARNING: Buffer configuration problem - Received frame too early");
73  getParentModule()->getDisplayString().setTagArg("i2", 0, "status/excl3");
74  getParentModule()->getDisplayString().setTagArg("tt", 0, "WARNING: Buffer configuration problem - Received frame too early");
75  }
76  delete msg;
77  }
78  //Check too late
79  else if (currentTicks > (uint32_t) par("receive_window_end").longValue())
80  {
81  emit(ctDroppedSignal, 1);
82  hadError=true;
83  if(ev.isGUI()){
84  ev.printf("Received frame in %s too late! Receive Time was %d Ticks, should have been between %d and %d! \n",
85  getName(), currentTicks, par("receive_window_start").longValue(),
86  par("receive_window_end").longValue());
87  bubble("Frame to late");
88  getDisplayString().setTagArg("i2", 0, "status/excl3");
89  getDisplayString().setTagArg("tt", 0, "WARNING: Buffer configuration problem - Received frame too late");
90  getParentModule()->getDisplayString().setTagArg("i2", 0, "status/excl3");
91  getParentModule()->getDisplayString().setTagArg("tt", 0, "WARNING: Buffer configuration problem - Received frame too late");
92  }
93  delete msg;
94  }
95  //Timing ok
96  else
97  {
98  //delay for permanence_pit
99  if(!hadError && ev.isGUI())
100  getDisplayString().setTagArg("i2", 0, "status/hourglass");
101  frame = (EtherFrame *) msg;
103  event->setAction_time(par("permanence_pit").doubleValue());
104  event->setDestinationGate(gate("schedulerIn"));
105  tteScheduler->registerEvent(event);
106  }
107  }
108  else if (msg->arrivedOn("schedulerIn") && msg->getKind() == ACTION_TIME_EVENT)
109  {
110  ASSERT(frame);
111  delete msg;
112  if(!hadError && ev.isGUI())
113  getDisplayString().setTagArg("i2", 0, "");
114  send(frame, "out");
115  frame = NULL;
116  }
117 
118 }
119 
120 } //namespace