Exemple #1
0
  @Override
  public String getControllerUuid(String controllerName, String controllerTarget) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, OvsdbConstant.CONTROLLER);
    if (rowStore == null) {
      log.debug("The controller uuid is null");
      return null;
    }

    ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore();
    if (controllerTableRows != null) {
      for (String uuid : controllerTableRows.keySet()) {

        Controller controller =
            (Controller)
                TableGenerator.getTable(
                    dbSchema, controllerTableRows.get(uuid), OvsdbTable.CONTROLLER);
        String target = (String) controller.getTargetColumn().data();
        if (target.equalsIgnoreCase(controllerTarget)) {
          return uuid;
        }
      }
    }
    return null;
  }
Exemple #2
0
  /**
   * Sets the Controller.
   *
   * @param bridgeUuid bridge uuid
   */
  private void setController(String bridgeUuid) {
    String controllerUuid = null;
    String iPAddress =
        IpAddress.valueOf(
                ((InetSocketAddress) channel.localAddress()).getAddress().getHostAddress())
            .toString();

    String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT;
    log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT);

    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    Controller controller =
        (Controller) TableGenerator.createTable(dbSchema, OvsdbTable.CONTROLLER);

    if (controller != null) {
      controller.setTarget(target);
      controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target);
      if (controllerUuid == null) {

        insertConfig(
            OvsdbConstant.CONTROLLER,
            "_uuid",
            OvsdbConstant.BRIDGE,
            "controller",
            bridgeUuid,
            controller.getRow());

      } else {

        Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
        Set<UUID> controllerUuids = new HashSet<>();
        controllerUuids.add(UUID.uuid(controllerUuid));
        bridge.setController(controllerUuids);
        updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow());
      }
    }
  }