Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename NetworkLink type to Link
[simgrid.git] / examples / java / reservationSurfPlugin / ReservationPlugin.java
1 /* Copyright (c) 2014. 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 package reservationSurfPlugin;
8
9 import org.simgrid.surf.*;
10 import org.simgrid.msg.Msg;
11 import java.util.HashMap;
12
13 public class ReservationPlugin extends Plugin {
14
15   public ReservationPlugin() {
16     activateNetworkCommunicateCallback();
17   }
18
19   //HashMap<String,Reservation> reservations;
20   double bandwidth = 0;
21   String src = "";
22   String dst = "";
23
24   public void limitBandwidthActions(String src, String dst, double bandwidth){
25     this.bandwidth = bandwidth;
26     this.src = src;
27     this.dst = dst;
28   }
29
30   public void updateBandwidthRoute(String src, String dst, double bandwidth){
31     Link[] route = Surf.getRoute(src, dst);
32     for (int i =0; i<route.length; i++){
33       Msg.info("Trace: bandwidth of "+route[i].getName()+" before "+route[i].getBandwidth());
34       route[i].updateBandwidth(bandwidth);//getName();
35       Msg.info("Trace: bandwidth of "+route[i].getName()+" after "+route[i].getBandwidth());
36     }
37   }
38
39   @Override
40   public void networkCommunicateCallback(NetworkAction action, RoutingEdge src, RoutingEdge dst, double size, double rate){
41     if (src.getName().equals(this.src) && dst.getName().equals(this.dst)) {
42       action.setBound(this.bandwidth);
43     }
44     Msg.info("Trace: Communicate message of size "+size+" with rate "+rate+" and bound "+action.getBound()+" from "+src.getName()+" to "+dst.getName());
45   }
46 }