Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
empty RoutingPlatf: move the loopback link to the network_model(s)
[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 == nullptr);
17   surf_network_model = new simgrid::surf::NetworkConstantModel();
18   all_existing_models->push_back(surf_network_model);
19
20   routing_model_create();
21 }
22
23 namespace simgrid {
24   namespace surf {
25   Link* NetworkConstantModel::createLink(const char* name, double bw, double lat, e_surf_link_sharing_policy_t policy)
26   {
27
28     xbt_die("Refusing to create the link %s: there is no link in the Constant network model. "
29             "Please remove any link from your platform (and switch to routing='None')",
30             name);
31     return nullptr;
32     }
33
34     double NetworkConstantModel::nextOccuringEvent(double /*now*/)
35     {
36       double min = -1.0;
37
38       ActionList *actionSet = getRunningActionSet();
39       for(auto it(actionSet->begin()), itend(actionSet->end()) ; it != itend ; ++it) {
40         NetworkConstantAction *action = static_cast<NetworkConstantAction*>(&*it);
41         if (action->latency_ > 0 && (min < 0 || action->latency_ < min))
42           min = action->latency_;
43       }
44
45       return min;
46     }
47
48     void NetworkConstantModel::updateActionsState(double /*now*/, double delta)
49     {
50       NetworkConstantAction *action = nullptr;
51       ActionList *actionSet = getRunningActionSet();
52       for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end())
53           ; it != itend ; it=itNext) {
54         ++itNext;
55         action = static_cast<NetworkConstantAction*>(&*it);
56         if (action->latency_ > 0) {
57           if (action->latency_ > delta) {
58             double_update(&(action->latency_), delta, sg_surf_precision);
59           } else {
60             action->latency_ = 0.0;
61           }
62         }
63         action->updateRemains(action->getCost() * delta / action->initialLatency_);
64         if (action->getMaxDuration() != NO_MAX_DURATION)
65           action->updateMaxDuration(delta);
66
67         if (action->getRemainsNoUpdate() <= 0) {
68           action->finish();
69           action->setState(Action::State::done);
70         } else if ((action->getMaxDuration() != NO_MAX_DURATION)
71             && (action->getMaxDuration() <= 0)) {
72           action->finish();
73           action->setState(Action::State::done);
74         }
75       }
76     }
77
78     Action* NetworkConstantModel::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate)
79     {
80       NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
81
82       Link::onCommunicate(action, src, dst);
83       return action;
84     }
85
86     /**********
87      * Action *
88      **********/
89     NetworkConstantAction::NetworkConstantAction(NetworkConstantModel *model_, double size, double latency)
90     : NetworkAction(model_, size, false)
91     , initialLatency_(latency)
92     {
93       latency_ = latency;
94       if (latency_ <= 0.0) {
95         stateSet_ = getModel()->getDoneActionSet();
96         stateSet_->push_back(*this);
97       }
98     };
99
100     NetworkConstantAction::~NetworkConstantAction() {}
101
102   }
103 }