Exemplo n.º 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);
    }
  }
Exemplo n.º 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();
 }
Exemplo 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();
    }
  }
Exemplo 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);
      }
    }
  }
Exemplo n.º 5
0
 public PropagationModel getModel(String name) {
   return (PropagationModel) models.get(name);
 }
Exemplo n.º 6
0
 public void setCurModel(String modelname) {
   PropagationModel m = (PropagationModel) models.get(modelname);
   if (m != null) {
     this.curModel = m;
   }
 }