Committed by
Gerrit Code Review
CORD-151 Implement initial compute node setup
Followings are changed - Changed nodeStore from eventually consistent map to consistent map - Removed ovsdb connection management(ovsdb controller has connection status) - Not only one leader but all onos instances make ovsdb session Following jobs are done - Reads compute node and ovsdb access info from network config - Initiates ovsdb connection to the nodes - Creates integration bridge on each ovsdbs - Creates vxlan tunnel port on each integration bridges Change-Id: I8df4061fcb1eae9b0abd545b7a3f540be50607a9
Showing
8 changed files
with
51 additions
and
243 deletions
| ... | @@ -49,6 +49,11 @@ | ... | @@ -49,6 +49,11 @@ |
| 49 | <artifactId>onos-core-serializers</artifactId> | 49 | <artifactId>onos-core-serializers</artifactId> |
| 50 | <version>${project.version}</version> | 50 | <version>${project.version}</version> |
| 51 | </dependency> | 51 | </dependency> |
| 52 | + <dependency> | ||
| 53 | + <groupId>org.onosproject</groupId> | ||
| 54 | + <artifactId>onos-ovsdb-api</artifactId> | ||
| 55 | + <version>${project.version}</version> | ||
| 56 | + </dependency> | ||
| 52 | </dependencies> | 57 | </dependencies> |
| 53 | 58 | ||
| 54 | </project> | 59 | </project> | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -20,6 +20,7 @@ import com.google.common.collect.Sets; | ... | @@ -20,6 +20,7 @@ import com.google.common.collect.Sets; |
| 20 | import org.onlab.packet.IpAddress; | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.TpPort; | 21 | import org.onlab.packet.TpPort; |
| 22 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
| 23 | +import org.onosproject.net.DeviceId; | ||
| 23 | import org.onosproject.net.config.Config; | 24 | import org.onosproject.net.config.Config; |
| 24 | 25 | ||
| 25 | import java.util.Set; | 26 | import java.util.Set; |
| ... | @@ -35,6 +36,7 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -35,6 +36,7 @@ public class CordVtnConfig extends Config<ApplicationId> { |
| 35 | public static final String HOST = "host"; | 36 | public static final String HOST = "host"; |
| 36 | public static final String IP = "ip"; | 37 | public static final String IP = "ip"; |
| 37 | public static final String PORT = "port"; | 38 | public static final String PORT = "port"; |
| 39 | + public static final String BRIDGE_ID = "bridgeId"; | ||
| 38 | 40 | ||
| 39 | /** | 41 | /** |
| 40 | * Returns the set of ovsdb nodes read from network config. | 42 | * Returns the set of ovsdb nodes read from network config. |
| ... | @@ -51,7 +53,8 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -51,7 +53,8 @@ public class CordVtnConfig extends Config<ApplicationId> { |
| 51 | nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig( | 53 | nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig( |
| 52 | jsonNode.path(HOST).asText(), | 54 | jsonNode.path(HOST).asText(), |
| 53 | IpAddress.valueOf(jsonNode.path(IP).asText()), | 55 | IpAddress.valueOf(jsonNode.path(IP).asText()), |
| 54 | - TpPort.tpPort(jsonNode.path(PORT).asInt())))); | 56 | + TpPort.tpPort(jsonNode.path(PORT).asInt()), |
| 57 | + DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())))); | ||
| 55 | 58 | ||
| 56 | return ovsdbNodes; | 59 | return ovsdbNodes; |
| 57 | } | 60 | } |
| ... | @@ -64,11 +67,13 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -64,11 +67,13 @@ public class CordVtnConfig extends Config<ApplicationId> { |
| 64 | private final String host; | 67 | private final String host; |
| 65 | private final IpAddress ip; | 68 | private final IpAddress ip; |
| 66 | private final TpPort port; | 69 | private final TpPort port; |
| 70 | + private final DeviceId bridgeId; | ||
| 67 | 71 | ||
| 68 | - public OvsdbNodeConfig(String host, IpAddress ip, TpPort port) { | 72 | + public OvsdbNodeConfig(String host, IpAddress ip, TpPort port, DeviceId bridgeId) { |
| 69 | this.host = checkNotNull(host); | 73 | this.host = checkNotNull(host); |
| 70 | this.ip = checkNotNull(ip); | 74 | this.ip = checkNotNull(ip); |
| 71 | this.port = checkNotNull(port); | 75 | this.port = checkNotNull(port); |
| 76 | + this.bridgeId = checkNotNull(bridgeId); | ||
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | /** | 79 | /** |
| ... | @@ -97,5 +102,9 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -97,5 +102,9 @@ public class CordVtnConfig extends Config<ApplicationId> { |
| 97 | public TpPort port() { | 102 | public TpPort port() { |
| 98 | return this.port; | 103 | return this.port; |
| 99 | } | 104 | } |
| 105 | + | ||
| 106 | + public DeviceId bridgeId() { | ||
| 107 | + return this.bridgeId; | ||
| 108 | + } | ||
| 100 | } | 109 | } |
| 101 | } | 110 | } | ... | ... |
| ... | @@ -20,11 +20,6 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -20,11 +20,6 @@ import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | -import org.onosproject.cluster.ClusterService; | ||
| 24 | -import org.onosproject.cluster.LeadershipEvent; | ||
| 25 | -import org.onosproject.cluster.LeadershipEventListener; | ||
| 26 | -import org.onosproject.cluster.LeadershipService; | ||
| 27 | -import org.onosproject.cluster.NodeId; | ||
| 28 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; | 24 | import org.onosproject.core.CoreService; |
| 30 | import org.onosproject.net.config.ConfigFactory; | 25 | import org.onosproject.net.config.ConfigFactory; |
| ... | @@ -35,7 +30,6 @@ import org.onosproject.net.config.NetworkConfigService; | ... | @@ -35,7 +30,6 @@ import org.onosproject.net.config.NetworkConfigService; |
| 35 | import org.onosproject.net.config.basics.SubjectFactories; | 30 | import org.onosproject.net.config.basics.SubjectFactories; |
| 36 | import org.slf4j.Logger; | 31 | import org.slf4j.Logger; |
| 37 | 32 | ||
| 38 | -import static org.onosproject.cordvtn.OvsdbNode.State.INIT; | ||
| 39 | import static org.slf4j.LoggerFactory.getLogger; | 33 | import static org.slf4j.LoggerFactory.getLogger; |
| 40 | 34 | ||
| 41 | /** | 35 | /** |
| ... | @@ -58,12 +52,6 @@ public class CordVtnConfigManager { | ... | @@ -58,12 +52,6 @@ public class CordVtnConfigManager { |
| 58 | protected NetworkConfigService configService; | 52 | protected NetworkConfigService configService; |
| 59 | 53 | ||
| 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 61 | - protected LeadershipService leadershipService; | ||
| 62 | - | ||
| 63 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 64 | - protected ClusterService clusterService; | ||
| 65 | - | ||
| 66 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 67 | protected CordVtnService cordVtnService; | 55 | protected CordVtnService cordVtnService; |
| 68 | 56 | ||
| 69 | private final ConfigFactory configFactory = | 57 | private final ConfigFactory configFactory = |
| ... | @@ -74,29 +62,22 @@ public class CordVtnConfigManager { | ... | @@ -74,29 +62,22 @@ public class CordVtnConfigManager { |
| 74 | } | 62 | } |
| 75 | }; | 63 | }; |
| 76 | 64 | ||
| 77 | - private final LeadershipEventListener leadershipListener = new InternalLeadershipListener(); | ||
| 78 | private final NetworkConfigListener configListener = new InternalConfigListener(); | 65 | private final NetworkConfigListener configListener = new InternalConfigListener(); |
| 79 | 66 | ||
| 80 | - private NodeId local; | ||
| 81 | private ApplicationId appId; | 67 | private ApplicationId appId; |
| 82 | 68 | ||
| 83 | @Activate | 69 | @Activate |
| 84 | protected void active() { | 70 | protected void active() { |
| 85 | - local = clusterService.getLocalNode().id(); | ||
| 86 | appId = coreService.getAppId(CordVtnService.CORDVTN_APP_ID); | 71 | appId = coreService.getAppId(CordVtnService.CORDVTN_APP_ID); |
| 87 | 72 | ||
| 88 | configService.addListener(configListener); | 73 | configService.addListener(configListener); |
| 89 | configRegistry.registerConfigFactory(configFactory); | 74 | configRegistry.registerConfigFactory(configFactory); |
| 90 | 75 | ||
| 91 | - leadershipService.addListener(leadershipListener); | 76 | + readConfiguration(); |
| 92 | - leadershipService.runForLeadership(CordVtnService.CORDVTN_APP_ID); | ||
| 93 | } | 77 | } |
| 94 | 78 | ||
| 95 | @Deactivate | 79 | @Deactivate |
| 96 | protected void deactivate() { | 80 | protected void deactivate() { |
| 97 | - leadershipService.removeListener(leadershipListener); | ||
| 98 | - leadershipService.withdraw(appId.name()); | ||
| 99 | - | ||
| 100 | configRegistry.unregisterConfigFactory(configFactory); | 81 | configRegistry.unregisterConfigFactory(configFactory); |
| 101 | configService.removeListener(configListener); | 82 | configService.removeListener(configListener); |
| 102 | } | 83 | } |
| ... | @@ -110,30 +91,13 @@ public class CordVtnConfigManager { | ... | @@ -110,30 +91,13 @@ public class CordVtnConfigManager { |
| 110 | } | 91 | } |
| 111 | 92 | ||
| 112 | config.ovsdbNodes().forEach(node -> { | 93 | config.ovsdbNodes().forEach(node -> { |
| 113 | - DefaultOvsdbNode ovsdbNode = | 94 | + DefaultOvsdbNode ovsdb = new DefaultOvsdbNode( |
| 114 | - new DefaultOvsdbNode(node.host(), node.ip(), node.port(), INIT); | 95 | + node.host(), node.ip(), node.port(), node.bridgeId()); |
| 115 | - cordVtnService.addNode(ovsdbNode); | 96 | + cordVtnService.addNode(ovsdb); |
| 116 | - log.info("Add new node {}", node.host()); | 97 | + cordVtnService.connect(ovsdb); |
| 117 | }); | 98 | }); |
| 118 | } | 99 | } |
| 119 | 100 | ||
| 120 | - private synchronized void processLeadershipChange(NodeId leader) { | ||
| 121 | - if (leader == null || !leader.equals(local)) { | ||
| 122 | - return; | ||
| 123 | - } | ||
| 124 | - readConfiguration(); | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - private class InternalLeadershipListener implements LeadershipEventListener { | ||
| 128 | - | ||
| 129 | - @Override | ||
| 130 | - public void event(LeadershipEvent event) { | ||
| 131 | - if (event.subject().topic().equals(appId.name())) { | ||
| 132 | - processLeadershipChange(event.subject().leader()); | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | private class InternalConfigListener implements NetworkConfigListener { | 101 | private class InternalConfigListener implements NetworkConfigListener { |
| 138 | 102 | ||
| 139 | @Override | 103 | @Override | ... | ... |
| ... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.cordvtn; | 16 | package org.onosproject.cordvtn; |
| 17 | 17 | ||
| 18 | -import org.onosproject.cordvtn.OvsdbNode.State; | ||
| 19 | import org.onosproject.net.DeviceId; | 18 | import org.onosproject.net.DeviceId; |
| 20 | 19 | ||
| 21 | import java.util.List; | 20 | import java.util.List; |
| ... | @@ -29,25 +28,30 @@ public interface CordVtnService { | ... | @@ -29,25 +28,30 @@ public interface CordVtnService { |
| 29 | /** | 28 | /** |
| 30 | * Adds a new node to the service. | 29 | * Adds a new node to the service. |
| 31 | * | 30 | * |
| 32 | - * @param ovsdbNode ovsdb node | 31 | + * @param ovsdb ovsdb node |
| 33 | */ | 32 | */ |
| 34 | - void addNode(OvsdbNode ovsdbNode); | 33 | + void addNode(OvsdbNode ovsdb); |
| 35 | 34 | ||
| 36 | /** | 35 | /** |
| 37 | * Deletes a node from the service. | 36 | * Deletes a node from the service. |
| 38 | * | 37 | * |
| 39 | - * @param ovsdbNode ovsdb node | 38 | + * @param ovsdb ovsdb node |
| 40 | */ | 39 | */ |
| 41 | - void deleteNode(OvsdbNode ovsdbNode); | 40 | + void deleteNode(OvsdbNode ovsdb); |
| 42 | 41 | ||
| 43 | /** | 42 | /** |
| 44 | - * Updates ovsdb node. | 43 | + * Connect to a node. |
| 45 | - * It only used for updating node's connection state. | ||
| 46 | * | 44 | * |
| 47 | - * @param ovsdbNode ovsdb node | 45 | + * @param ovsdb ovsdb node |
| 48 | - * @param state ovsdb connection state | ||
| 49 | */ | 46 | */ |
| 50 | - void updateNode(OvsdbNode ovsdbNode, State state); | 47 | + void connect(OvsdbNode ovsdb); |
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Disconnect a node. | ||
| 51 | + * | ||
| 52 | + * @param ovsdb ovsdb node | ||
| 53 | + */ | ||
| 54 | + void disconnect(OvsdbNode ovsdb); | ||
| 51 | 55 | ||
| 52 | /** | 56 | /** |
| 53 | * Returns the number of the nodes known to the service. | 57 | * Returns the number of the nodes known to the service. |
| ... | @@ -65,6 +69,14 @@ public interface CordVtnService { | ... | @@ -65,6 +69,14 @@ public interface CordVtnService { |
| 65 | OvsdbNode getNode(DeviceId deviceId); | 69 | OvsdbNode getNode(DeviceId deviceId); |
| 66 | 70 | ||
| 67 | /** | 71 | /** |
| 72 | + * Returns connection state of the node. | ||
| 73 | + * | ||
| 74 | + * @param ovsdb ovsdb node | ||
| 75 | + * @return true if the node is connected, false otherwise | ||
| 76 | + */ | ||
| 77 | + boolean isNodeConnected(OvsdbNode ovsdb); | ||
| 78 | + | ||
| 79 | + /** | ||
| 68 | * Returns all nodes known to the service. | 80 | * Returns all nodes known to the service. |
| 69 | * | 81 | * |
| 70 | * @return list of nodes | 82 | * @return list of nodes | ... | ... |
| ... | @@ -30,13 +30,13 @@ public class DefaultOvsdbNode implements OvsdbNode { | ... | @@ -30,13 +30,13 @@ public class DefaultOvsdbNode implements OvsdbNode { |
| 30 | private final String host; | 30 | private final String host; |
| 31 | private final IpAddress ip; | 31 | private final IpAddress ip; |
| 32 | private final TpPort port; | 32 | private final TpPort port; |
| 33 | - private final State state; | 33 | + private final DeviceId brId; |
| 34 | 34 | ||
| 35 | - public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, State state) { | 35 | + public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, DeviceId brId) { |
| 36 | this.host = host; | 36 | this.host = host; |
| 37 | this.ip = ip; | 37 | this.ip = ip; |
| 38 | this.port = port; | 38 | this.port = port; |
| 39 | - this.state = state; | 39 | + this.brId = brId; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | @Override | 42 | @Override |
| ... | @@ -55,8 +55,8 @@ public class DefaultOvsdbNode implements OvsdbNode { | ... | @@ -55,8 +55,8 @@ public class DefaultOvsdbNode implements OvsdbNode { |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | @Override | 57 | @Override |
| 58 | - public State state() { | 58 | + public DeviceId intBrId() { |
| 59 | - return this.state; | 59 | + return this.brId; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | @Override | 62 | @Override |
| ... | @@ -65,11 +65,6 @@ public class DefaultOvsdbNode implements OvsdbNode { | ... | @@ -65,11 +65,6 @@ public class DefaultOvsdbNode implements OvsdbNode { |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | @Override | 67 | @Override |
| 68 | - public DeviceId intBrId() { | ||
| 69 | - return DeviceId.deviceId("of:" + this.host); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - @Override | ||
| 73 | public boolean equals(Object o) { | 68 | public boolean equals(Object o) { |
| 74 | if (this == o) { | 69 | if (this == o) { |
| 75 | return true; | 70 | return true; |
| ... | @@ -79,7 +74,8 @@ public class DefaultOvsdbNode implements OvsdbNode { | ... | @@ -79,7 +74,8 @@ public class DefaultOvsdbNode implements OvsdbNode { |
| 79 | DefaultOvsdbNode that = (DefaultOvsdbNode) o; | 74 | DefaultOvsdbNode that = (DefaultOvsdbNode) o; |
| 80 | if (this.host.equals(that.host) && | 75 | if (this.host.equals(that.host) && |
| 81 | this.ip.equals(that.ip) && | 76 | this.ip.equals(that.ip) && |
| 82 | - this.port.equals(that.port)) { | 77 | + this.port.equals(that.port) && |
| 78 | + this.brId.equals(that.brId)) { | ||
| 83 | return true; | 79 | return true; |
| 84 | } | 80 | } |
| 85 | } | 81 | } |
| ... | @@ -97,7 +93,7 @@ public class DefaultOvsdbNode implements OvsdbNode { | ... | @@ -97,7 +93,7 @@ public class DefaultOvsdbNode implements OvsdbNode { |
| 97 | .add("host", host) | 93 | .add("host", host) |
| 98 | .add("ip", ip) | 94 | .add("ip", ip) |
| 99 | .add("port", port) | 95 | .add("port", port) |
| 100 | - .add("state", state) | 96 | + .add("bridgeId", brId) |
| 101 | .toString(); | 97 | .toString(); |
| 102 | } | 98 | } |
| 103 | } | 99 | } | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2014-2015 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.cordvtn; | ||
| 17 | - | ||
| 18 | -import org.apache.felix.scr.annotations.Activate; | ||
| 19 | -import org.apache.felix.scr.annotations.Component; | ||
| 20 | -import org.apache.felix.scr.annotations.Deactivate; | ||
| 21 | -import org.apache.felix.scr.annotations.Reference; | ||
| 22 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 23 | -import org.onosproject.cluster.ClusterService; | ||
| 24 | -import org.onosproject.cluster.LeadershipService; | ||
| 25 | -import org.onosproject.cluster.NodeId; | ||
| 26 | -import org.onosproject.mastership.MastershipService; | ||
| 27 | -import org.onosproject.net.Device; | ||
| 28 | -import org.onosproject.net.device.DeviceEvent; | ||
| 29 | -import org.onosproject.net.device.DeviceListener; | ||
| 30 | -import org.onosproject.net.device.DeviceService; | ||
| 31 | -import org.slf4j.Logger; | ||
| 32 | - | ||
| 33 | -import java.util.concurrent.Executors; | ||
| 34 | -import java.util.concurrent.ScheduledExecutorService; | ||
| 35 | -import java.util.concurrent.TimeUnit; | ||
| 36 | - | ||
| 37 | -import static org.onlab.util.Tools.groupedThreads; | ||
| 38 | -import static org.onosproject.cordvtn.OvsdbNode.State.CONNECTED; | ||
| 39 | -import static org.onosproject.cordvtn.OvsdbNode.State.DISCONNECTED; | ||
| 40 | -import static org.onosproject.cordvtn.OvsdbNode.State.READY; | ||
| 41 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 42 | - | ||
| 43 | -/** | ||
| 44 | - * Provides the connection state management of all nodes registered to the service | ||
| 45 | - * so that the nodes keep connected unless it is requested to be deleted. | ||
| 46 | - */ | ||
| 47 | -@Component(immediate = true) | ||
| 48 | -public class NodeConnectionManager { | ||
| 49 | - protected final Logger log = getLogger(getClass()); | ||
| 50 | - | ||
| 51 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 52 | - MastershipService mastershipService; | ||
| 53 | - | ||
| 54 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 55 | - LeadershipService leadershipService; | ||
| 56 | - | ||
| 57 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 58 | - ClusterService clusterService; | ||
| 59 | - | ||
| 60 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 61 | - DeviceService deviceService; | ||
| 62 | - | ||
| 63 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 64 | - CordVtnService cordVtnService; | ||
| 65 | - | ||
| 66 | - private static final int DELAY_SEC = 5; | ||
| 67 | - | ||
| 68 | - private final DeviceListener deviceListener = new InternalDeviceListener(); | ||
| 69 | - private final ScheduledExecutorService connectionExecutor = Executors | ||
| 70 | - .newSingleThreadScheduledExecutor(groupedThreads("onos/cordvtn", "connection-manager")); | ||
| 71 | - | ||
| 72 | - private NodeId localId; | ||
| 73 | - | ||
| 74 | - @Activate | ||
| 75 | - protected void activate() { | ||
| 76 | - localId = clusterService.getLocalNode().id(); | ||
| 77 | - deviceService.addListener(deviceListener); | ||
| 78 | - | ||
| 79 | - connectionExecutor.scheduleWithFixedDelay(() -> cordVtnService.getNodes() | ||
| 80 | - .stream() | ||
| 81 | - .filter(node -> localId.equals(getMaster(node))) | ||
| 82 | - .forEach(node -> { | ||
| 83 | - connect(node); | ||
| 84 | - disconnect(node); | ||
| 85 | - }), 0, DELAY_SEC, TimeUnit.SECONDS); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @Deactivate | ||
| 89 | - public void stop() { | ||
| 90 | - connectionExecutor.shutdown(); | ||
| 91 | - deviceService.removeListener(deviceListener); | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - public void connect(OvsdbNode ovsdbNode) { | ||
| 95 | - switch (ovsdbNode.state()) { | ||
| 96 | - case INIT: | ||
| 97 | - case DISCONNECTED: | ||
| 98 | - setPassiveMode(ovsdbNode); | ||
| 99 | - case READY: | ||
| 100 | - setupConnection(ovsdbNode); | ||
| 101 | - break; | ||
| 102 | - default: | ||
| 103 | - break; | ||
| 104 | - } | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public void disconnect(OvsdbNode ovsdbNode) { | ||
| 108 | - switch (ovsdbNode.state()) { | ||
| 109 | - case DISCONNECT: | ||
| 110 | - // TODO: disconnect | ||
| 111 | - break; | ||
| 112 | - default: | ||
| 113 | - break; | ||
| 114 | - } | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - private class InternalDeviceListener implements DeviceListener { | ||
| 118 | - | ||
| 119 | - @Override | ||
| 120 | - public void event(DeviceEvent event) { | ||
| 121 | - Device device = event.subject(); | ||
| 122 | - if (device.type() != Device.Type.CONTROLLER) { | ||
| 123 | - return; | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - DefaultOvsdbNode node; | ||
| 127 | - switch (event.type()) { | ||
| 128 | - case DEVICE_ADDED: | ||
| 129 | - node = (DefaultOvsdbNode) cordVtnService.getNode(device.id()); | ||
| 130 | - if (node != null) { | ||
| 131 | - cordVtnService.updateNode(node, CONNECTED); | ||
| 132 | - } | ||
| 133 | - break; | ||
| 134 | - case DEVICE_AVAILABILITY_CHANGED: | ||
| 135 | - node = (DefaultOvsdbNode) cordVtnService.getNode(device.id()); | ||
| 136 | - if (node != null) { | ||
| 137 | - cordVtnService.updateNode(node, DISCONNECTED); | ||
| 138 | - } | ||
| 139 | - break; | ||
| 140 | - default: | ||
| 141 | - break; | ||
| 142 | - } | ||
| 143 | - } | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | - private NodeId getMaster(OvsdbNode ovsdbNode) { | ||
| 147 | - NodeId master = mastershipService.getMasterFor(ovsdbNode.intBrId()); | ||
| 148 | - | ||
| 149 | - // master is null if there's no such device | ||
| 150 | - if (master == null) { | ||
| 151 | - master = leadershipService.getLeader(CordVtnService.CORDVTN_APP_ID); | ||
| 152 | - } | ||
| 153 | - return master; | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - private void setPassiveMode(OvsdbNode ovsdbNode) { | ||
| 157 | - // TODO: need ovsdb client implementation first | ||
| 158 | - // TODO: set the remove ovsdb server passive mode | ||
| 159 | - cordVtnService.updateNode(ovsdbNode, READY); | ||
| 160 | - } | ||
| 161 | - | ||
| 162 | - private void setupConnection(OvsdbNode ovsdbNode) { | ||
| 163 | - // TODO initiate connection | ||
| 164 | - } | ||
| 165 | -} |
| ... | @@ -23,12 +23,6 @@ import org.onosproject.net.DeviceId; | ... | @@ -23,12 +23,6 @@ import org.onosproject.net.DeviceId; |
| 23 | * Representation of a node with ovsdb server. | 23 | * Representation of a node with ovsdb server. |
| 24 | */ | 24 | */ |
| 25 | public interface OvsdbNode { | 25 | public interface OvsdbNode { |
| 26 | - /** | ||
| 27 | - * Ovsdb connection state. | ||
| 28 | - */ | ||
| 29 | - enum State { | ||
| 30 | - INIT, READY, CONNECTED, DISCONNECT, DISCONNECTED | ||
| 31 | - } | ||
| 32 | 26 | ||
| 33 | /** | 27 | /** |
| 34 | * Returns the IP address of the ovsdb server. | 28 | * Returns the IP address of the ovsdb server. |
| ... | @@ -53,13 +47,6 @@ public interface OvsdbNode { | ... | @@ -53,13 +47,6 @@ public interface OvsdbNode { |
| 53 | String host(); | 47 | String host(); |
| 54 | 48 | ||
| 55 | /** | 49 | /** |
| 56 | - * Returns the connection state of the ovsdb server. | ||
| 57 | - * | ||
| 58 | - * @return connection state | ||
| 59 | - */ | ||
| 60 | - State state(); | ||
| 61 | - | ||
| 62 | - /** | ||
| 63 | * Returns the device id of the ovsdb server. | 50 | * Returns the device id of the ovsdb server. |
| 64 | * | 51 | * |
| 65 | * @return device id | 52 | * @return device id | ... | ... |
-
Please register or login to post a comment