Ejemplo n.º 1
0
 public double getLossRate(int senderID, int receiverID) {
   Double d = (Double) connectivityGraph.get(graphKey(senderID, receiverID));
   if (d == null) {
     throw new ArrayIndexOutOfBoundsException(
         "no connectivity entry for " + senderID + " -> " + receiverID);
   }
   return d.doubleValue();
 }
Ejemplo n.º 2
0
  public void register() {
    debug.out.println("RADIOMODEL: registering radio model plugin");
    connectivityGraph = new Hashtable();

    EmpiricalModel empiricalModel = new EmpiricalModel();
    models.put("empirical", empiricalModel);
    curModel = empiricalModel;

    // User can use scaling factor to adjust
    DiscModel dm;
    dm = new DiscModel(10.0);
    models.put("disc10", dm);
    dm = new DiscModel(100.0);
    models.put("disc100", dm);
    dm = new DiscModel(1000.0);
    models.put("disc1000", dm);

    updateModel();
  }
Ejemplo n.º 3
0
  public void handleEvent(SimEvent event) {
    if (event instanceof SimObjectEvent) {
      SimObjectEvent simObjectEvent = (SimObjectEvent) event;
      SimObject simObject = simObjectEvent.getSimObject();
      switch (simObjectEvent.getType()) {
        case SimObjectEvent.OBJECT_ADDED:
        case SimObjectEvent.OBJECT_REMOVED:
          // always fully update the model
          debug.err.println("RADIOMODEL: sim object add/remove, updating model");
          updateModel();
          break;
      }
    } else if (event instanceof AttributeEvent) {
      AttributeEvent attributeEvent = (AttributeEvent) event;
      switch (attributeEvent.getType()) {
        case ATTRIBUTE_CHANGED:
          if (attributeEvent.getAttribute() instanceof MoteCoordinateAttribute) {
            MoteSimObject mote = (MoteSimObject) attributeEvent.getOwner();
            debug.err.println("RADIOMODEL: " + mote + " moved, updating links");
            updateLossRates(mote);
          }
          break;
      }
    }

    // XXX/demmer this isn't necessary since we already respond to the
    // updated location attributes
    //     else if (event instanceof SimObjectDraggedEvent) {
    //       updateModel(true);
    //     }

    else if (event instanceof OptionSetEvent) {
      OptionSetEvent ose = (OptionSetEvent) event;

      if (ose.name.equals("radiomodel")) {
        PropagationModel pm = (PropagationModel) models.get(ose.value);
        if (pm != null) {
          debug.err.println("RADIOMODEL: Setting model to " + pm);
          curModel = pm;
          updateModel();
        }
      }

      // also not necessary since it generates new simobjectevents
      //     } else if (event instanceof TossimInitEvent) {
      //       driver.pause();
      //       updateModel();
      //       publishModel();
      //       driver.resume();
    }
  }
Ejemplo n.º 4
0
  // Send the loss rate for all pairs of motes to the simulator
  public void publishModel() {
    debug.err.println("RADIOMODEL: Publishing model, current is " + curModel);
    Iterator it1 = state.getMoteSimObjects().iterator();
    while (it1.hasNext()) {
      MoteSimObject moteSender = (MoteSimObject) it1.next();
      MoteCoordinateAttribute moteSenderCoord = moteSender.getCoordinate();
      Iterator it2 = state.getMoteSimObjects().iterator();
      while (it2.hasNext()) {
        MoteSimObject moteReceiver = (MoteSimObject) it2.next();
        if (moteReceiver.getID() == moteSender.getID()) continue;

        String key = graphKey(moteSender, moteReceiver);
        double prob = ((Double) connectivityGraph.get(key)).doubleValue();
        publishLossRate(moteSender, moteReceiver, prob);
      }
    }
  }
Ejemplo n.º 5
0
  // Recalculate the loss rate for the pair of motes based on their
  // distance and the current model
  public void updateLossRate(MoteSimObject moteSender, MoteSimObject moteReceiver) {
    double distance = moteSender.getDistance(moteReceiver);
    double prob = curModel.getPacketLossRate(distance, this.scalingFactor);

    debug.out.println(
        "RADIOMODEL: "
            + moteSender
            + "->"
            + moteReceiver
            + " dist "
            + distance
            + " scale "
            + scalingFactor
            + " prob "
            + prob);

    long scaledBitLossRate = (long) (curModel.getBitLossRate(prob) * 10000);

    debug.out.println(
        "RADIOMODEL: sampleLossRate "
            + "[moteSender "
            + moteSender
            + "] 1"
            + "[moteReceiver "
            + moteReceiver
            + "] "
            + "[packetLossRate "
            + prob
            + "] "
            + "[scaledBitLossRate "
            + scaledBitLossRate
            + "]");

    connectivityGraph.put(graphKey(moteSender, moteReceiver), new Double(prob));

    if (autoPublish) {
      publishLossRate(moteSender, moteReceiver, prob);
    }
  }
Ejemplo n.º 6
0
 public PropagationModel getModel(String name) {
   return (PropagationModel) models.get(name);
 }
Ejemplo n.º 7
0
 public Enumeration getModels() {
   return models.elements();
 }
Ejemplo n.º 8
0
 public void setCurModel(String modelname) {
   PropagationModel m = (PropagationModel) models.get(modelname);
   if (m != null) {
     this.curModel = m;
   }
 }
Ejemplo n.º 9
0
 public void setLossRate(int senderID, int receiverID, double prob) {
   connectivityGraph.put(graphKey(senderID, receiverID), new Double(prob));
 }
Ejemplo n.º 10
0
 public void setLossRate(MoteSimObject sender, MoteSimObject receiver, double prob) {
   connectivityGraph.put(graphKey(sender, receiver), new Double(prob));
 }