-namespace simgrid {
- namespace surf {
-
- NetworkModel::~NetworkModel()
- {
- lmm_system_free(maxminSystem_);
- xbt_heap_free(actionHeap_);
- delete modifiedSet_;
- }
-
- 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::nextOccuringEventFull(double now)
- {
- double minRes = Model::nextOccuringEventFull(now);
-
- for(auto it(getRunningActionSet()->begin()), itend(getRunningActionSet()->end()); it != itend ; it++) {
- NetworkAction *action = static_cast<NetworkAction*>(&*it);
- if (action->latency_ > 0)
- minRes = (minRes < 0) ? action->latency_ : std::min(minRes, action->latency_);
- }
-
- XBT_DEBUG("Min of share resources %f", minRes);
-
- return minRes;
- }
-
- /************
- * Resource *
- ************/
-
- Link::Link(simgrid::surf::NetworkModel* model, const char* name, lmm_constraint_t constraint)
- : Resource(model, name, constraint), PropertyHolder(nullptr)
- {
- if (strcmp(name,"__loopback__"))
- xbt_assert(!Link::byName(name), "Link '%s' declared several times in the platform.", name);
-
- latency_.scale = 1;
- 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 required callbacks and destroy the object
- *
- * Don't delete directly a 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::latency()
- {
- return latency_.peak * latency_.scale;
- }
-
- double Link::bandwidth()
- {
- return bandwidth_.peak * 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(stateEvent_ == nullptr, "Cannot set a second state trace to Link %s", getName());
- stateEvent_ = future_evt_set->add_trace(trace, 0.0, this);
- }
- void Link::setBandwidthTrace(tmgr_trace_t trace)
- {
- xbt_assert(bandwidth_.event == nullptr, "Cannot set a second bandwidth trace to Link %s", getName());
- bandwidth_.event = future_evt_set->add_trace(trace, 0.0, this);
- }
- void Link::setLatencyTrace(tmgr_trace_t trace)
- {
- xbt_assert(latency_.event == nullptr, "Cannot set a second latency trace to Link %s", getName());
- latency_.event = future_evt_set->add_trace(trace, 0.0, this);
- }
-
-
- /**********
- * Action *
- **********/
-
- void NetworkAction::setState(Action::State state){
- Action::State old = getState();
- Action::setState(state);
- networkActionStateChangedCallbacks(this, old, state);
- }