public void bellmanFord(
      HashMap<String, HashMap<String, Integer>> adjMatrix,
      Host src,
      HashMap<String, String> predecessors,
      HashMap<String, Integer> fwdingToSrcPorts,
      HashMap<String, Integer> distances) {
    if (src.getSwitch() == null) return;
    for (Host host : this.getHosts()) {
      distances.put(host.getName(), this.INFINITY);
      if (host.getSwitch() != null) {
        // predecessors.put(host.getName(), host.getSwitch().getStringId());
        // fwdingToSrcPorts.put(host.getName(), host.getPort());
      }
    }
    for (IOFSwitch sw : this.getSwitches().values()) {
      String swIdName = String.valueOf(sw.getId());
      distances.put(swIdName, this.INFINITY);
    }
    distances.put(src.getName(), 0);
    predecessors.put(src.getName(), String.valueOf(src.getSwitch().getId()));
    // fwdingToSrcPorts.put(src.getName(), src.getPort());

    Set<String> allDeviceNames = this.adjMatrix.keySet();
    if (debug_level < 1) {
      System.out.println("BF : adjMetrix keyset size : " + allDeviceNames.size());
      System.out.println("Num Links : " + this.getLinks().size());
    }
    for (int i = 0; i < allDeviceNames.size(); i++) {
      // for each u, v
      for (String device : allDeviceNames) {
        for (Map.Entry<String, Integer> adjEntry : adjMatrix.get(device).entrySet()) {
          // for each v adjacent to u
          if (adjEntry.getValue() == 1) // 1 only if it is an edge
          {
            if ((distances.get(device) + 1) < distances.get(adjEntry.getKey())) {
              distances.put(adjEntry.getKey(), (distances.get(device) + 1));
              predecessors.put(adjEntry.getKey(), device);

              // fwding ports need to be populated only if it is a switch
              // case 1 : this switch's predecessor is the src
              if (device.equals(src.getName())) {
                fwdingToSrcPorts.put(adjEntry.getKey(), src.getPort());
              }
              // case 2 : this switch's predecessor is another switch
              else {
                for (Link link : this.getLinks()) {
                  if (String.valueOf(link.getDst()).equals(device)) {
                    if (String.valueOf(link.getSrc()).equals(adjEntry.getKey())) {
                      fwdingToSrcPorts.put(adjEntry.getKey(), link.getSrcPort());
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    if (debug_level < 2) displayBellmanFord(src, predecessors, fwdingToSrcPorts, distances);
  }
  public void bellmanFordOld(
      HashMap<String, HashMap<String, Integer>> adjMatrix,
      Host src,
      HashMap<String, String> predecessors,
      HashMap<String, Integer> fwdingToSrcPorts,
      HashMap<String, Integer> distances) {

    if (src.getSwitch() == null) return;
    for (Host host : this.getHosts()) {
      distances.put(host.getName(), this.INFINITY);
      if (host.getSwitch() != null) {
        predecessors.put(host.getName(), String.valueOf(host.getSwitch().getId()));
        fwdingToSrcPorts.put(host.getName(), host.getPort());
      }
    }
    for (long swId : this.getSwitches().keySet()) {
      String swIdName = String.valueOf(swId);
      distances.put(swIdName, this.INFINITY);
    }
    distances.put(src.getName(), 0);

    predecessors.put(src.getName(), String.valueOf(src.getSwitch().getId()));
    fwdingToSrcPorts.put(src.getName(), src.getPort());

    Set<String> allDeviceNames = this.adjMatrix.keySet();

    for (int i = 0; i < allDeviceNames.size() - 1; i++) {
      // for each u
      // for (Link link : this.getLinks())
      // {
      // System.out.println("Link Src: " + link.getSrc() + "\t" + link.getDst());
      // if(distances.get(String.valueOf(link.getSrc())) + 1 <
      // distances.get(String.valueOf(link.getDst())))
      // {
      // distances.put(String.valueOf(link.getDst()), distances.get(String.valueOf(link.getSrc())) +
      // 1);
      // predecessors.put(String.valueOf(link.getDst()), String.valueOf(link.getSrc()));
      // fwdingToSrcPorts.put(String.valueOf(link.getDst()), link.getDstPort());
      // }
      // }

    }
    if (debug_level < 2) displayBellmanFord(src, predecessors, fwdingToSrcPorts, distances);
  }
  /**
   * Event handler called when a host moves within the network.
   *
   * @param device information about the host
   */
  @Override
  public void deviceMoved(IDevice device) {
    Host host = this.knownHosts.get(device);
    if (null == host) {
      host = new Host(device, this.floodlightProv);
      this.knownHosts.put(device, host);
    }

    if (!host.isAttachedToSwitch()) {
      this.deviceRemoved(device);
      return;
    }
    log.info(
        String.format(
            "Host %s moved to s%d:%d", host.getName(), host.getSwitch().getId(), host.getPort()));

    /** ****************************************************************** */
    /* TODO: Update routing: change rules to route to host */
    updateAllRouting();

    /** ****************************************************************** */
  }