示例#1
0
  /**
   * Delete transact config.
   *
   * @param childTableName child table name
   * @param childColumnName child column name
   * @param childUuid child row uuid
   * @param parentTableName parent table name
   * @param parentColumnName parent column
   */
  private void deleteConfig(
      String childTableName,
      String childColumnName,
      String childUuid,
      String parentTableName,
      String parentColumnName) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);

    ArrayList<Operation> operations = Lists.newArrayList();
    if (parentTableName != null && parentColumnName != null) {
      TableSchema parentTableSchema = dbSchema.getTableSchema(parentTableName);
      ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(parentColumnName);
      List<Mutation> mutations = Lists.newArrayList();
      Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), UUID.uuid(childUuid));
      mutations.add(mutation);
      List<Condition> conditions = Lists.newArrayList();
      Condition condition = ConditionUtil.includes(parentColumnName, UUID.uuid(childUuid));
      conditions.add(condition);
      Mutate op = new Mutate(parentTableSchema, conditions, mutations);
      operations.add(op);
    }

    List<Condition> conditions = Lists.newArrayList();
    Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid));
    conditions.add(condition);
    Delete del = new Delete(childTableSchema, conditions);
    operations.add(del);
    transactConfig(OvsdbConstant.DATABASENAME, operations);

    return;
  }
示例#2
0
  @Override
  public String getInterfaceUuid(String portUuid, String portName) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);

    Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT, portUuid);
    Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);

    if (port != null) {
      OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data();
      @SuppressWarnings("unchecked")
      Set<UUID> interfaces = setInterfaces.set();

      if (interfaces == null || interfaces.size() == 0) {
        log.warn("The interface uuid is null");
        return null;
      }

      for (UUID uuid : interfaces) {
        Row intfRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.INTERFACE, uuid.value());
        Interface intf =
            (Interface) TableGenerator.getTable(dbSchema, intfRow, OvsdbTable.INTERFACE);
        if (intf != null && portName.equalsIgnoreCase(intf.getName())) {
          return uuid.value();
        }
      }
    }

    return null;
  }
示例#3
0
  @Override
  public String getPortUuid(String portName, String bridgeUuid) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);

    Row bridgeRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE, bridgeUuid);

    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
    if (bridge != null) {
      OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
      @SuppressWarnings("unchecked")
      Set<UUID> ports = setPorts.set();
      if (ports == null || ports.size() == 0) {
        log.warn("The port uuid is null");
        return null;
      }

      for (UUID uuid : ports) {
        Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT, uuid.value());
        Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);
        if (port != null && portName.equalsIgnoreCase(port.getName())) {
          return uuid.value();
        }
      }
    }
    return null;
  }
示例#4
0
  /**
   * Insert transact config.
   *
   * @param childTableName child table name
   * @param childColumnName child column name
   * @param parentTableName parent table name
   * @param parentColumnName parent column
   * @param parentUuid parent uuid
   * @param row the config data
   * @return uuid, empty if no uuid is find
   */
  private String insertConfig(
      String childTableName,
      String childColumnName,
      String parentTableName,
      String parentColumnName,
      String parentUuid,
      Row row) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    TableSchema tableSchema = dbSchema.getTableSchema(childTableName);

    String namedUuid = childTableName;
    Insert insert = new Insert(tableSchema, namedUuid, row);

    ArrayList<Operation> operations = Lists.newArrayList();
    operations.add(insert);

    if (parentTableName != null && parentColumnName != null) {
      TableSchema parentTableSchema = dbSchema.getTableSchema(parentTableName);
      ColumnSchema parentColumnSchema = parentTableSchema.getColumnSchema(parentColumnName);

      List<Mutation> mutations = Lists.newArrayList();
      Mutation mutation = MutationUtil.insert(parentColumnSchema.name(), UUID.uuid(namedUuid));
      mutations.add(mutation);

      List<Condition> conditions = Lists.newArrayList();
      Condition condition = ConditionUtil.equals("_uuid", UUID.uuid(parentUuid));
      conditions.add(condition);

      Mutate op = new Mutate(parentTableSchema, conditions, mutations);
      operations.add(op);
    }
    if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) {
      log.info("Handle port insert");
      Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE, row);

      if (intfInsert != null) {
        operations.add(intfInsert);
      }

      Insert ins = (Insert) operations.get(0);
      ins.getRow().put("interfaces", UUID.uuid(OvsdbConstant.INTERFACE));
    }

    List<OperationResult> results;
    try {
      results = transactConfig(OvsdbConstant.DATABASENAME, operations).get();

      return results.get(0).getUuid().value();
    } catch (InterruptedException e) {
      log.warn("Interrupted while waiting to get result");
      Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
      log.error("Exception thrown while to get result");
    }

    return null;
  }
示例#5
0
  /**
   * Update transact config.
   *
   * @param tableName table name
   * @param columnName column name
   * @param uuid uuid
   * @param row the config data
   */
  private void updateConfig(String tableName, String columnName, String uuid, Row row) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    TableSchema tableSchema = dbSchema.getTableSchema(tableName);

    List<Condition> conditions = Lists.newArrayList();
    Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid));
    conditions.add(condition);

    Update update = new Update(tableSchema, row, conditions);

    ArrayList<Operation> operations = Lists.newArrayList();
    operations.add(update);

    transactConfig(OvsdbConstant.DATABASENAME, operations);
  }
示例#6
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());
      }
    }
  }