Updating DefaultOvsdbClient
- Updating setControllerAuto to use setControllersWithUUID and cleaned up unnecessary conversions - Removed commented out code in setControllersWithUUID - Removed old setControllers method Change-Id: I1ee89d5237e58b64e880d9a6db4cee16815dd9a8
Showing
2 changed files
with
22 additions
and
74 deletions
| ... | @@ -93,18 +93,24 @@ public interface OvsdbClientService extends OvsdbRPC { | ... | @@ -93,18 +93,24 @@ public interface OvsdbClientService extends OvsdbRPC { |
| 93 | Set<ControllerInfo> getControllers(DeviceId openflowDeviceId); | 93 | Set<ControllerInfo> getControllers(DeviceId openflowDeviceId); |
| 94 | 94 | ||
| 95 | /** | 95 | /** |
| 96 | - * sets the controllers of the node to the ones passed in the list. | 96 | + * Sets the Controllers for the specified bridge. |
| 97 | + * <p/> | ||
| 98 | + * This method will replace the existing controller list with the new controller | ||
| 99 | + * list. | ||
| 97 | * | 100 | * |
| 98 | - * @param bridgeUuid UUid for the bridge we are settings the controls on | 101 | + * @param bridgeUuid bridge uuid |
| 99 | - * @param controllers of controllers; empty if no controller is find | 102 | + * @param controllers list of controllers |
| 100 | */ | 103 | */ |
| 101 | void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers); | 104 | void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers); |
| 102 | 105 | ||
| 103 | /** | 106 | /** |
| 104 | - * sets the controllers of the node to the ones passed in the list. | 107 | + * Sets the Controllers for the specified device. |
| 108 | + * <p/> | ||
| 109 | + * This method will replace the existing controller list with the new controller | ||
| 110 | + * list. | ||
| 105 | * | 111 | * |
| 106 | - * @param deviceId deviceId for the bridge we are settings the controls on | 112 | + * @param deviceId device id (likely Openflow device) |
| 107 | - * @param controllers of controllers; empty if no controller is find | 113 | + * @param controllers list of controllers |
| 108 | */ | 114 | */ |
| 109 | void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers); | 115 | void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers); |
| 110 | 116 | ... | ... |
| ... | @@ -17,6 +17,7 @@ package org.onosproject.ovsdb.controller.driver; | ... | @@ -17,6 +17,7 @@ package org.onosproject.ovsdb.controller.driver; |
| 17 | 17 | ||
| 18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.google.common.base.Function; | 19 | import com.google.common.base.Function; |
| 20 | +import com.google.common.collect.ImmutableList; | ||
| 20 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
| 22 | import com.google.common.collect.Sets; | 23 | import com.google.common.collect.Sets; |
| ... | @@ -481,30 +482,21 @@ public class DefaultOvsdbClient | ... | @@ -481,30 +482,21 @@ public class DefaultOvsdbClient |
| 481 | } | 482 | } |
| 482 | 483 | ||
| 483 | /** | 484 | /** |
| 484 | - * Sets the Controller. | 485 | + * Sets the bridge's controller automatically. |
| 486 | + * <p/> | ||
| 487 | + * The connection is a TCP connection to the local ONOS instance's IP | ||
| 488 | + * and the default OpenFlow port. | ||
| 485 | * | 489 | * |
| 486 | * @param bridgeUuid bridge uuid | 490 | * @param bridgeUuid bridge uuid |
| 487 | */ | 491 | */ |
| 488 | private void setControllerAuto(String bridgeUuid) { | 492 | private void setControllerAuto(String bridgeUuid) { |
| 489 | - String controllerUuid = null; | 493 | + IpAddress ipAddress = IpAddress.valueOf(((InetSocketAddress) channel.localAddress()).getAddress()); |
| 490 | - String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel | 494 | + ControllerInfo controllerInfo = new ControllerInfo(ipAddress, OvsdbConstant.OFPORT, "tcp"); |
| 491 | - .localAddress()) | 495 | + log.debug("Automatically setting controller for bridge {} to {}", |
| 492 | - .getAddress() | 496 | + bridgeUuid, controllerInfo.target()); |
| 493 | - .getHostAddress()) | 497 | + setControllersWithUUID(UUID.uuid(bridgeUuid), ImmutableList.of(controllerInfo)); |
| 494 | - .toString(); | ||
| 495 | - | ||
| 496 | - String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT; | ||
| 497 | - log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT); | ||
| 498 | - | ||
| 499 | - setController(bridgeUuid, target); | ||
| 500 | - | ||
| 501 | } | 498 | } |
| 502 | 499 | ||
| 503 | - /** | ||
| 504 | - * Sets the Controllers. | ||
| 505 | - * | ||
| 506 | - * @param bridgeUuid bridge uuid | ||
| 507 | - */ | ||
| 508 | @Override | 500 | @Override |
| 509 | public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) { | 501 | public void setControllersWithUUID(UUID bridgeUuid, List<ControllerInfo> controllers) { |
| 510 | 502 | ||
| ... | @@ -539,7 +531,6 @@ public class DefaultOvsdbClient | ... | @@ -539,7 +531,6 @@ public class DefaultOvsdbClient |
| 539 | return; | 531 | return; |
| 540 | } | 532 | } |
| 541 | 533 | ||
| 542 | -// removeControllers.forEach(c -> controllerRowStore.deleteRow(c.getRow().uuid().value())); | ||
| 543 | removeControllers.forEach(c -> deleteConfig(OvsdbConstant.CONTROLLER, "_uuid", c.getRow().uuid().value(), | 534 | removeControllers.forEach(c -> deleteConfig(OvsdbConstant.CONTROLLER, "_uuid", c.getRow().uuid().value(), |
| 544 | OvsdbConstant.BRIDGE, "controller")); | 535 | OvsdbConstant.BRIDGE, "controller")); |
| 545 | 536 | ||
| ... | @@ -549,16 +540,9 @@ public class DefaultOvsdbClient | ... | @@ -549,16 +540,9 @@ public class DefaultOvsdbClient |
| 549 | controller.setTarget(c.target()); | 540 | controller.setTarget(c.target()); |
| 550 | return controller; | 541 | return controller; |
| 551 | }).forEach(c -> { | 542 | }).forEach(c -> { |
| 552 | -// UUID uuid = c.getRow().uuid(); | ||
| 553 | -// controllerRowStore.insertRow(uuid.value(), c.getRow()); | ||
| 554 | -// newControllerUuids.add(uuid); | ||
| 555 | - | ||
| 556 | String uuid = insertConfig(OvsdbConstant.CONTROLLER, "_uuid", | 543 | String uuid = insertConfig(OvsdbConstant.CONTROLLER, "_uuid", |
| 557 | OvsdbConstant.BRIDGE, "controller", bridgeUuid.value(), | 544 | OvsdbConstant.BRIDGE, "controller", bridgeUuid.value(), |
| 558 | c.getRow()); | 545 | c.getRow()); |
| 559 | - log.warn("insertConfig uuid {}", uuid); | ||
| 560 | - log.warn("row uuid {}", c.getRow().uuid()); | ||
| 561 | - //log.warn("rowStore uuid {}", controllerRowStore.getRowStore()); | ||
| 562 | newControllerUuids.add(UUID.uuid(uuid)); | 546 | newControllerUuids.add(UUID.uuid(uuid)); |
| 563 | 547 | ||
| 564 | }); | 548 | }); |
| ... | @@ -574,55 +558,13 @@ public class DefaultOvsdbClient | ... | @@ -574,55 +558,13 @@ public class DefaultOvsdbClient |
| 574 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE); | 558 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE); |
| 575 | bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids)); | 559 | bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids)); |
| 576 | updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid.value(), bridge.getRow()); | 560 | updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid.value(), bridge.getRow()); |
| 577 | - | ||
| 578 | - //rowStore.insertRow(bridgeUuid.value(), bridge.getRow()); //TODO do we need to do this? | ||
| 579 | } | 561 | } |
| 580 | 562 | ||
| 581 | - /** | ||
| 582 | - * Sets the Controllers. | ||
| 583 | - * | ||
| 584 | - * @param deviceId bridge uuid | ||
| 585 | - */ | ||
| 586 | @Override | 563 | @Override |
| 587 | public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) { | 564 | public void setControllersWithDeviceId(DeviceId deviceId, List<ControllerInfo> controllers) { |
| 588 | setControllersWithUUID(getBridgeUUID(deviceId), controllers); | 565 | setControllersWithUUID(getBridgeUUID(deviceId), controllers); |
| 589 | } | 566 | } |
| 590 | 567 | ||
| 591 | - private void setController(String bridgeUuid, String target) { | ||
| 592 | - String controllerUuid; | ||
| 593 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | ||
| 594 | - | ||
| 595 | - // 1. get the bridge row | ||
| 596 | - // 2. delete different controllers and save the same controller. | ||
| 597 | - // 3. add new controllers | ||
| 598 | - // 4. update bridge row | ||
| 599 | - | ||
| 600 | - | ||
| 601 | - controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target); | ||
| 602 | - | ||
| 603 | - Controller controller = (Controller) TableGenerator | ||
| 604 | - .createTable(dbSchema, OvsdbTable.CONTROLLER); | ||
| 605 | - if (controller != null) { | ||
| 606 | - controller.setTarget(target); | ||
| 607 | - if (controllerUuid == null) { | ||
| 608 | - | ||
| 609 | - insertConfig(OvsdbConstant.CONTROLLER, "_uuid", | ||
| 610 | - OvsdbConstant.BRIDGE, "controller", bridgeUuid, | ||
| 611 | - controller.getRow()); | ||
| 612 | - | ||
| 613 | - } else { | ||
| 614 | - | ||
| 615 | - Bridge bridge = (Bridge) TableGenerator | ||
| 616 | - .createTable(dbSchema, OvsdbTable.BRIDGE); | ||
| 617 | - Set<UUID> controllerUuids = new HashSet<>(); | ||
| 618 | - controllerUuids.add(UUID.uuid(controllerUuid)); | ||
| 619 | - bridge.setController(OvsdbSet.ovsdbSet(controllerUuids)); | ||
| 620 | - updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow()); | ||
| 621 | - | ||
| 622 | - } | ||
| 623 | - } | ||
| 624 | - } | ||
| 625 | - | ||
| 626 | @Override | 568 | @Override |
| 627 | public void dropBridge(String bridgeName) { | 569 | public void dropBridge(String bridgeName) { |
| 628 | String bridgeUUID = getBridgeUuid(bridgeName); | 570 | String bridgeUUID = getBridgeUuid(bridgeName); | ... | ... |
-
Please register or login to post a comment