Example #1
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());
      }
    }
  }
Example #2
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");
  }