import org.opendaylight.ovsdb.lib.message.operations.InsertOperation;
import org.opendaylight.ovsdb.lib.message.operations.MutateOperation;
import org.opendaylight.ovsdb.lib.message.operations.Operation;
+import org.opendaylight.ovsdb.lib.message.operations.OperationResult;
import org.opendaylight.ovsdb.lib.notation.Condition;
import org.opendaylight.ovsdb.lib.notation.Function;
import org.opendaylight.ovsdb.lib.notation.Mutation;
import org.opendaylight.ovsdb.lib.notation.Mutator;
+import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.table.Bridge;
import org.opendaylight.ovsdb.lib.table.Interface;
import org.opendaylight.ovsdb.lib.table.Open_vSwitch;
import java.util.Map;
import java.util.concurrent.ExecutionException;
-public class OVSDBNettyFactoryTest {
-
+public class OVSDBNettyFactoryTest implements OVSDB.Callback {
+ InventoryServiceInternal inventoryService;
+ private static String bridgeIdentifier = "br1";
@Test
public void testSome() throws InterruptedException, ExecutionException {
-
ConnectionService service = new ConnectionService();
- InventoryServiceInternal inventoryService = new InventoryService();
+ 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);
List<ChannelHandler> _handlers = Lists.newArrayList();
- _handlers.add(new LoggingHandler(LogLevel.INFO));
+ //_handlers.add(new LoggingHandler(LogLevel.INFO));
_handlers.add(new JsonRpcDecoder(100000));
_handlers.add(new StringEncoder(CharsetUtil.UTF_8));
_handlers.add(binderHandler);
}
OVSDB ovsdb = factory.getClient(node, OVSDB.class);
+ ovsdb.registerCallback(this);
//GET DB-SCHEMA
List<String> dbNames = Arrays.asList(Open_vSwitch.NAME.getName());
TableUpdates updates = monResponse.get();
inventoryService.processTableUpdates(node, updates);
inventoryService.printCache(node);
+
// TRANSACT INSERT TEST
Map<String, Table<?>> ovsTable = inventoryService.getTableCache(node, Open_vSwitch.NAME.getName());
String newPort = "new_port";
String newSwitch = "new_switch";
- String bridgeIdentifier = "br6";
Operation addSwitchRequest = null;
if(ovsTable != null){
String ovsTableUUID = (String) ovsTable.keySet().toArray()[0];
- List<String> bridgeUuidPair = new ArrayList<String>();
- bridgeUuidPair.add("named-uuid");
- bridgeUuidPair.add(newBridge);
-
+ UUID bridgeUuidPair = new UUID(newBridge);
Mutation bm = new Mutation("bridges", Mutator.INSERT, bridgeUuidPair);
List<Mutation> mutations = new ArrayList<Mutation>();
mutations.add(bm);
- List<String> uuid = new ArrayList<String>();
- uuid.add("uuid");
- uuid.add(ovsTableUUID);
-
- //UUID uuid = new UUID(ovsTableUUID);
+ UUID uuid = new UUID(ovsTableUUID);
Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
-
List<Condition> where = new ArrayList<Condition>();
where.add(condition);
-
addSwitchRequest = new MutateOperation(Open_vSwitch.NAME.getName(), where, mutations);
}
else{
Map<String, Object> vswitchRow = new HashMap<String, Object>();
- ArrayList<String> bridges = new ArrayList<String>();
- bridges.add("named-uuid");
- bridges.add(newBridge);
- vswitchRow.put("bridges", bridges);
+ UUID bridgeUuidPair = new UUID(newBridge);
+ vswitchRow.put("bridges", bridgeUuidPair);
addSwitchRequest = new InsertOperation(Open_vSwitch.NAME.getName(), newSwitch, vswitchRow);
}
Map<String, Object> bridgeRow = new HashMap<String, Object>();
bridgeRow.put("name", bridgeIdentifier);
- ArrayList<String> ports = new ArrayList<String>();
- ports.add("named-uuid");
- ports.add(newPort);
+ UUID ports = new UUID(newPort);
bridgeRow.put("ports", ports);
InsertOperation addBridgeRequest = new InsertOperation(Bridge.NAME.getName(), newBridge, bridgeRow);
Map<String, Object> portRow = new HashMap<String, Object>();
portRow.put("name", bridgeIdentifier);
- ArrayList<String> interfaces = new ArrayList<String>();
- interfaces.add("named-uuid");
- interfaces.add(newInterface);
+ UUID interfaces = new UUID(newInterface);
portRow.put("interfaces", interfaces);
InsertOperation addPortRequest = new InsertOperation(Port.NAME.getName(), newPort, portRow);
transaction.addOperations(new ArrayList<Operation>(
Arrays.asList(addSwitchRequest, addIntfRequest, addPortRequest, addBridgeRequest)));
- ListenableFuture<List<Object>> transResponse = ovsdb.transact(transaction);
+ ListenableFuture<List<OperationResult>> transResponse = ovsdb.transact(transaction);
System.out.println("Transcation sent :");
- Object tr = transResponse.get();
- System.out.println(tr.toString());
+ List<OperationResult> tr = transResponse.get();
+ System.out.println("Transaction response : "+transResponse.toString());
+ List<Operation> requests = transaction.getRequests();
+ for (int i = 0; i < tr.size() ; i++) {
+ if (i < requests.size()) requests.get(i).setResult(tr.get(i));
+ }
+
+ System.out.println("Request + Response : "+requests.toString());
+ if (tr.size() > requests.size()) {
+ System.out.println("ERROR : "+tr.get(tr.size()-1).getError());
+ }
+
// TEST ECHO
ListenableFuture<List<String>> some = ovsdb.echo();
// TEST ECHO REQUEST/REPLY
- Thread.sleep(10);
service.disconnect(node);
}
+ @Override
+ public void update(Node node, UpdateNotification updateNotification) {
+ inventoryService.processTableUpdates(node, updateNotification.getUpdate());
+ inventoryService.printCache(node);
+ }
+
+ @Override
+ public void locked(Node node, Object json_value) {
+ }
+
}