GreenCloud Simulator
tskoutsink.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
2 /*
3  */
4 
5 #ifndef lint
6 static const char rcsid[] =
7  "@(#) $Header: /cvsroot/nsnam/ns-2/tools/TskOutSink.cc,v 1.18 2000/09/01 03:04:06 haoboy Exp $ (LBL)";
8 #endif
9 
10 #include <tclcl.h>
11 
12 #include "agent.h"
13 #include "config.h"
14 #include "packet.h"
15 #include "ip.h"
16 #include "rtp.h"
17 #include "bytecounter.h"
18 #include "tskoutsink.h"
19 #include "dchost.h"
20 
21 
22 static class TskOutSinkClass : public TclClass {
23 public:
24  TskOutSinkClass() : TclClass("Agent/TCPSink/TskOutSink") {}
25  TclObject* create(int, const char*const*) {
26  return (new TskOutSink());
27  }
29 
30 TskOutSink::TskOutSink() : TcpSink(new Acker()), poa_(NULL)
31 {
32 
33 }
34 
36 {
37  res_provider_ = NULL;
38 }
39 
40 void TskOutSink::recv(Packet* pkt, Handler* h)
41 {
42  /* Get TskObject and start its execution */
43  CloudTask *recvTskObj = (CloudTask*)hdr_cmn::access(pkt)->pt_obj_addr();
44  if (recvTskObj) { /* Valid pointer and can be executed */
45 // std::cout << "Task id:" << recvTskObj->id_ << "exits the DC at: "<< Scheduler::instance().clock() <<"\n";
46  recvTskObj->info_->finalizeDcExitTime(Scheduler::instance().clock());
47  poa_->tryToSend();
49  }
50  TcpSink::recv(pkt,h);
51 }
52 
53 
54 int TskOutSink::command(int argc, const char*const* argv)
55 {
56  if (argc == 2) {
57  if (strcmp(argv[1], "clear") == 0) {
58  expected_ = -1;
59  return (TCL_OK);
60  }
61  }
62  if (argc == 3) {
63  if (strcmp(argv[1], "connect-tskoutagent") == 0) {
64  ProviderOutAgent *poa =(ProviderOutAgent*)(TclObject::lookup(argv[2]));
65  if(poa){
66  poa_ = poa;
67  return (TCL_OK);
68  }
69  return (TCL_ERROR);
70  }
71  }
72 
73  return (Agent::command(argc, argv));
74 }
75 
76 
ResourceProvider * res_provider_
Definition: tskoutsink.h:37
virtual ~TskOutSink()
Definition: tskoutsink.cc:35
TaskInfo * info_
Definition: cloudtask.h:61
ProviderOutAgent * poa_
Definition: tskoutsink.h:35
void finalizeDcExitTime(double time)
Definition: taskinfo.cc:45
static const char rcsid[]
Definition: tskoutsink.cc:6
virtual void updateEnergyAndConsumption()
Definition: dchost.cc:138
virtual int command(int argc, const char *const *argv)
Definition: tskoutsink.cc:54
TskOutSinkClass class_tsk_outsink
ResourceProvider * getResourceProvider()
Definition: taskinfo.cc:49
TclObject * create(int, const char *const *)
Definition: tskoutsink.cc:25
virtual void recv(Packet *pkt, Handler *)
Definition: tskoutsink.cc:40
int expected_
Definition: tskoutsink.h:31