TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TrafficSourceAppBase.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 "TrafficSourceAppBase.h"
17 #include "CTFrame.h"
18 #include "TTFrame_m.h"
19 #include "RCFrame_m.h"
20 #include "TTE4INETDefs.h"
21 
22 namespace TTEthernetModel {
23 
24 Define_Module( TrafficSourceAppBase);
25 
27 {
28  scheduleAt(simTime(), new cMessage("ACTIVATOR!"));
29 }
30 
32  int ctID = par("ct_id").longValue();
33  if(ctID == -1){
34 
35  }
36  else{
37  std::list<Buffer*> buffer = buffers[ctID];
38  if(buffer.size()==0){
39  ev.printf("No buffer with such CT \n");
40  bubble("No buffer with such CT");
41  getDisplayString().setTagArg("i2", 0, "status/excl3");
42  getDisplayString().setTagArg("tt", 0, "WARNING: No buffer with such CT");
43  getParentModule()->getDisplayString().setTagArg("i2", 0, "status/excl3");
44  getParentModule()->getDisplayString().setTagArg("tt", 0, "No buffer with such CT");
45  }
46  else{
47  for(std::list<Buffer*>::iterator buf = buffer.begin();
48  buf!=buffer.end();buf++){
49  CTFrame *frame;
50  if(dynamic_cast<TTBuffer*>(*buf)){
51  frame = new TTFrame("");
52  }
53  else if(dynamic_cast<RCBuffer*>(*buf)){
54  frame = new RCFrame("");
55  }
56  else{
57  continue;
58  }
59  frame->setByteLength(par("payload").longValue()+ETHER_MAC_FRAME_BYTES);
60  //Padding
61  if(frame->getByteLength()<MIN_ETHERNET_FRAME_BYTES){
62  frame->setByteLength(MIN_ETHERNET_FRAME_BYTES);
63  }
64  frame->setCtID(ctID);
65  //TODO Error check
66  Incoming* in = (Incoming *)(*buf)->gate("in")->getPathStartGate()->getOwner();
67  //TODO Better name for Frame
68  frame->setName((*buf)->getName());
69  sendDirect(frame, in->gate("in"));
70  }
71  }
72  }
73 }
74 
75 
76 } //namespace