public ConnectionInfo getConnectionInfo(Node ovsdbNode) { ConnectionInfo connectionInfo = null; OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode); if (ovsdbNodeAugmentation != null) { connectionInfo = ovsdbNodeAugmentation.getConnectionInfo(); } return connectionInfo; }
public ConnectionInfo getConnectionInfo(Node ovsdbNode) { ConnectionInfo connectionInfo = null; OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode); if (ovsdbNodeAugmentation != null) { connectionInfo = ovsdbNodeAugmentation.getConnectionInfo(); } return connectionInfo; }
public ConnectionInfo getConnectionInfo(Node ovsdbNode) { ConnectionInfo connectionInfo = null; OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode); if (ovsdbNodeAugmentation != null) { connectionInfo = ovsdbNodeAugmentation.getConnectionInfo(); } return connectionInfo; }
@Override public boolean reconcileConfiguration(OvsdbConnectionManager connectionManagerOfDevice) { boolean result = false; connectionAttempt.incrementAndGet(); InstanceIdentifier<Node> ndIid = (InstanceIdentifier<Node>) nodeIid; OvsdbNodeAugmentation ovsdbNode = (OvsdbNodeAugmentation)configData; LOG.info("Retry({}) connection to Ovsdb Node {} ", connectionAttempt.get(), ovsdbNode.getConnectionInfo()); OvsdbClient client = null; try { client = connectionManagerOfDevice.connect(ndIid, ovsdbNode); if (client != null) { LOG.info("Successfully connected to Ovsdb Node {} ", ovsdbNode.getConnectionInfo()); result = true; } else { LOG.warn("Connection retry({}) failed for {}.", connectionAttempt.get(), ovsdbNode.getConnectionInfo()); } } catch (UnknownHostException | ConnectException e) { LOG.warn("Connection retry({}) failed with exception. ",connectionAttempt.get(), e); } return result; }
public OvsdbConnectionInstance getConnectionInstance(OvsdbBridgeAttributes mn) { Optional<OvsdbNodeAugmentation> optional = SouthboundUtil.getManagingNode(db, mn); if (optional.isPresent()) { return getConnectionInstance(optional.get().getConnectionInfo()); } else { return null; } }
@Override public void onSuccess(@Nullable Optional<Node> node) { if (node.isPresent()) { LOG.info("Disconnected/Failed connection {} was controller initiated, attempting " + "reconnection", ovsdbNode.getConnectionInfo()); reconciliationManager.enqueue(task); } else { LOG.debug("Connection {} was switch initiated, no reconciliation is required", iid.firstKeyOf(Node.class).getNodeId()); } }
public void disconnect(OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException { LOG.info("Disconnecting from {}", SouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo())); OvsdbConnectionInstance client = getConnectionInstance(ovsdbNode.getConnectionInfo()); if (client != null) { // Unregister Cluster Onwership for ConnectionInfo unregisterEntityForOwnership(client); client.disconnect(); removeInstanceIdentifier(ovsdbNode.getConnectionInfo()); stopBridgeConfigReconciliationIfActive(client.getInstanceIdentifier()); } else { LOG.debug("disconnect : connection instance not found for {}",ovsdbNode.getConnectionInfo()); } }
private String getRemoteIp(Node ovsdbNode) { Preconditions.checkNotNull(ovsdbNode, "The ovsdbNode was null"); String ip = null; OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNodeAugmentation != null && ovsdbNodeAugmentation.getConnectionInfo() != null) { ip = ovsdbNodeAugmentation.getConnectionInfo().getRemoteIp().getIpv4Address().getValue(); } if (ip == null) { LOG.warn("remote_ip was not found for node: {}", ovsdbNode); ip = ""; } return ip; }
private static PortNumber getRemotePort(DataBroker dataBroker, UniAugmentation uni) { PortNumber remotePort = null; final Optional<Node> optionalNode = findOvsdbNode(dataBroker, uni); if (optionalNode.isPresent()) { remotePort = optionalNode.get() .getAugmentation(OvsdbNodeAugmentation.class) .getConnectionInfo().getRemotePort(); } return remotePort; }
private static List<ControllerEntry> getControllerEntries(OvsdbNodeAugmentation connection) { ControllerEntryBuilder controllerBuilder = new ControllerEntryBuilder(); List<ControllerEntry> result = new ArrayList<>(); if (connection.getConnectionInfo().getLocalIp() != null) { String localIp = String.valueOf(connection.getConnectionInfo().getLocalIp().getValue()); String targetString = "tcp:" + localIp + ":" + OF_PORT; controllerBuilder.setTarget(new Uri(targetString)); result.add(controllerBuilder.build()); } return result; }
/** * Returns controller details of the Node. * * @param ovnode OVSDB node augmentation. * @return Controller information. */ private String getControllerTarget(@Nonnull OvsdbNodeAugmentation ovnode) { String setControllerStr = null; String controllerIpStr = null; short openflowPort = OPENFLOW_PORT; // Check if ovsdb node has connection info ConnectionInfo connectionInfo = ovnode.getConnectionInfo(); if (connectionInfo != null && connectionInfo.getLocalIp() != null) { controllerIpStr = new String(connectionInfo.getLocalIp().getValue()); } else { LOG.warn("Ovsdb Node does not contains connection info : {}", ovnode); } if (controllerIpStr != null) { LOG.trace("Target OpenFlow Controller found : {}", controllerIpStr); setControllerStr = OPENFLOW_CONNECTION_PROTOCOL + ":" + controllerIpStr + ":" + openflowPort; } else { LOG.warn("Failed to determine OpenFlow controller ip address"); } return setControllerStr; }
public OvsdbConnectionInstance getConnectionInstance(Node node) { Preconditions.checkNotNull(node); OvsdbNodeAugmentation ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class); OvsdbBridgeAugmentation ovsdbManagedNode = node.getAugmentation(OvsdbBridgeAugmentation.class); if (ovsdbNode != null) { return getConnectionInstance(ovsdbNode.getConnectionInfo()); } else if (ovsdbManagedNode != null) { return getConnectionInstance(ovsdbManagedNode); } else { LOG.warn("This is not a node that gives any hint how to find its OVSDB Manager: {}",node); return null; } }
public OvsdbClient connect(InstanceIdentifier<Node> iid, OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException, ConnectException { LOG.info("Connecting to {}", SouthboundUtil.connectionInfoToString(ovsdbNode.getConnectionInfo())); // TODO handle case where we already have a connection // TODO use transaction chains to handle ordering issues between disconnected // TODO and connected when writing to the operational store InetAddress ip = SouthboundMapper.createInetAddress(ovsdbNode.getConnectionInfo().getRemoteIp()); OvsdbClient client = ovsdbConnection.connect(ip, ovsdbNode.getConnectionInfo().getRemotePort().getValue()); // For connections from the controller to the ovs instance, the library doesn't call // this method for us if (client != null) { putInstanceIdentifier(ovsdbNode.getConnectionInfo(), iid.firstIdentifierOf(Node.class)); OvsdbConnectionInstance ovsdbConnectionInstance = connectedButCallBacksNotRegistered(client); ovsdbConnectionInstance.setOvsdbNodeAugmentation(ovsdbNode); // Register Cluster Ownership for ConnectionInfo registerEntityForOwnership(ovsdbConnectionInstance); } else { LOG.warn("Failed to connect to OVSDB Node {}", ovsdbNode.getConnectionInfo()); } return client; }
/** * Retrieves the connection information from an Ovsdb Connection by * using the Ovsdb Node Id. * @param dataBroker The dataBroker instance to create transactions * @param ovsdbNodeId The NodeId of the OVSDB node * @return The ConnectionInfo object */ public static ConnectionInfo getConnectionInfo(DataBroker dataBroker, NodeId ovsdbNodeId) { final InstanceIdentifier<Node> nodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId); final Optional<Node> node = MdsalUtils.readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, nodeIid); if (node.isPresent()) { final Node ovsdbNode = node.get(); final OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode .getAugmentation(OvsdbNodeAugmentation.class); return ovsdbNodeAugmentation.getConnectionInfo(); } else { return null; } }
public static String getNodeIpAddress(OvsdbNodeAugmentation ovsdbNode) { //Currently we support only ipv4 return ovsdbNode.getConnectionInfo().getRemoteIp().getIpv4Address().getValue(); }
public static String getControllerTarget(Node ovsdbNode) { String target = null; String ipAddr = null; OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class); ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo(); LOG.info("connectionInfo: {}", connectionInfo); if (connectionInfo != null && connectionInfo.getLocalIp() != null) { ipAddr = String.valueOf(connectionInfo.getLocalIp().getValue()); } if (ipAddr == null) { ipAddr = getLocalControllerHostIpAddress(); } if (ipAddr != null) { target = SouthboundConstants.OPENFLOW_CONNECTION_PROTOCOL + ":" + ipAddr + ":" + SouthboundConstants.DEFAULT_OPENFLOW_PORT; } return target; }
private void connect(@Nonnull Collection<DataTreeModification<Node>> changes) { for (DataTreeModification<Node> change : changes) { if (change.getRootNode().getModificationType() == DataObjectModification.ModificationType.WRITE || change .getRootNode().getModificationType() == DataObjectModification.ModificationType.SUBTREE_MODIFIED) { DataObjectModification<OvsdbNodeAugmentation> ovsdbNodeModification = change.getRootNode().getModifiedAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNodeModification != null && ovsdbNodeModification.getDataBefore() == null && ovsdbNodeModification.getDataAfter() != null && ovsdbNodeModification.getDataAfter().getConnectionInfo() != null) { OvsdbNodeAugmentation ovsdbNode = ovsdbNodeModification.getDataAfter(); ConnectionInfo key = ovsdbNode.getConnectionInfo(); InstanceIdentifier<Node> iid = cm.getInstanceIdentifier(key); if ( iid != null) { LOG.warn("Connection to device {} already exists. Plugin does not allow multiple connections " + "to same device, hence dropping the request {}", key, ovsdbNode); } else { try { InstanceIdentifier<Node> instanceIdentifier = change.getRootPath().getRootIdentifier(); cm.connect(instanceIdentifier, ovsdbNode); LOG.info("OVSDB node has been connected: {}",ovsdbNode); } catch (UnknownHostException | ConnectException e) { LOG.warn("Failed to connect to ovsdbNode", e); } } } } } }
private void disconnect(@Nonnull Collection<DataTreeModification<Node>> changes) { for (DataTreeModification<Node> change : changes) { if (change.getRootNode().getModificationType() == DataObjectModification.ModificationType.DELETE) { DataObjectModification<OvsdbNodeAugmentation> ovsdbNodeModification = change.getRootNode().getModifiedAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNodeModification != null && ovsdbNodeModification.getDataBefore() != null) { OvsdbNodeAugmentation ovsdbNode = ovsdbNodeModification.getDataBefore(); ConnectionInfo key = ovsdbNode.getConnectionInfo(); InstanceIdentifier<Node> iid = cm.getInstanceIdentifier(key); try { cm.disconnect(ovsdbNode); LOG.info("OVSDB node has been disconnected:{}", ovsdbNode); cm.stopConnectionReconciliationIfActive(iid.firstIdentifierOf(Node.class), ovsdbNode); } catch (UnknownHostException e) { LOG.warn("Failed to disconnect ovsdbNode", e); } } } } }
private void updateConnections(@Nonnull Collection<DataTreeModification<Node>> changes) { for (DataTreeModification<Node> change : changes) { if (change.getRootNode().getModificationType() == DataObjectModification.ModificationType.WRITE || change .getRootNode().getModificationType() == DataObjectModification.ModificationType.SUBTREE_MODIFIED) { DataObjectModification<OvsdbNodeAugmentation> ovsdbNodeModification = change.getRootNode().getModifiedAugmentation(OvsdbNodeAugmentation.class); if (ovsdbNodeModification != null && ovsdbNodeModification.getDataBefore() != null && ovsdbNodeModification.getDataAfter() != null && ovsdbNodeModification.getDataAfter().getConnectionInfo() != null) { OvsdbClient client = cm.getClient(ovsdbNodeModification.getDataAfter().getConnectionInfo()); if (client == null) { if (ovsdbNodeModification.getDataBefore() != null) { try { cm.disconnect(ovsdbNodeModification.getDataBefore()); cm.connect(change.getRootPath().getRootIdentifier(), ovsdbNodeModification .getDataAfter()); } catch (UnknownHostException | ConnectException e) { LOG.warn("Error disconnecting from or connecting to ovsdbNode", e); } } } } } } }
public OvsdbNodeAugmentationBuilder(OvsdbNodeAugmentation base) { this._autoattach = base.getAutoattach(); this._connectionInfo = base.getConnectionInfo(); this._datapathTypeEntry = base.getDatapathTypeEntry(); this._dbVersion = base.getDbVersion(); this._interfaceTypeEntry = base.getInterfaceTypeEntry(); this._managedNodeEntry = base.getManagedNodeEntry(); this._managerEntry = base.getManagerEntry(); this._openvswitchExternalIds = base.getOpenvswitchExternalIds(); this._openvswitchOtherConfigs = base.getOpenvswitchOtherConfigs(); this._ovsVersion = base.getOvsVersion(); this._qosEntries = base.getQosEntries(); this._queues = base.getQueues(); }