Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sort out the Link::onCommunicate signal
[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   simgrid::surf::on_link.connect(netlink_parse_init);
23 }
24
25 namespace simgrid {
26   namespace surf {
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     }
34
35     double NetworkConstantModel::next_occuring_event(double /*now*/)
36     {
37       NetworkConstantAction *action = NULL;
38       double min = -1.0;
39
40       ActionList *actionSet = getRunningActionSet();
41       for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
42           ; it != itend ; ++it) {
43         action = static_cast<NetworkConstantAction*>(&*it);
44         if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
45           min = action->latency_;
46       }
47
48       return min;
49     }
50
51     void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
52     {
53       NetworkConstantAction *action = NULL;
54       ActionList *actionSet = getRunningActionSet();
55       for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
56           ; it != itend ; it=itNext) {
57         ++itNext;
58         action = static_cast<NetworkConstantAction*>(&*it);
59         if (action->latency_ > 0) {
60           if (action->latency_ > delta) {
61             double_update(&(action->latency_), delta, sg_surf_precision);
62           } else {
63             action->latency_ = 0.0;
64           }
65         }
66         action->updateRemains(action->getCost() * delta / action->m_latInit);
67         if (action->getMaxDuration() != NO_MAX_DURATION)
68           action->updateMaxDuration(delta);
69
70         if (action->getRemainsNoUpdate() <= 0) {
71           action->finish();
72           action->setState(Action::State::done);
73         } else if ((action->getMaxDuration() != NO_MAX_DURATION)
74             && (action->getMaxDuration() <= 0)) {
75           action->finish();
76           action->setState(Action::State::done);
77         }
78       }
79     }
80
81     Action *NetworkConstantModel::communicate(NetCard *src, NetCard *dst, double size, double rate)
82     {
83       NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
84
85       Link::onCommunicate(action, src, dst);
86       return action;
87     }
88
89     /**********
90      * Action *
91      **********/
92
93     int NetworkConstantAction::unref()
94     {
95       m_refcount--;
96       if (!m_refcount) {
97         if (action_hook.is_linked())
98           p_stateSet->erase(p_stateSet->iterator_to(*this));
99         delete this;
100         return 1;
101       }
102       return 0;
103     }
104
105     void NetworkConstantAction::cancel()
106     {
107       return;
108     }
109
110   }
111 }