示例#1
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;
  }
示例#2
0
  @Override
  public String getBridgeUuid(String bridgeName) {
    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);

    OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE);
    if (rowStore == null) {
      log.debug("The bridge uuid is null");
      return null;
    }

    ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
    if (bridgeTableRows == null) {
      log.debug("The bridge uuid is null");
      return null;
    }

    for (String uuid : bridgeTableRows.keySet()) {
      Bridge bridge =
          (Bridge) TableGenerator.getTable(dbSchema, bridgeTableRows.get(uuid), OvsdbTable.BRIDGE);

      if (bridge.getName().equals(bridgeName)) {
        return uuid;
      }
    }
    return null;
  }
示例#3
0
  //// Gets ovsdb bridge.
  private OvsdbBridge getOvsdbBridge(Row row) {
    DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
    if (bridge == null) {
      return null;
    }

    OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
    @SuppressWarnings("unchecked")
    Set<String> datapathIds = datapathIdSet.set();
    if (datapathIds == null || datapathIds.size() == 0) {
      return null;
    }
    String datapathId = (String) datapathIds.toArray()[0];
    String bridgeName = bridge.getName();
    if ((datapathId == null) || (bridgeName == null)) {
      return null;
    }

    OvsdbBridge ovsdbBridge =
        new OvsdbBridge(new OvsdbBridgeName(bridgeName), new OvsdbDatapathId(datapathId));
    return ovsdbBridge;
  }
示例#4
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());
      }
    }
  }
示例#5
0
  @Override
  public void createBridge(String bridgeName) {
    log.debug("create bridge {}", bridgeName);

    DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
    if (dbSchema == null) {
      log.warn("The schema is null");
      return;
    }

    Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
    if (bridge == null) {
      log.debug("Can not create bridge");
      return;
    }

    Set<String> failModes = new HashSet<>();
    failModes.add("secure");
    bridge.setFailMode(failModes);

    Set<String> protocols = new HashSet<>();
    protocols.add(OvsdbConstant.OPENFLOW13);
    bridge.setProtocols(protocols);

    String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME);
    if (ovsUuid == null) {
      log.warn("The Open_vSwitch is null");
      return;
    }

    String bridgeUuid = getBridgeUuid(bridgeName);
    if (bridgeUuid == null) {
      log.debug("Create a new bridge");

      bridge.setName(bridgeName);
      bridgeUuid =
          insertConfig(
              OvsdbConstant.BRIDGE,
              "_uuid",
              OvsdbConstant.DATABASENAME,
              "bridges",
              ovsUuid,
              bridge.getRow());

      if (bridgeUuid != null) {
        Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
        if (port != null) {
          log.debug("the port is not null");
          port.setName(bridgeName);

          insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, port.getRow());
        }
      }

    } else {
      log.info("Update a bridge");
      updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
    }

    setController(bridgeUuid);
    log.info("Create bridge success");
  }