Esempio n. 1
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;
  }
Esempio n. 2
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;
  }
Esempio n. 3
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;
  }
Esempio n. 4
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;
  }
Esempio n. 5
0
  // Gets ovsdb port.
  private OvsdbPort getOvsdbPort(Row row) {
    DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
    Interface intf = (Interface) TableGenerator.getTable(dbSchema, row, OvsdbTable.INTERFACE);
    if (intf == null) {
      return null;
    }
    long ofPort = getOfPort(intf);
    String portName = intf.getName();
    if ((ofPort < 0) || (portName == null)) {
      return null;
    }

    OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), new OvsdbPortName(portName));
    return ovsdbPort;
  }
Esempio n. 6
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;
  }