Committed by
Gerrit Code Review
Refactored bridge config to take bridge description
OVSDB provides lots of bridge configuration options but the exisisting bridge config implementation only allows some of them by overloading addBridge method. Also some of the bridge properties were set static and unable to configure. This patch fixes these limitations. - Added some bridge config options to the bridge description - Deprecated multiple overloaded addBridge methods - Some code clean up Change-Id: Ibc828177b210bd4b215aea0b63cc359776c13e03
Showing
14 changed files
with
780 additions
and
598 deletions
... | @@ -35,8 +35,10 @@ import org.onosproject.net.Device; | ... | @@ -35,8 +35,10 @@ import org.onosproject.net.Device; |
35 | import org.onosproject.net.DeviceId; | 35 | import org.onosproject.net.DeviceId; |
36 | import org.onosproject.net.Port; | 36 | import org.onosproject.net.Port; |
37 | import org.onosproject.net.behaviour.BridgeConfig; | 37 | import org.onosproject.net.behaviour.BridgeConfig; |
38 | +import org.onosproject.net.behaviour.BridgeDescription; | ||
38 | import org.onosproject.net.behaviour.BridgeName; | 39 | import org.onosproject.net.behaviour.BridgeName; |
39 | import org.onosproject.net.behaviour.ControllerInfo; | 40 | import org.onosproject.net.behaviour.ControllerInfo; |
41 | +import org.onosproject.net.behaviour.DefaultBridgeDescription; | ||
40 | import org.onosproject.net.behaviour.DefaultTunnelDescription; | 42 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
41 | import org.onosproject.net.behaviour.TunnelConfig; | 43 | import org.onosproject.net.behaviour.TunnelConfig; |
42 | import org.onosproject.net.behaviour.TunnelDescription; | 44 | import org.onosproject.net.behaviour.TunnelDescription; |
... | @@ -399,7 +401,16 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -399,7 +401,16 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
399 | try { | 401 | try { |
400 | DriverHandler handler = driverService.createHandler(node.ovsdbId()); | 402 | DriverHandler handler = driverService.createHandler(node.ovsdbId()); |
401 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | 403 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
402 | - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers); | 404 | + |
405 | + BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() | ||
406 | + .name(DEFAULT_BRIDGE) | ||
407 | + .failMode(BridgeDescription.FailMode.SECURE) | ||
408 | + .datapathId(dpid) | ||
409 | + .disableInBand() | ||
410 | + .controllers(controllers) | ||
411 | + .build(); | ||
412 | + | ||
413 | + bridgeConfig.addBridge(bridgeDesc); | ||
403 | } catch (ItemNotFoundException e) { | 414 | } catch (ItemNotFoundException e) { |
404 | log.warn("Failed to create integration bridge on {}", node.ovsdbId()); | 415 | log.warn("Failed to create integration bridge on {}", node.ovsdbId()); |
405 | } | 416 | } | ... | ... |
... | @@ -715,24 +715,17 @@ public class VtnManager implements VtnService { | ... | @@ -715,24 +715,17 @@ public class VtnManager implements VtnService { |
715 | .filter(d -> !("ovsdb:" + ipAddress).equals(d.id().toString())) | 715 | .filter(d -> !("ovsdb:" + ipAddress).equals(d.id().toString())) |
716 | .forEach(d -> { | 716 | .forEach(d -> { |
717 | DriverHandler handler = driverService.createHandler(d.id()); | 717 | DriverHandler handler = driverService.createHandler(d.id()); |
718 | - BridgeConfig bridgeConfig = handler | 718 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
719 | - .behaviour(BridgeConfig.class); | 719 | + Collection<BridgeDescription> bridgeDescriptions = bridgeConfig.getBridges(); |
720 | - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig | 720 | + for (BridgeDescription sw : bridgeDescriptions) { |
721 | - .getBridges(); | 721 | + if (sw.name().equals(VtnConfig.DEFAULT_BRIDGE_NAME) && |
722 | - Iterator<BridgeDescription> it = bridgeDescriptions | 722 | + sw.deviceId().isPresent()) { |
723 | - .iterator(); | 723 | + List<Port> ports = deviceService.getPorts(sw.deviceId().get()); |
724 | - while (it.hasNext()) { | 724 | + ports.stream().filter(p -> p.annotations().value(AnnotationKeys.PORT_NAME) |
725 | - BridgeDescription sw = it.next(); | ||
726 | - if (sw.bridgeName().name().equals(VtnConfig.DEFAULT_BRIDGE_NAME)) { | ||
727 | - List<Port> ports = deviceService.getPorts(sw.deviceId()); | ||
728 | - ports.stream() | ||
729 | - .filter(p -> p.annotations().value(AnnotationKeys.PORT_NAME) | ||
730 | .equalsIgnoreCase(tunnelName)) | 725 | .equalsIgnoreCase(tunnelName)) |
731 | - .forEach(p -> { | 726 | + .forEach(p -> l2ForwardService.programTunnelOut( |
732 | - l2ForwardService.programTunnelOut(sw.deviceId(), | 727 | + sw.deviceId().get(), segmentationId, p.number(), |
733 | - segmentationId, p.number(), | 728 | + dstMac, type, ipAddress)); |
734 | - dstMac, type, ipAddress); | ||
735 | - }); | ||
736 | break; | 729 | break; |
737 | } | 730 | } |
738 | } | 731 | } | ... | ... |
... | @@ -23,7 +23,9 @@ import org.onlab.packet.IpAddress; | ... | @@ -23,7 +23,9 @@ import org.onlab.packet.IpAddress; |
23 | import org.onosproject.net.DefaultAnnotations; | 23 | import org.onosproject.net.DefaultAnnotations; |
24 | import org.onosproject.net.PortNumber; | 24 | import org.onosproject.net.PortNumber; |
25 | import org.onosproject.net.behaviour.BridgeConfig; | 25 | import org.onosproject.net.behaviour.BridgeConfig; |
26 | +import org.onosproject.net.behaviour.BridgeDescription; | ||
26 | import org.onosproject.net.behaviour.BridgeName; | 27 | import org.onosproject.net.behaviour.BridgeName; |
28 | +import org.onosproject.net.behaviour.DefaultBridgeDescription; | ||
27 | import org.onosproject.net.behaviour.DefaultTunnelDescription; | 29 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
28 | import org.onosproject.net.behaviour.IpTunnelEndPoint; | 30 | import org.onosproject.net.behaviour.IpTunnelEndPoint; |
29 | import org.onosproject.net.behaviour.TunnelConfig; | 31 | import org.onosproject.net.behaviour.TunnelConfig; |
... | @@ -62,7 +64,16 @@ public final class VtnConfig { | ... | @@ -62,7 +64,16 @@ public final class VtnConfig { |
62 | */ | 64 | */ |
63 | public static void applyBridgeConfig(DriverHandler handler, String dpid, String exPortName) { | 65 | public static void applyBridgeConfig(DriverHandler handler, String dpid, String exPortName) { |
64 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); | 66 | BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
65 | - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), dpid, exPortName); | 67 | + BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() |
68 | + .name(DEFAULT_BRIDGE_NAME) | ||
69 | + .failMode(BridgeDescription.FailMode.SECURE) | ||
70 | + .datapathId(dpid) | ||
71 | + .disableInBand() | ||
72 | + .enableLocalController() | ||
73 | + .build(); | ||
74 | + | ||
75 | + bridgeConfig.addBridge(bridgeDesc); | ||
76 | + bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), exPortName); | ||
66 | } | 77 | } |
67 | 78 | ||
68 | /** | 79 | /** | ... | ... |
... | @@ -31,31 +31,45 @@ public interface BridgeConfig extends HandlerBehaviour { | ... | @@ -31,31 +31,45 @@ public interface BridgeConfig extends HandlerBehaviour { |
31 | /** | 31 | /** |
32 | * Add a bridge. | 32 | * Add a bridge. |
33 | * | 33 | * |
34 | + * @deprecated version 1.7.0 - Hummingbird | ||
34 | * @param bridgeName bridge name | 35 | * @param bridgeName bridge name |
35 | */ | 36 | */ |
37 | + @Deprecated | ||
36 | void addBridge(BridgeName bridgeName); | 38 | void addBridge(BridgeName bridgeName); |
37 | 39 | ||
38 | /** | 40 | /** |
39 | * Adds a bridge with given bridge name, dpid and exPortName. | 41 | * Adds a bridge with given bridge name, dpid and exPortName. |
40 | * | 42 | * |
43 | + * @deprecated version 1.7.0 - Hummingbird | ||
41 | * @param bridgeName bridge name | 44 | * @param bridgeName bridge name |
42 | * @param dpid dpid | 45 | * @param dpid dpid |
43 | * @param exPortName external port name | 46 | * @param exPortName external port name |
44 | */ | 47 | */ |
48 | + @Deprecated | ||
45 | void addBridge(BridgeName bridgeName, String dpid, String exPortName); | 49 | void addBridge(BridgeName bridgeName, String dpid, String exPortName); |
46 | 50 | ||
47 | /** | 51 | /** |
48 | * Adds a bridge with given bridge name and dpid, and sets the controller | 52 | * Adds a bridge with given bridge name and dpid, and sets the controller |
49 | * of the bridge with given controllers. | 53 | * of the bridge with given controllers. |
50 | * | 54 | * |
55 | + * @deprecated version 1.7.0 - Hummingbird | ||
51 | * @param bridgeName bridge name | 56 | * @param bridgeName bridge name |
52 | * @param dpid dpid | 57 | * @param dpid dpid |
53 | * @param controllers list of controller | 58 | * @param controllers list of controller |
54 | * @return true if succeeds, fail otherwise | 59 | * @return true if succeeds, fail otherwise |
55 | */ | 60 | */ |
61 | + @Deprecated | ||
56 | boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers); | 62 | boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers); |
57 | 63 | ||
58 | /** | 64 | /** |
65 | + * Adds a bridge with a given description. | ||
66 | + * | ||
67 | + * @param bridgeDescription bridge description | ||
68 | + * @return true if succeeds, or false | ||
69 | + */ | ||
70 | + boolean addBridge(BridgeDescription bridgeDescription); | ||
71 | + | ||
72 | + /** | ||
59 | * Remove a bridge. | 73 | * Remove a bridge. |
60 | * | 74 | * |
61 | * @param bridgeName bridge name | 75 | * @param bridgeName bridge name | ... | ... |
... | @@ -18,29 +18,140 @@ package org.onosproject.net.behaviour; | ... | @@ -18,29 +18,140 @@ package org.onosproject.net.behaviour; |
18 | import org.onosproject.net.Description; | 18 | import org.onosproject.net.Description; |
19 | import org.onosproject.net.DeviceId; | 19 | import org.onosproject.net.DeviceId; |
20 | 20 | ||
21 | +import java.util.List; | ||
22 | +import java.util.Optional; | ||
23 | + | ||
21 | /** | 24 | /** |
22 | - * The abstraction of bridge in OVSDB protocol. | 25 | + * The abstraction of a bridge. Bridge represents an Ethernet switch with no or |
26 | + * multiple OpenFlow controllers. Only OVSDB device provides bridge config behavior | ||
27 | + * now and the bridge description is based on OVSDB schema. | ||
23 | */ | 28 | */ |
24 | public interface BridgeDescription extends Description { | 29 | public interface BridgeDescription extends Description { |
25 | 30 | ||
31 | + enum FailMode { | ||
32 | + /** | ||
33 | + * The bridge will not set up flows on its own when the controller | ||
34 | + * connection fails or no controllers are defined. | ||
35 | + */ | ||
36 | + SECURE, | ||
37 | + /** | ||
38 | + * The bridge will take over responsibility of setting up flows. | ||
39 | + */ | ||
40 | + STANDALONE | ||
41 | + } | ||
42 | + | ||
26 | /** | 43 | /** |
27 | * Returns bridge name. | 44 | * Returns bridge name. |
28 | * | 45 | * |
29 | * @return bridge name | 46 | * @return bridge name |
30 | */ | 47 | */ |
31 | - BridgeName bridgeName(); | 48 | + String name(); |
49 | + | ||
50 | + /** | ||
51 | + * Returns OpenFlow controllers of the bridge. | ||
52 | + * If it's empty, then no OpenFlow controllers are used for the bridge. | ||
53 | + * | ||
54 | + * @return set of controllers | ||
55 | + */ | ||
56 | + List<ControllerInfo> controllers(); | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns whether to use local controller as an OpenFlow controller of the | ||
60 | + * bridge if no controllers are specified. | ||
61 | + * | ||
62 | + * @return true to set local controller, false otherwise | ||
63 | + */ | ||
64 | + boolean enableLocalController(); | ||
65 | + | ||
66 | + /** | ||
67 | + * Returns fail mode of the bridge. | ||
68 | + * If it's not set, the default setting of the bridge is used. | ||
69 | + * | ||
70 | + * @return fail mode | ||
71 | + */ | ||
72 | + Optional<FailMode> failMode(); | ||
73 | + | ||
74 | + /** | ||
75 | + * Returns OpenFlow datapath ID of the bridge. Valid only if OpenFlow controller | ||
76 | + * is configured for the bridge. | ||
77 | + * | ||
78 | + * @return datapath id | ||
79 | + */ | ||
80 | + Optional<String> datapathId(); | ||
81 | + | ||
82 | + /** | ||
83 | + * Returns OpenFlow device ID. Valid only if OpenFlow controller is configured | ||
84 | + * for the bridge. | ||
85 | + * | ||
86 | + * @return device id | ||
87 | + */ | ||
88 | + Optional<DeviceId> deviceId(); | ||
89 | + | ||
90 | + /** | ||
91 | + * Returns in band control is enabled or not. If set to true, disable in-band | ||
92 | + * control on the bridge regardless of controller and manager settings. | ||
93 | + * If it's not set, the default setting of the bridge is used. | ||
94 | + * | ||
95 | + * @return true if in-band is disabled, false if in-band is enabled | ||
96 | + */ | ||
97 | + Optional<Boolean> disableInBand(); | ||
98 | + | ||
99 | + /** | ||
100 | + * Builder of bridge description entities. | ||
101 | + */ | ||
102 | + interface Builder { | ||
103 | + | ||
104 | + /** | ||
105 | + * Returns bridge description builder with a given name. | ||
106 | + * | ||
107 | + * @param name bridge name | ||
108 | + * @return bridge description builder | ||
109 | + */ | ||
110 | + Builder name(String name); | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns bridge description builder with given controllers. | ||
114 | + * | ||
115 | + * @param controllers set of controllers | ||
116 | + * @return bridge description builder | ||
117 | + */ | ||
118 | + Builder controllers(List<ControllerInfo> controllers); | ||
119 | + | ||
120 | + /** | ||
121 | + * Returns bridge description builder with local controller enabled. | ||
122 | + * | ||
123 | + * @return bridge description builder | ||
124 | + */ | ||
125 | + Builder enableLocalController(); | ||
126 | + | ||
127 | + /** | ||
128 | + * Returns bridge description builder with a given fail mode. | ||
129 | + * | ||
130 | + * @param failMode fail mode | ||
131 | + * @return bridge description builder | ||
132 | + */ | ||
133 | + Builder failMode(FailMode failMode); | ||
134 | + | ||
135 | + /** | ||
136 | + * Returns bridge description builder with a given datapath ID. | ||
137 | + * | ||
138 | + * @param datapathId datapath id | ||
139 | + * @return bridge description builder | ||
140 | + */ | ||
141 | + Builder datapathId(String datapathId); | ||
32 | 142 | ||
33 | /** | 143 | /** |
34 | - * Returns controller identifier that this bridge belongs to. | 144 | + * Returns bridge description builder with in-band control disabled. |
35 | * | 145 | * |
36 | - * @return controller identifier | 146 | + * @return bridge description builder |
37 | */ | 147 | */ |
38 | - DeviceId cotrollerDeviceId(); | 148 | + Builder disableInBand(); |
39 | 149 | ||
40 | /** | 150 | /** |
41 | - * Returns bridge identifier . | 151 | + * Builds an immutable bridge description. |
42 | * | 152 | * |
43 | - * @return bridge identifier | 153 | + * @return bridge description |
44 | */ | 154 | */ |
45 | - DeviceId deviceId(); | 155 | + BridgeDescription build(); |
156 | + } | ||
46 | } | 157 | } | ... | ... |
... | @@ -15,73 +15,158 @@ | ... | @@ -15,73 +15,158 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.behaviour; | 16 | package org.onosproject.net.behaviour; |
17 | 17 | ||
18 | -import java.util.Objects; | 18 | +import com.google.common.base.Strings; |
19 | - | 19 | +import com.google.common.collect.Lists; |
20 | -import org.onosproject.net.AbstractDescription; | ||
21 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.SparseAnnotations; | 21 | import org.onosproject.net.SparseAnnotations; |
23 | 22 | ||
24 | -import com.google.common.base.MoreObjects; | 23 | +import java.util.List; |
24 | +import java.util.Optional; | ||
25 | + | ||
26 | +import static com.google.common.base.Preconditions.checkArgument; | ||
27 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | 28 | ||
26 | /** | 29 | /** |
27 | * The default implementation of bridge. | 30 | * The default implementation of bridge. |
28 | */ | 31 | */ |
29 | -public final class DefaultBridgeDescription extends AbstractDescription | 32 | +public final class DefaultBridgeDescription implements BridgeDescription { |
30 | - implements BridgeDescription { | ||
31 | 33 | ||
32 | - private final BridgeName name; | 34 | + private final String name; |
33 | - private final DeviceId deviceId; | ||
34 | - private final DeviceId controllerId; | ||
35 | 35 | ||
36 | - public DefaultBridgeDescription(BridgeName name, DeviceId controllerId, | 36 | + /* Optional OpenFlow configurations */ |
37 | - DeviceId deviceId, | 37 | + private final List<ControllerInfo> controllers; |
38 | - SparseAnnotations... annotations) { | 38 | + private final boolean enableLocalController; |
39 | - super(annotations); | 39 | + private final Optional<FailMode> failMode; |
40 | - this.name = name; | 40 | + private final Optional<String> datapathId; |
41 | - this.deviceId = deviceId; | 41 | + private final Optional<Boolean> disableInBand; |
42 | - this.controllerId = controllerId; | 42 | + |
43 | + /* Adds more configurations */ | ||
44 | + | ||
45 | + private DefaultBridgeDescription(String name, | ||
46 | + List<ControllerInfo> controllers, | ||
47 | + boolean enableLocalController, | ||
48 | + Optional<FailMode> failMode, | ||
49 | + Optional<String> datapathId, | ||
50 | + Optional<Boolean> disableInBand) { | ||
51 | + this.name = checkNotNull(name); | ||
52 | + this.controllers = controllers; | ||
53 | + this.enableLocalController = enableLocalController; | ||
54 | + this.failMode = failMode; | ||
55 | + this.datapathId = datapathId; | ||
56 | + this.disableInBand = disableInBand; | ||
43 | } | 57 | } |
44 | 58 | ||
45 | @Override | 59 | @Override |
46 | - public BridgeName bridgeName() { | 60 | + public SparseAnnotations annotations() { |
61 | + return null; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public String name() { | ||
47 | return name; | 66 | return name; |
48 | } | 67 | } |
49 | 68 | ||
50 | @Override | 69 | @Override |
51 | - public DeviceId deviceId() { | 70 | + public List<ControllerInfo> controllers() { |
52 | - return deviceId; | 71 | + return controllers; |
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public boolean enableLocalController() { | ||
76 | + return enableLocalController; | ||
53 | } | 77 | } |
54 | 78 | ||
55 | @Override | 79 | @Override |
56 | - public DeviceId cotrollerDeviceId() { | 80 | + public Optional<FailMode> failMode() { |
57 | - return controllerId; | 81 | + return failMode; |
58 | } | 82 | } |
59 | 83 | ||
60 | @Override | 84 | @Override |
61 | - public int hashCode() { | 85 | + public Optional<String> datapathId() { |
62 | - return Objects.hash(name, deviceId, controllerId); | 86 | + return datapathId; |
63 | } | 87 | } |
64 | 88 | ||
65 | @Override | 89 | @Override |
66 | - public boolean equals(Object obj) { | 90 | + public Optional<DeviceId> deviceId() { |
67 | - if (this == obj) { | 91 | + if (datapathId.isPresent()) { |
68 | - return true; | 92 | + return Optional.of(DeviceId.deviceId("of:" + datapathId.get())); |
93 | + } else { | ||
94 | + return Optional.empty(); | ||
69 | } | 95 | } |
70 | - if (obj instanceof DefaultBridgeDescription) { | ||
71 | - final DefaultBridgeDescription that = (DefaultBridgeDescription) obj; | ||
72 | - return this.getClass() == that.getClass() | ||
73 | - && Objects.equals(this.name, that.name) | ||
74 | - && Objects.equals(this.deviceId, that.deviceId) | ||
75 | - && Objects.equals(this.controllerId, that.controllerId); | ||
76 | } | 96 | } |
77 | - return false; | 97 | + |
98 | + @Override | ||
99 | + public Optional<Boolean> disableInBand() { | ||
100 | + return disableInBand; | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Creates and returns a new builder instance. | ||
105 | + * | ||
106 | + * @return new builder | ||
107 | + */ | ||
108 | + public static BridgeDescription.Builder builder() { | ||
109 | + return new Builder(); | ||
110 | + } | ||
111 | + | ||
112 | + public static final class Builder implements BridgeDescription.Builder { | ||
113 | + | ||
114 | + private String name; | ||
115 | + private List<ControllerInfo> controllers = Lists.newArrayList(); | ||
116 | + private boolean enableLocalController = false; | ||
117 | + private Optional<FailMode> failMode = Optional.empty(); | ||
118 | + private Optional<String> datapathId = Optional.empty(); | ||
119 | + private Optional<Boolean> disableInBand = Optional.empty(); | ||
120 | + | ||
121 | + private Builder() { | ||
78 | } | 122 | } |
79 | 123 | ||
80 | @Override | 124 | @Override |
81 | - public String toString() { | 125 | + public BridgeDescription build() { |
82 | - return MoreObjects.toStringHelper(getClass()).add("name", name) | 126 | + return new DefaultBridgeDescription(name, controllers, |
83 | - .add("deviceId", deviceId).add("controllerId", controllerId) | 127 | + enableLocalController, |
84 | - .toString(); | 128 | + failMode, |
129 | + datapathId, | ||
130 | + disableInBand); | ||
85 | } | 131 | } |
86 | 132 | ||
133 | + @Override | ||
134 | + public Builder name(String name) { | ||
135 | + checkArgument(!Strings.isNullOrEmpty(name)); | ||
136 | + this.name = name; | ||
137 | + return this; | ||
138 | + } | ||
139 | + | ||
140 | + @Override | ||
141 | + public Builder controllers(List<ControllerInfo> controllers) { | ||
142 | + if (controllers != null) { | ||
143 | + this.controllers = Lists.newArrayList(controllers); | ||
144 | + } | ||
145 | + return this; | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public Builder enableLocalController() { | ||
150 | + this.enableLocalController = true; | ||
151 | + return this; | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public Builder failMode(FailMode failMode) { | ||
156 | + this.failMode = Optional.ofNullable(failMode); | ||
157 | + return this; | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public Builder datapathId(String datapathId) { | ||
162 | + this.datapathId = Optional.ofNullable(datapathId); | ||
163 | + return this; | ||
164 | + } | ||
165 | + | ||
166 | + @Override | ||
167 | + public Builder disableInBand() { | ||
168 | + this.disableInBand = Optional.of(Boolean.TRUE); | ||
169 | + return this; | ||
170 | + } | ||
171 | + } | ||
87 | } | 172 | } | ... | ... |
... | @@ -49,48 +49,74 @@ import java.util.stream.Collectors; | ... | @@ -49,48 +49,74 @@ import java.util.stream.Collectors; |
49 | public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | 49 | public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
50 | implements BridgeConfig { | 50 | implements BridgeConfig { |
51 | 51 | ||
52 | + @Deprecated | ||
52 | @Override | 53 | @Override |
53 | public void addBridge(BridgeName bridgeName) { | 54 | public void addBridge(BridgeName bridgeName) { |
54 | - DriverHandler handler = handler(); | 55 | + BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() |
55 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 56 | + .name(bridgeName.name()) |
56 | - clientService.createBridge(bridgeName.name()); | 57 | + .build(); |
58 | + | ||
59 | + addBridge(bridgeDesc); | ||
57 | } | 60 | } |
58 | 61 | ||
62 | + @Deprecated | ||
59 | @Override | 63 | @Override |
60 | public void addBridge(BridgeName bridgeName, String dpid, String exPortName) { | 64 | public void addBridge(BridgeName bridgeName, String dpid, String exPortName) { |
61 | - DriverHandler handler = handler(); | 65 | + BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() |
62 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 66 | + .name(bridgeName.name()) |
63 | - clientService.createBridge(bridgeName.name(), dpid, exPortName); | 67 | + .failMode(BridgeDescription.FailMode.SECURE) |
68 | + .datapathId(dpid) | ||
69 | + .disableInBand() | ||
70 | + .enableLocalController() | ||
71 | + .build(); | ||
72 | + | ||
73 | + addBridge(bridgeDesc); | ||
74 | + | ||
75 | + OvsdbClientService client = getOvsdbClientService(handler()); | ||
76 | + client.createPort(bridgeName.name(), exPortName); | ||
64 | } | 77 | } |
65 | 78 | ||
79 | + @Deprecated | ||
66 | @Override | 80 | @Override |
67 | public boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers) { | 81 | public boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers) { |
68 | - DriverHandler handler = handler(); | 82 | + BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() |
69 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 83 | + .name(bridgeName.name()) |
70 | - return clientService.createBridge(bridgeName.name(), dpid, controllers); | 84 | + .failMode(BridgeDescription.FailMode.SECURE) |
85 | + .datapathId(dpid) | ||
86 | + .disableInBand() | ||
87 | + .controllers(controllers) | ||
88 | + .build(); | ||
89 | + | ||
90 | + return addBridge(bridgeDesc); | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public boolean addBridge(BridgeDescription bridgeDesc) { | ||
95 | + OvsdbClientService client = getOvsdbClientService(handler()); | ||
96 | + | ||
97 | + OvsdbBridge.Builder bridgeBuilder = OvsdbBridge.builder(bridgeDesc); | ||
98 | + if (bridgeDesc.enableLocalController()) { | ||
99 | + bridgeBuilder.controller(client.localController()); | ||
100 | + } | ||
101 | + return client.createBridge(bridgeBuilder.build()); | ||
71 | } | 102 | } |
72 | 103 | ||
73 | @Override | 104 | @Override |
74 | public void deleteBridge(BridgeName bridgeName) { | 105 | public void deleteBridge(BridgeName bridgeName) { |
75 | - DriverHandler handler = handler(); | 106 | + OvsdbClientService client = getOvsdbClientService(handler()); |
76 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 107 | + client.dropBridge(bridgeName.name()); |
77 | - clientService.dropBridge(bridgeName.name()); | ||
78 | } | 108 | } |
79 | 109 | ||
80 | @Override | 110 | @Override |
81 | public Collection<BridgeDescription> getBridges() { | 111 | public Collection<BridgeDescription> getBridges() { |
82 | - DriverHandler handler = handler(); | 112 | + OvsdbClientService client = getOvsdbClientService(handler()); |
83 | - DeviceId deviceId = handler.data().deviceId(); | 113 | + Set<OvsdbBridge> bridges = client.getBridges(); |
84 | - OvsdbClientService clientService = getOvsdbClientService(handler); | ||
85 | - Set<OvsdbBridge> bridges = clientService.getBridges(); | ||
86 | 114 | ||
87 | return bridges.stream() | 115 | return bridges.stream() |
88 | - .map(x -> new DefaultBridgeDescription( | 116 | + .map(bridge -> DefaultBridgeDescription.builder() |
89 | - BridgeName.bridgeName(x.bridgeName().value()), | 117 | + .name(bridge.name()) |
90 | - deviceId, | 118 | + .datapathId(bridge.datapathId().get()) |
91 | - DeviceId.deviceId("of:" + x.datapathId().value()) | 119 | + .build()) |
92 | - ) | ||
93 | - ) | ||
94 | .collect(Collectors.toSet()); | 120 | .collect(Collectors.toSet()); |
95 | } | 121 | } |
96 | 122 | ||
... | @@ -98,49 +124,42 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -98,49 +124,42 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
98 | @Deprecated | 124 | @Deprecated |
99 | @Override | 125 | @Override |
100 | public void addPort(PortDescription port) { | 126 | public void addPort(PortDescription port) { |
101 | - DriverHandler handler = handler(); | 127 | + OvsdbClientService client = getOvsdbClientService(handler()); |
102 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 128 | + Set<OvsdbBridge> ovsdbSet = client.getBridges(); |
103 | - Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); | ||
104 | if (ovsdbSet != null && ovsdbSet.size() > 0) { | 129 | if (ovsdbSet != null && ovsdbSet.size() > 0) { |
105 | OvsdbBridge bridge = ovsdbSet.iterator().next(); | 130 | OvsdbBridge bridge = ovsdbSet.iterator().next(); |
106 | - clientService.createPort(bridge.bridgeName().value(), port | 131 | + client.createPort(bridge.name(), port.portNumber().toString()); |
107 | - .portNumber().toString()); | ||
108 | } | 132 | } |
109 | } | 133 | } |
110 | 134 | ||
111 | @Override | 135 | @Override |
112 | public void addPort(BridgeName bridgeName, String portName) { | 136 | public void addPort(BridgeName bridgeName, String portName) { |
113 | - DriverHandler handler = handler(); | 137 | + OvsdbClientService client = getOvsdbClientService(handler()); |
114 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 138 | + client.createPort(bridgeName.name(), portName); |
115 | - clientService.createPort(bridgeName.name(), portName); | ||
116 | } | 139 | } |
117 | 140 | ||
118 | //Deprecated from version 1.5.0 - Falcon | 141 | //Deprecated from version 1.5.0 - Falcon |
119 | @Deprecated | 142 | @Deprecated |
120 | @Override | 143 | @Override |
121 | public void deletePort(PortDescription port) { | 144 | public void deletePort(PortDescription port) { |
122 | - DriverHandler handler = handler(); | 145 | + OvsdbClientService client = getOvsdbClientService(handler()); |
123 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 146 | + Set<OvsdbBridge> ovsdbSet = client.getBridges(); |
124 | - Set<OvsdbBridge> ovsdbSet = clientService.getBridges(); | ||
125 | if (ovsdbSet != null && ovsdbSet.size() > 0) { | 147 | if (ovsdbSet != null && ovsdbSet.size() > 0) { |
126 | OvsdbBridge bridge = ovsdbSet.iterator().next(); | 148 | OvsdbBridge bridge = ovsdbSet.iterator().next(); |
127 | - clientService.dropPort(bridge.bridgeName().value(), port | 149 | + client.dropPort(bridge.name(), port.portNumber().toString()); |
128 | - .portNumber().toString()); | ||
129 | } | 150 | } |
130 | } | 151 | } |
131 | 152 | ||
132 | @Override | 153 | @Override |
133 | public void deletePort(BridgeName bridgeName, String portName) { | 154 | public void deletePort(BridgeName bridgeName, String portName) { |
134 | - DriverHandler handler = handler(); | 155 | + OvsdbClientService client = getOvsdbClientService(handler()); |
135 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 156 | + client.dropPort(bridgeName.name(), portName); |
136 | - clientService.dropPort(bridgeName.name(), portName); | ||
137 | } | 157 | } |
138 | 158 | ||
139 | @Override | 159 | @Override |
140 | public Collection<PortDescription> getPorts() { | 160 | public Collection<PortDescription> getPorts() { |
141 | - DriverHandler handler = handler(); | 161 | + OvsdbClientService client = getOvsdbClientService(handler()); |
142 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 162 | + Set<OvsdbPort> ports = client.getPorts(); |
143 | - Set<OvsdbPort> ports = clientService.getPorts(); | ||
144 | 163 | ||
145 | return ports.stream() | 164 | return ports.stream() |
146 | .map(x -> new DefaultPortDescription( | 165 | .map(x -> new DefaultPortDescription( |
... | @@ -174,8 +193,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -174,8 +193,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
174 | @Override | 193 | @Override |
175 | public Set<PortNumber> getPortNumbers() { | 194 | public Set<PortNumber> getPortNumbers() { |
176 | DriverHandler handler = handler(); | 195 | DriverHandler handler = handler(); |
177 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 196 | + OvsdbClientService client = getOvsdbClientService(handler); |
178 | - Set<OvsdbPort> ports = clientService.getPorts(); | 197 | + Set<OvsdbPort> ports = client.getPorts(); |
179 | 198 | ||
180 | return ports.stream() | 199 | return ports.stream() |
181 | .map(x -> PortNumber.portNumber( | 200 | .map(x -> PortNumber.portNumber( |
... | @@ -190,8 +209,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour | ... | @@ -190,8 +209,8 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour |
190 | public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { | 209 | public List<PortNumber> getLocalPorts(Iterable<String> ifaceIds) { |
191 | List<PortNumber> ports = new ArrayList<>(); | 210 | List<PortNumber> ports = new ArrayList<>(); |
192 | DriverHandler handler = handler(); | 211 | DriverHandler handler = handler(); |
193 | - OvsdbClientService clientService = getOvsdbClientService(handler); | 212 | + OvsdbClientService client = getOvsdbClientService(handler); |
194 | - Set<OvsdbPort> ovsdbSet = clientService.getLocalPorts(ifaceIds); | 213 | + Set<OvsdbPort> ovsdbSet = client.getLocalPorts(ifaceIds); |
195 | ovsdbSet.forEach(o -> { | 214 | ovsdbSet.forEach(o -> { |
196 | PortNumber port = PortNumber.portNumber(o.portNumber().value(), | 215 | PortNumber port = PortNumber.portNumber(o.portNumber().value(), |
197 | o.portName().value()); | 216 | o.portName().value()); | ... | ... |
... | @@ -36,6 +36,7 @@ import java.util.List; | ... | @@ -36,6 +36,7 @@ import java.util.List; |
36 | import java.util.Set; | 36 | import java.util.Set; |
37 | import java.util.stream.Collectors; | 37 | import java.util.stream.Collectors; |
38 | 38 | ||
39 | +import static com.google.common.base.Preconditions.checkArgument; | ||
39 | import static com.google.common.base.Preconditions.checkState; | 40 | import static com.google.common.base.Preconditions.checkState; |
40 | import static org.onlab.util.Tools.delay; | 41 | import static org.onlab.util.Tools.delay; |
41 | 42 | ||
... | @@ -96,7 +97,9 @@ public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements C | ... | @@ -96,7 +97,9 @@ public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements C |
96 | } | 97 | } |
97 | 98 | ||
98 | private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) { | 99 | private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) { |
99 | - String bridgeDpid = "of:" + bridge.datapathId().value(); | 100 | + checkArgument(bridge.datapathId().isPresent()); |
101 | + | ||
102 | + String bridgeDpid = "of:" + bridge.datapathId().get(); | ||
100 | String ofDpid = deviceId.toString(); | 103 | String ofDpid = deviceId.toString(); |
101 | return bridgeDpid.equals(ofDpid); | 104 | return bridgeDpid.equals(ofDpid); |
102 | } | 105 | } | ... | ... |
... | @@ -15,32 +15,55 @@ | ... | @@ -15,32 +15,55 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.ovsdb.controller; | 16 | package org.onosproject.ovsdb.controller; |
17 | 17 | ||
18 | +import com.google.common.collect.Lists; | ||
19 | +import com.google.common.collect.Maps; | ||
20 | +import org.onosproject.net.behaviour.BridgeDescription; | ||
21 | +import org.onosproject.net.behaviour.BridgeDescription.FailMode; | ||
22 | +import org.onosproject.net.behaviour.ControllerInfo; | ||
23 | + | ||
18 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
19 | -import static com.google.common.base.Preconditions.checkNotNull; | 25 | +import static org.onosproject.ovsdb.controller.OvsdbConstant.DATAPATH_ID; |
26 | +import static org.onosproject.ovsdb.controller.OvsdbConstant.DISABLE_INBAND; | ||
20 | 27 | ||
28 | +import java.util.List; | ||
29 | +import java.util.Map; | ||
21 | import java.util.Objects; | 30 | import java.util.Objects; |
31 | +import java.util.Optional; | ||
32 | + | ||
33 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
22 | 34 | ||
23 | /** | 35 | /** |
24 | - * The class representing an ovsdb bridge. | 36 | + * The class representing an OVSDB bridge. |
25 | * This class is immutable. | 37 | * This class is immutable. |
26 | */ | 38 | */ |
27 | public final class OvsdbBridge { | 39 | public final class OvsdbBridge { |
28 | 40 | ||
29 | - private final OvsdbBridgeName bridgeName; | 41 | + private final String name; |
30 | - private final OvsdbDatapathId datapathId; | 42 | + |
43 | + /* OpenFlow properties */ | ||
44 | + private final Optional<FailMode> failMode; | ||
45 | + private final List<ControllerInfo> controllers; | ||
46 | + | ||
47 | + /* Adds more properties */ | ||
48 | + | ||
49 | + /* other optional configs */ | ||
50 | + private final Map<String, String> otherConfigs; | ||
31 | 51 | ||
32 | /** | 52 | /** |
33 | - * Constructor from an OvsdbBridgeName bridgeName and an OvsdbDatapathId | 53 | + * Default constructor. |
34 | - * datapathId. | ||
35 | * | 54 | * |
36 | - * @param bridgeName the bridgeName to use | 55 | + * @param name name of the bridge |
37 | - * @param datapathId the datapathId to use | 56 | + * @param failMode openflow controller fail mode policy |
57 | + * @param controllers list of openflow controllers | ||
58 | + * @param otherConfigs other configs | ||
38 | */ | 59 | */ |
39 | - public OvsdbBridge(OvsdbBridgeName bridgeName, OvsdbDatapathId datapathId) { | 60 | + private OvsdbBridge(String name, Optional<FailMode> failMode, |
40 | - checkNotNull(bridgeName, "bridgeName is not null"); | 61 | + List<ControllerInfo> controllers, |
41 | - checkNotNull(datapathId, "datapathId is not null"); | 62 | + Map<String, String> otherConfigs) { |
42 | - this.bridgeName = bridgeName; | 63 | + this.name = checkNotNull(name); |
43 | - this.datapathId = datapathId; | 64 | + this.failMode = failMode; |
65 | + this.controllers = controllers; | ||
66 | + this.otherConfigs = otherConfigs; | ||
44 | } | 67 | } |
45 | 68 | ||
46 | /** | 69 | /** |
... | @@ -48,22 +71,49 @@ public final class OvsdbBridge { | ... | @@ -48,22 +71,49 @@ public final class OvsdbBridge { |
48 | * | 71 | * |
49 | * @return the bridge name of bridge | 72 | * @return the bridge name of bridge |
50 | */ | 73 | */ |
51 | - public OvsdbBridgeName bridgeName() { | 74 | + public String name() { |
52 | - return bridgeName; | 75 | + return name; |
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Returns the controllers of the bridge. | ||
80 | + * | ||
81 | + * @return list of controllers | ||
82 | + */ | ||
83 | + public List<ControllerInfo> controllers() { | ||
84 | + return controllers; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Returns fail mode of the bridge. | ||
89 | + * | ||
90 | + * @return fail mode | ||
91 | + */ | ||
92 | + public Optional<FailMode> failMode() { | ||
93 | + return failMode; | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Returns other configurations of the bridge. | ||
98 | + * | ||
99 | + * @return map of configurations | ||
100 | + */ | ||
101 | + public Map<String, String> otherConfigs() { | ||
102 | + return otherConfigs; | ||
53 | } | 103 | } |
54 | 104 | ||
55 | /** | 105 | /** |
56 | * Gets the datapathId of bridge. | 106 | * Gets the datapathId of bridge. |
57 | * | 107 | * |
58 | - * @return datapathId the datapathId to use | 108 | + * @return datapath id; null if not used |
59 | */ | 109 | */ |
60 | - public OvsdbDatapathId datapathId() { | 110 | + public Optional<String> datapathId() { |
61 | - return datapathId; | 111 | + return Optional.ofNullable(otherConfigs.get(DATAPATH_ID)); |
62 | } | 112 | } |
63 | 113 | ||
64 | @Override | 114 | @Override |
65 | public int hashCode() { | 115 | public int hashCode() { |
66 | - return Objects.hash(bridgeName, datapathId); | 116 | + return Objects.hash(name); |
67 | } | 117 | } |
68 | 118 | ||
69 | @Override | 119 | @Override |
... | @@ -73,16 +123,154 @@ public final class OvsdbBridge { | ... | @@ -73,16 +123,154 @@ public final class OvsdbBridge { |
73 | } | 123 | } |
74 | if (obj instanceof OvsdbBridge) { | 124 | if (obj instanceof OvsdbBridge) { |
75 | final OvsdbBridge otherOvsdbBridge = (OvsdbBridge) obj; | 125 | final OvsdbBridge otherOvsdbBridge = (OvsdbBridge) obj; |
76 | - return Objects.equals(this.bridgeName, otherOvsdbBridge.bridgeName) | 126 | + return Objects.equals(this.name, otherOvsdbBridge.name); |
77 | - && Objects.equals(this.datapathId, | ||
78 | - otherOvsdbBridge.datapathId); | ||
79 | } | 127 | } |
80 | return false; | 128 | return false; |
81 | } | 129 | } |
82 | 130 | ||
83 | @Override | 131 | @Override |
84 | public String toString() { | 132 | public String toString() { |
85 | - return toStringHelper(this).add("bridgeName", bridgeName.value()) | 133 | + return toStringHelper(this) |
86 | - .add("datapathId", datapathId.value()).toString(); | 134 | + .add("bridgeName", name) |
135 | + .add("failMode", failMode) | ||
136 | + .add("controllers", controllers) | ||
137 | + .add("otherConfigs", otherConfigs) | ||
138 | + .toString(); | ||
139 | + } | ||
140 | + | ||
141 | + /** | ||
142 | + * Returns a new builder instance. | ||
143 | + * | ||
144 | + * @return ovsdb bridge builder | ||
145 | + */ | ||
146 | + public static OvsdbBridge.Builder builder() { | ||
147 | + return new Builder(); | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * Returns OVSDB bridge object with a given bridge description. | ||
152 | + * | ||
153 | + * @param bridgeDesc bridge description | ||
154 | + * @return ovsdb bridge | ||
155 | + */ | ||
156 | + public static OvsdbBridge.Builder builder(BridgeDescription bridgeDesc) { | ||
157 | + return new Builder(bridgeDesc); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * Builder of OVSDB bridge entities. | ||
162 | + */ | ||
163 | + public static final class Builder { | ||
164 | + private String name; | ||
165 | + private Optional<FailMode> failMode = Optional.empty(); | ||
166 | + private List<ControllerInfo> controllers = Lists.newArrayList(); | ||
167 | + private Map<String, String> otherConfigs = Maps.newHashMap(); | ||
168 | + | ||
169 | + private Builder() { | ||
170 | + } | ||
171 | + | ||
172 | + /** | ||
173 | + * Constructs OVSDB bridge builder with a given bridge description. | ||
174 | + * | ||
175 | + * @param bridgeDesc bridge description | ||
176 | + */ | ||
177 | + private Builder(BridgeDescription bridgeDesc) { | ||
178 | + if (bridgeDesc.datapathId().isPresent()) { | ||
179 | + otherConfigs.put(DATAPATH_ID, bridgeDesc.datapathId().get()); | ||
180 | + } | ||
181 | + if (bridgeDesc.disableInBand().isPresent()) { | ||
182 | + otherConfigs.put(DISABLE_INBAND, | ||
183 | + bridgeDesc.disableInBand().get().toString()); | ||
184 | + } | ||
185 | + | ||
186 | + this.name = bridgeDesc.name(); | ||
187 | + this.failMode = bridgeDesc.failMode(); | ||
188 | + this.controllers = Lists.newArrayList(bridgeDesc.controllers()); | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * Builds an immutable OVSDB bridge. | ||
193 | + * | ||
194 | + * @return ovsdb bridge | ||
195 | + */ | ||
196 | + public OvsdbBridge build() { | ||
197 | + return new OvsdbBridge(name, failMode, controllers, otherConfigs); | ||
198 | + } | ||
199 | + | ||
200 | + /** | ||
201 | + * Returns OVSDB bridge builder with a given name. | ||
202 | + * | ||
203 | + * @param name name of the bridge | ||
204 | + * @return ovsdb bridge builder | ||
205 | + */ | ||
206 | + public Builder name(String name) { | ||
207 | + this.name = name; | ||
208 | + return this; | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * Returns OVSDB bridge builder with a given fail mode. | ||
213 | + * | ||
214 | + * @param failMode fail mode | ||
215 | + * @return ovsdb bridge builder | ||
216 | + */ | ||
217 | + public Builder failMode(FailMode failMode) { | ||
218 | + this.failMode = Optional.ofNullable(failMode); | ||
219 | + return this; | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * Returns OVSDB bridge builder with given controllers. | ||
224 | + * | ||
225 | + * @param controllers list of controllers | ||
226 | + * @return ovsdb bridge builder | ||
227 | + */ | ||
228 | + public Builder controllers(List<ControllerInfo> controllers) { | ||
229 | + this.controllers = Lists.newArrayList(controllers); | ||
230 | + return this; | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * Returns OVSDB bridge builder with a given controller. | ||
235 | + * | ||
236 | + * @param controller controller | ||
237 | + * @return ovsdb bridge builder | ||
238 | + */ | ||
239 | + public Builder controller(ControllerInfo controller) { | ||
240 | + this.controllers = Lists.newArrayList(controller); | ||
241 | + return this; | ||
242 | + } | ||
243 | + | ||
244 | + /** | ||
245 | + * Returns OVSDB bridge builder with given configs. | ||
246 | + * | ||
247 | + * @param otherConfigs other configs | ||
248 | + * @return ovsdb bridge builder | ||
249 | + */ | ||
250 | + public Builder otherConfigs(Map<String, String> otherConfigs) { | ||
251 | + this.otherConfigs = Maps.newHashMap(otherConfigs); | ||
252 | + return this; | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * Returns OVSDB bridge builder with a given datapath ID. | ||
257 | + * | ||
258 | + * @param datapathId datapath id | ||
259 | + * @return ovsdb bridge builder | ||
260 | + */ | ||
261 | + public Builder datapathId(String datapathId) { | ||
262 | + otherConfigs.put(DATAPATH_ID, datapathId); | ||
263 | + return this; | ||
264 | + } | ||
265 | + | ||
266 | + /** | ||
267 | + * Returns OVSDB bridge builder with a given disable in-band config. | ||
268 | + * | ||
269 | + * @return ovsdb bridge builder | ||
270 | + */ | ||
271 | + public Builder disableInBand() { | ||
272 | + otherConfigs.put(DATAPATH_ID, Boolean.TRUE.toString()); | ||
273 | + return this; | ||
274 | + } | ||
87 | } | 275 | } |
88 | } | 276 | } | ... | ... |
protocols/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridgeName.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2015-present Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.ovsdb.controller; | ||
17 | - | ||
18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
19 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
20 | - | ||
21 | -import java.util.Objects; | ||
22 | - | ||
23 | -/** | ||
24 | - * The class representing a bridge name. | ||
25 | - * This class is immutable. | ||
26 | - */ | ||
27 | -public final class OvsdbBridgeName { | ||
28 | - | ||
29 | - private final String value; | ||
30 | - | ||
31 | - /** | ||
32 | - * Constructor from a String. | ||
33 | - * | ||
34 | - * @param value the bridge name to use | ||
35 | - */ | ||
36 | - public OvsdbBridgeName(String value) { | ||
37 | - checkNotNull(value, "value is not null"); | ||
38 | - this.value = value; | ||
39 | - } | ||
40 | - | ||
41 | - /** | ||
42 | - * Gets the value of bridge name. | ||
43 | - * | ||
44 | - * @return the value of the bridge name | ||
45 | - */ | ||
46 | - public String value() { | ||
47 | - return value; | ||
48 | - } | ||
49 | - | ||
50 | - @Override | ||
51 | - public int hashCode() { | ||
52 | - return value.hashCode(); | ||
53 | - } | ||
54 | - | ||
55 | - @Override | ||
56 | - public boolean equals(Object obj) { | ||
57 | - if (this == obj) { | ||
58 | - return true; | ||
59 | - } | ||
60 | - if (obj instanceof OvsdbBridgeName) { | ||
61 | - final OvsdbBridgeName otherBridgeName = (OvsdbBridgeName) obj; | ||
62 | - return Objects.equals(this.value, otherBridgeName.value); | ||
63 | - } | ||
64 | - return false; | ||
65 | - } | ||
66 | - | ||
67 | - @Override | ||
68 | - public String toString() { | ||
69 | - return toStringHelper(this).add("value", value).toString(); | ||
70 | - } | ||
71 | - | ||
72 | -} |
... | @@ -72,31 +72,45 @@ public interface OvsdbClientService extends OvsdbRpc { | ... | @@ -72,31 +72,45 @@ public interface OvsdbClientService extends OvsdbRpc { |
72 | /** | 72 | /** |
73 | * Creates a bridge. | 73 | * Creates a bridge. |
74 | * | 74 | * |
75 | + * @deprecated version 1.7.0 - Hummingbird | ||
75 | * @param bridgeName bridge name | 76 | * @param bridgeName bridge name |
76 | */ | 77 | */ |
78 | + @Deprecated | ||
77 | void createBridge(String bridgeName); | 79 | void createBridge(String bridgeName); |
78 | 80 | ||
79 | /** | 81 | /** |
80 | * Creates a bridge. | 82 | * Creates a bridge. |
81 | * | 83 | * |
84 | + * @deprecated version 1.7.0 - Hummingbird | ||
82 | * @param bridgeName bridge name | 85 | * @param bridgeName bridge name |
83 | * @param dpid data path id | 86 | * @param dpid data path id |
84 | * @param exPortName external port name | 87 | * @param exPortName external port name |
85 | */ | 88 | */ |
89 | + @Deprecated | ||
86 | void createBridge(String bridgeName, String dpid, String exPortName); | 90 | void createBridge(String bridgeName, String dpid, String exPortName); |
87 | 91 | ||
88 | /** | 92 | /** |
89 | * Creates a bridge with given name and dpid. | 93 | * Creates a bridge with given name and dpid. |
90 | * Sets the bridge's controller with given controllers. | 94 | * Sets the bridge's controller with given controllers. |
91 | * | 95 | * |
96 | + * @deprecated version 1.7.0 - Hummingbird | ||
92 | * @param bridgeName bridge name | 97 | * @param bridgeName bridge name |
93 | * @param dpid data path id | 98 | * @param dpid data path id |
94 | * @param controllers controllers | 99 | * @param controllers controllers |
95 | * @return true if bridge creation is successful, false otherwise | 100 | * @return true if bridge creation is successful, false otherwise |
96 | */ | 101 | */ |
102 | + @Deprecated | ||
97 | boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers); | 103 | boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers); |
98 | 104 | ||
99 | /** | 105 | /** |
106 | + * Creates a bridge with a given bridge description. | ||
107 | + * | ||
108 | + * @param ovsdbBridge ovsdb bridge description | ||
109 | + * @return true if bridge creation is successful, otherwise false | ||
110 | + */ | ||
111 | + boolean createBridge(OvsdbBridge ovsdbBridge); | ||
112 | + | ||
113 | + /** | ||
100 | * Drops a bridge. | 114 | * Drops a bridge. |
101 | * | 115 | * |
102 | * @param bridgeName bridge name | 116 | * @param bridgeName bridge name |
... | @@ -119,6 +133,15 @@ public interface OvsdbClientService extends OvsdbRpc { | ... | @@ -119,6 +133,15 @@ public interface OvsdbClientService extends OvsdbRpc { |
119 | Set<ControllerInfo> getControllers(DeviceId openflowDeviceId); | 133 | Set<ControllerInfo> getControllers(DeviceId openflowDeviceId); |
120 | 134 | ||
121 | /** | 135 | /** |
136 | + * Returns local controller information. | ||
137 | + * The connection is a TCP connection to the local ONOS instance's IP | ||
138 | + * and the default OpenFlow port. | ||
139 | + * | ||
140 | + * @return local controller | ||
141 | + */ | ||
142 | + ControllerInfo localController(); | ||
143 | + | ||
144 | + /** | ||
122 | * Sets the Controllers for the specified bridge. | 145 | * Sets the Controllers for the specified bridge. |
123 | * <p> | 146 | * <p> |
124 | * This method will replace the existing controller list with the new controller | 147 | * This method will replace the existing controller list with the new controller | ... | ... |
... | @@ -29,40 +29,46 @@ public final class OvsdbConstant { | ... | @@ -29,40 +29,46 @@ public final class OvsdbConstant { |
29 | private OvsdbConstant() { | 29 | private OvsdbConstant() { |
30 | } | 30 | } |
31 | 31 | ||
32 | + /** Common column names. */ | ||
33 | + public static final String UUID = "_uuid"; | ||
34 | + | ||
32 | /** Ovsdb database Open_vSwitch. */ | 35 | /** Ovsdb database Open_vSwitch. */ |
33 | public static final String DATABASENAME = "Open_vSwitch"; | 36 | public static final String DATABASENAME = "Open_vSwitch"; |
34 | 37 | ||
35 | - /** Ovsdb table Bridge. */ | 38 | + /** Open_vSwitch table. */ |
39 | + public static final String BRIDGES = "bridges"; | ||
40 | + | ||
41 | + /** Bridge table. */ | ||
36 | public static final String BRIDGE = "Bridge"; | 42 | public static final String BRIDGE = "Bridge"; |
43 | + public static final String PORTS = "ports"; | ||
44 | + // other configs | ||
45 | + public static final String DATAPATH_ID = "datapath-id"; | ||
46 | + public static final String DISABLE_INBAND = "disable-in-band"; | ||
37 | 47 | ||
38 | - /** Ovsdb table Interface. */ | 48 | + /** Interface table. */ |
39 | public static final String INTERFACE = "Interface"; | 49 | public static final String INTERFACE = "Interface"; |
50 | + // type | ||
51 | + public static final String TYPEVXLAN = "vxlan"; | ||
52 | + // virtual machine identifiers | ||
53 | + public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id"; | ||
54 | + public static final String EXTERNAL_ID_VM_MAC = "attached-mac"; | ||
40 | 55 | ||
41 | - /** Ovsdb table Controller. */ | 56 | + /** Controller table. */ |
42 | public static final String CONTROLLER = "Controller"; | 57 | public static final String CONTROLLER = "Controller"; |
43 | 58 | ||
44 | - /** Ovsdb table Port. */ | 59 | + /** Port table. */ |
45 | public static final String PORT = "Port"; | 60 | public static final String PORT = "Port"; |
46 | 61 | ||
47 | /** Ovsdb bridge name. */ | 62 | /** Ovsdb bridge name. */ |
63 | + // TODO remove this particular bridge name from OVSDB provider | ||
48 | public static final String INTEGRATION_BRIDGE = "br-int"; | 64 | public static final String INTEGRATION_BRIDGE = "br-int"; |
49 | 65 | ||
50 | - /** Ovsdb vxlan tunnel type. */ | ||
51 | - public static final String TYPEVXLAN = "vxlan"; | ||
52 | - | ||
53 | /** Openflow version. */ | 66 | /** Openflow version. */ |
54 | public static final String OPENFLOW13 = "OpenFlow13"; | 67 | public static final String OPENFLOW13 = "OpenFlow13"; |
55 | 68 | ||
56 | - /** Ovsdb external_id_interface_id.. */ | ||
57 | - public static final String EXTERNAL_ID_INTERFACE_ID = "iface-id"; | ||
58 | - | ||
59 | - /** Ovsdb external_id_vm_mac. */ | ||
60 | - public static final String EXTERNAL_ID_VM_MAC = "attached-mac"; | ||
61 | - | ||
62 | /** Openflow port. */ | 69 | /** Openflow port. */ |
63 | public static final int OFPORT = 6653; | 70 | public static final int OFPORT = 6653; |
64 | 71 | ||
65 | /** Ovsdb port. */ | 72 | /** Ovsdb port. */ |
66 | public static final int OVSDBPORT = 6640; | 73 | public static final int OVSDBPORT = 6640; |
67 | - | ||
68 | } | 74 | } | ... | ... |
... | @@ -17,7 +17,6 @@ package org.onosproject.ovsdb.controller.driver; | ... | @@ -17,7 +17,6 @@ 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; | ||
21 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
22 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
23 | import com.google.common.collect.Sets; | 22 | import com.google.common.collect.Sets; |
... | @@ -29,12 +28,10 @@ import io.netty.channel.Channel; | ... | @@ -29,12 +28,10 @@ import io.netty.channel.Channel; |
29 | 28 | ||
30 | import org.onlab.packet.IpAddress; | 29 | import org.onlab.packet.IpAddress; |
31 | import org.onosproject.net.DeviceId; | 30 | import org.onosproject.net.DeviceId; |
31 | +import org.onosproject.net.behaviour.BridgeDescription; | ||
32 | import org.onosproject.net.behaviour.ControllerInfo; | 32 | import org.onosproject.net.behaviour.ControllerInfo; |
33 | import org.onosproject.ovsdb.controller.OvsdbBridge; | 33 | import org.onosproject.ovsdb.controller.OvsdbBridge; |
34 | -import org.onosproject.ovsdb.controller.OvsdbBridgeName; | ||
35 | import org.onosproject.ovsdb.controller.OvsdbClientService; | 34 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
36 | -import org.onosproject.ovsdb.controller.OvsdbConstant; | ||
37 | -import org.onosproject.ovsdb.controller.OvsdbDatapathId; | ||
38 | import org.onosproject.ovsdb.controller.OvsdbNodeId; | 35 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
39 | import org.onosproject.ovsdb.controller.OvsdbPort; | 36 | import org.onosproject.ovsdb.controller.OvsdbPort; |
40 | import org.onosproject.ovsdb.controller.OvsdbPortName; | 37 | import org.onosproject.ovsdb.controller.OvsdbPortName; |
... | @@ -43,7 +40,6 @@ import org.onosproject.ovsdb.controller.OvsdbRowStore; | ... | @@ -43,7 +40,6 @@ import org.onosproject.ovsdb.controller.OvsdbRowStore; |
43 | import org.onosproject.ovsdb.controller.OvsdbStore; | 40 | import org.onosproject.ovsdb.controller.OvsdbStore; |
44 | import org.onosproject.ovsdb.controller.OvsdbTableStore; | 41 | import org.onosproject.ovsdb.controller.OvsdbTableStore; |
45 | import org.onosproject.ovsdb.controller.OvsdbTunnel; | 42 | import org.onosproject.ovsdb.controller.OvsdbTunnel; |
46 | -import org.onosproject.ovsdb.rfc.exception.BridgeCreateException; | ||
47 | import org.onosproject.ovsdb.rfc.jsonrpc.Callback; | 43 | import org.onosproject.ovsdb.rfc.jsonrpc.Callback; |
48 | import org.onosproject.ovsdb.rfc.message.OperationResult; | 44 | import org.onosproject.ovsdb.rfc.message.OperationResult; |
49 | import org.onosproject.ovsdb.rfc.message.TableUpdates; | 45 | import org.onosproject.ovsdb.rfc.message.TableUpdates; |
... | @@ -77,7 +73,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -77,7 +73,6 @@ import org.slf4j.LoggerFactory; |
77 | import java.net.InetSocketAddress; | 73 | import java.net.InetSocketAddress; |
78 | import java.util.ArrayList; | 74 | import java.util.ArrayList; |
79 | import java.util.Arrays; | 75 | import java.util.Arrays; |
80 | -import java.util.HashMap; | ||
81 | import java.util.HashSet; | 76 | import java.util.HashSet; |
82 | import java.util.Iterator; | 77 | import java.util.Iterator; |
83 | import java.util.List; | 78 | import java.util.List; |
... | @@ -88,28 +83,24 @@ import java.util.concurrent.ExecutionException; | ... | @@ -88,28 +83,24 @@ import java.util.concurrent.ExecutionException; |
88 | import java.util.concurrent.atomic.AtomicReference; | 83 | import java.util.concurrent.atomic.AtomicReference; |
89 | import java.util.stream.Collectors; | 84 | import java.util.stream.Collectors; |
90 | 85 | ||
86 | +import static org.onosproject.ovsdb.controller.OvsdbConstant.*; | ||
87 | + | ||
91 | /** | 88 | /** |
92 | * An representation of an ovsdb client. | 89 | * An representation of an ovsdb client. |
93 | */ | 90 | */ |
94 | -public class DefaultOvsdbClient | 91 | +public class DefaultOvsdbClient implements OvsdbProviderService, OvsdbClientService { |
95 | - implements OvsdbProviderService, OvsdbClientService { | ||
96 | 92 | ||
97 | - private final Logger log = LoggerFactory | 93 | + private final Logger log = LoggerFactory.getLogger(DefaultOvsdbClient.class); |
98 | - .getLogger(DefaultOvsdbClient.class); | ||
99 | 94 | ||
100 | private Channel channel; | 95 | private Channel channel; |
101 | - | ||
102 | private OvsdbAgent agent; | 96 | private OvsdbAgent agent; |
103 | private boolean connected; | 97 | private boolean connected; |
104 | private OvsdbNodeId nodeId; | 98 | private OvsdbNodeId nodeId; |
105 | private Callback monitorCallBack; | 99 | private Callback monitorCallBack; |
106 | - | ||
107 | private OvsdbStore ovsdbStore = new OvsdbStore(); | 100 | private OvsdbStore ovsdbStore = new OvsdbStore(); |
108 | 101 | ||
109 | private final Map<String, String> requestMethod = Maps.newHashMap(); | 102 | private final Map<String, String> requestMethod = Maps.newHashMap(); |
110 | - private final Map<String, SettableFuture<? extends Object>> requestResult = Maps | 103 | + private final Map<String, SettableFuture<? extends Object>> requestResult = Maps.newHashMap(); |
111 | - .newHashMap(); | ||
112 | - | ||
113 | private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); | 104 | private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); |
114 | private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); | 105 | private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); |
115 | 106 | ||
... | @@ -245,11 +236,9 @@ public class DefaultOvsdbClient | ... | @@ -245,11 +236,9 @@ public class DefaultOvsdbClient |
245 | 236 | ||
246 | @Override | 237 | @Override |
247 | public String getPortUuid(String portName, String bridgeUuid) { | 238 | public String getPortUuid(String portName, String bridgeUuid) { |
248 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 239 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
249 | - | ||
250 | - Row bridgeRow = getRow(OvsdbConstant.DATABASENAME, | ||
251 | - OvsdbConstant.BRIDGE, bridgeUuid); | ||
252 | 240 | ||
241 | + Row bridgeRow = getRow(DATABASENAME, BRIDGE, bridgeUuid); | ||
253 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, | 242 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, |
254 | OvsdbTable.BRIDGE); | 243 | OvsdbTable.BRIDGE); |
255 | if (bridge != null) { | 244 | if (bridge != null) { |
... | @@ -262,27 +251,23 @@ public class DefaultOvsdbClient | ... | @@ -262,27 +251,23 @@ public class DefaultOvsdbClient |
262 | } | 251 | } |
263 | 252 | ||
264 | for (Uuid uuid : ports) { | 253 | for (Uuid uuid : ports) { |
265 | - Row portRow = getRow(OvsdbConstant.DATABASENAME, | 254 | + Row portRow = getRow(DATABASENAME, PORT, uuid.value()); |
266 | - OvsdbConstant.PORT, uuid.value()); | ||
267 | Port port = (Port) TableGenerator.getTable(dbSchema, portRow, | 255 | Port port = (Port) TableGenerator.getTable(dbSchema, portRow, |
268 | OvsdbTable.PORT); | 256 | OvsdbTable.PORT); |
269 | if (port != null && portName.equalsIgnoreCase(port.getName())) { | 257 | if (port != null && portName.equalsIgnoreCase(port.getName())) { |
270 | return uuid.value(); | 258 | return uuid.value(); |
271 | } | 259 | } |
272 | } | 260 | } |
273 | - | ||
274 | } | 261 | } |
275 | return null; | 262 | return null; |
276 | } | 263 | } |
277 | 264 | ||
278 | @Override | 265 | @Override |
279 | public String getInterfaceUuid(String portUuid, String portName) { | 266 | public String getInterfaceUuid(String portUuid, String portName) { |
280 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 267 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
281 | 268 | ||
282 | - Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT, | 269 | + Row portRow = getRow(DATABASENAME, PORT, portUuid); |
283 | - portUuid); | 270 | + Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT); |
284 | - Port port = (Port) TableGenerator.getTable(dbSchema, portRow, | ||
285 | - OvsdbTable.PORT); | ||
286 | 271 | ||
287 | if (port != null) { | 272 | if (port != null) { |
288 | OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data(); | 273 | OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data(); |
... | @@ -295,26 +280,22 @@ public class DefaultOvsdbClient | ... | @@ -295,26 +280,22 @@ public class DefaultOvsdbClient |
295 | } | 280 | } |
296 | 281 | ||
297 | for (Uuid uuid : interfaces) { | 282 | for (Uuid uuid : interfaces) { |
298 | - Row intfRow = getRow(OvsdbConstant.DATABASENAME, | 283 | + Row intfRow = getRow(DATABASENAME, INTERFACE, uuid.value()); |
299 | - OvsdbConstant.INTERFACE, uuid.value()); | ||
300 | Interface intf = (Interface) TableGenerator | 284 | Interface intf = (Interface) TableGenerator |
301 | .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); | 285 | .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); |
302 | if (intf != null && portName.equalsIgnoreCase(intf.getName())) { | 286 | if (intf != null && portName.equalsIgnoreCase(intf.getName())) { |
303 | return uuid.value(); | 287 | return uuid.value(); |
304 | } | 288 | } |
305 | } | 289 | } |
306 | - | ||
307 | } | 290 | } |
308 | - | ||
309 | return null; | 291 | return null; |
310 | } | 292 | } |
311 | 293 | ||
312 | @Override | 294 | @Override |
313 | public String getBridgeUuid(String bridgeName) { | 295 | public String getBridgeUuid(String bridgeName) { |
314 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 296 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
315 | 297 | ||
316 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | 298 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE); |
317 | - OvsdbConstant.BRIDGE); | ||
318 | if (rowStore == null) { | 299 | if (rowStore == null) { |
319 | log.debug("The bridge uuid is null"); | 300 | log.debug("The bridge uuid is null"); |
320 | return null; | 301 | return null; |
... | @@ -328,23 +309,18 @@ public class DefaultOvsdbClient | ... | @@ -328,23 +309,18 @@ public class DefaultOvsdbClient |
328 | 309 | ||
329 | for (String uuid : bridgeTableRows.keySet()) { | 310 | for (String uuid : bridgeTableRows.keySet()) { |
330 | Bridge bridge = (Bridge) TableGenerator | 311 | Bridge bridge = (Bridge) TableGenerator |
331 | - .getTable(dbSchema, bridgeTableRows.get(uuid), | 312 | + .getTable(dbSchema, bridgeTableRows.get(uuid), OvsdbTable.BRIDGE); |
332 | - OvsdbTable.BRIDGE); | ||
333 | - | ||
334 | if (bridge.getName().equals(bridgeName)) { | 313 | if (bridge.getName().equals(bridgeName)) { |
335 | return uuid; | 314 | return uuid; |
336 | } | 315 | } |
337 | - | ||
338 | } | 316 | } |
339 | return null; | 317 | return null; |
340 | } | 318 | } |
341 | 319 | ||
342 | @Override | 320 | @Override |
343 | - public String getControllerUuid(String controllerName, | 321 | + public String getControllerUuid(String controllerName, String controllerTarget) { |
344 | - String controllerTarget) { | 322 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
345 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 323 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, CONTROLLER); |
346 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | ||
347 | - OvsdbConstant.CONTROLLER); | ||
348 | if (rowStore == null) { | 324 | if (rowStore == null) { |
349 | log.debug("The controller uuid is null"); | 325 | log.debug("The controller uuid is null"); |
350 | return null; | 326 | return null; |
... | @@ -353,7 +329,6 @@ public class DefaultOvsdbClient | ... | @@ -353,7 +329,6 @@ public class DefaultOvsdbClient |
353 | ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore(); | 329 | ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore(); |
354 | if (controllerTableRows != null) { | 330 | if (controllerTableRows != null) { |
355 | for (String uuid : controllerTableRows.keySet()) { | 331 | for (String uuid : controllerTableRows.keySet()) { |
356 | - | ||
357 | Controller controller = (Controller) TableGenerator | 332 | Controller controller = (Controller) TableGenerator |
358 | .getTable(dbSchema, controllerTableRows.get(uuid), | 333 | .getTable(dbSchema, controllerTableRows.get(uuid), |
359 | OvsdbTable.CONTROLLER); | 334 | OvsdbTable.CONTROLLER); |
... | @@ -361,7 +336,6 @@ public class DefaultOvsdbClient | ... | @@ -361,7 +336,6 @@ public class DefaultOvsdbClient |
361 | if (target.equalsIgnoreCase(controllerTarget)) { | 336 | if (target.equalsIgnoreCase(controllerTarget)) { |
362 | return uuid; | 337 | return uuid; |
363 | } | 338 | } |
364 | - | ||
365 | } | 339 | } |
366 | } | 340 | } |
367 | return null; | 341 | return null; |
... | @@ -369,8 +343,7 @@ public class DefaultOvsdbClient | ... | @@ -369,8 +343,7 @@ public class DefaultOvsdbClient |
369 | 343 | ||
370 | @Override | 344 | @Override |
371 | public String getOvsUuid(String dbName) { | 345 | public String getOvsUuid(String dbName) { |
372 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | 346 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, DATABASENAME); |
373 | - OvsdbConstant.DATABASENAME); | ||
374 | if (rowStore == null) { | 347 | if (rowStore == null) { |
375 | log.debug("The bridge uuid is null"); | 348 | log.debug("The bridge uuid is null"); |
376 | return null; | 349 | return null; |
... | @@ -392,26 +365,19 @@ public class DefaultOvsdbClient | ... | @@ -392,26 +365,19 @@ public class DefaultOvsdbClient |
392 | public void createPort(String bridgeName, String portName) { | 365 | public void createPort(String bridgeName, String portName) { |
393 | String bridgeUuid = getBridgeUuid(bridgeName); | 366 | String bridgeUuid = getBridgeUuid(bridgeName); |
394 | if (bridgeUuid == null) { | 367 | if (bridgeUuid == null) { |
395 | - log.error("Can't find bridge {} in {}", bridgeName, | 368 | + log.error("Can't find bridge {} in {}", bridgeName, nodeId.getIpAddress()); |
396 | - nodeId.getIpAddress()); | ||
397 | return; | 369 | return; |
398 | } | 370 | } |
399 | 371 | ||
400 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 372 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
401 | String portUuid = getPortUuid(portName, bridgeUuid); | 373 | String portUuid = getPortUuid(portName, bridgeUuid); |
402 | - | 374 | + Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT); |
403 | - Port port = (Port) TableGenerator | ||
404 | - .createTable(dbSchema, OvsdbTable.PORT); | ||
405 | - | ||
406 | port.setName(portName); | 375 | port.setName(portName); |
407 | if (portUuid == null) { | 376 | if (portUuid == null) { |
408 | - insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE, | 377 | + insertConfig(PORT, UUID, BRIDGE, PORTS, bridgeUuid, port.getRow()); |
409 | - "ports", bridgeUuid, port.getRow()); | ||
410 | } else { | 378 | } else { |
411 | - updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow()); | 379 | + updateConfig(PORT, UUID, portUuid, port.getRow()); |
412 | } | 380 | } |
413 | - | ||
414 | - return; | ||
415 | } | 381 | } |
416 | 382 | ||
417 | @Override | 383 | @Override |
... | @@ -425,220 +391,103 @@ public class DefaultOvsdbClient | ... | @@ -425,220 +391,103 @@ public class DefaultOvsdbClient |
425 | String portUuid = getPortUuid(portName, bridgeUuid); | 391 | String portUuid = getPortUuid(portName, bridgeUuid); |
426 | if (portUuid != null) { | 392 | if (portUuid != null) { |
427 | log.info("Port {} delete", portName); | 393 | log.info("Port {} delete", portName); |
428 | - deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid, | 394 | + deleteConfig(PORT, UUID, portUuid, BRIDGE, PORTS); |
429 | - OvsdbConstant.BRIDGE, "ports"); | ||
430 | } | 395 | } |
431 | } | 396 | } |
432 | 397 | ||
398 | + @Deprecated | ||
433 | @Override | 399 | @Override |
434 | public void createBridge(String bridgeName) { | 400 | public void createBridge(String bridgeName) { |
435 | - log.debug("create bridge {}", bridgeName); | 401 | + OvsdbBridge ovsdbBridge = OvsdbBridge.builder() |
436 | - | 402 | + .name(bridgeName) |
437 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 403 | + .build(); |
438 | - if (dbSchema == null) { | ||
439 | - log.warn("The schema is null"); | ||
440 | - return; | ||
441 | - } | ||
442 | - | ||
443 | - Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, | ||
444 | - OvsdbTable.BRIDGE); | ||
445 | - if (bridge == null) { | ||
446 | - log.debug("Can not create bridge"); | ||
447 | - return; | ||
448 | - } | ||
449 | - | ||
450 | - Set<String> failModes = new HashSet<>(); | ||
451 | - failModes.add("secure"); | ||
452 | - bridge.setFailMode(failModes); | ||
453 | - | ||
454 | - Set<String> protocols = new HashSet<>(); | ||
455 | - protocols.add(OvsdbConstant.OPENFLOW13); | ||
456 | - bridge.setProtocols(protocols); | ||
457 | - | ||
458 | - String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); | ||
459 | - if (ovsUuid == null) { | ||
460 | - log.warn("The Open_vSwitch is null"); | ||
461 | - return; | ||
462 | - } | ||
463 | - | ||
464 | - Map<String, String> options = new HashMap<>(); | ||
465 | - options.put("disable-in-band", "true"); | ||
466 | - bridge.setOtherConfig(options); | ||
467 | 404 | ||
468 | - String bridgeUuid = getBridgeUuid(bridgeName); | 405 | + createBridge(ovsdbBridge); |
469 | - if (bridgeUuid == null) { | ||
470 | - log.debug("Create a new bridge"); | ||
471 | - | ||
472 | - bridge.setName(bridgeName); | ||
473 | - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", | ||
474 | - OvsdbConstant.DATABASENAME, "bridges", | ||
475 | - ovsUuid, bridge.getRow()); | ||
476 | - | ||
477 | - if (bridgeUuid != null) { | ||
478 | - Port port = (Port) TableGenerator.createTable(dbSchema, | ||
479 | - OvsdbTable.PORT); | ||
480 | - if (port != null) { | ||
481 | - log.debug("the port is not null"); | ||
482 | - port.setName(bridgeName); | ||
483 | - | ||
484 | - insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, | ||
485 | - port.getRow()); | ||
486 | - } | ||
487 | - } else { | ||
488 | - String message = BridgeCreateException.createMessage(ovsUuid); | ||
489 | - throw new BridgeCreateException(message); | ||
490 | - } | ||
491 | - | ||
492 | - } else { | ||
493 | - log.info("Update a bridge"); | ||
494 | - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); | ||
495 | - } | ||
496 | - | ||
497 | - setControllerAuto(bridgeUuid); | ||
498 | - log.info("Create bridge success"); | ||
499 | } | 406 | } |
500 | 407 | ||
408 | + @Deprecated | ||
501 | @Override | 409 | @Override |
502 | public void createBridge(String bridgeName, String dpid, String exPortName) { | 410 | public void createBridge(String bridgeName, String dpid, String exPortName) { |
503 | - log.debug("create bridge {}", bridgeName); | 411 | + OvsdbBridge ovsdbBridge = OvsdbBridge.builder() |
504 | - | 412 | + .name(bridgeName) |
505 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 413 | + .failMode(BridgeDescription.FailMode.SECURE) |
506 | - if (dbSchema == null) { | 414 | + .datapathId(dpid) |
507 | - log.warn("The schema is null"); | 415 | + .disableInBand() |
508 | - return; | 416 | + .controllers(Lists.newArrayList(localController())) |
509 | - } | 417 | + .build(); |
510 | - | ||
511 | - Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, | ||
512 | - OvsdbTable.BRIDGE); | ||
513 | - if (bridge == null) { | ||
514 | - log.debug("Can not create bridge"); | ||
515 | - return; | ||
516 | - } | ||
517 | - | ||
518 | - Set<String> failModes = new HashSet<>(); | ||
519 | - failModes.add("secure"); | ||
520 | - bridge.setFailMode(failModes); | ||
521 | - | ||
522 | - Set<String> protocols = new HashSet<>(); | ||
523 | - protocols.add(OvsdbConstant.OPENFLOW13); | ||
524 | - bridge.setProtocols(protocols); | ||
525 | - | ||
526 | - String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); | ||
527 | - if (ovsUuid == null) { | ||
528 | - log.warn("The Open_vSwitch is null"); | ||
529 | - return; | ||
530 | - } | ||
531 | - | ||
532 | - Map<String, String> options = new HashMap<>(); | ||
533 | - options.put("disable-in-band", "true"); | ||
534 | - if (dpid != null) { | ||
535 | - options.put("datapath-id", dpid); | ||
536 | - } | ||
537 | - bridge.setOtherConfig(options); | ||
538 | 418 | ||
539 | - String bridgeUuid = getBridgeUuid(bridgeName); | 419 | + createBridge(ovsdbBridge); |
540 | - if (bridgeUuid == null) { | ||
541 | - log.debug("Create a new bridge"); | ||
542 | - | ||
543 | - bridge.setName(bridgeName); | ||
544 | - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", | ||
545 | - OvsdbConstant.DATABASENAME, "bridges", | ||
546 | - ovsUuid, bridge.getRow()); | ||
547 | 420 | ||
548 | - if (bridgeUuid != null) { | ||
549 | - Port port = (Port) TableGenerator.createTable(dbSchema, | ||
550 | - OvsdbTable.PORT); | ||
551 | - if (port != null) { | ||
552 | - log.debug("the port is not null"); | ||
553 | - port.setName(bridgeName); | ||
554 | - | ||
555 | - insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, | ||
556 | - port.getRow()); | ||
557 | - } | ||
558 | - } else { | ||
559 | - String message = BridgeCreateException.createMessage(ovsUuid); | ||
560 | - throw new BridgeCreateException(message); | ||
561 | - } | ||
562 | - | ||
563 | - } else { | ||
564 | - log.info("Update a bridge"); | ||
565 | - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); | ||
566 | - } | ||
567 | - // Create external port | ||
568 | if (exPortName != null) { | 421 | if (exPortName != null) { |
569 | createPort(bridgeName, exPortName); | 422 | createPort(bridgeName, exPortName); |
570 | } | 423 | } |
571 | - | ||
572 | - setControllerAuto(bridgeUuid); | ||
573 | - log.info("Create bridge success"); | ||
574 | } | 424 | } |
575 | 425 | ||
426 | + @Deprecated | ||
576 | @Override | 427 | @Override |
577 | public boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers) { | 428 | public boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers) { |
429 | + OvsdbBridge ovsdbBridge = OvsdbBridge.builder() | ||
430 | + .name(bridgeName) | ||
431 | + .failMode(BridgeDescription.FailMode.SECURE) | ||
432 | + .datapathId(dpid) | ||
433 | + .disableInBand() | ||
434 | + .controllers(controllers) | ||
435 | + .build(); | ||
578 | 436 | ||
579 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 437 | + return createBridge(ovsdbBridge); |
580 | - String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); | 438 | + } |
439 | + | ||
440 | + @Override | ||
441 | + public boolean createBridge(OvsdbBridge ovsdbBridge) { | ||
442 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); | ||
443 | + String ovsUuid = getOvsUuid(DATABASENAME); | ||
581 | 444 | ||
582 | if (dbSchema == null || ovsUuid == null) { | 445 | if (dbSchema == null || ovsUuid == null) { |
583 | - log.warn("Couldn't find database Open_vSwitch"); | 446 | + log.error("Can't find database Open_vSwitch"); |
584 | return false; | 447 | return false; |
585 | } | 448 | } |
586 | 449 | ||
587 | Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE); | 450 | Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE); |
588 | - Set<String> failMode = new HashSet<>(Arrays.asList("secure")); | 451 | + bridge.setOtherConfig(ovsdbBridge.otherConfigs()); |
589 | - bridge.setFailMode(failMode); | ||
590 | - | ||
591 | - Set<String> protocols = new HashSet<>(Arrays.asList(OvsdbConstant.OPENFLOW13)); | ||
592 | - bridge.setProtocols(protocols); | ||
593 | 452 | ||
594 | - Map<String, String> options = new HashMap<>(); | 453 | + if (ovsdbBridge.failMode().isPresent()) { |
595 | - options.put("disable-in-band", "true"); | 454 | + String failMode = ovsdbBridge.failMode().get().name().toLowerCase(); |
596 | - if (dpid != null) { | 455 | + bridge.setFailMode(Sets.newHashSet(failMode)); |
597 | - options.put("datapath-id", dpid); | ||
598 | } | 456 | } |
599 | - bridge.setOtherConfig(options); | ||
600 | 457 | ||
601 | - String bridgeUuid = getBridgeUuid(bridgeName); | 458 | + String bridgeUuid = getBridgeUuid(ovsdbBridge.name()); |
602 | if (bridgeUuid == null) { | 459 | if (bridgeUuid == null) { |
603 | - bridge.setName(bridgeName); | 460 | + bridge.setName(ovsdbBridge.name()); |
604 | - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", | 461 | + bridgeUuid = insertConfig( |
605 | - OvsdbConstant.DATABASENAME, "bridges", | 462 | + BRIDGE, UUID, DATABASENAME, BRIDGES, |
606 | ovsUuid, bridge.getRow()); | 463 | ovsUuid, bridge.getRow()); |
607 | } else { | 464 | } else { |
608 | - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); | 465 | + // update the bridge if it's already existing |
466 | + updateConfig(BRIDGE, UUID, bridgeUuid, bridge.getRow()); | ||
609 | } | 467 | } |
610 | 468 | ||
611 | - if (bridgeUuid != null) { | 469 | + if (bridgeUuid == null) { |
612 | - createPort(bridgeName, bridgeName); | 470 | + log.warn("Failed to create bridge {} on {}", ovsdbBridge.name(), nodeId); |
613 | - } else { | ||
614 | - log.warn("Failed to create bridge {} on {}", bridgeName, nodeId.toString()); | ||
615 | return false; | 471 | return false; |
616 | } | 472 | } |
617 | 473 | ||
618 | - setControllersWithUuid(Uuid.uuid(bridgeUuid), controllers); | 474 | + createPort(ovsdbBridge.name(), ovsdbBridge.name()); |
475 | + setControllersWithUuid(Uuid.uuid(bridgeUuid), ovsdbBridge.controllers()); | ||
476 | + | ||
477 | + log.info("Created bridge {}", ovsdbBridge.name()); | ||
619 | return true; | 478 | return true; |
620 | } | 479 | } |
621 | 480 | ||
622 | - /** | 481 | + @Override |
623 | - * Sets the bridge's controller automatically. | 482 | + public ControllerInfo localController() { |
624 | - * <p/> | 483 | + IpAddress ipAddress = IpAddress.valueOf(((InetSocketAddress) |
625 | - * The connection is a TCP connection to the local ONOS instance's IP | 484 | + channel.localAddress()).getAddress()); |
626 | - * and the default OpenFlow port. | 485 | + return new ControllerInfo(ipAddress, OFPORT, "tcp"); |
627 | - * | ||
628 | - * @param bridgeUuid bridge uuid | ||
629 | - */ | ||
630 | - private void setControllerAuto(String bridgeUuid) { | ||
631 | - IpAddress ipAddress = IpAddress.valueOf(((InetSocketAddress) channel.localAddress()).getAddress()); | ||
632 | - ControllerInfo controllerInfo = new ControllerInfo(ipAddress, OvsdbConstant.OFPORT, "tcp"); | ||
633 | - log.debug("Automatically setting controller for bridge {} to {}", | ||
634 | - bridgeUuid, controllerInfo.target()); | ||
635 | - setControllersWithUuid(Uuid.uuid(bridgeUuid), ImmutableList.of(controllerInfo)); | ||
636 | } | 486 | } |
637 | 487 | ||
638 | @Override | 488 | @Override |
639 | public void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) { | 489 | public void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) { |
640 | - | 490 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
641 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | ||
642 | if (dbSchema == null) { | 491 | if (dbSchema == null) { |
643 | log.debug("There is no schema"); | 492 | log.debug("There is no schema"); |
644 | return; | 493 | return; |
... | @@ -662,31 +511,27 @@ public class DefaultOvsdbClient | ... | @@ -662,31 +511,27 @@ public class DefaultOvsdbClient |
662 | removeControllers.add(controller); | 511 | removeControllers.add(controller); |
663 | } | 512 | } |
664 | }); | 513 | }); |
665 | - OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME, | 514 | + OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER); |
666 | - OvsdbConstant.CONTROLLER); | ||
667 | if (controllerRowStore == null) { | 515 | if (controllerRowStore == null) { |
668 | log.debug("There is no controller table"); | 516 | log.debug("There is no controller table"); |
669 | return; | 517 | return; |
670 | } | 518 | } |
671 | 519 | ||
672 | - removeControllers.forEach(c -> deleteConfig(OvsdbConstant.CONTROLLER, "_uuid", c.getRow().uuid().value(), | 520 | + removeControllers.forEach(c -> deleteConfig(CONTROLLER, UUID, c.getRow().uuid().value(), |
673 | - OvsdbConstant.BRIDGE, "controller")); | 521 | + BRIDGE, "controller")); |
674 | - | ||
675 | newControllers.stream().map(c -> { | 522 | newControllers.stream().map(c -> { |
676 | Controller controller = (Controller) TableGenerator | 523 | Controller controller = (Controller) TableGenerator |
677 | .createTable(dbSchema, OvsdbTable.CONTROLLER); | 524 | .createTable(dbSchema, OvsdbTable.CONTROLLER); |
678 | controller.setTarget(c.target()); | 525 | controller.setTarget(c.target()); |
679 | return controller; | 526 | return controller; |
680 | }).forEach(c -> { | 527 | }).forEach(c -> { |
681 | - String uuid = insertConfig(OvsdbConstant.CONTROLLER, "_uuid", | 528 | + String uuid = insertConfig(CONTROLLER, UUID, BRIDGE, "controller", bridgeUuid.value(), |
682 | - OvsdbConstant.BRIDGE, "controller", bridgeUuid.value(), | ||
683 | c.getRow()); | 529 | c.getRow()); |
684 | newControllerUuids.add(Uuid.uuid(uuid)); | 530 | newControllerUuids.add(Uuid.uuid(uuid)); |
685 | 531 | ||
686 | }); | 532 | }); |
687 | 533 | ||
688 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | 534 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE); |
689 | - OvsdbConstant.BRIDGE); | ||
690 | if (rowStore == null) { | 535 | if (rowStore == null) { |
691 | log.debug("There is no bridge table"); | 536 | log.debug("There is no bridge table"); |
692 | return; | 537 | return; |
... | @@ -695,7 +540,7 @@ public class DefaultOvsdbClient | ... | @@ -695,7 +540,7 @@ public class DefaultOvsdbClient |
695 | Row bridgeRow = rowStore.getRow(bridgeUuid.value()); | 540 | Row bridgeRow = rowStore.getRow(bridgeUuid.value()); |
696 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE); | 541 | Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE); |
697 | bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids)); | 542 | bridge.setController(OvsdbSet.ovsdbSet(newControllerUuids)); |
698 | - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid.value(), bridge.getRow()); | 543 | + updateConfig(BRIDGE, UUID, bridgeUuid.value(), bridge.getRow()); |
699 | } | 544 | } |
700 | 545 | ||
701 | @Override | 546 | @Override |
... | @@ -710,13 +555,11 @@ public class DefaultOvsdbClient | ... | @@ -710,13 +555,11 @@ public class DefaultOvsdbClient |
710 | log.warn("Could not find bridge in node", nodeId.getIpAddress()); | 555 | log.warn("Could not find bridge in node", nodeId.getIpAddress()); |
711 | return; | 556 | return; |
712 | } | 557 | } |
713 | - deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, | 558 | + deleteConfig(BRIDGE, UUID, bridgeUuid, DATABASENAME, "bridges"); |
714 | - OvsdbConstant.DATABASENAME, "bridges"); | ||
715 | } | 559 | } |
716 | 560 | ||
717 | @Override | 561 | @Override |
718 | public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) { | 562 | public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) { |
719 | - | ||
720 | String bridgeUuid = getBridgeUuid(bridgeName); | 563 | String bridgeUuid = getBridgeUuid(bridgeName); |
721 | if (bridgeUuid == null) { | 564 | if (bridgeUuid == null) { |
722 | log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress()); | 565 | log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress()); |
... | @@ -730,7 +573,7 @@ public class DefaultOvsdbClient | ... | @@ -730,7 +573,7 @@ public class DefaultOvsdbClient |
730 | } | 573 | } |
731 | 574 | ||
732 | ArrayList<Operation> operations = Lists.newArrayList(); | 575 | ArrayList<Operation> operations = Lists.newArrayList(); |
733 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 576 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
734 | 577 | ||
735 | // insert a new port to the port table | 578 | // insert a new port to the port table |
736 | Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT); | 579 | Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT); |
... | @@ -740,8 +583,8 @@ public class DefaultOvsdbClient | ... | @@ -740,8 +583,8 @@ public class DefaultOvsdbClient |
740 | operations.add(portInsert); | 583 | operations.add(portInsert); |
741 | 584 | ||
742 | // update the bridge table | 585 | // update the bridge table |
743 | - Condition condition = ConditionUtil.isEqual("_uuid", Uuid.uuid(bridgeUuid)); | 586 | + Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid)); |
744 | - Mutation mutation = MutationUtil.insert("ports", Uuid.uuid("Port")); | 587 | + Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid("Port")); |
745 | List<Condition> conditions = new ArrayList<>(Arrays.asList(condition)); | 588 | List<Condition> conditions = new ArrayList<>(Arrays.asList(condition)); |
746 | List<Mutation> mutations = new ArrayList<>(Arrays.asList(mutation)); | 589 | List<Mutation> mutations = new ArrayList<>(Arrays.asList(mutation)); |
747 | operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations)); | 590 | operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations)); |
... | @@ -754,15 +597,15 @@ public class DefaultOvsdbClient | ... | @@ -754,15 +597,15 @@ public class DefaultOvsdbClient |
754 | Insert intfInsert = new Insert(dbSchema.getTableSchema("Interface"), "Interface", intf.getRow()); | 597 | Insert intfInsert = new Insert(dbSchema.getTableSchema("Interface"), "Interface", intf.getRow()); |
755 | operations.add(intfInsert); | 598 | operations.add(intfInsert); |
756 | 599 | ||
757 | - transactConfig(OvsdbConstant.DATABASENAME, operations); | 600 | + transactConfig(DATABASENAME, operations); |
758 | return true; | 601 | return true; |
759 | } | 602 | } |
760 | 603 | ||
761 | @Override | 604 | @Override |
762 | public void dropTunnel(IpAddress srcIp, IpAddress dstIp) { | 605 | public void dropTunnel(IpAddress srcIp, IpAddress dstIp) { |
763 | - String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE; | 606 | + String bridgeName = INTEGRATION_BRIDGE; |
764 | - String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp); | 607 | + String portName = getTunnelName(TYPEVXLAN, dstIp); |
765 | - String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); | 608 | + String bridgeUuid = getBridgeUuid(INTEGRATION_BRIDGE); |
766 | if (bridgeUuid == null) { | 609 | if (bridgeUuid == null) { |
767 | log.warn("Could not find bridge {} in {}", bridgeName, | 610 | log.warn("Could not find bridge {} in {}", bridgeName, |
768 | nodeId.getIpAddress()); | 611 | nodeId.getIpAddress()); |
... | @@ -772,11 +615,8 @@ public class DefaultOvsdbClient | ... | @@ -772,11 +615,8 @@ public class DefaultOvsdbClient |
772 | String portUuid = getPortUuid(portName, bridgeUuid); | 615 | String portUuid = getPortUuid(portName, bridgeUuid); |
773 | if (portUuid != null) { | 616 | if (portUuid != null) { |
774 | log.info("Delete tunnel"); | 617 | log.info("Delete tunnel"); |
775 | - deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid, | 618 | + deleteConfig(PORT, UUID, portUuid, BRIDGE, PORTS); |
776 | - OvsdbConstant.BRIDGE, "ports"); | ||
777 | } | 619 | } |
778 | - | ||
779 | - return; | ||
780 | } | 620 | } |
781 | 621 | ||
782 | /** | 622 | /** |
... | @@ -791,7 +631,7 @@ public class DefaultOvsdbClient | ... | @@ -791,7 +631,7 @@ public class DefaultOvsdbClient |
791 | private void deleteConfig(String childTableName, String childColumnName, | 631 | private void deleteConfig(String childTableName, String childColumnName, |
792 | String childUuid, String parentTableName, | 632 | String childUuid, String parentTableName, |
793 | String parentColumnName) { | 633 | String parentColumnName) { |
794 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 634 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
795 | TableSchema childTableSchema = dbSchema.getTableSchema(childTableName); | 635 | TableSchema childTableSchema = dbSchema.getTableSchema(childTableName); |
796 | 636 | ||
797 | ArrayList<Operation> operations = Lists.newArrayList(); | 637 | ArrayList<Operation> operations = Lists.newArrayList(); |
... | @@ -817,9 +657,7 @@ public class DefaultOvsdbClient | ... | @@ -817,9 +657,7 @@ public class DefaultOvsdbClient |
817 | conditions.add(condition); | 657 | conditions.add(condition); |
818 | Delete del = new Delete(childTableSchema, conditions); | 658 | Delete del = new Delete(childTableSchema, conditions); |
819 | operations.add(del); | 659 | operations.add(del); |
820 | - transactConfig(OvsdbConstant.DATABASENAME, operations); | 660 | + transactConfig(DATABASENAME, operations); |
821 | - | ||
822 | - return; | ||
823 | } | 661 | } |
824 | 662 | ||
825 | /** | 663 | /** |
... | @@ -832,7 +670,7 @@ public class DefaultOvsdbClient | ... | @@ -832,7 +670,7 @@ public class DefaultOvsdbClient |
832 | */ | 670 | */ |
833 | private void updateConfig(String tableName, String columnName, String uuid, | 671 | private void updateConfig(String tableName, String columnName, String uuid, |
834 | Row row) { | 672 | Row row) { |
835 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 673 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
836 | TableSchema tableSchema = dbSchema.getTableSchema(tableName); | 674 | TableSchema tableSchema = dbSchema.getTableSchema(tableName); |
837 | 675 | ||
838 | List<Condition> conditions = Lists.newArrayList(); | 676 | List<Condition> conditions = Lists.newArrayList(); |
... | @@ -844,7 +682,7 @@ public class DefaultOvsdbClient | ... | @@ -844,7 +682,7 @@ public class DefaultOvsdbClient |
844 | ArrayList<Operation> operations = Lists.newArrayList(); | 682 | ArrayList<Operation> operations = Lists.newArrayList(); |
845 | operations.add(update); | 683 | operations.add(update); |
846 | 684 | ||
847 | - transactConfig(OvsdbConstant.DATABASENAME, operations); | 685 | + transactConfig(DATABASENAME, operations); |
848 | } | 686 | } |
849 | 687 | ||
850 | /** | 688 | /** |
... | @@ -861,7 +699,7 @@ public class DefaultOvsdbClient | ... | @@ -861,7 +699,7 @@ public class DefaultOvsdbClient |
861 | private String insertConfig(String childTableName, String childColumnName, | 699 | private String insertConfig(String childTableName, String childColumnName, |
862 | String parentTableName, String parentColumnName, | 700 | String parentTableName, String parentColumnName, |
863 | String parentUuid, Row row) { | 701 | String parentUuid, Row row) { |
864 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 702 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
865 | TableSchema tableSchema = dbSchema.getTableSchema(childTableName); | 703 | TableSchema tableSchema = dbSchema.getTableSchema(childTableName); |
866 | 704 | ||
867 | Insert insert = new Insert(tableSchema, childTableName, row); | 705 | Insert insert = new Insert(tableSchema, childTableName, row); |
... | @@ -881,32 +719,27 @@ public class DefaultOvsdbClient | ... | @@ -881,32 +719,27 @@ public class DefaultOvsdbClient |
881 | mutations.add(mutation); | 719 | mutations.add(mutation); |
882 | 720 | ||
883 | List<Condition> conditions = Lists.newArrayList(); | 721 | List<Condition> conditions = Lists.newArrayList(); |
884 | - Condition condition = ConditionUtil.isEqual("_uuid", | 722 | + Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(parentUuid)); |
885 | - Uuid.uuid(parentUuid)); | ||
886 | conditions.add(condition); | 723 | conditions.add(condition); |
887 | 724 | ||
888 | Mutate op = new Mutate(parentTableSchema, conditions, mutations); | 725 | Mutate op = new Mutate(parentTableSchema, conditions, mutations); |
889 | operations.add(op); | 726 | operations.add(op); |
890 | } | 727 | } |
891 | - if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) { | 728 | + if (childTableName.equalsIgnoreCase(PORT)) { |
892 | - log.info("Handle port insert"); | 729 | + log.debug("Handle port insert"); |
893 | - Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE, | 730 | + Insert intfInsert = handlePortInsertTable(INTERFACE, row); |
894 | - row); | ||
895 | 731 | ||
896 | if (intfInsert != null) { | 732 | if (intfInsert != null) { |
897 | operations.add(intfInsert); | 733 | operations.add(intfInsert); |
898 | } | 734 | } |
899 | 735 | ||
900 | Insert ins = (Insert) operations.get(0); | 736 | Insert ins = (Insert) operations.get(0); |
901 | - ins.getRow().put("interfaces", | 737 | + ins.getRow().put("interfaces", Uuid.uuid(INTERFACE)); |
902 | - Uuid.uuid(OvsdbConstant.INTERFACE)); | ||
903 | } | 738 | } |
904 | 739 | ||
905 | List<OperationResult> results; | 740 | List<OperationResult> results; |
906 | try { | 741 | try { |
907 | - results = transactConfig(OvsdbConstant.DATABASENAME, operations) | 742 | + results = transactConfig(DATABASENAME, operations).get(); |
908 | - .get(); | ||
909 | - | ||
910 | return results.get(0).getUuid().value(); | 743 | return results.get(0).getUuid().value(); |
911 | } catch (InterruptedException e) { | 744 | } catch (InterruptedException e) { |
912 | log.warn("Interrupted while waiting to get result"); | 745 | log.warn("Interrupted while waiting to get result"); |
... | @@ -926,30 +759,23 @@ public class DefaultOvsdbClient | ... | @@ -926,30 +759,23 @@ public class DefaultOvsdbClient |
926 | * @return insert, empty if null | 759 | * @return insert, empty if null |
927 | */ | 760 | */ |
928 | private Insert handlePortInsertTable(String tableName, Row portRow) { | 761 | private Insert handlePortInsertTable(String tableName, Row portRow) { |
929 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 762 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
930 | 763 | ||
931 | - TableSchema portTableSchema = dbSchema | 764 | + TableSchema portTableSchema = dbSchema.getTableSchema(PORT); |
932 | - .getTableSchema(OvsdbConstant.PORT); | ||
933 | ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name"); | 765 | ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name"); |
934 | 766 | ||
935 | String portName = (String) portRow.getColumn(portColumnSchema.name()).data(); | 767 | String portName = (String) portRow.getColumn(portColumnSchema.name()).data(); |
936 | - | 768 | + Interface inf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE); |
937 | - Interface inf = (Interface) TableGenerator | ||
938 | - .createTable(dbSchema, OvsdbTable.INTERFACE); | ||
939 | - | ||
940 | inf.setName(portName); | 769 | inf.setName(portName); |
941 | 770 | ||
942 | - TableSchema intfTableSchema = dbSchema | 771 | + TableSchema intfTableSchema = dbSchema.getTableSchema(INTERFACE); |
943 | - .getTableSchema(OvsdbConstant.INTERFACE); | 772 | + return new Insert(intfTableSchema, INTERFACE, inf.getRow()); |
944 | - Insert insert = new Insert(intfTableSchema, OvsdbConstant.INTERFACE, | ||
945 | - inf.getRow()); | ||
946 | - return insert; | ||
947 | } | 773 | } |
948 | 774 | ||
949 | /** | 775 | /** |
950 | * Gets tunnel name. | 776 | * Gets tunnel name. |
951 | * | 777 | * |
952 | - * @param tunnelType | 778 | + * @param tunnelType tunnel type |
953 | * @param dstIp the remote ip address | 779 | * @param dstIp the remote ip address |
954 | * @return tunnel name | 780 | * @return tunnel name |
955 | */ | 781 | */ |
... | @@ -966,20 +792,15 @@ public class DefaultOvsdbClient | ... | @@ -966,20 +792,15 @@ public class DefaultOvsdbClient |
966 | if (databaseSchema == null) { | 792 | if (databaseSchema == null) { |
967 | List<String> dbNames = new ArrayList<String>(); | 793 | List<String> dbNames = new ArrayList<String>(); |
968 | dbNames.add(dbName); | 794 | dbNames.add(dbName); |
969 | - Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() { | 795 | + Function<JsonNode, DatabaseSchema> rowFunction = input -> { |
970 | - @Override | 796 | + log.debug("Get ovsdb database schema {}", dbName); |
971 | - public DatabaseSchema apply(JsonNode input) { | 797 | + DatabaseSchema dbSchema = FromJsonUtil.jsonNodeToDbSchema(dbName, input); |
972 | - log.info("Get ovsdb database schema {}", dbName); | ||
973 | - DatabaseSchema dbSchema = FromJsonUtil | ||
974 | - .jsonNodeToDbSchema(dbName, input); | ||
975 | if (dbSchema == null) { | 798 | if (dbSchema == null) { |
976 | log.debug("Get ovsdb database schema error"); | 799 | log.debug("Get ovsdb database schema error"); |
977 | return null; | 800 | return null; |
978 | } | 801 | } |
979 | schema.put(dbName, dbSchema); | 802 | schema.put(dbName, dbSchema); |
980 | - | ||
981 | return dbSchema; | 803 | return dbSchema; |
982 | - } | ||
983 | }; | 804 | }; |
984 | 805 | ||
985 | ListenableFuture<JsonNode> input = getSchema(dbNames); | 806 | ListenableFuture<JsonNode> input = getSchema(dbNames); |
... | @@ -999,18 +820,14 @@ public class DefaultOvsdbClient | ... | @@ -999,18 +820,14 @@ public class DefaultOvsdbClient |
999 | } | 820 | } |
1000 | DatabaseSchema dbSchema = schema.get(dbName); | 821 | DatabaseSchema dbSchema = schema.get(dbName); |
1001 | if (dbSchema != null) { | 822 | if (dbSchema != null) { |
1002 | - Function<JsonNode, TableUpdates> rowFunction = new Function<JsonNode, TableUpdates>() { | 823 | + Function<JsonNode, TableUpdates> rowFunction = input -> { |
1003 | - @Override | 824 | + log.debug("Get table updates"); |
1004 | - public TableUpdates apply(JsonNode input) { | 825 | + TableUpdates updates = FromJsonUtil.jsonNodeToTableUpdates(input, dbSchema); |
1005 | - log.info("Get table updates"); | ||
1006 | - TableUpdates updates = FromJsonUtil | ||
1007 | - .jsonNodeToTableUpdates(input, dbSchema); | ||
1008 | if (updates == null) { | 826 | if (updates == null) { |
1009 | log.debug("Get table updates error"); | 827 | log.debug("Get table updates error"); |
1010 | return null; | 828 | return null; |
1011 | } | 829 | } |
1012 | return updates; | 830 | return updates; |
1013 | - } | ||
1014 | }; | 831 | }; |
1015 | return Futures.transform(monitor(dbSchema, id), rowFunction); | 832 | return Futures.transform(monitor(dbSchema, id), rowFunction); |
1016 | } | 833 | } |
... | @@ -1026,18 +843,15 @@ public class DefaultOvsdbClient | ... | @@ -1026,18 +843,15 @@ public class DefaultOvsdbClient |
1026 | DatabaseSchema dbSchema = schema.get(dbName); | 843 | DatabaseSchema dbSchema = schema.get(dbName); |
1027 | if (dbSchema != null) { | 844 | if (dbSchema != null) { |
1028 | Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> { | 845 | Function<List<JsonNode>, List<OperationResult>> rowFunction = (input -> { |
1029 | - log.info("Get ovsdb operation result"); | 846 | + log.debug("Get ovsdb operation result"); |
1030 | - List<OperationResult> result = FromJsonUtil | 847 | + List<OperationResult> result = FromJsonUtil.jsonNodeToOperationResult(input, operations); |
1031 | - .jsonNodeToOperationResult(input, operations); | ||
1032 | - | ||
1033 | if (result == null) { | 848 | if (result == null) { |
1034 | log.debug("The operation result is null"); | 849 | log.debug("The operation result is null"); |
1035 | return null; | 850 | return null; |
1036 | } | 851 | } |
1037 | return result; | 852 | return result; |
1038 | }); | 853 | }); |
1039 | - return Futures.transform(transact(dbSchema, operations), | 854 | + return Futures.transform(transact(dbSchema, operations), rowFunction); |
1040 | - rowFunction); | ||
1041 | } | 855 | } |
1042 | return null; | 856 | return null; |
1043 | } | 857 | } |
... | @@ -1053,7 +867,6 @@ public class DefaultOvsdbClient | ... | @@ -1053,7 +867,6 @@ public class DefaultOvsdbClient |
1053 | 867 | ||
1054 | channel.writeAndFlush(getSchemaString); | 868 | channel.writeAndFlush(getSchemaString); |
1055 | return sf; | 869 | return sf; |
1056 | - | ||
1057 | } | 870 | } |
1058 | 871 | ||
1059 | @Override | 872 | @Override |
... | @@ -1067,7 +880,6 @@ public class DefaultOvsdbClient | ... | @@ -1067,7 +880,6 @@ public class DefaultOvsdbClient |
1067 | 880 | ||
1068 | channel.writeAndFlush(echoString); | 881 | channel.writeAndFlush(echoString); |
1069 | return sf; | 882 | return sf; |
1070 | - | ||
1071 | } | 883 | } |
1072 | 884 | ||
1073 | @Override | 885 | @Override |
... | @@ -1083,7 +895,6 @@ public class DefaultOvsdbClient | ... | @@ -1083,7 +895,6 @@ public class DefaultOvsdbClient |
1083 | 895 | ||
1084 | channel.writeAndFlush(monitorString); | 896 | channel.writeAndFlush(monitorString); |
1085 | return sf; | 897 | return sf; |
1086 | - | ||
1087 | } | 898 | } |
1088 | 899 | ||
1089 | @Override | 900 | @Override |
... | @@ -1097,7 +908,6 @@ public class DefaultOvsdbClient | ... | @@ -1097,7 +908,6 @@ public class DefaultOvsdbClient |
1097 | 908 | ||
1098 | channel.writeAndFlush(listDbsString); | 909 | channel.writeAndFlush(listDbsString); |
1099 | return sf; | 910 | return sf; |
1100 | - | ||
1101 | } | 911 | } |
1102 | 912 | ||
1103 | @Override | 913 | @Override |
... | @@ -1113,7 +923,6 @@ public class DefaultOvsdbClient | ... | @@ -1113,7 +923,6 @@ public class DefaultOvsdbClient |
1113 | 923 | ||
1114 | channel.writeAndFlush(transactString); | 924 | channel.writeAndFlush(transactString); |
1115 | return sf; | 925 | return sf; |
1116 | - | ||
1117 | } | 926 | } |
1118 | 927 | ||
1119 | @SuppressWarnings({"rawtypes", "unchecked"}) | 928 | @SuppressWarnings({"rawtypes", "unchecked"}) |
... | @@ -1127,12 +936,7 @@ public class DefaultOvsdbClient | ... | @@ -1127,12 +936,7 @@ public class DefaultOvsdbClient |
1127 | return; | 936 | return; |
1128 | } | 937 | } |
1129 | String methodName = requestMethod.get(requestId); | 938 | String methodName = requestMethod.get(requestId); |
1130 | - | 939 | + sf.set(FromJsonUtil.jsonResultParser(response, methodName)); |
1131 | - Object result; | ||
1132 | - result = FromJsonUtil.jsonResultParser(response, methodName); | ||
1133 | - | ||
1134 | - sf.set(result); | ||
1135 | - return; | ||
1136 | } | 940 | } |
1137 | 941 | ||
1138 | @Override | 942 | @Override |
... | @@ -1143,12 +947,8 @@ public class DefaultOvsdbClient | ... | @@ -1143,12 +947,8 @@ public class DefaultOvsdbClient |
1143 | 947 | ||
1144 | String replyString = FromJsonUtil.getEchoRequestStr(requestJson); | 948 | String replyString = FromJsonUtil.getEchoRequestStr(requestJson); |
1145 | channel.writeAndFlush(replyString); | 949 | channel.writeAndFlush(replyString); |
1146 | - | ||
1147 | - return; | ||
1148 | } else { | 950 | } else { |
1149 | - FromJsonUtil | 951 | + FromJsonUtil.jsonCallbackRequestParser(requestJson, monitorCallBack); |
1150 | - .jsonCallbackRequestParser(requestJson, monitorCallBack); | ||
1151 | - return; | ||
1152 | } | 952 | } |
1153 | } | 953 | } |
1154 | 954 | ||
... | @@ -1164,19 +964,18 @@ public class DefaultOvsdbClient | ... | @@ -1164,19 +964,18 @@ public class DefaultOvsdbClient |
1164 | 964 | ||
1165 | @Override | 965 | @Override |
1166 | public Set<OvsdbBridge> getBridges() { | 966 | public Set<OvsdbBridge> getBridges() { |
1167 | - Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>(); | 967 | + Set<OvsdbBridge> ovsdbBridges = new HashSet<>(); |
1168 | - OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | 968 | + OvsdbTableStore tableStore = getTableStore(DATABASENAME); |
1169 | if (tableStore == null) { | 969 | if (tableStore == null) { |
1170 | return null; | 970 | return null; |
1171 | } | 971 | } |
1172 | - OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.BRIDGE); | 972 | + OvsdbRowStore rowStore = tableStore.getRows(BRIDGE); |
1173 | if (rowStore == null) { | 973 | if (rowStore == null) { |
1174 | return null; | 974 | return null; |
1175 | } | 975 | } |
1176 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | 976 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); |
1177 | for (String uuid : rows.keySet()) { | 977 | for (String uuid : rows.keySet()) { |
1178 | - Row row = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE, | 978 | + Row row = getRow(DATABASENAME, BRIDGE, uuid); |
1179 | - uuid); | ||
1180 | OvsdbBridge ovsdbBridge = getOvsdbBridge(row); | 979 | OvsdbBridge ovsdbBridge = getOvsdbBridge(row); |
1181 | if (ovsdbBridge != null) { | 980 | if (ovsdbBridge != null) { |
1182 | ovsdbBridges.add(ovsdbBridge); | 981 | ovsdbBridges.add(ovsdbBridge); |
... | @@ -1197,19 +996,17 @@ public class DefaultOvsdbClient | ... | @@ -1197,19 +996,17 @@ public class DefaultOvsdbClient |
1197 | log.warn("bad list of controllers"); | 996 | log.warn("bad list of controllers"); |
1198 | return null; | 997 | return null; |
1199 | } | 998 | } |
1200 | - return controllers.stream(). | 999 | + return controllers.stream().map(controller -> new ControllerInfo( |
1201 | - map(controller -> new ControllerInfo( | ||
1202 | (String) controller.getTargetColumn() | 1000 | (String) controller.getTargetColumn() |
1203 | .data())).collect(Collectors.toSet()); | 1001 | .data())).collect(Collectors.toSet()); |
1204 | } | 1002 | } |
1205 | 1003 | ||
1206 | private List<Controller> getControllers(Uuid bridgeUuid) { | 1004 | private List<Controller> getControllers(Uuid bridgeUuid) { |
1207 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 1005 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
1208 | if (dbSchema == null) { | 1006 | if (dbSchema == null) { |
1209 | return null; | 1007 | return null; |
1210 | } | 1008 | } |
1211 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | 1009 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE); |
1212 | - OvsdbConstant.BRIDGE); | ||
1213 | if (rowStore == null) { | 1010 | if (rowStore == null) { |
1214 | log.debug("There is no bridge table"); | 1011 | log.debug("There is no bridge table"); |
1215 | return null; | 1012 | return null; |
... | @@ -1224,10 +1021,8 @@ public class DefaultOvsdbClient | ... | @@ -1224,10 +1021,8 @@ public class DefaultOvsdbClient |
1224 | .data().getClass()); | 1021 | .data().getClass()); |
1225 | Set<Uuid> controllerUuids = (Set<Uuid>) ((OvsdbSet) bridge | 1022 | Set<Uuid> controllerUuids = (Set<Uuid>) ((OvsdbSet) bridge |
1226 | .getControllerColumn().data()).set(); | 1023 | .getControllerColumn().data()).set(); |
1227 | -// Set<String> controllerUuidStrings = (Set<String>) bridge.getControllerColumn().data(); | ||
1228 | 1024 | ||
1229 | - OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME, | 1025 | + OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER); |
1230 | - OvsdbConstant.CONTROLLER); | ||
1231 | if (controllerRowStore == null) { | 1026 | if (controllerRowStore == null) { |
1232 | log.debug("There is no controller table"); | 1027 | log.debug("There is no controller table"); |
1233 | return null; | 1028 | return null; |
... | @@ -1248,12 +1043,11 @@ public class DefaultOvsdbClient | ... | @@ -1248,12 +1043,11 @@ public class DefaultOvsdbClient |
1248 | 1043 | ||
1249 | 1044 | ||
1250 | private Uuid getBridgeUuid(DeviceId openflowDeviceId) { | 1045 | private Uuid getBridgeUuid(DeviceId openflowDeviceId) { |
1251 | - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); | 1046 | + DatabaseSchema dbSchema = schema.get(DATABASENAME); |
1252 | if (dbSchema == null) { | 1047 | if (dbSchema == null) { |
1253 | return null; | 1048 | return null; |
1254 | } | 1049 | } |
1255 | - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, | 1050 | + OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE); |
1256 | - OvsdbConstant.BRIDGE); | ||
1257 | if (rowStore == null) { | 1051 | if (rowStore == null) { |
1258 | log.debug("There is no bridge table"); | 1052 | log.debug("There is no bridge table"); |
1259 | return null; | 1053 | return null; |
... | @@ -1262,10 +1056,12 @@ public class DefaultOvsdbClient | ... | @@ -1262,10 +1056,12 @@ public class DefaultOvsdbClient |
1262 | ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore(); | 1056 | ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore(); |
1263 | final AtomicReference<Uuid> uuid = new AtomicReference<>(); | 1057 | final AtomicReference<Uuid> uuid = new AtomicReference<>(); |
1264 | for (Map.Entry<String, Row> entry : bridgeTableRows.entrySet()) { | 1058 | for (Map.Entry<String, Row> entry : bridgeTableRows.entrySet()) { |
1265 | - Bridge b = (Bridge) TableGenerator.getTable(dbSchema, | 1059 | + Bridge bridge = (Bridge) TableGenerator.getTable( |
1060 | + dbSchema, | ||
1266 | entry.getValue(), | 1061 | entry.getValue(), |
1267 | OvsdbTable.BRIDGE); | 1062 | OvsdbTable.BRIDGE); |
1268 | - if (matchesDpid(b, openflowDeviceId)) { | 1063 | + |
1064 | + if (matchesDpid(bridge, openflowDeviceId)) { | ||
1269 | uuid.set(Uuid.uuid(entry.getKey())); | 1065 | uuid.set(Uuid.uuid(entry.getKey())); |
1270 | break; | 1066 | break; |
1271 | } | 1067 | } |
... | @@ -1274,7 +1070,6 @@ public class DefaultOvsdbClient | ... | @@ -1274,7 +1070,6 @@ public class DefaultOvsdbClient |
1274 | log.debug("There is no bridge for {}", openflowDeviceId); | 1070 | log.debug("There is no bridge for {}", openflowDeviceId); |
1275 | } | 1071 | } |
1276 | return uuid.get(); | 1072 | return uuid.get(); |
1277 | - | ||
1278 | } | 1073 | } |
1279 | 1074 | ||
1280 | private static boolean matchesDpid(Bridge b, DeviceId deviceId) { | 1075 | private static boolean matchesDpid(Bridge b, DeviceId deviceId) { |
... | @@ -1286,19 +1081,18 @@ public class DefaultOvsdbClient | ... | @@ -1286,19 +1081,18 @@ public class DefaultOvsdbClient |
1286 | 1081 | ||
1287 | @Override | 1082 | @Override |
1288 | public Set<OvsdbPort> getPorts() { | 1083 | public Set<OvsdbPort> getPorts() { |
1289 | - Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | 1084 | + Set<OvsdbPort> ovsdbPorts = new HashSet<>(); |
1290 | - OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | 1085 | + OvsdbTableStore tableStore = getTableStore(DATABASENAME); |
1291 | if (tableStore == null) { | 1086 | if (tableStore == null) { |
1292 | return null; | 1087 | return null; |
1293 | } | 1088 | } |
1294 | - OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); | 1089 | + OvsdbRowStore rowStore = tableStore.getRows(INTERFACE); |
1295 | if (rowStore == null) { | 1090 | if (rowStore == null) { |
1296 | return null; | 1091 | return null; |
1297 | } | 1092 | } |
1298 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | 1093 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); |
1299 | for (String uuid : rows.keySet()) { | 1094 | for (String uuid : rows.keySet()) { |
1300 | - Row row = getRow(OvsdbConstant.DATABASENAME, | 1095 | + Row row = getRow(DATABASENAME, INTERFACE, uuid); |
1301 | - OvsdbConstant.INTERFACE, uuid); | ||
1302 | OvsdbPort ovsdbPort = getOvsdbPort(row); | 1096 | OvsdbPort ovsdbPort = getOvsdbPort(row); |
1303 | if (ovsdbPort != null) { | 1097 | if (ovsdbPort != null) { |
1304 | ovsdbPorts.add(ovsdbPort); | 1098 | ovsdbPorts.add(ovsdbPort); |
... | @@ -1312,9 +1106,8 @@ public class DefaultOvsdbClient | ... | @@ -1312,9 +1106,8 @@ public class DefaultOvsdbClient |
1312 | return schema.get(dbName); | 1106 | return schema.get(dbName); |
1313 | } | 1107 | } |
1314 | 1108 | ||
1315 | - //Gets ovsdb port. | ||
1316 | private OvsdbPort getOvsdbPort(Row row) { | 1109 | private OvsdbPort getOvsdbPort(Row row) { |
1317 | - DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); | 1110 | + DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME); |
1318 | Interface intf = (Interface) TableGenerator | 1111 | Interface intf = (Interface) TableGenerator |
1319 | .getTable(dbSchema, row, OvsdbTable.INTERFACE); | 1112 | .getTable(dbSchema, row, OvsdbTable.INTERFACE); |
1320 | if (intf == null) { | 1113 | if (intf == null) { |
... | @@ -1325,17 +1118,12 @@ public class DefaultOvsdbClient | ... | @@ -1325,17 +1118,12 @@ public class DefaultOvsdbClient |
1325 | if ((ofPort < 0) || (portName == null)) { | 1118 | if ((ofPort < 0) || (portName == null)) { |
1326 | return null; | 1119 | return null; |
1327 | } | 1120 | } |
1328 | - | 1121 | + return new OvsdbPort(new OvsdbPortNumber(ofPort), new OvsdbPortName(portName)); |
1329 | - OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), | ||
1330 | - new OvsdbPortName(portName)); | ||
1331 | - return ovsdbPort; | ||
1332 | } | 1122 | } |
1333 | 1123 | ||
1334 | - ////Gets ovsdb bridge. | ||
1335 | private OvsdbBridge getOvsdbBridge(Row row) { | 1124 | private OvsdbBridge getOvsdbBridge(Row row) { |
1336 | - DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); | 1125 | + DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME); |
1337 | - Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, | 1126 | + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE); |
1338 | - OvsdbTable.BRIDGE); | ||
1339 | if (bridge == null) { | 1127 | if (bridge == null) { |
1340 | return null; | 1128 | return null; |
1341 | } | 1129 | } |
... | @@ -1351,18 +1139,14 @@ public class DefaultOvsdbClient | ... | @@ -1351,18 +1139,14 @@ public class DefaultOvsdbClient |
1351 | if ((datapathId == null) || (bridgeName == null)) { | 1139 | if ((datapathId == null) || (bridgeName == null)) { |
1352 | return null; | 1140 | return null; |
1353 | } | 1141 | } |
1354 | - | 1142 | + return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build(); |
1355 | - OvsdbBridge ovsdbBridge = new OvsdbBridge(new OvsdbBridgeName(bridgeName), | ||
1356 | - new OvsdbDatapathId(datapathId)); | ||
1357 | - return ovsdbBridge; | ||
1358 | } | 1143 | } |
1359 | 1144 | ||
1360 | - //Gets ofPort in the interface. | ||
1361 | private long getOfPort(Interface intf) { | 1145 | private long getOfPort(Interface intf) { |
1362 | OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); | 1146 | OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); |
1363 | @SuppressWarnings("unchecked") | 1147 | @SuppressWarnings("unchecked") |
1364 | Set<Integer> ofPorts = ofPortSet.set(); | 1148 | Set<Integer> ofPorts = ofPortSet.set(); |
1365 | - while (ofPorts == null || ofPorts.size() <= 0) { | 1149 | + if (ofPorts == null || ofPorts.size() <= 0) { |
1366 | log.debug("The ofport is null in {}", intf.getName()); | 1150 | log.debug("The ofport is null in {}", intf.getName()); |
1367 | return -1; | 1151 | return -1; |
1368 | } | 1152 | } |
... | @@ -1373,41 +1157,38 @@ public class DefaultOvsdbClient | ... | @@ -1373,41 +1157,38 @@ public class DefaultOvsdbClient |
1373 | 1157 | ||
1374 | @Override | 1158 | @Override |
1375 | public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) { | 1159 | public Set<OvsdbPort> getLocalPorts(Iterable<String> ifaceids) { |
1376 | - Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); | 1160 | + Set<OvsdbPort> ovsdbPorts = new HashSet<>(); |
1377 | - OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); | 1161 | + OvsdbTableStore tableStore = getTableStore(DATABASENAME); |
1378 | if (tableStore == null) { | 1162 | if (tableStore == null) { |
1379 | return null; | 1163 | return null; |
1380 | } | 1164 | } |
1381 | - OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); | 1165 | + OvsdbRowStore rowStore = tableStore.getRows(INTERFACE); |
1382 | if (rowStore == null) { | 1166 | if (rowStore == null) { |
1383 | return null; | 1167 | return null; |
1384 | } | 1168 | } |
1385 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); | 1169 | ConcurrentMap<String, Row> rows = rowStore.getRowStore(); |
1386 | for (String uuid : rows.keySet()) { | 1170 | for (String uuid : rows.keySet()) { |
1387 | - Row row = getRow(OvsdbConstant.DATABASENAME, | 1171 | + Row row = getRow(DATABASENAME, INTERFACE, uuid); |
1388 | - OvsdbConstant.INTERFACE, uuid); | 1172 | + DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME); |
1389 | - DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); | ||
1390 | Interface intf = (Interface) TableGenerator | 1173 | Interface intf = (Interface) TableGenerator |
1391 | .getTable(dbSchema, row, OvsdbTable.INTERFACE); | 1174 | .getTable(dbSchema, row, OvsdbTable.INTERFACE); |
1392 | if (intf == null || getIfaceid(intf) == null) { | 1175 | if (intf == null || getIfaceid(intf) == null) { |
1393 | continue; | 1176 | continue; |
1394 | } | 1177 | } |
1395 | String portName = intf.getName(); | 1178 | String portName = intf.getName(); |
1179 | + if (portName == null) { | ||
1180 | + continue; | ||
1181 | + } | ||
1396 | Set<String> ifaceidSet = Sets.newHashSet(ifaceids); | 1182 | Set<String> ifaceidSet = Sets.newHashSet(ifaceids); |
1397 | - if (portName.startsWith("vxlan") | 1183 | + if (portName.startsWith(TYPEVXLAN) || !ifaceidSet.contains(getIfaceid(intf))) { |
1398 | - || !ifaceidSet.contains(getIfaceid(intf))) { | ||
1399 | continue; | 1184 | continue; |
1400 | } | 1185 | } |
1401 | long ofPort = getOfPort(intf); | 1186 | long ofPort = getOfPort(intf); |
1402 | - if ((ofPort < 0) || (portName == null)) { | 1187 | + if (ofPort < 0) { |
1403 | continue; | 1188 | continue; |
1404 | } | 1189 | } |
1405 | - | 1190 | + ovsdbPorts.add(new OvsdbPort(new OvsdbPortNumber(ofPort), |
1406 | - OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), | 1191 | + new OvsdbPortName(portName))); |
1407 | - new OvsdbPortName(portName)); | ||
1408 | - if (ovsdbPort != null) { | ||
1409 | - ovsdbPorts.add(ovsdbPort); | ||
1410 | - } | ||
1411 | } | 1192 | } |
1412 | return ovsdbPorts; | 1193 | return ovsdbPorts; |
1413 | } | 1194 | } |
... | @@ -1420,8 +1201,7 @@ public class DefaultOvsdbClient | ... | @@ -1420,8 +1201,7 @@ public class DefaultOvsdbClient |
1420 | log.warn("The external_ids is null"); | 1201 | log.warn("The external_ids is null"); |
1421 | return null; | 1202 | return null; |
1422 | } | 1203 | } |
1423 | - String ifaceid = externalIds | 1204 | + String ifaceid = externalIds.get(EXTERNAL_ID_INTERFACE_ID); |
1424 | - .get(OvsdbConstant.EXTERNAL_ID_INTERFACE_ID); | ||
1425 | if (ifaceid == null) { | 1205 | if (ifaceid == null) { |
1426 | log.warn("The ifaceid is null"); | 1206 | log.warn("The ifaceid is null"); |
1427 | return null; | 1207 | return null; | ... | ... |
... | @@ -74,6 +74,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { | ... | @@ -74,6 +74,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { |
74 | } | 74 | } |
75 | 75 | ||
76 | @Override | 76 | @Override |
77 | + public boolean createBridge(OvsdbBridge ovsdbBridge) { | ||
78 | + return true; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
77 | public void dropBridge(String bridgeName) { | 82 | public void dropBridge(String bridgeName) { |
78 | 83 | ||
79 | } | 84 | } |
... | @@ -89,6 +94,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { | ... | @@ -89,6 +94,11 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { |
89 | } | 94 | } |
90 | 95 | ||
91 | @Override | 96 | @Override |
97 | + public ControllerInfo localController() { | ||
98 | + return null; | ||
99 | + } | ||
100 | + | ||
101 | + @Override | ||
92 | public void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) { | 102 | public void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) { |
93 | 103 | ||
94 | } | 104 | } | ... | ... |
-
Please register or login to post a comment