コード例 #1
0
  private void receiveRREP(RouteReply routeReply)
      throws NoSuchRouteException, InvalidRouteException {

    if (BuildConfig.DEBUG) {
      Debug.debugMessage(routeReply, getMyAddresses(), true, false);
    }

    createOrUpdatePathTo(
        routeReply.getPreviousHop(),
        Constants.UNKNOWN_SEQUENCE_NUMBER,
        routeReply.getPreviousHop(),
        1);

    routeReply.incrementHopCount();

    if (createOrUpdatePathTo(
            routeReply.getDestinationAddress(),
            routeReply.getDestinationSequenceNumber(),
            routeReply.getPreviousHop(),
            routeReply.getHopCount())
        == true) {
      if (!getMyAddresses().contains(routeReply.getSourceAddress())) {
        String nextHop = routingTable.getPathToDestination(routeReply.getSourceAddress());
        routingTable.addPrecursorNode(routeReply.getDestinationAddress(), nextHop);
        routingTable.addPrecursorNode(routeReply.getPreviousHop(), nextHop);

        getSender().queueRoutingMessage(routeReply);
      }
    }
  }
コード例 #2
0
 void queueNewRouteRequest(String destinationAddress, int lastKnownSequenceNumber) {
   if (!sendRREQ(destinationAddress, lastKnownSequenceNumber)) {
     if (BuildConfig.DEBUG) {
       StringBuffer message = new StringBuffer("Nao enviou RREQ apos RRER");
       Log.d(getClass().getName(), message.toString());
       Debug.debugMessage(message);
     }
   }
 }
コード例 #3
0
 private void receiveHello(Hello hello) {
   try {
     routingTable.updateByHello(hello.getSourceAddress(), hello.getSourceSequenceNumber());
   } catch (NoSuchRouteException e) {
     routingTable.createForwardRouteEntry(
         hello.getSourceAddress(), hello.getSourceSequenceNumber(), hello.getSourceAddress(), 1);
   }
   Debug.debugMessage(
       new StringBuffer("Receiver: received hello pdu from: " + hello.getSourceAddress()));
 }
コード例 #4
0
  @Override
  public void routeMessage(RoutingMessage message) throws RoutingException {
    super.routeMessage(message);
    try {
      if (message.getType().equalsIgnoreCase(AODVMessage.AODV_MESSAGE)) {
        AODVMessage aodvMessage = (AODVMessage) message;
        switch (aodvMessage.getMessageType()) {
          case RREQ:
            receiveRREQ((RouteRequest) aodvMessage);
            break;

          case RREP:
            receiveRREP((RouteReply) aodvMessage);
            break;

          case RRER:
            receiveRRER((RouteError) aodvMessage);
            break;

          case HELLO:
            receiveHello((Hello) aodvMessage);
            break;

          default:
            break;
        }
      } else {
        if (message.getType().equalsIgnoreCase(UserDataMessage.class.getCanonicalName())) {
          Debug.debugMessage((UserDataMessage) message, getMyAddresses(), true, false);
          if (getMyAddresses().contains(message.getDestinationAddress())) {
            getReceiver().queueDataMesssage((UserDataMessage) message);
          } else {
            if (isBrodcastMessage(message)) {
              ((UserDataMessage) message).decrementTtl();
              getReceiver().queueDataMesssage((UserDataMessage) message);
            }
            forwardData(message);
          }
        }
      }
    } catch (TimeToLiveExpiredException e) {
      e.printStackTrace();
    } catch (NoSuchRouteException e) {
      e.printStackTrace();
    } catch (InvalidRouteException e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
 private void receiveRRER(RouteError routeError) {
   if (BuildConfig.DEBUG) {
     Debug.debugMessage(routeError, getMyAddresses(), true, false);
   }
   try {
     int lastKnowSequenceNumber =
         routingTable.getDestinationSequenceNumberTo(routeError.getUnreachableNodeAddress());
     if (routeError.getUnreachableNodeSequenceNumber() >= lastKnowSequenceNumber) {
       queueRouteErrorMessage(
           routeError.getUnreachableNodeAddress(),
           routeError.getUnreachableNodeSequenceNumber(),
           routingTable.getPrecusors(routeError.getUnreachableNodeAddress()));
       routingTable.setInvalid(
           routeError.getUnreachableNodeAddress(), routeError.getUnreachableNodeSequenceNumber());
     }
   } catch (AODVException e) {
     e.printStackTrace();
   }
 }
コード例 #6
0
  private void receiveRREQ(RouteRequest routeRequest) {
    if (BuildConfig.DEBUG) {
      Debug.debugMessage(routeRequest, getMyAddresses(), true, false);
    }

    createOrUpdatePathTo(
        routeRequest.getPreviousHop(),
        Constants.UNKNOWN_SEQUENCE_NUMBER,
        routeRequest.getPreviousHop(),
        1);

    if (routingTable.routeRequestExist(routeRequest)) {
      return;
    }

    routingTable.addRouteRequest(routeRequest, false);

    routeRequest.incrementHopCount();

    createOrUpdatePathTo(
        routeRequest.getSourceAddress(),
        routeRequest.getSourceSequenceNumber(),
        routeRequest.getPreviousHop(),
        routeRequest.getHopCount());

    RouteReply rrep = null;
    try {
      rrep = sendRREP(routeRequest);
    } catch (InvalidRouteException e) {
      routeRequest.setDestinationSequenceNumber(
          Math.max(e.getLastSequenceNumber(), routeRequest.getDestinationSequenceNumber()));
    } catch (NoSuchRouteException e) {
    } finally {
      if (rrep != null) {
        sender.queueRoutingMessage(rrep);
      } else {
        sender.queueRoutingMessage(routeRequest);
      }
    }
  }