- Port tunnelPort = ovsdbConfigurationService.createTypedRow(node, Port.class);
- tunnelPort.setName(portName);
- StatusWithUuid statusWithUuid = ovsdbConfigurationService
- .insertRow(node, ovsdbConfigurationService.getTableName(node, Port.class), bridgeUUID, tunnelPort.getRow());
- if (!statusWithUuid.isSuccess()) {
- logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
- return statusWithUuid;
- }
-
- String tunnelPortUUID = statusWithUuid.getUuid().toString();
- String interfaceUUID = null;
- int timeout = 6;
- while ((interfaceUUID == null) && (timeout > 0)) {
- Row portRow = ovsdbConfigurationService
- .getRow(node, ovsdbConfigurationService.getTableName(node, Port.class), tunnelPortUUID);
- tunnelPort = ovsdbConfigurationService.getTypedRow(node, Port.class, portRow);
- Set<UUID> interfaces = tunnelPort.getInterfacesColumn().getData();
- if (interfaces == null || interfaces.size() == 0) {
- // Wait for the OVSDB update to sync up the Local cache.
- Thread.sleep(500);
- timeout--;
- continue;
- }
- interfaceUUID = interfaces.toArray()[0].toString();
- Row intfRow = ovsdbConfigurationService
- .getRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), interfaceUUID);
- Interface intf = ovsdbConfigurationService.getTypedRow(node, Interface.class, intfRow);
- if (intf == null) interfaceUUID = null;
- }
-
- if (interfaceUUID == null) {
- logger.error("Cannot identify Tunnel Interface for port {}/{}", portName, tunnelPortUUID);
- return new Status(StatusCode.INTERNALERROR);
- }
-
- Interface tunInterface = ovsdbConfigurationService.createTypedRow(node, Interface.class);
- tunInterface.setType(tunnelType);
- Map<String, String> options = Maps.newHashMap();
- options.put("key", "flow");
- options.put("local_ip", src.getHostAddress());
- options.put("remote_ip", dst.getHostAddress());
- tunInterface.setOptions(options);
- Status status = ovsdbConfigurationService
- .updateRow(node, ovsdbConfigurationService.getTableName(node, Interface.class), tunnelPortUUID, interfaceUUID, tunInterface.getRow());
- logger.debug("Tunnel {} add status : {}", tunInterface, status);
- return status;
- } catch (Exception e) {
- logger.error("Exception in addTunnelPort", e);
- return new Status(StatusCode.INTERNALERROR);