Ejemplo n.º 1
0
 @Override
 public void onPacketReceived(PacketReceived potentialArp) {
   Arp arp = ArpResolverUtils.getArpFrom(potentialArp);
   if (arp != null) {
     if (arp.getOperation() != ArpOperation.REPLY.intValue()) {
       LOG.trace("Packet is not ARP REPLY packet.");
       return;
     }
     if (LOG.isTraceEnabled()) {
       LOG.trace("ARP REPLY received - {}", ArpUtils.getArpToStringFormat(arp));
     }
     NodeKey nodeKey = potentialArp.getIngress().getValue().firstKeyOf(Node.class, NodeKey.class);
     if (nodeKey == null) {
       LOG.info("Unknown source node of ARP packet: {}", potentialArp);
       return;
     }
     Ipv4Address gatewayIpAddress = ArpUtils.bytesToIp(arp.getSenderProtocolAddress());
     MacAddress gatewayMacAddress = ArpUtils.bytesToMac(arp.getSenderHardwareAddress());
     ArpResolverMetadata candidateGatewayIp = gatewayToArpMetadataMap.get(gatewayIpAddress);
     if (candidateGatewayIp != null) {
       LOG.debug(
           "Resolved MAC for Gateway Ip {} is {}",
           gatewayIpAddress.getValue(),
           gatewayMacAddress.getValue());
       candidateGatewayIp.setGatewayMacAddress(gatewayMacAddress);
       resetFlowToRemove(gatewayIpAddress, candidateGatewayIp);
     }
   }
 }
Ejemplo n.º 2
0
  public void send(
      int version,
      int type_of_service,
      int identification,
      int DF,
      int MF,
      int fragment_offset,
      int time_to_live,
      int protocol,
      int[] ipDestino,
      int[] dado,
      int[] tipoDeDadoMac) {

    PacoteIp pacoteIP = new PacoteIp();
    pacoteIP.setVersion(version);
    pacoteIP.setType_of_service(type_of_service);
    pacoteIP.setIdentification(identification);
    pacoteIP.setDF(DF);
    pacoteIP.setMF(MF);
    pacoteIP.setFragment_offset(fragment_offset);
    pacoteIP.setTime_to_live(time_to_live);
    pacoteIP.setProtocol(protocol);
    pacoteIP.setIpDestino(ipDestino);
    pacoteIP.setIpOrigem(Constantes.ipOrigem);
    pacoteIP.setDado(dado);
    if (!ce.estaTransmitindo()) {
      int[] endDestinoMac;
      if ((endDestinoMac = pegaNaTabelaMacIp(ipDestino)) != null || true) {
        endDestinoMac = Constantes.enderecoDeDestino;
        // SE EXISTE NA TABELA ENVIA
        ce.send(pacoteIP.toArray(), endDestinoMac, tipoDeDadoMac);
      } else {
        // RESOLVE O MAC E COLOCA NA LISTA DE ESPERA
        arp.resolverEndereco(ipDestino);
        synchronized (lista) {
          lista.add(pacoteIP);
        }
      }
    }
  }