GreenCloud Simulator
Public Member Functions | Protected Attributes | List of all members
TskComAgent Class Reference

#include <tskagent.h>

Inheritance diagram for TskComAgent:
Inheritance graph
[legend]
Collaboration diagram for TskComAgent:
Collaboration graph
[legend]

Public Member Functions

 TskComAgent ()
 
 TskComAgent (packet_t)
 
virtual void sendmsg (int nbytes, void *pTaskObj, const char *flags=0)
 
virtual void sendmsg (int nbytes, AppData *data, void *pTaskObj, const char *flags=0)
 
virtual void recv (Packet *pkt, Handler *)
 
virtual int command (int argc, const char *const *argv)
 

Protected Attributes

int seqno_
 

Detailed Description

Definition at line 17 of file tskagent.h.

Constructor & Destructor Documentation

TskComAgent::TskComAgent ( )

Definition at line 29 of file tskagent.cc.

29  : Agent(PT_UDP), seqno_(-1)
30 {
31  bind("packetSize_", &size_);
32 }
int seqno_
Definition: tskagent.h:29
TskComAgent::TskComAgent ( packet_t  type)

Definition at line 34 of file tskagent.cc.

34  : Agent(type)
35 {
36  bind("packetSize_", &size_);
37 }

Member Function Documentation

int TskComAgent::command ( int  argc,
const char *const *  argv 
)
virtual

Definition at line 126 of file tskagent.cc.

127 {
128  // Tcl& tcl = Tcl::instance();
129  // if (argc == 4) {
130  // if (strcmp(argv[1], "send") == 0) {
131  // PacketData* data = new PacketData(1 + strlen(argv[3]));
132  // strcpy((char*)data->data(), argv[3]);
133  // sendmsg(atoi(argv[2]), data, 0);
134  // return (TCL_OK);
135  // }
136  // } else if (argc == 5) {
137  // if (strcmp(argv[1], "sendmsg") == 0) {
138  // PacketData* data = new PacketData(1 + strlen(argv[3]));
139  // strcpy((char*)data->data(), argv[3]);
140  // sendmsg(atoi(argv[2]), data, 0, argv[4]);
141  // return (TCL_OK);
142  // }
143  // }
144 
145  return (Agent::command(argc, argv));
146 }
void TskComAgent::recv ( Packet *  pkt,
Handler *   
)
virtual

Definition at line 100 of file tskagent.cc.

101 {
102  if (app_ ) {
103  // If an application is attached, pass the data to the app
104  hdr_cmn* h = hdr_cmn::access(pkt);
105  app_->process_data(h->size(), pkt->userdata());
106  } else if (pkt->userdata() && pkt->userdata()->type() == PACKET_DATA) {
107  // otherwise if it's just PacketData, pass it to Tcl
108  //
109  // Note that a Tcl procedure Agent/Udp recv {from data}
110  // needs to be defined. For example,
111  //
112  // Agent/Udp instproc recv {from data} {puts data}
113 
114  PacketData* data = (PacketData*)pkt->userdata();
115 
116  hdr_ip* iph = hdr_ip::access(pkt);
117  Tcl& tcl = Tcl::instance();
118  tcl.evalf("%s process_data %d {%s}", name(),
119  iph->src_.addr_ >> Address::instance().NodeShift_[1],
120  data->data());
121  }
122  Packet::free(pkt);
123 }
virtual void TskComAgent::sendmsg ( int  nbytes,
void *  pTaskObj,
const char *  flags = 0 
)
inlinevirtual

Definition at line 21 of file tskagent.h.

22  {
23  sendmsg(nbytes, NULL, pTaskObj, flags);
24  }
virtual void sendmsg(int nbytes, void *pTaskObj, const char *flags=0)
Definition: tskagent.h:21
void TskComAgent::sendmsg ( int  nbytes,
AppData *  data,
void *  pTaskObj,
const char *  flags = 0 
)
virtual

Definition at line 39 of file tskagent.cc.

40 {
41  Packet *p;
42  int n;
43 
44  assert (size_ > 0);
45 
46  n = nbytes / size_;
47  int initialseqno = seqno_;
48 
49  if (nbytes == -1) {
50  printf("Error: sendmsg() for Tsk should not be -1\n");
51  return;
52  }
53 
54  // If they are sending data, then it must fit within a single packet.
55  if (data && nbytes > size_) {
56  printf("Error: data greater than maximum Tsk packet size\n");
57  return;
58  }
59 
60  double local_time = Scheduler::instance().clock();
61  while (n-- > 0) {
62  p = allocpkt();
63  hdr_cmn::access(p)->size() = size_;
64  hdr_cmn::access(p)->pt_obj_addr() = 0;
65  if (initialseqno == seqno_){
66  /* Add pointer to TaskObj for the first packet in the bulk */
67  hdr_cmn::access(p)->pt_obj_addr() = pTaskObj;
68  }
69  hdr_rtp* rh = hdr_rtp::access(p);
70  rh->flags() = 0;
71  rh->seqno() = ++seqno_;
72  hdr_cmn::access(p)->timestamp() =
73  (u_int32_t)(SAMPLERATE*local_time);
74  if (flags && (0 ==strcmp(flags, "NEW_BURST")))
75  rh->flags() |= RTP_M;
76  p->setdata(data);
77  target_->recv(p);
78  }
79  n = nbytes % size_;
80  if (n > 0) {
81  p = allocpkt();
82  hdr_cmn::access(p)->size() = n;
83  hdr_cmn::access(p)->pt_obj_addr() = 0;
84  if (initialseqno == seqno_){
85  /* Add pointer to TaskObj for the first packet in the bulk */
86  hdr_cmn::access(p)->pt_obj_addr() = pTaskObj;
87  }
88  hdr_rtp* rh = hdr_rtp::access(p);
89  rh->flags() = 0;
90  rh->seqno() = ++seqno_;
91  hdr_cmn::access(p)->timestamp() =
92  (u_int32_t)(SAMPLERATE*local_time);
93  if (flags && (0 == strcmp(flags, "NEW_BURST")))
94  rh->flags() |= RTP_M;
95  p->setdata(data);
96  target_->recv(p);
97  }
98  idle();
99 }
#define SAMPLERATE
Definition: tskagent.h:14
#define RTP_M
Definition: tskagent.h:15
int seqno_
Definition: tskagent.h:29

Member Data Documentation

int TskComAgent::seqno_
protected

Definition at line 29 of file tskagent.h.


The documentation for this class was generated from the following files: