Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
[simgrid.git] / src / surf / network_constant.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "network_constant.hpp"
8
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
10
11 /*********
12  * Model *
13  *********/
14 void surf_network_model_init_Constant()
15 {
16   xbt_assert(surf_network_model == NULL);
17   surf_network_model = new simgrid::surf::NetworkConstantModel();
18   xbt_dynar_push(all_existing_models, &surf_network_model);
19
20   routing_model_create(NULL);
21 }
22
23 namespace simgrid {
24   namespace surf {
25
26     NetworkConstantModel::~NetworkConstantModel() {}
27
28     Link* NetworkConstantModel::createLink(const char *name, double bw, double lat, e_surf_link_sharing_policy_t policy,
29         xbt_dict_t properties) {
30
31       xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
32           "Please remove any link from your platform (and switch to routing='None')", name);
33       return nullptr;
34     }
35
36     double NetworkConstantModel::next_occuring_event(double /*now*/)
37     {
38       NetworkConstantAction *action = NULL;
39       double min = -1.0;
40
41       ActionList *actionSet = getRunningActionSet();
42       for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
43           ; it != itend ; ++it) {
44         action = static_cast<NetworkConstantAction*>(&*it);
45         if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
46           min = action->latency_;
47       }
48
49       return min;
50     }
51
52     void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
53     {
54       NetworkConstantAction *action = NULL;
55       ActionList *actionSet = getRunningActionSet();
56       for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
57           ; it != itend ; it=itNext) {
58         ++itNext;
59         action = static_cast<NetworkConstantAction*>(&*it);
60         if (action->latency_ > 0) {
61           if (action->latency_ > delta) {
62             double_update(&(action->latency_), delta, sg_surf_precision);
63           } else {
64             action->latency_ = 0.0;
65           }
66         }
67         action->updateRemains(action->getCost() * delta / action->initialLatency_);
68         if (action->getMaxDuration() != NO_MAX_DURATION)
69           action->updateMaxDuration(delta);
70
71         if (action->getRemainsNoUpdate() <= 0) {
72           action->finish();
73           action->setState(Action::State::done);
74         } else if ((action->getMaxDuration() != NO_MAX_DURATION)
75             && (action->getMaxDuration() <= 0)) {
76           action->finish();
77           action->setState(Action::State::done);
78         }
79       }
80     }
81
82     Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst, double size, double rate)
83     {
84       NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
85
86       Link::onCommunicate(action, src, dst);
87       return action;
88     }
89
90     /**********
91      * Action *
92      **********/
93     NetworkConstantAction::NetworkConstantAction(NetworkConstantModel *model_, double size, double latency)
94     : NetworkAction(model_, size, false)
95     , initialLatency_(latency)
96     {
97       latency_ = latency;
98       if (latency_ <= 0.0) {
99         stateSet_ = getModel()->getDoneActionSet();
100         stateSet_->push_back(*this);
101       }
102     };
103
104     NetworkConstantAction::~NetworkConstantAction() {}
105
106   }
107 }