-namespace simgrid {
- namespace surf {
-
- double NetworkModel::latencyFactor(double /*size*/) {
- return sg_latency_factor;
- }
-
- double NetworkModel::bandwidthFactor(double /*size*/) {
- return sg_bandwidth_factor;
- }
-
- double NetworkModel::bandwidthConstraint(double rate, double /*bound*/, double /*size*/) {
- return rate;
- }
-
- double NetworkModel::next_occuring_event_full(double now)
- {
- NetworkAction *action = NULL;
- ActionList *runningActions = surf_network_model->getRunningActionSet();
- double minRes;
-
- minRes = shareResourcesMaxMin(runningActions, surf_network_model->maxminSystem_, surf_network_model->f_networkSolve);
-
- for(ActionList::iterator it(runningActions->begin()), itend(runningActions->end())
- ; it != itend ; ++it) {
- action = static_cast<NetworkAction*>(&*it);
- if (action->m_latency > 0) {
- minRes = (minRes < 0) ? action->m_latency : std::min(minRes, action->m_latency);
- }
- }
-
- XBT_DEBUG("Min of share resources %f", minRes);
-
- return minRes;
- }
-
- /************
- * Resource *
- ************/
-
- Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props)
- : Resource(model, name),
- PropertyHolder(props)
- {
- links->insert({name, this});
-
- m_latency.scale = 1;
- m_bandwidth.scale = 1;
- XBT_DEBUG("Create link '%s'",name);
- }
-
- Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint)
- : Resource(model, name, constraint),
- PropertyHolder(props)
- {
- if (strcmp(name,"__loopback__"))
- xbt_assert(!Link::byName(name), "Link '%s' declared several times in the platform.", name);
-
- m_latency.scale = 1;
- m_bandwidth.scale = 1;
-
- links->insert({name, this});
- XBT_DEBUG("Create link '%s'",name);
-
- }
-
- /** @brief use destroy() instead of this destructor */
- Link::~Link() {
- xbt_assert(currentlyDestroying_, "Don't delete Links directly. Call destroy() instead.");
- }
- /** @brief Fire the require callbacks and destroy the object
- *
- * Don't delete directly an Link, call l->destroy() instead.
- */
- void Link::destroy()
- {
- if (!currentlyDestroying_) {
- currentlyDestroying_ = true;
- onDestruction(this);
- delete this;
- }
- }
-
- bool Link::isUsed()
- {
- return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint());
- }
-
- double Link::getLatency()
- {
- return m_latency.peak * m_latency.scale;
- }
-
- double Link::getBandwidth()
- {
- return m_bandwidth.peak * m_bandwidth.scale;
- }
-
- int Link::sharingPolicy()
- {
- return lmm_constraint_sharing_policy(getConstraint());
- }
-
- void Link::turnOn(){
- if (isOff()) {
- Resource::turnOn();
- onStateChange(this);
- }
- }
- void Link::turnOff(){
- if (isOn()) {
- Resource::turnOff();
- onStateChange(this);
- }
- }
- void Link::setStateTrace(tmgr_trace_t trace) {
- xbt_assert(m_stateEvent==NULL,"Cannot set a second state trace to Link %s", getName());
- m_stateEvent = future_evt_set->add_trace(trace, 0.0, this);
- }
- void Link::setBandwidthTrace(tmgr_trace_t trace)
- {
- xbt_assert(m_bandwidth.event==NULL,"Cannot set a second bandwidth trace to Link %s", getName());
- m_bandwidth.event = future_evt_set->add_trace(trace, 0.0, this);
- }
- void Link::setLatencyTrace(tmgr_trace_t trace)
- {
- xbt_assert(m_latency.event==NULL,"Cannot set a second latency trace to Link %s", getName());
- m_latency.event = future_evt_set->add_trace(trace, 0.0, this);
- }
-
-
- /**********
- * Action *
- **********/
-
- void NetworkAction::setState(e_surf_action_state_t state){
- e_surf_action_state_t old = getState();
- Action::setState(state);
- networkActionStateChangedCallbacks(this, old, state);
- }