import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.ovsdb.lib.message.OVSDB;
+import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
ObjectMapper objectMapper;
Channel nettyChannel;
Map<String, CallContext> methodContext = Maps.newHashMap();
- Map<Node, OVSDB.Callback> requestCallbacks = Maps.newHashMap();
+ Map<Node, OvsdbRPC.Callback> requestCallbacks = Maps.newHashMap();
public JsonRpcEndpoint(ObjectMapper objectMapper, Channel channel) {
this.objectMapper = objectMapper;
return Reflection.newProxy(klazz, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().equals(OVSDB.REGISTER_CALLBACK_METHOD)) {
- if ((args == null) || args.length != 1 || !(args[0] instanceof OVSDB.Callback)) return false;
- requestCallbacks.put(node, (OVSDB.Callback)args[0]);
+ if (method.getName().equals(OvsdbRPC.REGISTER_CALLBACK_METHOD)) {
+ if ((args == null) || args.length != 1 || !(args[0] instanceof OvsdbRPC.Callback)) return false;
+ requestCallbacks.put(node, (OvsdbRPC.Callback)args[0]);
return true;
}
JsonRpc10Request request = new JsonRpc10Request(requestJson.get("id").asText());
request.setMethod(requestJson.get("method").asText());
logger.debug("Request : {} {}", requestJson.get("method"), requestJson.get("params"));
- OVSDB.Callback callback = requestCallbacks.get(node);
+ OvsdbRPC.Callback callback = requestCallbacks.get(node);
if (callback != null) {
Method[] methods = callback.getClass().getDeclaredMethods();
for (Method m : methods) {
import org.opendaylight.ovsdb.lib.database.DatabaseSchema;
import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
-public interface OVSDB {
+public interface OvsdbRPC {
public static final String REGISTER_CALLBACK_METHOD = "registerCallback";
public ListenableFuture<DatabaseSchema> get_schema(List<String> db_names);
package org.opendaylight.ovsdb.plugin;
import io.netty.channel.Channel;
+
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private Node node;
private String identifier;
private Channel channel;
+ private OvsdbRPC rpc;
public Long getIdCounter() {
return idCounter;
this.node = node;
}
+ public OvsdbRPC getRpc() {
+ return rpc;
+ }
+
+ public void setRpc(OvsdbRPC rpc) {
+ this.rpc = rpc;
+ }
+
public void sendMessage(String message) throws IOException {
try {
channel.writeAndFlush(message);
public Status disconnect() {
try {
- channel.pipeline().get("messageHandler");
channel.close();
} catch (Exception e) {
e.printStackTrace();
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcDecoder;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcEndpoint;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcServiceBinderHandler;
+import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
+import org.opendaylight.ovsdb.lib.message.UpdateNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import java.net.InetAddress;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
* Represents the openflow plugin component in charge of programming the flows
* the flow programming and relay them to functional modules above SAL.
*/
-public class ConnectionService implements IPluginInConnectionService, IConnectionServiceInternal {
+public class ConnectionService implements IPluginInConnectionService, IConnectionServiceInternal, OvsdbRPC.Callback {
protected static final Logger logger = LoggerFactory.getLogger(ConnectionService.class);
private static final Integer defaultOvsdbPort = 6632;
- ConcurrentMap<String, Connection> ovsdbConnections;
- List<ChannelHandler> handlers = null;
- InventoryServiceInternal inventoryServiceInternal;
+ private ConcurrentMap<String, Connection> ovsdbConnections;
+ private List<ChannelHandler> handlers = null;
+ private InventoryServiceInternal inventoryServiceInternal;
+
+ public InventoryServiceInternal getInventoryServiceInternal() {
+ return inventoryServiceInternal;
+ }
public void setInventoryServiceInternal(InventoryServiceInternal inventoryServiceInternal) {
this.inventoryServiceInternal = inventoryServiceInternal;
bootstrap.channel(NioSocketChannel.class);
bootstrap.option(ChannelOption.TCP_NODELAY, true);
bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
+
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel channel) throws Exception {
-// ObjectMapper objectMapper = new ObjectMapper();
-// JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, ConnectionService.this);
- /*Add new Handlers here.
- Break out into todo break out into channel Init Class*/
if (handlers == null) {
channel.pipeline().addLast(
new LoggingHandler(LogLevel.INFO),
new JsonRpcDecoder(100000),
- new StringEncoder(CharsetUtil.UTF_8),
- // new JsonRpcServiceBinderHandler(factory),
- new MessageHandler());
+ new StringEncoder(CharsetUtil.UTF_8));
} else {
for (ChannelHandler handler : handlers) {
channel.pipeline().addLast(handler);
}
}
});
+
ChannelFuture future = bootstrap.connect(address, port).sync();
Channel channel = future.channel();
Connection connection = new Connection(identifier, channel);
+ Node node = connection.getNode();
- ovsdbConnections.put(identifier, connection);
- return connection.getNode();
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, channel);
+ JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
+ binderHandler.setNode(node);
+ channel.pipeline().addLast(binderHandler);
+
+ OvsdbRPC ovsdb = factory.getClient(node, OvsdbRPC.class);
+ connection.setRpc(ovsdb);
+ ovsdb.registerCallback(this);
+
+ ovsdbConnections.put(identifier, connection);
+ return node;
} catch (Exception e) {
e.printStackTrace();
}
@Override
public void notifyNodeDisconnectFromMaster(Node arg0) {
}
+
+ @Override
+ public void update(Node node, UpdateNotification updateNotification) {
+ inventoryServiceInternal.processTableUpdates(node, updateNotification.getUpdate());
+ inventoryServiceInternal.printCache(node);
+ }
+
+ @Override
+ public void locked(Node node, List<String> ids) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void stolen(Node node, List<String> ids) {
+ // TODO Auto-generated method stub
+ }
+
}
* dependencies are satisfied
*
*/
- void init() {
+ public void init() {
nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
- dbCache = new ConcurrentHashMap<Node, NodeDB<Table<?>>>();
Node.NodeIDType.registerIDType("OVS", String.class);
NodeConnector.NodeConnectorIDType.registerIDType("OVS", String.class, "OVS");
}
* example bundle is being stopped.
*
*/
- void destroy() {
+ public void destroy() {
}
/**
* the services provided by the class are registered in the service registry
*
*/
- void start() {
+ public void start() {
}
/**
* calls
*
*/
- void stop() {
+ public void stop() {
}
/**
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcEndpoint;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcServiceBinderHandler;
import org.opendaylight.ovsdb.lib.message.MonitorRequestBuilder;
-import org.opendaylight.ovsdb.lib.message.OVSDB;
+import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
import org.opendaylight.ovsdb.lib.message.operations.InsertOperation;
import org.opendaylight.ovsdb.lib.message.operations.MutateOperation;
import org.opendaylight.ovsdb.lib.table.Port;
import org.opendaylight.ovsdb.lib.table.internal.Table;
import org.opendaylight.ovsdb.lib.table.internal.Tables;
+import org.opendaylight.ovsdb.plugin.Connection;
import org.opendaylight.ovsdb.plugin.ConnectionService;
import org.opendaylight.ovsdb.plugin.InventoryService;
import org.opendaylight.ovsdb.plugin.InventoryServiceInternal;
import java.util.Map;
import java.util.concurrent.ExecutionException;
-public class OVSDBNettyFactoryTest implements OVSDB.Callback {
- InventoryServiceInternal inventoryService;
+public class OVSDBNettyFactoryTest {
+ InventoryService inventoryService;
private static String bridgeIdentifier = "br1";
@Test
public void testSome() throws InterruptedException, ExecutionException {
ConnectionService connectionService = new ConnectionService();
connectionService.init();
- List<ChannelHandler> _handlers = Lists.newArrayList();
- _handlers.add(new LoggingHandler(LogLevel.INFO));
- _handlers.add(new JsonRpcDecoder(100000));
- _handlers.add(new StringEncoder(CharsetUtil.UTF_8));
- connectionService.setHandlers(_handlers);
-
inventoryService = new InventoryService();
+ inventoryService.init();
+ connectionService.setInventoryServiceInternal(inventoryService);
Node.NodeIDType.registerIDType("OVS", String.class);
Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
params.put(ConnectionConstants.ADDRESS, "192.168.56.101");
return;
}
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- Channel channel = connectionService.getConnection(node).getChannel();
- JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, channel);
- JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
- binderHandler.setNode(node);
- channel.pipeline().addLast(binderHandler);
+ Connection connection = connectionService.getConnection(node);
+ if (connection == null) {
+ System.out.println("ERROR : Unable to connect to the host");
+ return;
+ }
- OVSDB ovsdb = factory.getClient(node, OVSDB.class);
- ovsdb.registerCallback(this);
+ OvsdbRPC ovsdb = connection.getRpc();
+ if (ovsdb == null) {
+ System.out.println("ERROR : Unable to obtain RPC instance");
+ return;
+ }
//GET DB-SCHEMA
List<String> dbNames = Arrays.asList(Open_vSwitch.NAME.getName());
connectionService.disconnect(node);
}
-
- @Override
- public void update(Node node, UpdateNotification updateNotification) {
- inventoryService.processTableUpdates(node, updateNotification.getUpdate());
- inventoryService.printCache(node);
- }
-
- @Override
- public void locked(Node node, List<String> ids) {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void stolen(Node node, List<String> ids) {
- // TODO Auto-generated method stub
- }
}