Hyunsun Moon
Committed by Gerrit Code Review

Fixed some bugs

- Update br-int rather than do nothing if it already exists
- Make only the leader performs node bootstrap
- Check mastership on HOST event not flow rule populator
- Install/uninstall flow rules for vSG always from master, or the rules
  stay in PENDING_ADDED state

Change-Id: I4bd5cf6f84bf36f2617288b2d843435819c76ba8
...@@ -145,6 +145,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -145,6 +145,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
145 private static final String DATA_PLANE_IP = "dataPlaneIp"; 145 private static final String DATA_PLANE_IP = "dataPlaneIp";
146 private static final String DATA_PLANE_INTF = "dataPlaneIntf"; 146 private static final String DATA_PLANE_INTF = "dataPlaneIntf";
147 private static final String S_TAG = "stag"; 147 private static final String S_TAG = "stag";
148 + private static final String VSG_HOST_ID = "vsgHostId";
148 149
149 private static final Ip4Address DEFAULT_DNS = Ip4Address.valueOf("8.8.8.8"); 150 private static final Ip4Address DEFAULT_DNS = Ip4Address.valueOf("8.8.8.8");
150 151
...@@ -175,7 +176,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -175,7 +176,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
175 deviceService, 176 deviceService,
176 driverService, 177 driverService,
177 groupService, 178 groupService,
178 - mastershipService,
179 DEFAULT_TUNNEL); 179 DEFAULT_TUNNEL);
180 180
181 arpProxy = new CordVtnArpProxy(appId, packetService, hostService); 181 arpProxy = new CordVtnArpProxy(appId, packetService, hostService);
...@@ -301,30 +301,28 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -301,30 +301,28 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
301 @Override 301 @Override
302 public void updateVirtualSubscriberGateways(HostId vSgHostId, String serviceVlan, 302 public void updateVirtualSubscriberGateways(HostId vSgHostId, String serviceVlan,
303 Map<IpAddress, MacAddress> vSgs) { 303 Map<IpAddress, MacAddress> vSgs) {
304 - Host vSgVm = hostService.getHost(vSgHostId); 304 + Host vSgHost = hostService.getHost(vSgHostId);
305 - 305 + if (vSgHost == null || !vSgHost.annotations().value(S_TAG).equals(serviceVlan)) {
306 - if (vSgVm == null || !vSgVm.annotations().value(S_TAG).equals(serviceVlan)) {
307 log.debug("Invalid vSG updates for {}", serviceVlan); 306 log.debug("Invalid vSG updates for {}", serviceVlan);
308 return; 307 return;
309 } 308 }
310 309
311 - log.info("Updates vSGs in {} with {}", vSgVm.id(), vSgs.toString()); 310 + log.info("Updates vSGs in {} with {}", vSgHost.id(), vSgs.toString());
312 vSgs.entrySet().stream() 311 vSgs.entrySet().stream()
312 + .filter(entry -> hostService.getHostsByMac(entry.getValue()).isEmpty())
313 .forEach(entry -> addVirtualSubscriberGateway( 313 .forEach(entry -> addVirtualSubscriberGateway(
314 - vSgVm, 314 + vSgHost,
315 entry.getKey(), 315 entry.getKey(),
316 entry.getValue(), 316 entry.getValue(),
317 serviceVlan)); 317 serviceVlan));
318 318
319 - hostService.getConnectedHosts(vSgVm.location()).stream() 319 + hostService.getConnectedHosts(vSgHost.location()).stream()
320 - .filter(host -> !host.mac().equals(vSgVm.mac())) 320 + .filter(host -> !host.mac().equals(vSgHost.mac()))
321 .filter(host -> !vSgs.values().contains(host.mac())) 321 .filter(host -> !vSgs.values().contains(host.mac()))
322 .forEach(host -> { 322 .forEach(host -> {
323 log.info("Removed vSG {}", host.toString()); 323 log.info("Removed vSG {}", host.toString());
324 hostProvider.hostVanished(host.id()); 324 hostProvider.hostVanished(host.id());
325 }); 325 });
326 -
327 - ruleInstaller.populateSubscriberGatewayRules(vSgVm, vSgs.keySet());
328 } 326 }
329 327
330 /** 328 /**
...@@ -337,16 +335,12 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -337,16 +335,12 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
337 */ 335 */
338 private void addVirtualSubscriberGateway(Host vSgHost, IpAddress vSgIp, MacAddress vSgMac, 336 private void addVirtualSubscriberGateway(Host vSgHost, IpAddress vSgIp, MacAddress vSgMac,
339 String serviceVlan) { 337 String serviceVlan) {
340 - HostId hostId = HostId.hostId(vSgMac); 338 + log.info("vSG with IP({}) MAC({}) added", vSgIp.toString(), vSgMac.toString());
341 - Host host = hostService.getHost(hostId);
342 - if (host != null) {
343 - log.trace("vSG with {} already exists", vSgMac.toString());
344 - return;
345 - }
346 339
347 - log.info("vSG with IP({}) MAC({}) detected", vSgIp.toString(), vSgMac.toString()); 340 + HostId hostId = HostId.hostId(vSgMac);
348 DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() 341 DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
349 - .set(S_TAG, serviceVlan); 342 + .set(S_TAG, serviceVlan)
343 + .set(VSG_HOST_ID, vSgHost.id().toString());
350 344
351 HostDescription hostDesc = new DefaultHostDescription( 345 HostDescription hostDesc = new DefaultHostDescription(
352 vSgMac, 346 vSgMac,
...@@ -529,6 +523,11 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -529,6 +523,11 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
529 * @param host host 523 * @param host host
530 */ 524 */
531 private void serviceVmAdded(Host host) { 525 private void serviceVmAdded(Host host) {
526 + String serviceVlan = host.annotations().value(S_TAG);
527 + if (serviceVlan != null) {
528 + virtualSubscriberGatewayAdded(host, serviceVlan);
529 + }
530 +
532 String vNetId = host.annotations().value(SERVICE_ID); 531 String vNetId = host.annotations().value(SERVICE_ID);
533 if (vNetId == null) { 532 if (vNetId == null) {
534 // ignore this host, it is not the service VM, or it's a vSG 533 // ignore this host, it is not the service VM, or it's a vSG
...@@ -538,8 +537,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -538,8 +537,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
538 OpenstackNetwork vNet = openstackService.network(vNetId); 537 OpenstackNetwork vNet = openstackService.network(vNetId);
539 if (vNet == null) { 538 if (vNet == null) {
540 log.warn("Failed to get OpenStack network {} for VM {}({}).", 539 log.warn("Failed to get OpenStack network {} for VM {}({}).",
541 - vNetId, 540 + vNetId, host.id(),
542 - host.id(),
543 host.annotations().value(OPENSTACK_VM_ID)); 541 host.annotations().value(OPENSTACK_VM_ID));
544 return; 542 return;
545 } 543 }
...@@ -572,20 +570,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -572,20 +570,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
572 570
573 registerDhcpLease(host, service); 571 registerDhcpLease(host, service);
574 ruleInstaller.populateBasicConnectionRules(host, getTunnelIp(host), vNet); 572 ruleInstaller.populateBasicConnectionRules(host, getTunnelIp(host), vNet);
575 -
576 - String serviceVlan = host.annotations().value(S_TAG);
577 - if (serviceVlan != null) {
578 - log.debug("vSG VM detected {}", host.id());
579 - Map<IpAddress, MacAddress> vSgs = getSubscriberGateways(host);
580 - vSgs.entrySet().stream()
581 - .forEach(entry -> addVirtualSubscriberGateway(
582 - host,
583 - entry.getKey(),
584 - entry.getValue(),
585 - serviceVlan));
586 -
587 - ruleInstaller.populateSubscriberGatewayRules(host, vSgs.keySet());
588 - }
589 } 573 }
590 574
591 /** 575 /**
...@@ -594,21 +578,21 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -594,21 +578,21 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
594 * @param host host 578 * @param host host
595 */ 579 */
596 private void serviceVmRemoved(Host host) { 580 private void serviceVmRemoved(Host host) {
581 + String serviceVlan = host.annotations().value(S_TAG);
582 + if (serviceVlan != null) {
583 + virtualSubscriberGatewayRemoved(host);
584 + }
585 +
597 String vNetId = host.annotations().value(SERVICE_ID); 586 String vNetId = host.annotations().value(SERVICE_ID);
598 if (vNetId == null) { 587 if (vNetId == null) {
599 // ignore it, it's not the service VM or it's a vSG 588 // ignore it, it's not the service VM or it's a vSG
600 - String serviceVlan = host.annotations().value(S_TAG);
601 - if (serviceVlan != null) {
602 - log.info("vSG {} removed", host.id());
603 - }
604 return; 589 return;
605 } 590 }
606 591
607 OpenstackNetwork vNet = openstackService.network(vNetId); 592 OpenstackNetwork vNet = openstackService.network(vNetId);
608 if (vNet == null) { 593 if (vNet == null) {
609 log.warn("Failed to get OpenStack network {} for VM {}({}).", 594 log.warn("Failed to get OpenStack network {} for VM {}({}).",
610 - vNetId, 595 + vNetId, host.id(),
611 - host.id(),
612 host.annotations().value(OPENSTACK_VM_ID)); 596 host.annotations().value(OPENSTACK_VM_ID));
613 return; 597 return;
614 } 598 }
...@@ -642,6 +626,62 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -642,6 +626,62 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
642 } 626 }
643 } 627 }
644 628
629 +
630 + /**
631 + * Handles virtual subscriber gateway VM or container.
632 + *
633 + * @param host new host with stag, it can be vsg VM or vsg
634 + * @param serviceVlan service vlan
635 + */
636 + private void virtualSubscriberGatewayAdded(Host host, String serviceVlan) {
637 + Map<IpAddress, MacAddress> vSgs;
638 + Host vSgHost;
639 +
640 + String vSgHostId = host.annotations().value(VSG_HOST_ID);
641 + if (vSgHostId == null) {
642 + log.debug("vSG VM detected {}", host.id());
643 +
644 + vSgHost = host;
645 + vSgs = getSubscriberGateways(vSgHost);
646 + vSgs.entrySet().stream().forEach(entry -> addVirtualSubscriberGateway(
647 + vSgHost,
648 + entry.getKey(),
649 + entry.getValue(),
650 + serviceVlan));
651 + } else {
652 + vSgHost = hostService.getHost(HostId.hostId(vSgHostId));
653 + if (vSgHost == null) {
654 + return;
655 + }
656 +
657 + log.debug("vSG detected {}", host.id());
658 + vSgs = getSubscriberGateways(vSgHost);
659 + }
660 +
661 + ruleInstaller.populateSubscriberGatewayRules(vSgHost, vSgs.keySet());
662 + }
663 +
664 + /**
665 + * Handles virtual subscriber gateway removed.
666 + *
667 + * @param vSg vsg host to remove
668 + */
669 + private void virtualSubscriberGatewayRemoved(Host vSg) {
670 + String vSgHostId = vSg.annotations().value(VSG_HOST_ID);
671 + if (vSgHostId == null) {
672 + return;
673 + }
674 +
675 + Host vSgHost = hostService.getHost(HostId.hostId(vSgHostId));
676 + if (vSgHost == null) {
677 + return;
678 + }
679 +
680 + log.info("vSG removed {}", vSg.id());
681 + Map<IpAddress, MacAddress> vSgs = getSubscriberGateways(vSgHost);
682 + ruleInstaller.populateSubscriberGatewayRules(vSgHost, vSgs.keySet());
683 + }
684 +
645 /** 685 /**
646 * Sets service network gateway MAC address and sends out gratuitous ARP to all 686 * Sets service network gateway MAC address and sends out gratuitous ARP to all
647 * VMs to update the gateway MAC address. 687 * VMs to update the gateway MAC address.
...@@ -709,10 +749,14 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -709,10 +749,14 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
709 749
710 switch (event.type()) { 750 switch (event.type()) {
711 case HOST_ADDED: 751 case HOST_ADDED:
712 - eventExecutor.submit(() -> serviceVmAdded(host)); 752 + if (mastershipService.isLocalMaster(host.location().deviceId())) {
753 + eventExecutor.submit(() -> serviceVmAdded(host));
754 + }
713 break; 755 break;
714 case HOST_REMOVED: 756 case HOST_REMOVED:
715 - eventExecutor.submit(() -> serviceVmRemoved(host)); 757 + if (mastershipService.isLocalMaster(host.location().deviceId())) {
758 + eventExecutor.submit(() -> serviceVmRemoved(host));
759 + }
716 break; 760 break;
717 default: 761 default:
718 break; 762 break;
......
...@@ -27,9 +27,10 @@ import org.onlab.packet.IpAddress; ...@@ -27,9 +27,10 @@ import org.onlab.packet.IpAddress;
27 import org.onlab.util.ItemNotFoundException; 27 import org.onlab.util.ItemNotFoundException;
28 import org.onlab.util.KryoNamespace; 28 import org.onlab.util.KryoNamespace;
29 import org.onosproject.cluster.ClusterService; 29 import org.onosproject.cluster.ClusterService;
30 +import org.onosproject.cluster.LeadershipService;
31 +import org.onosproject.cluster.NodeId;
30 import org.onosproject.core.ApplicationId; 32 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.CoreService; 33 import org.onosproject.core.CoreService;
32 -import org.onosproject.mastership.MastershipService;
33 import org.onosproject.net.ConnectPoint; 34 import org.onosproject.net.ConnectPoint;
34 import org.onosproject.net.DefaultAnnotations; 35 import org.onosproject.net.DefaultAnnotations;
35 import org.onosproject.net.Device; 36 import org.onosproject.net.Device;
...@@ -70,6 +71,7 @@ import java.util.ArrayList; ...@@ -70,6 +71,7 @@ import java.util.ArrayList;
70 import java.util.HashMap; 71 import java.util.HashMap;
71 import java.util.List; 72 import java.util.List;
72 import java.util.Map; 73 import java.util.Map;
74 +import java.util.Objects;
73 import java.util.Set; 75 import java.util.Set;
74 import java.util.concurrent.ExecutorService; 76 import java.util.concurrent.ExecutorService;
75 import java.util.stream.Collectors; 77 import java.util.stream.Collectors;
...@@ -149,7 +151,7 @@ public class CordVtnNodeManager { ...@@ -149,7 +151,7 @@ public class CordVtnNodeManager {
149 protected FlowRuleService flowRuleService; 151 protected FlowRuleService flowRuleService;
150 152
151 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 153 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
152 - protected MastershipService mastershipService; 154 + protected LeadershipService leadershipService;
153 155
154 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 156 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
155 protected GroupService groupService; 157 protected GroupService groupService;
...@@ -169,6 +171,7 @@ public class CordVtnNodeManager { ...@@ -169,6 +171,7 @@ public class CordVtnNodeManager {
169 private ConsistentMap<String, CordVtnNode> nodeStore; 171 private ConsistentMap<String, CordVtnNode> nodeStore;
170 private CordVtnRuleInstaller ruleInstaller; 172 private CordVtnRuleInstaller ruleInstaller;
171 private ApplicationId appId; 173 private ApplicationId appId;
174 + private NodeId localNodeId;
172 175
173 private enum NodeState implements CordVtnNodeState { 176 private enum NodeState implements CordVtnNodeState {
174 177
...@@ -217,6 +220,9 @@ public class CordVtnNodeManager { ...@@ -217,6 +220,9 @@ public class CordVtnNodeManager {
217 @Activate 220 @Activate
218 protected void active() { 221 protected void active() {
219 appId = coreService.getAppId(CordVtnService.CORDVTN_APP_ID); 222 appId = coreService.getAppId(CordVtnService.CORDVTN_APP_ID);
223 + localNodeId = clusterService.getLocalNode().id();
224 + leadershipService.runForLeadership(appId.name());
225 +
220 nodeStore = storageService.<String, CordVtnNode>consistentMapBuilder() 226 nodeStore = storageService.<String, CordVtnNode>consistentMapBuilder()
221 .withSerializer(Serializer.using(NODE_SERIALIZER.build())) 227 .withSerializer(Serializer.using(NODE_SERIALIZER.build()))
222 .withName("cordvtn-nodestore") 228 .withName("cordvtn-nodestore")
...@@ -227,7 +233,6 @@ public class CordVtnNodeManager { ...@@ -227,7 +233,6 @@ public class CordVtnNodeManager {
227 deviceService, 233 deviceService,
228 driverService, 234 driverService,
229 groupService, 235 groupService,
230 - mastershipService,
231 DEFAULT_TUNNEL); 236 DEFAULT_TUNNEL);
232 237
233 deviceService.addListener(deviceListener); 238 deviceService.addListener(deviceListener);
...@@ -242,6 +247,7 @@ public class CordVtnNodeManager { ...@@ -242,6 +247,7 @@ public class CordVtnNodeManager {
242 247
243 eventExecutor.shutdown(); 248 eventExecutor.shutdown();
244 nodeStore.clear(); 249 nodeStore.clear();
250 + leadershipService.withdraw(appId.name());
245 } 251 }
246 252
247 /** 253 /**
...@@ -285,6 +291,13 @@ public class CordVtnNodeManager { ...@@ -285,6 +291,13 @@ public class CordVtnNodeManager {
285 return; 291 return;
286 } 292 }
287 293
294 + NodeId leaderNodeId = leadershipService.getLeader(appId.name());
295 + log.debug("Node init requested, local: {} leader: {}", localNodeId, leaderNodeId);
296 + if (!Objects.equals(localNodeId, leaderNodeId)) {
297 + // only the leader performs node init
298 + return;
299 + }
300 +
288 NodeState state = getNodeState(node); 301 NodeState state = getNodeState(node);
289 log.debug("Init node: {} state: {}", node.hostname(), state.toString()); 302 log.debug("Init node: {} state: {}", node.hostname(), state.toString());
290 state.process(this, node); 303 state.process(this, node);
...@@ -839,6 +852,12 @@ public class CordVtnNodeManager { ...@@ -839,6 +852,12 @@ public class CordVtnNodeManager {
839 @Override 852 @Override
840 public void event(DeviceEvent event) { 853 public void event(DeviceEvent event) {
841 854
855 + NodeId leaderNodeId = leadershipService.getLeader(appId.name());
856 + if (!Objects.equals(localNodeId, leaderNodeId)) {
857 + // only the leader processes events
858 + return;
859 + }
860 +
842 Device device = event.subject(); 861 Device device = event.subject();
843 ConnectionHandler<Device> handler = 862 ConnectionHandler<Device> handler =
844 (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler); 863 (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler);
......
...@@ -30,7 +30,6 @@ import org.onlab.util.ItemNotFoundException; ...@@ -30,7 +30,6 @@ import org.onlab.util.ItemNotFoundException;
30 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.DefaultGroupId; 31 import org.onosproject.core.DefaultGroupId;
32 import org.onosproject.core.GroupId; 32 import org.onosproject.core.GroupId;
33 -import org.onosproject.mastership.MastershipService;
34 import org.onosproject.net.Device; 33 import org.onosproject.net.Device;
35 import org.onosproject.net.DeviceId; 34 import org.onosproject.net.DeviceId;
36 import org.onosproject.net.Host; 35 import org.onosproject.net.Host;
...@@ -120,13 +119,13 @@ public class CordVtnRuleInstaller { ...@@ -120,13 +119,13 @@ public class CordVtnRuleInstaller {
120 private static final String PORT_NAME = "portName"; 119 private static final String PORT_NAME = "portName";
121 private static final String DATA_PLANE_INTF = "dataPlaneIntf"; 120 private static final String DATA_PLANE_INTF = "dataPlaneIntf";
122 private static final String S_TAG = "stag"; 121 private static final String S_TAG = "stag";
122 + private static final String OVS_HW_VERSION = "Open vSwitch";
123 123
124 private final ApplicationId appId; 124 private final ApplicationId appId;
125 private final FlowRuleService flowRuleService; 125 private final FlowRuleService flowRuleService;
126 private final DeviceService deviceService; 126 private final DeviceService deviceService;
127 private final DriverService driverService; 127 private final DriverService driverService;
128 private final GroupService groupService; 128 private final GroupService groupService;
129 - private final MastershipService mastershipService;
130 private final String tunnelType; 129 private final String tunnelType;
131 130
132 /** 131 /**
...@@ -137,7 +136,6 @@ public class CordVtnRuleInstaller { ...@@ -137,7 +136,6 @@ public class CordVtnRuleInstaller {
137 * @param deviceService device service 136 * @param deviceService device service
138 * @param driverService driver service 137 * @param driverService driver service
139 * @param groupService group service 138 * @param groupService group service
140 - * @param mastershipService mastership service
141 * @param tunnelType tunnel type 139 * @param tunnelType tunnel type
142 */ 140 */
143 public CordVtnRuleInstaller(ApplicationId appId, 141 public CordVtnRuleInstaller(ApplicationId appId,
...@@ -145,14 +143,12 @@ public class CordVtnRuleInstaller { ...@@ -145,14 +143,12 @@ public class CordVtnRuleInstaller {
145 DeviceService deviceService, 143 DeviceService deviceService,
146 DriverService driverService, 144 DriverService driverService,
147 GroupService groupService, 145 GroupService groupService,
148 - MastershipService mastershipService,
149 String tunnelType) { 146 String tunnelType) {
150 this.appId = appId; 147 this.appId = appId;
151 this.flowRuleService = flowRuleService; 148 this.flowRuleService = flowRuleService;
152 this.deviceService = deviceService; 149 this.deviceService = deviceService;
153 this.driverService = driverService; 150 this.driverService = driverService;
154 this.groupService = groupService; 151 this.groupService = groupService;
155 - this.mastershipService = mastershipService;
156 this.tunnelType = checkNotNull(tunnelType); 152 this.tunnelType = checkNotNull(tunnelType);
157 } 153 }
158 154
...@@ -187,10 +183,6 @@ public class CordVtnRuleInstaller { ...@@ -187,10 +183,6 @@ public class CordVtnRuleInstaller {
187 checkNotNull(vNet); 183 checkNotNull(vNet);
188 184
189 DeviceId deviceId = host.location().deviceId(); 185 DeviceId deviceId = host.location().deviceId();
190 - if (!mastershipService.isLocalMaster(deviceId)) {
191 - return;
192 - }
193 -
194 PortNumber inPort = host.location().port(); 186 PortNumber inPort = host.location().port();
195 MacAddress dstMac = host.mac(); 187 MacAddress dstMac = host.mac();
196 IpAddress hostIp = host.ipAddresses().stream().findFirst().get(); 188 IpAddress hostIp = host.ipAddresses().stream().findFirst().get();
...@@ -225,10 +217,6 @@ public class CordVtnRuleInstaller { ...@@ -225,10 +217,6 @@ public class CordVtnRuleInstaller {
225 PortNumber port = host.location().port(); 217 PortNumber port = host.location().port();
226 IpAddress ip = host.ipAddresses().stream().findFirst().orElse(null); 218 IpAddress ip = host.ipAddresses().stream().findFirst().orElse(null);
227 219
228 - if (!mastershipService.isLocalMaster(deviceId)) {
229 - return;
230 - }
231 -
232 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) { 220 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) {
233 if (flowRule.deviceId().equals(deviceId)) { 221 if (flowRule.deviceId().equals(deviceId)) {
234 PortNumber inPort = getInPort(flowRule); 222 PortNumber inPort = getInPort(flowRule);
...@@ -284,6 +272,10 @@ public class CordVtnRuleInstaller { ...@@ -284,6 +272,10 @@ public class CordVtnRuleInstaller {
284 Map<DeviceId, Set<PortNumber>> inPorts = Maps.newHashMap(); 272 Map<DeviceId, Set<PortNumber>> inPorts = Maps.newHashMap();
285 273
286 for (Device device : deviceService.getAvailableDevices(SWITCH)) { 274 for (Device device : deviceService.getAvailableDevices(SWITCH)) {
275 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
276 + continue;
277 + }
278 +
287 GroupId groupId = createServiceGroup(device.id(), pService); 279 GroupId groupId = createServiceGroup(device.id(), pService);
288 outGroups.put(device.id(), groupId); 280 outGroups.put(device.id(), groupId);
289 281
...@@ -320,12 +312,16 @@ public class CordVtnRuleInstaller { ...@@ -320,12 +312,16 @@ public class CordVtnRuleInstaller {
320 Map<DeviceId, GroupId> outGroups = Maps.newHashMap(); 312 Map<DeviceId, GroupId> outGroups = Maps.newHashMap();
321 GroupKey groupKey = new DefaultGroupKey(pService.id().id().getBytes()); 313 GroupKey groupKey = new DefaultGroupKey(pService.id().id().getBytes());
322 314
323 - deviceService.getAvailableDevices(SWITCH).forEach(device -> { 315 + for (Device device : deviceService.getAvailableDevices(SWITCH)) {
316 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
317 + continue;
318 + }
319 +
324 Group group = groupService.getGroup(device.id(), groupKey); 320 Group group = groupService.getGroup(device.id(), groupKey);
325 if (group != null) { 321 if (group != null) {
326 outGroups.put(device.id(), group.id()); 322 outGroups.put(device.id(), group.id());
327 } 323 }
328 - }); 324 + }
329 325
330 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) { 326 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) {
331 IpPrefix dstIp = getDstIpFromSelector(flowRule); 327 IpPrefix dstIp = getDstIpFromSelector(flowRule);
...@@ -368,11 +364,11 @@ public class CordVtnRuleInstaller { ...@@ -368,11 +364,11 @@ public class CordVtnRuleInstaller {
368 GroupKey groupKey = getGroupKey(service.id()); 364 GroupKey groupKey = getGroupKey(service.id());
369 365
370 for (Device device : deviceService.getAvailableDevices(SWITCH)) { 366 for (Device device : deviceService.getAvailableDevices(SWITCH)) {
371 - DeviceId deviceId = device.id(); 367 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
372 - if (!mastershipService.isLocalMaster(deviceId)) {
373 continue; 368 continue;
374 } 369 }
375 370
371 + DeviceId deviceId = device.id();
376 Group group = groupService.getGroup(deviceId, groupKey); 372 Group group = groupService.getGroup(deviceId, groupKey);
377 if (group == null) { 373 if (group == null) {
378 log.trace("No group exists for service {} in {}, do nothing.", service.id(), deviceId); 374 log.trace("No group exists for service {} in {}, do nothing.", service.id(), deviceId);
...@@ -421,10 +417,6 @@ public class CordVtnRuleInstaller { ...@@ -421,10 +417,6 @@ public class CordVtnRuleInstaller {
421 DeviceId deviceId = host.location().deviceId(); 417 DeviceId deviceId = host.location().deviceId();
422 IpAddress hostIp = host.ipAddresses().stream().findFirst().get(); 418 IpAddress hostIp = host.ipAddresses().stream().findFirst().get();
423 419
424 - if (!mastershipService.isLocalMaster(deviceId)) {
425 - return;
426 - }
427 -
428 TrafficSelector selector = DefaultTrafficSelector.builder() 420 TrafficSelector selector = DefaultTrafficSelector.builder()
429 .matchEthType(Ethernet.TYPE_ARP) 421 .matchEthType(Ethernet.TYPE_ARP)
430 .matchArpTpa(mService.serviceIp().getIp4Address()) 422 .matchArpTpa(mService.serviceIp().getIp4Address())
...@@ -520,10 +512,6 @@ public class CordVtnRuleInstaller { ...@@ -520,10 +512,6 @@ public class CordVtnRuleInstaller {
520 */ 512 */
521 public void removeManagementNetworkRules(Host host, CordService mService) { 513 public void removeManagementNetworkRules(Host host, CordService mService) {
522 checkNotNull(mService); 514 checkNotNull(mService);
523 -
524 - if (!mastershipService.isLocalMaster(host.location().deviceId())) {
525 - return;
526 - }
527 // TODO remove management network specific rules 515 // TODO remove management network specific rules
528 } 516 }
529 517
...@@ -980,6 +968,10 @@ public class CordVtnRuleInstaller { ...@@ -980,6 +968,10 @@ public class CordVtnRuleInstaller {
980 .build(); 968 .build();
981 969
982 for (Device device : deviceService.getAvailableDevices(SWITCH)) { 970 for (Device device : deviceService.getAvailableDevices(SWITCH)) {
971 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
972 + continue;
973 + }
974 +
983 FlowRule flowRuleDirect = DefaultFlowRule.builder() 975 FlowRule flowRuleDirect = DefaultFlowRule.builder()
984 .fromApp(appId) 976 .fromApp(appId)
985 .withSelector(selector) 977 .withSelector(selector)
...@@ -1011,6 +1003,10 @@ public class CordVtnRuleInstaller { ...@@ -1011,6 +1003,10 @@ public class CordVtnRuleInstaller {
1011 .build(); 1003 .build();
1012 1004
1013 for (Device device : deviceService.getAvailableDevices(SWITCH)) { 1005 for (Device device : deviceService.getAvailableDevices(SWITCH)) {
1006 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
1007 + continue;
1008 + }
1009 +
1014 FlowRule flowRuleDirect = DefaultFlowRule.builder() 1010 FlowRule flowRuleDirect = DefaultFlowRule.builder()
1015 .fromApp(appId) 1011 .fromApp(appId)
1016 .withSelector(selector) 1012 .withSelector(selector)
...@@ -1138,6 +1134,10 @@ public class CordVtnRuleInstaller { ...@@ -1138,6 +1134,10 @@ public class CordVtnRuleInstaller {
1138 processFlowRule(true, flowRule); 1134 processFlowRule(true, flowRule);
1139 1135
1140 for (Device device : deviceService.getAvailableDevices(SWITCH)) { 1136 for (Device device : deviceService.getAvailableDevices(SWITCH)) {
1137 + if (!device.hwVersion().equals(OVS_HW_VERSION)) {
1138 + continue;
1139 + }
1140 +
1141 if (device.id().equals(deviceId)) { 1141 if (device.id().equals(deviceId)) {
1142 continue; 1142 continue;
1143 } 1143 }
......
...@@ -578,11 +578,6 @@ public class DefaultOvsdbClient ...@@ -578,11 +578,6 @@ public class DefaultOvsdbClient
578 return false; 578 return false;
579 } 579 }
580 580
581 - String bridgeUuid = getBridgeUuid(bridgeName);
582 - if (bridgeUuid != null) {
583 - return false;
584 - }
585 -
586 Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE); 581 Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
587 Set<String> failMode = new HashSet<>(Arrays.asList("secure")); 582 Set<String> failMode = new HashSet<>(Arrays.asList("secure"));
588 bridge.setFailMode(failMode); 583 bridge.setFailMode(failMode);
...@@ -594,10 +589,15 @@ public class DefaultOvsdbClient ...@@ -594,10 +589,15 @@ public class DefaultOvsdbClient
594 options.put("datapath-id", dpid); 589 options.put("datapath-id", dpid);
595 bridge.setOtherConfig(options); 590 bridge.setOtherConfig(options);
596 591
597 - bridge.setName(bridgeName); 592 + String bridgeUuid = getBridgeUuid(bridgeName);
598 - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", 593 + if (bridgeUuid == null) {
599 - OvsdbConstant.DATABASENAME, "bridges", 594 + bridge.setName(bridgeName);
600 - ovsUuid, bridge.getRow()); 595 + bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
596 + OvsdbConstant.DATABASENAME, "bridges",
597 + ovsUuid, bridge.getRow());
598 + } else {
599 + updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
600 + }
601 601
602 if (bridgeUuid != null) { 602 if (bridgeUuid != null) {
603 createPort(bridgeName, bridgeName); 603 createPort(bridgeName, bridgeName);
......