GreenCloud Simulator
resourceprovider.h
Go to the documentation of this file.
1 
8 #ifndef RESOURCEPROVIDER_H_
9 #define RESOURCEPROVIDER_H_
10 
11 #include <stdlib.h>
12 #include <vector>
13 #include <string.h>
14 
15 
16 #include "resource.h"
17 #include "dcresource.h"
18 #include "cpu.h"
19 #include "nic.h"
20 #include "resourceconsumer.h"
21 #include "cloudtask.h"
22 
23 #include "scheduler.h"
24 #include "agent.h"
25 #include "tcp.h"
26 #include "provideroutagent.h"
27 #include "vmmigrationsink.h"
28 #include "corescheduler.h"
29 #include "tskagent.h"
30 #include "taskinfo.h"
31 
32 class DcHost;
33 class VM;
34 class TskComSink;
35 class VmMigrationSink;
36 
37 
38 class ResourceProvider : public Handler {
39 public:
41  virtual ~ResourceProvider();
42  std::vector <std::vector <DcResource*> > resource_list; /*The resources are ordered by type*/
43  void setTskComSink(TskComSink* tcs);
44 
45  int tryToAllocate(ResourceConsumer * rc); /* Check for space for new consumer. At the moment the resources are selected in a greedy way.*/
46  bool releaseAllocation(ResourceConsumer * rc); /*Release the resources allocated resource consumer.*/
47 
48  bool addVM(VM* newVm);
49  bool removeVM(VM* vm);
52 
53 
54  void recv(ResourceConsumer *rcobj);
55  virtual int command(int argc, const char*const* argv);
56 
57 
58  double getResTypeUtil(res_type type);
59 // void computeCurrentLoad(); /* updates current load of the server after task is received or its execution completed */
60 
61 
62 
63  virtual void print()=0;
64  virtual void printTasklist();
65 
66  virtual void addResource(DcResource* res);
67  double getTotalCap(res_type type);
68 
69  virtual void updateEnergyAndConsumption()= 0;
70 
71  int id_;
72 
73 
74  /* Stats */
75  int ntasks_;
76  double currentLoad_;
80 
81 
83  int trySchedulingTsk(CloudTask *tskobj);
84  void sendTaskOutput(CloudTask* task);
85  void scheduleNextExent(double nextDeadline);
86 
87 
89 
90 
92 
94  static double uplink_overhead;
95  static double MTU;
96  static double useful_bytes;
97 
100 
101 
102 protected:
104  std::vector <ResourceConsumer*> hosted_vms_;
105  std::vector <VmMigrationSink*> vm_migration_sinks_;
106  std::vector <ProviderOutAgent *> vm_migration_sources_;
109 
111 
112 
113  virtual void handle(Event* event);
114  void updateEvent();
115  void nextEvent(double delay);
116 
117  double getCurrentLoad();
118  double updateResTypeUtil(res_type type);
119 
120  double getFreeCap(res_type type);
121  double getFreeCapRecursive(res_type type);
122 
123  double getUsedNet(bool in, bool out);
124  double getUsedNetRecursive(bool in, bool out);
125 
126  void setTskComAgent(TskComAgent* agnt);
127  void setAgent(ProviderOutAgent* agent);
128  TcpAgent* getAgent();
129 
130  void attachSink(VmMigrationSink* vm_mig_sink);
131  void attachSource(ProviderOutAgent* tcp_agent);
132  void detachSink(VmMigrationSink* vm_mig_sink);
133  void detachSource(ProviderOutAgent* tcp_agent);
134 
135 
136 
137  bool started_;
138  int status_;
139  Event event_;
140 
141 
142 private:
143 
144  inline void _sched(double delay);
145  inline void _cancel();
146 
147 };
148 
149 
150 #endif /* RESOURCEOPROVIDER_H_ */
double getFreeCapRecursive(res_type type)
std::vector< std::vector< DcResource * > > resource_list
void setTskComAgent(TskComAgent *agnt)
void scheduleNextExent(double nextDeadline)
void setTskComSink(TskComSink *tcs)
void detachSource(ProviderOutAgent *tcp_agent)
virtual ~ResourceProvider()
TskComSink * tskComSink_
res_type
Definition: resource.h:19
void sendTaskOutput(CloudTask *task)
double updateResTypeUtil(res_type type)
std::vector< ProviderOutAgent * > vm_migration_sources_
int trySchedulingTsk(CloudTask *tskobj)
virtual void addResource(DcResource *res)
static double useful_bytes
void attachSource(ProviderOutAgent *tcp_agent)
virtual void print()=0
static double uplink_overhead
ProviderOutAgent * poagent_
double getResTypeUtil(res_type type)
TskComAgent * tskComAgent
double getTotalCap(res_type type)
virtual void printTasklist()
double getUsedNet(bool in, bool out)
bool addVM(VM *newVm)
double getUsedNetRecursive(bool in, bool out)
TskComAgent * getTskComAgent()
void attachSink(VmMigrationSink *vm_mig_sink)
int tryToAllocate(ResourceConsumer *rc)
void recv(ResourceConsumer *rcobj)
std::vector< VmMigrationSink * > vm_migration_sinks_
ResourceProvider * host
bool removeVM(VM *vm)
virtual void handle(Event *event)
double getFreeCap(res_type type)
Definition: dchost.h:27
double resource_utilization[LastResType+1]
void nextEvent(double delay)
bool releaseAllocation(ResourceConsumer *rc)
void setAgent(ProviderOutAgent *agent)
std::vector< ResourceConsumer * > hosted_vms_
void detachSink(VmMigrationSink *vm_mig_sink)
ResourceProvider * getHost()
virtual void updateEnergyAndConsumption()=0
int testSchedulingPossibility(CloudTask *tskobj)
virtual int command(int argc, const char *const *argv)
TcpAgent * getAgent()
Definition: vm.h:29
void _sched(double delay)
static double MTU