public OvsdbConnectionInfo getConnectionInfo() { return client.getConnectionInfo(); }
private static List<OvsdbClient> getPassiveClientsFromSameNode(OvsdbClient ovsdbClient) { List<OvsdbClient> passiveClients = new ArrayList<>(); for (OvsdbClient client : connections.keySet()) { if (!client.equals(ovsdbClient) && client.getConnectionInfo().getRemoteAddress() .equals(ovsdbClient.getConnectionInfo().getRemoteAddress()) && client.getConnectionInfo().getType() == ConnectionType.PASSIVE) { passiveClients.add(client); } } return passiveClients; }
@Override public void run() { LOG.trace("Connection {} notified to listener {}", client.getConnectionInfo(), listener); listener.connected(client); } });
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response getNode(@PathParam("id") String id) throws JsonProcessingException { OvsdbClient client = NodeResource.getOvsdbClient(id, this); String response = objectMapper.writeValueAsString(client.getConnectionInfo()); return Response.status(Response.Status.OK) .entity(response) .build(); }
@Override public void onFailure(Throwable failureException) { LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo()); client.disconnect(); } }, connectionNotifierService);
/** * Notify the service that the given client has disconnected. * @param disconnectedClient the client just disconnected */ public void clientDisconnected(OvsdbClient disconnectedClient) { for (OvsdbClient pendingClient : pendingConnectionClients.keySet()) { // set the future result for pending connections that wait for this client to be disconnected if (pendingClient.getConnectionInfo().getRemoteAddress() .equals(disconnectedClient.getConnectionInfo().getRemoteAddress())) { Map<OvsdbClient, SettableFuture> clientFutureMap = pendingConnectionClients.get(pendingClient); if (clientFutureMap.containsKey(disconnectedClient)) { clientFutureMap.get(disconnectedClient).set(null); } } } }
@Override public void onSuccess(@Nullable List<String> result) { LOG.debug("Probe was successful to OVSDB switch {}",client.getConnectionInfo()); List<OvsdbClient> clientsFromSameNode = getPassiveClientsFromSameNode(client); if (clientsFromSameNode.size() == 0) { notifyListenerForPassiveConnection(client); } else { STALE_PASSIVE_CONNECTION_SERVICE.handleNewPassiveConnection(client, clientsFromSameNode); } }
private static void handleNewPassiveConnection(OvsdbClient client) { ListenableFuture<List<String>> echoFuture = client.echo(); LOG.debug("Send echo message to probe the OVSDB switch {}",client.getConnectionInfo()); Futures.addCallback(echoFuture, new FutureCallback<List<String>>() { @Override public void onSuccess(@Nullable List<String> result) { LOG.debug("Probe was successful to OVSDB switch {}",client.getConnectionInfo()); List<OvsdbClient> clientsFromSameNode = getPassiveClientsFromSameNode(client); if (clientsFromSameNode.size() == 0) { notifyListenerForPassiveConnection(client); } else { STALE_PASSIVE_CONNECTION_SERVICE.handleNewPassiveConnection(client, clientsFromSameNode); } } @Override public void onFailure(Throwable failureException) { LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo()); client.disconnect(); } }, connectionNotifierService); }
private String getConnectionIdentifier(OvsdbClient client) { OvsdbConnectionInfo info = client.getConnectionInfo(); return info.getRemoteAddress().getHostAddress()+":"+info.getRemotePort(); }
@Override public void connected(@Nonnull final OvsdbClient externalClient) { LOG.info("Library connected {} from {}:{} to {}:{}", externalClient.getConnectionInfo().getType(), externalClient.getConnectionInfo().getRemoteAddress(), externalClient.getConnectionInfo().getRemotePort(), externalClient.getConnectionInfo().getLocalAddress(), externalClient.getConnectionInfo().getLocalPort()); List<String> databases = new ArrayList<>(); try { databases = externalClient.getDatabases().get(DB_FETCH_TIMEOUT, TimeUnit.MILLISECONDS); if (databases.contains(SouthboundConstants.OPEN_V_SWITCH)) { OvsdbConnectionInstance client = connectedButCallBacksNotRegistered(externalClient); // Register Cluster Ownership for ConnectionInfo registerEntityForOwnership(client); } } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to fetch Database list from device {}. Disconnecting from the device.", externalClient.getConnectionInfo().getRemoteAddress(), e); externalClient.disconnect(); } }
public static void channelClosed(final OvsdbClient client) { LOG.info("Connection closed {}", client.getConnectionInfo().toString()); connections.remove(client); if (client.isConnectionPublished()) { for (OvsdbConnectionListener listener : connectionListeners) { listener.disconnected(client); } } STALE_PASSIVE_CONNECTION_SERVICE.clientDisconnected(client); }
controllerIP = connection.getClient().getConnectionInfo().getLocalAddress(); return controllerIP; } catch (Exception e) {
private void initializeInventoryForNewNode (Connection connection) throws InterruptedException, ExecutionException, IOException { OvsdbClient client = connection.getClient(); InetAddress address = client.getConnectionInfo().getRemoteAddress(); int port = client.getConnectionInfo().getRemotePort(); List<String> databases = client.getDatabases().get(); if (databases == null) { logger.error("Unable to get Databases for the ovsdb connection : {}", client.getConnectionInfo()); return; } for (String database : databases) { DatabaseSchema dbSchema = client.getSchema(database).get(); TableUpdates updates = this.monitorTables(connection.getNode(), dbSchema); ovsdbInventoryService.processTableUpdates(connection.getNode(), dbSchema.getName(), updates); } logger.info("Notifying Inventory Listeners for Node Added: {}", connection.getNode().toString()); ovsdbInventoryService.notifyNodeAdded(connection.getNode(), address, port); }
public static ConnectionInfo createConnectionInfo(OvsdbClient client) { ConnectionInfoBuilder connectionInfoBuilder = new ConnectionInfoBuilder(); connectionInfoBuilder.setRemoteIp(createIpAddress(client.getConnectionInfo().getRemoteAddress())); connectionInfoBuilder.setRemotePort(new PortNumber(client.getConnectionInfo().getRemotePort())); connectionInfoBuilder.setLocalIp(createIpAddress(client.getConnectionInfo().getLocalAddress())); connectionInfoBuilder.setLocalPort(new PortNumber(client.getConnectionInfo().getLocalPort())); return connectionInfoBuilder.build(); }
@Override public void disconnected(OvsdbClient client) { LOG.info("Library disconnected {} from {}:{} to {}:{}. Cleaning up the operational data store", client.getConnectionInfo().getType(), client.getConnectionInfo().getRemoteAddress(), client.getConnectionInfo().getRemotePort(), client.getConnectionInfo().getLocalAddress(), client.getConnectionInfo().getLocalPort()); ConnectionInfo key = SouthboundMapper.createConnectionInfo(client); OvsdbConnectionInstance ovsdbConnectionInstance = getConnectionInstance(key); if (ovsdbConnectionInstance != null) { // Unregister Entity ownership as soon as possible ,so this instance should // not be used as a candidate in Entity election (given that this instance is // about to disconnect as well), if current owner get disconnected from // OVSDB device. unregisterEntityForOwnership(ovsdbConnectionInstance); txInvoker.invoke(new OvsdbNodeRemoveCommand(ovsdbConnectionInstance, null, null)); removeConnectionInstance(key); //Controller initiated connection can be terminated from switch side. //So cleanup the instance identifier cache. removeInstanceIdentifier(key); stopBridgeConfigReconciliationIfActive(ovsdbConnectionInstance.getInstanceIdentifier()); retryConnection(ovsdbConnectionInstance.getInstanceIdentifier(), ovsdbConnectionInstance.getOvsdbNodeAugmentation(), ConnectionReconciliationTriggers.ON_DISCONNECT); } else { LOG.warn("disconnected : Connection instance not found for OVSDB Node {} ", key); } LOG.trace("OvsdbConnectionManager: exit disconnected client: {}", client); }
public TableUpdates monitorTables(Node node, DatabaseSchema dbSchema) throws ExecutionException, InterruptedException, IOException { Connection connection = getConnection(node); OvsdbClient client = connection.getClient(); if (dbSchema == null) { logger.error("Unable to get Database Schema for the ovsdb connection : {}", client.getConnectionInfo()); return null; } Set<String> tables = dbSchema.getTables(); if (tables == null) { logger.warn("Database {} without any tables. Strange !", dbSchema.getName()); return null; } List<MonitorRequest> monitorRequests = Lists.newArrayList(); for (String tableName : tables) { GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class); monitorRequests.add(this.getAllColumnsMonitorRequest(tableSchema)); } return client.monitor(dbSchema, monitorRequests, new UpdateMonitor(node)); }
public OvsdbConnectionInstance connectedButCallBacksNotRegistered(final OvsdbClient externalClient) { LOG.info("OVSDB Connection from {}:{}",externalClient.getConnectionInfo().getRemoteAddress(), externalClient.getConnectionInfo().getRemotePort()); ConnectionInfo key = SouthboundMapper.createConnectionInfo(externalClient); OvsdbConnectionInstance ovsdbConnectionInstance = getConnectionInstance(key); // Check if existing ovsdbConnectionInstance for the OvsdbClient present. // In such cases, we will see if the ovsdbConnectionInstance has same externalClient. if (ovsdbConnectionInstance != null) { if (ovsdbConnectionInstance.hasOvsdbClient(externalClient)) { LOG.warn("OVSDB Connection Instance {} already exists for client {}", key, externalClient); return ovsdbConnectionInstance; } LOG.warn("OVSDB Connection Instance {} being replaced with client {}", key, externalClient); // Unregister Cluster Ownership for ConnectionInfo // Because the ovsdbConnectionInstance is about to be completely replaced! unregisterEntityForOwnership(ovsdbConnectionInstance); ovsdbConnectionInstance.disconnect(); removeConnectionInstance(key); stopBridgeConfigReconciliationIfActive(ovsdbConnectionInstance.getInstanceIdentifier()); } ovsdbConnectionInstance = new OvsdbConnectionInstance(key, externalClient, txInvoker, getInstanceIdentifier(key)); ovsdbConnectionInstance.createTransactInvokers(); return ovsdbConnectionInstance; }
client.getConnectionInfo(), databaseName, tableName, uuid, parentColumn[0], parentColumn[1]);
client.getConnectionInfo(), tableName, parentColumn[0], parentColumn[1], parentUuid, row);
client.getConnectionInfo(), databaseName, tableName, rowUuid, row.toString()); try{ DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName);