Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Boolean setBridgeOFController(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> configs) {
- try{
- if (connectionService == null) {
- logger.error("Couldn't refer to the ConnectionService");
- return false;
- }
- Connection connection = this.getConnection(node);
- if (connection == null) {
- return false;
- }
- if (connection != null) {
- List<InetAddress> ofControlAddr = getControllerIPAddresses();
- short ofControlPort = getControllerOFPort();
- InetAddress addr = InetAddress.getLocalHost();
- String newController = "new_controller";
- Controller controllerRow = new Controller();
- controllerRow.setTarget("tcp:6633:192.168.254.128");
- InsertOperation addCtlRequest = new InsertOperation(Controller.NAME.getName(), newController, controllerRow);
- String brCntrlUuid = null;
- Map<String, Table<?>> brTableCache = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
- for (String uuid : brTableCache.keySet()) {
- Bridge bridge = (Bridge)brTableCache.get(uuid);
- if (bridge.getName().contains(bridgeIdentifier)) {
- brCntrlUuid = uuid;
- }
- }
- Operation addControlRequest = null;
- UUID controlUuidPair = new UUID(newController);
- System.out.println("WTF "+ controlUuidPair);
- Mutation bm = new Mutation("controller", Mutator.INSERT, controlUuidPair);
- List<Mutation> mutations = new ArrayList<Mutation>();
- mutations.add(bm);
- UUID uuid = new UUID(brCntrlUuid);
- Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
- List<Condition> where = new ArrayList<Condition>();
- where.add(condition);
- addControlRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
- TransactBuilder transaction = new TransactBuilder();
- transaction.addOperations(new ArrayList<Operation>(Arrays.asList(addCtlRequest, addControlRequest)));
- ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
- List<OperationResult> tr = transResponse.get();
- List<Operation> requests = transaction.getRequests();
- Status status = new Status(StatusCode.SUCCESS);
- for (int i = 0; i < tr.size() ; i++) {
- if (i < requests.size()) requests.get(i).setResult(tr.get(i));
- if (tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
- OperationResult result = tr.get(i);
- status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
- }
- }
- if (tr.size() > requests.size()) {
- OperationResult result = tr.get(tr.size()-1);
- logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
- result.getError(),
- result.getDetails());
- status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment