Esempio n. 1
0
 public CamadaRede() {
   super();
   tabelaEnderecosMacIp = new Hashtable<String, int[]>();
   ce = new CamadaEnlace();
   ce.add(this);
   arp = new Arp(ce);
   lista = Collections.synchronizedList(new ArrayList<PacoteIp>());
   ce.setPriority(Thread.MIN_PRIORITY);
   ce.start();
   // this.start();
 }
Esempio n. 2
0
  public void run() {
    while (true) {
      synchronized (lista) {
        Iterator<PacoteIp> itLista = lista.iterator();

        while (itLista.hasNext()) {
          PacoteIp pacote = itLista.next();
          int[] enderecoMac = null;
          if ((enderecoMac = pegaNaTabelaMacIp(pacote.getIpDestino())) != null) {
            ce.send(pacote.toArray(), enderecoMac, Constantes.tipoDado);
            lista.remove(pacote);
          } else {
            if (pacote.getContadorAuxiliarLista() > PacoteIp.MAXIMO_CONTADORLISTA) {
              lista.remove(pacote);
            } else pacote.setContadorAuxiliarLista(pacote.getContadorAuxiliarLista() + 1);
          }
        }
        try {
          sleep(1000);
        } catch (InterruptedException ex) {
          System.out.println("ERRO 1");
        }
      }
    }
  }
Esempio n. 3
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);
        }
      }
    }
  }