示例#1
0
  public synchronized void messageReceived(int to, Message m) {

    DrainMsg mhMsg = (DrainMsg) m;

    log.debug(
        "incoming: localDest: "
            + to
            + " type:"
            + mhMsg.get_type()
            + " hops:"
            + (16 - mhMsg.get_ttl())
            + " seqNo:"
            + mhMsg.get_seqNo()
            + " source:"
            + mhMsg.get_source()
            + " finalDest:"
            + mhMsg.get_dest());

    // lets assume that the network cannot buffer more than 25 drain msgs from a single source at a
    // time (should be more than reasonable)
    if (seqNos.containsKey(new Integer(mhMsg.get_source()))) {
      int oldSeqNo = ((Integer) seqNos.get(new Integer(mhMsg.get_source()))).intValue();
      int upperBound = mhMsg.get_seqNo() + 25;
      int wrappedUpperBound = 25 - (255 - mhMsg.get_seqNo());
      if ((oldSeqNo >= mhMsg.get_seqNo() && oldSeqNo < upperBound)
          || (oldSeqNo >= 0 && oldSeqNo < wrappedUpperBound)) {
        log.debug(
            "Dropping message from "
                + mhMsg.get_source()
                + " with duplicate seqNo: "
                + mhMsg.get_seqNo());
        return;
      }
    }
    seqNos.put(new Integer(mhMsg.get_source()), new Integer(mhMsg.get_seqNo()));

    if (to != spAddr && to != MoteIF.TOS_BCAST_ADDR && to != TOS_UART_ADDR) {
      log.debug("Dropping message not for me.");
      return;
    }

    HashSet promiscuousSet = (HashSet) idTable.get(new Integer(BCAST_ID));
    HashSet listenerSet = (HashSet) idTable.get(new Integer(mhMsg.get_type()));

    if (listenerSet != null && promiscuousSet != null) {
      listenerSet.addAll(promiscuousSet);
    } else if (listenerSet == null && promiscuousSet != null) {
      listenerSet = promiscuousSet;
    }

    if (listenerSet == null) {
      log.debug("No Listener for type: " + mhMsg.get_type());
      return;
    }

    for (Iterator it = listenerSet.iterator(); it.hasNext(); ) {
      MessageListener ml = (MessageListener) it.next();
      ml.messageReceived(to, mhMsg);
    }
  }
示例#2
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();
 }
示例#3
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();
  }
示例#4
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();
    }
  }
示例#5
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);
      }
    }
  }
示例#6
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);
    }
  }
示例#7
0
 public PropagationModel getModel(String name) {
   return (PropagationModel) models.get(name);
 }
示例#8
0
 public Enumeration getModels() {
   return models.elements();
 }
示例#9
0
 public void setCurModel(String modelname) {
   PropagationModel m = (PropagationModel) models.get(modelname);
   if (m != null) {
     this.curModel = m;
   }
 }
示例#10
0
 public void setLossRate(int senderID, int receiverID, double prob) {
   connectivityGraph.put(graphKey(senderID, receiverID), new Double(prob));
 }
示例#11
0
 public void setLossRate(MoteSimObject sender, MoteSimObject receiver, double prob) {
   connectivityGraph.put(graphKey(sender, receiver), new Double(prob));
 }