Hyunsun Moon
Committed by Gerrit Code Review

Fixed to read virtual switches from network config

Change-Id: I8740b8484dd7ed16897233eec472f964bab8004f
...@@ -176,6 +176,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -176,6 +176,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
176 deviceService, 176 deviceService,
177 driverService, 177 driverService,
178 groupService, 178 groupService,
179 + configRegistry,
179 DEFAULT_TUNNEL); 180 DEFAULT_TUNNEL);
180 181
181 arpProxy = new CordVtnArpProxy(appId, packetService, hostService); 182 arpProxy = new CordVtnArpProxy(appId, packetService, hostService);
......
...@@ -233,6 +233,7 @@ public class CordVtnNodeManager { ...@@ -233,6 +233,7 @@ public class CordVtnNodeManager {
233 deviceService, 233 deviceService,
234 driverService, 234 driverService,
235 groupService, 235 groupService,
236 + configRegistry,
236 DEFAULT_TUNNEL); 237 DEFAULT_TUNNEL);
237 238
238 deviceService.addListener(deviceListener); 239 deviceService.addListener(deviceListener);
......
...@@ -17,6 +17,7 @@ package org.onosproject.cordvtn; ...@@ -17,6 +17,7 @@ package org.onosproject.cordvtn;
17 17
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 import com.google.common.collect.Maps; 19 import com.google.common.collect.Maps;
20 +import com.google.common.collect.Sets;
20 import org.onlab.packet.Ethernet; 21 import org.onlab.packet.Ethernet;
21 import org.onlab.packet.IPv4; 22 import org.onlab.packet.IPv4;
22 import org.onlab.packet.Ip4Address; 23 import org.onlab.packet.Ip4Address;
...@@ -30,12 +31,12 @@ import org.onlab.util.ItemNotFoundException; ...@@ -30,12 +31,12 @@ import org.onlab.util.ItemNotFoundException;
30 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.DefaultGroupId; 32 import org.onosproject.core.DefaultGroupId;
32 import org.onosproject.core.GroupId; 33 import org.onosproject.core.GroupId;
33 -import org.onosproject.net.Device;
34 import org.onosproject.net.DeviceId; 34 import org.onosproject.net.DeviceId;
35 import org.onosproject.net.Host; 35 import org.onosproject.net.Host;
36 import org.onosproject.net.Port; 36 import org.onosproject.net.Port;
37 import org.onosproject.net.PortNumber; 37 import org.onosproject.net.PortNumber;
38 import org.onosproject.net.behaviour.ExtensionTreatmentResolver; 38 import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
39 +import org.onosproject.net.config.NetworkConfigRegistry;
39 import org.onosproject.net.device.DeviceService; 40 import org.onosproject.net.device.DeviceService;
40 import org.onosproject.net.driver.DefaultDriverData; 41 import org.onosproject.net.driver.DefaultDriverData;
41 import org.onosproject.net.driver.DefaultDriverHandler; 42 import org.onosproject.net.driver.DefaultDriverHandler;
...@@ -82,7 +83,6 @@ import java.util.Set; ...@@ -82,7 +83,6 @@ import java.util.Set;
82 import java.util.stream.Collectors; 83 import java.util.stream.Collectors;
83 84
84 import static com.google.common.base.Preconditions.checkNotNull; 85 import static com.google.common.base.Preconditions.checkNotNull;
85 -import static org.onosproject.net.Device.Type.SWITCH;
86 import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT; 86 import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
87 import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST; 87 import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST;
88 import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_SRC; 88 import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_SRC;
...@@ -119,13 +119,13 @@ public class CordVtnRuleInstaller { ...@@ -119,13 +119,13 @@ public class CordVtnRuleInstaller {
119 private static final String PORT_NAME = "portName"; 119 private static final String PORT_NAME = "portName";
120 private static final String DATA_PLANE_INTF = "dataPlaneIntf"; 120 private static final String DATA_PLANE_INTF = "dataPlaneIntf";
121 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 122
124 private final ApplicationId appId; 123 private final ApplicationId appId;
125 private final FlowRuleService flowRuleService; 124 private final FlowRuleService flowRuleService;
126 private final DeviceService deviceService; 125 private final DeviceService deviceService;
127 private final DriverService driverService; 126 private final DriverService driverService;
128 private final GroupService groupService; 127 private final GroupService groupService;
128 + private final NetworkConfigRegistry configRegistry;
129 private final String tunnelType; 129 private final String tunnelType;
130 130
131 /** 131 /**
...@@ -143,12 +143,14 @@ public class CordVtnRuleInstaller { ...@@ -143,12 +143,14 @@ public class CordVtnRuleInstaller {
143 DeviceService deviceService, 143 DeviceService deviceService,
144 DriverService driverService, 144 DriverService driverService,
145 GroupService groupService, 145 GroupService groupService,
146 + NetworkConfigRegistry configRegistry,
146 String tunnelType) { 147 String tunnelType) {
147 this.appId = appId; 148 this.appId = appId;
148 this.flowRuleService = flowRuleService; 149 this.flowRuleService = flowRuleService;
149 this.deviceService = deviceService; 150 this.deviceService = deviceService;
150 this.driverService = driverService; 151 this.driverService = driverService;
151 this.groupService = groupService; 152 this.groupService = groupService;
153 + this.configRegistry = configRegistry;
152 this.tunnelType = checkNotNull(tunnelType); 154 this.tunnelType = checkNotNull(tunnelType);
153 } 155 }
154 156
...@@ -278,21 +280,17 @@ public class CordVtnRuleInstaller { ...@@ -278,21 +280,17 @@ public class CordVtnRuleInstaller {
278 Map<DeviceId, GroupId> outGroups = Maps.newHashMap(); 280 Map<DeviceId, GroupId> outGroups = Maps.newHashMap();
279 Map<DeviceId, Set<PortNumber>> inPorts = Maps.newHashMap(); 281 Map<DeviceId, Set<PortNumber>> inPorts = Maps.newHashMap();
280 282
281 - for (Device device : deviceService.getAvailableDevices(SWITCH)) { 283 + getVirtualSwitches().stream().forEach(deviceId -> {
282 - if (!device.hwVersion().equals(OVS_HW_VERSION)) { 284 + GroupId groupId = createServiceGroup(deviceId, pService);
283 - continue; 285 + outGroups.put(deviceId, groupId);
284 - }
285 -
286 - GroupId groupId = createServiceGroup(device.id(), pService);
287 - outGroups.put(device.id(), groupId);
288 286
289 Set<PortNumber> vms = tService.hosts().keySet() 287 Set<PortNumber> vms = tService.hosts().keySet()
290 .stream() 288 .stream()
291 - .filter(host -> host.location().deviceId().equals(device.id())) 289 + .filter(host -> host.location().deviceId().equals(deviceId))
292 .map(host -> host.location().port()) 290 .map(host -> host.location().port())
293 .collect(Collectors.toSet()); 291 .collect(Collectors.toSet());
294 - inPorts.put(device.id(), vms); 292 + inPorts.put(deviceId, vms);
295 - } 293 + });
296 294
297 populateIndirectAccessRule(srcRange, serviceIp, outGroups); 295 populateIndirectAccessRule(srcRange, serviceIp, outGroups);
298 populateDirectAccessRule(srcRange, dstRange); 296 populateDirectAccessRule(srcRange, dstRange);
...@@ -319,16 +317,12 @@ public class CordVtnRuleInstaller { ...@@ -319,16 +317,12 @@ public class CordVtnRuleInstaller {
319 Map<DeviceId, GroupId> outGroups = Maps.newHashMap(); 317 Map<DeviceId, GroupId> outGroups = Maps.newHashMap();
320 GroupKey groupKey = new DefaultGroupKey(pService.id().id().getBytes()); 318 GroupKey groupKey = new DefaultGroupKey(pService.id().id().getBytes());
321 319
322 - for (Device device : deviceService.getAvailableDevices(SWITCH)) { 320 + getVirtualSwitches().stream().forEach(deviceId -> {
323 - if (!device.hwVersion().equals(OVS_HW_VERSION)) { 321 + Group group = groupService.getGroup(deviceId, groupKey);
324 - continue;
325 - }
326 -
327 - Group group = groupService.getGroup(device.id(), groupKey);
328 if (group != null) { 322 if (group != null) {
329 - outGroups.put(device.id(), group.id()); 323 + outGroups.put(deviceId, group.id());
330 - }
331 } 324 }
325 + });
332 326
333 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) { 327 for (FlowRule flowRule : flowRuleService.getFlowRulesById(appId)) {
334 IpPrefix dstIp = getDstIpFromSelector(flowRule); 328 IpPrefix dstIp = getDstIpFromSelector(flowRule);
...@@ -370,12 +364,7 @@ public class CordVtnRuleInstaller { ...@@ -370,12 +364,7 @@ public class CordVtnRuleInstaller {
370 364
371 GroupKey groupKey = getGroupKey(service.id()); 365 GroupKey groupKey = getGroupKey(service.id());
372 366
373 - for (Device device : deviceService.getAvailableDevices(SWITCH)) { 367 + for (DeviceId deviceId : getVirtualSwitches()) {
374 - if (!device.hwVersion().equals(OVS_HW_VERSION)) {
375 - continue;
376 - }
377 -
378 - DeviceId deviceId = device.id();
379 Group group = groupService.getGroup(deviceId, groupKey); 368 Group group = groupService.getGroup(deviceId, groupKey);
380 if (group == null) { 369 if (group == null) {
381 log.trace("No group exists for service {} in {}, do nothing.", service.id(), deviceId); 370 log.trace("No group exists for service {} in {}, do nothing.", service.id(), deviceId);
...@@ -974,23 +963,20 @@ public class CordVtnRuleInstaller { ...@@ -974,23 +963,20 @@ public class CordVtnRuleInstaller {
974 .transition(TABLE_DST_IP) 963 .transition(TABLE_DST_IP)
975 .build(); 964 .build();
976 965
977 - for (Device device : deviceService.getAvailableDevices(SWITCH)) {
978 - if (!device.hwVersion().equals(OVS_HW_VERSION)) {
979 - continue;
980 - }
981 966
967 + getVirtualSwitches().stream().forEach(deviceId -> {
982 FlowRule flowRuleDirect = DefaultFlowRule.builder() 968 FlowRule flowRuleDirect = DefaultFlowRule.builder()
983 .fromApp(appId) 969 .fromApp(appId)
984 .withSelector(selector) 970 .withSelector(selector)
985 .withTreatment(treatment) 971 .withTreatment(treatment)
986 .withPriority(DEFAULT_PRIORITY) 972 .withPriority(DEFAULT_PRIORITY)
987 - .forDevice(device.id()) 973 + .forDevice(deviceId)
988 .forTable(TABLE_ACCESS_TYPE) 974 .forTable(TABLE_ACCESS_TYPE)
989 .makePermanent() 975 .makePermanent()
990 .build(); 976 .build();
991 977
992 processFlowRule(true, flowRuleDirect); 978 processFlowRule(true, flowRuleDirect);
993 - } 979 + });
994 } 980 }
995 981
996 /** 982 /**
...@@ -1009,23 +995,19 @@ public class CordVtnRuleInstaller { ...@@ -1009,23 +995,19 @@ public class CordVtnRuleInstaller {
1009 .drop() 995 .drop()
1010 .build(); 996 .build();
1011 997
1012 - for (Device device : deviceService.getAvailableDevices(SWITCH)) { 998 + getVirtualSwitches().stream().forEach(deviceId -> {
1013 - if (!device.hwVersion().equals(OVS_HW_VERSION)) {
1014 - continue;
1015 - }
1016 -
1017 FlowRule flowRuleDirect = DefaultFlowRule.builder() 999 FlowRule flowRuleDirect = DefaultFlowRule.builder()
1018 .fromApp(appId) 1000 .fromApp(appId)
1019 .withSelector(selector) 1001 .withSelector(selector)
1020 .withTreatment(treatment) 1002 .withTreatment(treatment)
1021 .withPriority(LOW_PRIORITY) 1003 .withPriority(LOW_PRIORITY)
1022 - .forDevice(device.id()) 1004 + .forDevice(deviceId)
1023 .forTable(TABLE_ACCESS_TYPE) 1005 .forTable(TABLE_ACCESS_TYPE)
1024 .makePermanent() 1006 .makePermanent()
1025 .build(); 1007 .build();
1026 1008
1027 processFlowRule(true, flowRuleDirect); 1009 processFlowRule(true, flowRuleDirect);
1028 - } 1010 + });
1029 } 1011 }
1030 1012
1031 /** 1013 /**
...@@ -1140,16 +1122,12 @@ public class CordVtnRuleInstaller { ...@@ -1140,16 +1122,12 @@ public class CordVtnRuleInstaller {
1140 1122
1141 processFlowRule(true, flowRule); 1123 processFlowRule(true, flowRule);
1142 1124
1143 - for (Device device : deviceService.getAvailableDevices(SWITCH)) { 1125 + for (DeviceId vSwitchId : getVirtualSwitches()) {
1144 - if (!device.hwVersion().equals(OVS_HW_VERSION)) { 1126 + if (vSwitchId.equals(deviceId)) {
1145 continue; 1127 continue;
1146 } 1128 }
1147 1129
1148 - if (device.id().equals(deviceId)) { 1130 + ExtensionTreatment tunnelDst = getTunnelDst(vSwitchId, tunnelIp.getIp4Address());
1149 - continue;
1150 - }
1151 -
1152 - ExtensionTreatment tunnelDst = getTunnelDst(device.id(), tunnelIp.getIp4Address());
1153 if (tunnelDst == null) { 1131 if (tunnelDst == null) {
1154 continue; 1132 continue;
1155 } 1133 }
...@@ -1157,8 +1135,8 @@ public class CordVtnRuleInstaller { ...@@ -1157,8 +1135,8 @@ public class CordVtnRuleInstaller {
1157 treatment = DefaultTrafficTreatment.builder() 1135 treatment = DefaultTrafficTreatment.builder()
1158 .setEthDst(dstMac) 1136 .setEthDst(dstMac)
1159 .setTunnelId(tunnelId) 1137 .setTunnelId(tunnelId)
1160 - .extension(tunnelDst, device.id()) 1138 + .extension(tunnelDst, vSwitchId)
1161 - .setOutput(getTunnelPort(device.id())) 1139 + .setOutput(getTunnelPort(vSwitchId))
1162 .build(); 1140 .build();
1163 1141
1164 flowRule = DefaultFlowRule.builder() 1142 flowRule = DefaultFlowRule.builder()
...@@ -1166,7 +1144,7 @@ public class CordVtnRuleInstaller { ...@@ -1166,7 +1144,7 @@ public class CordVtnRuleInstaller {
1166 .withSelector(selector) 1144 .withSelector(selector)
1167 .withTreatment(treatment) 1145 .withTreatment(treatment)
1168 .withPriority(DEFAULT_PRIORITY) 1146 .withPriority(DEFAULT_PRIORITY)
1169 - .forDevice(device.id()) 1147 + .forDevice(vSwitchId)
1170 .forTable(TABLE_DST_IP) 1148 .forTable(TABLE_DST_IP)
1171 .makePermanent() 1149 .makePermanent()
1172 .build(); 1150 .build();
...@@ -1536,5 +1514,21 @@ public class CordVtnRuleInstaller { ...@@ -1536,5 +1514,21 @@ public class CordVtnRuleInstaller {
1536 return null; 1514 return null;
1537 } 1515 }
1538 } 1516 }
1517 +
1518 + /**
1519 + * Returns integration bridges configured in the system.
1520 + *
1521 + * @return set of device ids
1522 + */
1523 + private Set<DeviceId> getVirtualSwitches() {
1524 + CordVtnConfig config = configRegistry.getConfig(appId, CordVtnConfig.class);
1525 + if (config == null) {
1526 + log.debug("No configuration found for {}", appId.name());
1527 + return Sets.newHashSet();
1528 + }
1529 +
1530 + return config.cordVtnNodes().stream()
1531 + .map(CordVtnNode::intBrId).collect(Collectors.toSet());
1532 + }
1539 } 1533 }
1540 1534
......