public Node connect(String identifier, Map<ConnectionConstants, String> params) { InetAddress address; Integer port; try { address = InetAddress.getByName(params.get(ConnectionConstants.ADDRESS)); } catch (Exception e) { logger.error("Unable to resolve " + params.get(ConnectionConstants.ADDRESS), e); return null; } try { port = Integer.parseInt(params.get(ConnectionConstants.PORT)); if (port == 0) { port = DEFAULT_OVSDB_PORT; } } catch (Exception e) { port = DEFAULT_OVSDB_PORT; } try { OvsdbClient client = connectionLib.connect(address, port); return handleNewConnection(identifier, client); } catch (InterruptedException e) { logger.error("Thread was interrupted during connect", e); } catch (ExecutionException e) { logger.error("ExecutionException in handleNewConnection for identifier " + identifier, e); } return null; }
public void handleOwnershipChange(EntityOwnershipChange ownershipChange) { if (ownershipChange.isOwner()) { LOG.info("*This* instance of OVSDB southbound provider is set as a MASTER instance"); LOG.info("Initialize OVSDB topology {} in operational and config data store if not already present", SouthboundConstants.OVSDB_TOPOLOGY_ID); initializeOvsdbTopology(LogicalDatastoreType.OPERATIONAL); initializeOvsdbTopology(LogicalDatastoreType.CONFIGURATION); } else { LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance"); } ovsdbConnection.registerConnectionListener(cm); ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { LOG.debug("Get idle state event"); IdleStateEvent event = (IdleStateEvent) evt; if (event.state() == IdleState.READER_IDLE) { LOG.debug("Reader idle state. Send echo message to peer"); //Send echo message to peer OvsdbClient client = OvsdbConnectionService.getService().getClient(ctx.channel()); client.echo(); } } } }
/** * Function called by dependency manager after "init ()" is called and after * the services provided by the class are registered in the service registry */ void start() { /* Start ovsdb server before getting connection clients */ String portString = ConfigProperties.getProperty(OvsdbConnectionService.class, OVSDB_LISTENPORT); int ovsdbListenPort = DEFAULT_OVSDB_PORT; if (portString != null) { ovsdbListenPort = Integer.decode(portString).intValue(); } if (!connectionLib.startOvsdbManager(ovsdbListenPort)) { logger.warn("Start OVSDB manager call from ConnectionService was not necessary"); } /* Then get connection clients */ Collection<OvsdbClient> connections = connectionLib.getConnections(); for (OvsdbClient client : connections) { logger.info("CONNECT start connected clients client = {}", client); this.connected(client); } }
/** * Used by blueprint when starting the container. */ public void init() { LOG.info("SouthboundProvider Session Initiated"); this.txInvoker = new TransactionInvokerImpl(db); cm = new OvsdbConnectionManager(db,txInvoker,entityOwnershipService, ovsdbConnection); ovsdbDataTreeChangeListener = new OvsdbDataTreeChangeListener(db, cm); //Register listener for entityOnwership changes providerOwnershipChangeListener = new SouthboundPluginInstanceEntityOwnershipListener(this,this.entityOwnershipService); //register instance entity to get the ownership of the provider Entity instanceEntity = new Entity(ENTITY_TYPE, ENTITY_TYPE); try { Optional<EntityOwnershipState> ownershipStateOpt = entityOwnershipService.getOwnershipState(instanceEntity); registration = entityOwnershipService.registerCandidate(instanceEntity); if (ownershipStateOpt.isPresent()) { EntityOwnershipState ownershipState = ownershipStateOpt.get(); if (ownershipState.hasOwner() && !ownershipState.isOwner()) { ovsdbConnection.registerConnectionListener(cm); ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT); LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance"); } } } catch (CandidateAlreadyRegisteredException e) { LOG.warn("OVSDB Southbound Provider instance entity {} was already " + "registered for ownership", instanceEntity, e); } }
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; }