import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.common.collect.Maps;
import com.google.common.reflect.Reflection;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.ovsdb.lib.message.OVSDB;
-import org.opendaylight.ovsdb.lib.message.Response;
-import org.opendaylight.ovsdb.plugin.Connection;
-import org.opendaylight.ovsdb.plugin.ConnectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import io.netty.channel.Channel;
public class JsonRpcEndpoint {
}
ObjectMapper objectMapper;
- ConnectionService service;
+ Channel nettyChannel;
Map<String, CallContext> methodContext = Maps.newHashMap();
Map<Node, OVSDB.Callback> requestCallbacks = Maps.newHashMap();
- public JsonRpcEndpoint(ObjectMapper objectMapper, ConnectionService service) {
+ public JsonRpcEndpoint(ObjectMapper objectMapper, Channel channel) {
this.objectMapper = objectMapper;
- this.service = service;
+ this.nettyChannel = channel;
}
public <T> T getClient(final Node node, Class<T> klazz) {
SettableFuture<Object> sf = SettableFuture.create();
methodContext.put(request.getId(), new CallContext(request, method, sf));
- Connection connection = service.getConnection(node);
- connection.getChannel().writeAndFlush(s);
+ nettyChannel.writeAndFlush(s);
return sf;
}
);
}
- @SuppressWarnings("deprecation")
public void processResult(JsonNode response) throws NoSuchMethodException {
CallContext returnCtxt = methodContext.get(response.get("id").asText());
response.setError(null);
try {
String s = objectMapper.writeValueAsString(response);
- Connection connection = service.getConnection(node);
- connection.getChannel().writeAndFlush(s);
+ nettyChannel.writeAndFlush(s);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
public class OVSDBNettyFactoryTest implements OVSDB.Callback {
InventoryServiceInternal inventoryService;
private static String bridgeIdentifier = "br1";
+
@Test
public void testSome() throws InterruptedException, ExecutionException {
- ConnectionService service = new ConnectionService();
- inventoryService = new InventoryService();
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, service);
- JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
-
+ 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));
- _handlers.add(binderHandler);
+ connectionService.setHandlers(_handlers);
- service.init();
- service.setHandlers(_handlers);
- String identifier = "TEST";
+ inventoryService = new InventoryService();
Node.NodeIDType.registerIDType("OVS", String.class);
Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
params.put(ConnectionConstants.ADDRESS, "192.168.56.101");
params.put(ConnectionConstants.PORT, "6634");
- Node node = service.connect(identifier, params);
- if (node != null) {
- binderHandler.setNode(node);
+ Node node = connectionService.connect("TEST", params);
+ if (node == null) {
+ System.out.println("ERROR : Unable to connect to the host");
+ 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);
+
OVSDB ovsdb = factory.getClient(node, OVSDB.class);
ovsdb.registerCallback(this);
System.out.println("Request + Response : "+requests.toString());
if (tr.size() > requests.size()) {
System.out.println("ERROR : "+tr.get(tr.size()-1).getError());
+ System.out.println("Details : "+tr.get(tr.size()-1).getDetails());
}
// TEST ECHO
System.out.printf("Result of echo is %s \n", s);
// TEST ECHO REQUEST/REPLY
+ Thread.sleep(10000);
- service.disconnect(node);
+ connectionService.disconnect(node);
}
@Override
}
@Override
- public void locked(Node node, Object json_value) {
+ 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
+ }
}