Charles Chan
Committed by Gerrit Code Review

Improve SegmentRoutingAppConfig

- Separate host and subnet suppression
- Use port instead of interface to specify which SR should ignore

Change-Id: Ie6491950cddf0860924565f081504b4f4d788179
...@@ -473,7 +473,7 @@ public class RoutingRulePopulator { ...@@ -473,7 +473,7 @@ public class RoutingRulePopulator {
473 for (Port port : srManager.deviceService.getPorts(deviceId)) { 473 for (Port port : srManager.deviceService.getPorts(deviceId)) {
474 ConnectPoint cp = new ConnectPoint(deviceId, port.number()); 474 ConnectPoint cp = new ConnectPoint(deviceId, port.number());
475 // TODO: Handles dynamic port events when we are ready for dynamic config 475 // TODO: Handles dynamic port events when we are ready for dynamic config
476 - if (!srManager.deviceConfiguration.excludedPorts().contains(cp) && 476 + if (!srManager.deviceConfiguration.suppressSubnet().contains(cp) &&
477 port.isEnabled()) { 477 port.isEnabled()) {
478 Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number()); 478 Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number());
479 VlanId assignedVlan = (portSubnet == null) 479 VlanId assignedVlan = (portSubnet == null)
......
...@@ -991,7 +991,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -991,7 +991,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
991 Set<IpAddress> ips = event.subject().ipAddresses(); 991 Set<IpAddress> ips = event.subject().ipAddresses();
992 log.info("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port); 992 log.info("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
993 993
994 - if (!deviceConfiguration.excludedPorts() 994 + if (!deviceConfiguration.suppressHost()
995 .contains(new ConnectPoint(deviceId, port))) { 995 .contains(new ConnectPoint(deviceId, port))) {
996 // Populate bridging table entry 996 // Populate bridging table entry
997 log.debug("Populate L2 table entry for host {} at {}:{}", 997 log.debug("Populate L2 table entry for host {} at {}:{}",
...@@ -1020,7 +1020,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1020,7 +1020,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1020 Set<IpAddress> ips = event.subject().ipAddresses(); 1020 Set<IpAddress> ips = event.subject().ipAddresses();
1021 log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port); 1021 log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port);
1022 1022
1023 - if (!deviceConfiguration.excludedPorts() 1023 + if (!deviceConfiguration.suppressHost()
1024 .contains(new ConnectPoint(deviceId, port))) { 1024 .contains(new ConnectPoint(deviceId, port))) {
1025 // Revoke bridging table entry 1025 // Revoke bridging table entry
1026 ForwardingObjective.Builder fob = 1026 ForwardingObjective.Builder fob =
...@@ -1051,7 +1051,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1051,7 +1051,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1051 log.debug("Host {}/{} is moved from {}:{} to {}:{}", 1051 log.debug("Host {}/{} is moved from {}:{} to {}:{}",
1052 mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort); 1052 mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort);
1053 1053
1054 - if (!deviceConfiguration.excludedPorts() 1054 + if (!deviceConfiguration.suppressHost()
1055 .contains(new ConnectPoint(prevDeviceId, prevPort))) { 1055 .contains(new ConnectPoint(prevDeviceId, prevPort))) {
1056 // Revoke previous bridging table entry 1056 // Revoke previous bridging table entry
1057 ForwardingObjective.Builder prevFob = 1057 ForwardingObjective.Builder prevFob =
...@@ -1069,7 +1069,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1069,7 +1069,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1069 }); 1069 });
1070 } 1070 }
1071 1071
1072 - if (!deviceConfiguration.excludedPorts() 1072 + if (!deviceConfiguration.suppressHost()
1073 .contains(new ConnectPoint(newDeviceId, newPort))) { 1073 .contains(new ConnectPoint(newDeviceId, newPort))) {
1074 // Populate new bridging table entry 1074 // Populate new bridging table entry
1075 ForwardingObjective.Builder newFob = 1075 ForwardingObjective.Builder newFob =
...@@ -1099,7 +1099,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1099,7 +1099,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1099 Set<IpAddress> newIps = event.subject().ipAddresses(); 1099 Set<IpAddress> newIps = event.subject().ipAddresses();
1100 log.debug("Host {}/{} is updated", mac, vlanId); 1100 log.debug("Host {}/{} is updated", mac, vlanId);
1101 1101
1102 - if (!deviceConfiguration.excludedPorts() 1102 + if (!deviceConfiguration.suppressHost()
1103 .contains(new ConnectPoint(prevDeviceId, prevPort))) { 1103 .contains(new ConnectPoint(prevDeviceId, prevPort))) {
1104 // Revoke previous IP table entry 1104 // Revoke previous IP table entry
1105 prevIps.forEach(ip -> { 1105 prevIps.forEach(ip -> {
...@@ -1110,7 +1110,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -1110,7 +1110,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
1110 }); 1110 });
1111 } 1111 }
1112 1112
1113 - if (!deviceConfiguration.excludedPorts() 1113 + if (!deviceConfiguration.suppressHost()
1114 .contains(new ConnectPoint(newDeviceId, newPort))) { 1114 .contains(new ConnectPoint(newDeviceId, newPort))) {
1115 // Populate new IP table entry 1115 // Populate new IP table entry
1116 newIps.forEach(ip -> { 1116 newIps.forEach(ip -> {
......
...@@ -18,7 +18,6 @@ package org.onosproject.segmentrouting.config; ...@@ -18,7 +18,6 @@ package org.onosproject.segmentrouting.config;
18 import com.google.common.collect.HashMultimap; 18 import com.google.common.collect.HashMultimap;
19 import com.google.common.collect.ImmutableSet; 19 import com.google.common.collect.ImmutableSet;
20 import com.google.common.collect.SetMultimap; 20 import com.google.common.collect.SetMultimap;
21 -import com.google.common.collect.Sets;
22 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
23 import org.onlab.packet.Ip4Prefix; 22 import org.onlab.packet.Ip4Prefix;
24 import org.onlab.packet.IpPrefix; 23 import org.onlab.packet.IpPrefix;
...@@ -30,6 +29,7 @@ import org.onosproject.incubator.net.config.basics.InterfaceConfig; ...@@ -30,6 +29,7 @@ import org.onosproject.incubator.net.config.basics.InterfaceConfig;
30 import org.onosproject.incubator.net.intf.Interface; 29 import org.onosproject.incubator.net.intf.Interface;
31 import org.onosproject.net.ConnectPoint; 30 import org.onosproject.net.ConnectPoint;
32 import org.onosproject.net.config.NetworkConfigRegistry; 31 import org.onosproject.net.config.NetworkConfigRegistry;
32 +import org.onosproject.net.config.NetworkConfigService;
33 import org.onosproject.net.host.InterfaceIpAddress; 33 import org.onosproject.net.host.InterfaceIpAddress;
34 import org.onosproject.net.DeviceId; 34 import org.onosproject.net.DeviceId;
35 import org.onosproject.net.PortNumber; 35 import org.onosproject.net.PortNumber;
...@@ -57,7 +57,8 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -57,7 +57,8 @@ public class DeviceConfiguration implements DeviceProperties {
57 private final List<Integer> allSegmentIds = new ArrayList<>(); 57 private final List<Integer> allSegmentIds = new ArrayList<>();
58 private final Map<DeviceId, SegmentRouterInfo> deviceConfigMap = new ConcurrentHashMap<>(); 58 private final Map<DeviceId, SegmentRouterInfo> deviceConfigMap = new ConcurrentHashMap<>();
59 private final Map<VlanId, List<ConnectPoint>> xConnects = new ConcurrentHashMap<>(); 59 private final Map<VlanId, List<ConnectPoint>> xConnects = new ConcurrentHashMap<>();
60 - private final Set<ConnectPoint> excludedPorts = Sets.newConcurrentHashSet(); 60 + private ApplicationId appId;
61 + private NetworkConfigService cfgService;
61 private SegmentRoutingAppConfig appConfig; 62 private SegmentRoutingAppConfig appConfig;
62 63
63 private class SegmentRouterInfo { 64 private class SegmentRouterInfo {
...@@ -85,6 +86,9 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -85,6 +86,9 @@ public class DeviceConfiguration implements DeviceProperties {
85 */ 86 */
86 public DeviceConfiguration(ApplicationId appId, 87 public DeviceConfiguration(ApplicationId appId,
87 NetworkConfigRegistry cfgService) { 88 NetworkConfigRegistry cfgService) {
89 + this.appId = appId;
90 + this.cfgService = cfgService;
91 +
88 // Read config from device subject, excluding gatewayIps and subnets. 92 // Read config from device subject, excluding gatewayIps and subnets.
89 Set<DeviceId> deviceSubjects = 93 Set<DeviceId> deviceSubjects =
90 cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class); 94 cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
...@@ -103,15 +107,18 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -103,15 +107,18 @@ public class DeviceConfiguration implements DeviceProperties {
103 allSegmentIds.add(info.nodeSid); 107 allSegmentIds.add(info.nodeSid);
104 }); 108 });
105 109
106 - // Read excluded port names from config 110 + // Read SegmentRoutingAppConfig
107 appConfig = cfgService.getConfig(appId, SegmentRoutingAppConfig.class); 111 appConfig = cfgService.getConfig(appId, SegmentRoutingAppConfig.class);
108 - Set<String> excludePorts = (appConfig != null) ?
109 - appConfig.excludePorts() : ImmutableSet.of();
110 112
111 // Read gatewayIps and subnets from port subject. 113 // Read gatewayIps and subnets from port subject.
112 Set<ConnectPoint> portSubjects = 114 Set<ConnectPoint> portSubjects =
113 cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class); 115 cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
114 portSubjects.forEach(subject -> { 116 portSubjects.forEach(subject -> {
117 + // Do not process excluded ports
118 + if (suppressSubnet().contains(subject)) {
119 + return;
120 + }
121 +
115 InterfaceConfig config = 122 InterfaceConfig config =
116 cfgService.getConfig(subject, InterfaceConfig.class); 123 cfgService.getConfig(subject, InterfaceConfig.class);
117 Set<Interface> networkInterfaces; 124 Set<Interface> networkInterfaces;
...@@ -122,12 +129,6 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -122,12 +129,6 @@ public class DeviceConfiguration implements DeviceProperties {
122 return; 129 return;
123 } 130 }
124 networkInterfaces.forEach(networkInterface -> { 131 networkInterfaces.forEach(networkInterface -> {
125 - // Do not process excluded ports
126 - if (excludePorts.contains(networkInterface.name())) {
127 - excludedPorts.add(subject);
128 - return;
129 - }
130 -
131 VlanId vlanId = networkInterface.vlan(); 132 VlanId vlanId = networkInterface.vlan();
132 ConnectPoint connectPoint = networkInterface.connectPoint(); 133 ConnectPoint connectPoint = networkInterface.connectPoint();
133 DeviceId dpid = connectPoint.deviceId(); 134 DeviceId dpid = connectPoint.deviceId();
...@@ -366,7 +367,7 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -366,7 +367,7 @@ public class DeviceConfiguration implements DeviceProperties {
366 367
367 ImmutableSet.Builder<Ip4Prefix> builder = ImmutableSet.builder(); 368 ImmutableSet.Builder<Ip4Prefix> builder = ImmutableSet.builder();
368 builder.addAll(srinfo.subnets.values()); 369 builder.addAll(srinfo.subnets.values());
369 - if (deviceId.equals(appConfig.vRouterId())) { 370 + if (appConfig != null && deviceId.equals(appConfig.vRouterId())) {
370 builder.add(Ip4Prefix.valueOf("0.0.0.0/0")); 371 builder.add(Ip4Prefix.valueOf("0.0.0.0/0"));
371 } 372 }
372 return builder.build(); 373 return builder.build();
...@@ -491,12 +492,11 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -491,12 +492,11 @@ public class DeviceConfiguration implements DeviceProperties {
491 return srinfo != null && srinfo.adjacencySids.containsKey(sid); 492 return srinfo != null && srinfo.adjacencySids.containsKey(sid);
492 } 493 }
493 494
494 - /** 495 + public Set<ConnectPoint> suppressSubnet() {
495 - * Returns a set of excluded ports. 496 + return (appConfig != null) ? appConfig.suppressSubnet() : ImmutableSet.of();
496 - * 497 + }
497 - * @return excluded ports 498 +
498 - */ 499 + public Set<ConnectPoint> suppressHost() {
499 - public Set<ConnectPoint> excludedPorts() { 500 + return (appConfig != null) ? appConfig.suppressHost() : ImmutableSet.of();
500 - return excludedPorts;
501 } 501 }
502 } 502 }
......
...@@ -21,8 +21,11 @@ import com.fasterxml.jackson.databind.node.ArrayNode; ...@@ -21,8 +21,11 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
21 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
22 import org.onlab.packet.MacAddress; 22 import org.onlab.packet.MacAddress;
23 import org.onosproject.core.ApplicationId; 23 import org.onosproject.core.ApplicationId;
24 +import org.onosproject.net.ConnectPoint;
24 import org.onosproject.net.DeviceId; 25 import org.onosproject.net.DeviceId;
25 import org.onosproject.net.config.Config; 26 import org.onosproject.net.config.Config;
27 +
28 +import java.util.Optional;
26 import java.util.Set; 29 import java.util.Set;
27 30
28 import static com.google.common.base.MoreObjects.toStringHelper; 31 import static com.google.common.base.MoreObjects.toStringHelper;
...@@ -33,23 +36,25 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -33,23 +36,25 @@ import static com.google.common.base.MoreObjects.toStringHelper;
33 public class SegmentRoutingAppConfig extends Config<ApplicationId> { 36 public class SegmentRoutingAppConfig extends Config<ApplicationId> {
34 private static final String VROUTER_MACS = "vRouterMacs"; 37 private static final String VROUTER_MACS = "vRouterMacs";
35 private static final String VROUTER_ID = "vRouterId"; 38 private static final String VROUTER_ID = "vRouterId";
36 - private static final String EXCLUDE_PORTS = "excludePorts"; 39 + private static final String SUPPRESS_SUBNET = "suppressSubnet";
40 + private static final String SUPPRESS_HOST = "suppressHost";
37 41
38 @Override 42 @Override
39 public boolean isValid() { 43 public boolean isValid() {
40 - return hasOnlyFields(VROUTER_MACS, VROUTER_ID, EXCLUDE_PORTS) && 44 + return hasOnlyFields(VROUTER_MACS, VROUTER_ID, SUPPRESS_SUBNET, SUPPRESS_HOST) &&
41 vRouterMacs() != null && vRouterId() != null && 45 vRouterMacs() != null && vRouterId() != null &&
42 - excludePorts() != null; 46 + suppressSubnet() != null && suppressHost() != null;
43 } 47 }
44 48
45 /** 49 /**
46 * Gets vRouters from the config. 50 * Gets vRouters from the config.
47 * 51 *
48 - * @return a set of vRouter MAC addresses 52 + * @return Set of vRouter MAC addresses, empty is not specified,
53 + * or null if not valid
49 */ 54 */
50 public Set<MacAddress> vRouterMacs() { 55 public Set<MacAddress> vRouterMacs() {
51 if (!object.has(VROUTER_MACS)) { 56 if (!object.has(VROUTER_MACS)) {
52 - return null; 57 + return ImmutableSet.of();
53 } 58 }
54 59
55 ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder(); 60 ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder();
...@@ -96,15 +101,16 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> { ...@@ -96,15 +101,16 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> {
96 /** 101 /**
97 * Gets vRouter device ID. 102 * Gets vRouter device ID.
98 * 103 *
99 - * @return vRouter device ID, or null if not valid 104 + * @return Optional vRouter device ID,
105 + * empty is not specified or null if not valid
100 */ 106 */
101 - public DeviceId vRouterId() { 107 + public Optional<DeviceId> vRouterId() {
102 if (!object.has(VROUTER_ID)) { 108 if (!object.has(VROUTER_ID)) {
103 - return null; 109 + return Optional.empty();
104 } 110 }
105 111
106 try { 112 try {
107 - return DeviceId.deviceId(object.path(VROUTER_ID).asText()); 113 + return Optional.of(DeviceId.deviceId(object.path(VROUTER_ID).asText()));
108 } catch (IllegalArgumentException e) { 114 } catch (IllegalArgumentException e) {
109 return null; 115 return null;
110 } 116 }
...@@ -126,42 +132,95 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> { ...@@ -126,42 +132,95 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> {
126 } 132 }
127 133
128 /** 134 /**
129 - * Gets names of ports that are ignored by SegmentRouting. 135 + * Gets names of ports to which SegmentRouting does not push subnet rules.
130 * 136 *
131 - * @return set of port names 137 + * @return Set of port names, empty if not specified, or null
138 + * if not valid
132 */ 139 */
133 - public Set<String> excludePorts() { 140 + public Set<ConnectPoint> suppressSubnet() {
134 - if (!object.has(EXCLUDE_PORTS)) { 141 + if (!object.has(SUPPRESS_SUBNET)) {
135 - return null; 142 + return ImmutableSet.of();
136 } 143 }
137 144
138 - ImmutableSet.Builder<String> builder = ImmutableSet.builder(); 145 + ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
139 - ArrayNode arrayNode = (ArrayNode) object.path(EXCLUDE_PORTS); 146 + ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_SUBNET);
140 for (JsonNode jsonNode : arrayNode) { 147 for (JsonNode jsonNode : arrayNode) {
141 String portName = jsonNode.asText(null); 148 String portName = jsonNode.asText(null);
142 if (portName == null) { 149 if (portName == null) {
143 return null; 150 return null;
144 } 151 }
145 - builder.add(portName); 152 + try {
153 + builder.add(ConnectPoint.deviceConnectPoint(portName));
154 + } catch (IllegalArgumentException e) {
155 + return null;
156 + }
157 + }
158 + return builder.build();
159 + }
160 +
161 + /**
162 + * Sets names of ports to which SegmentRouting does not push subnet rules.
163 + *
164 + * @param suppressSubnet names of ports to which SegmentRouting does not push
165 + * subnet rules
166 + * @return this {@link SegmentRoutingAppConfig}
167 + */
168 + public SegmentRoutingAppConfig setSuppressSubnet(Set<ConnectPoint> suppressSubnet) {
169 + if (suppressSubnet == null) {
170 + object.remove(SUPPRESS_SUBNET);
171 + } else {
172 + ArrayNode arrayNode = mapper.createArrayNode();
173 + suppressSubnet.forEach(connectPoint -> {
174 + arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port());
175 + });
176 + object.set(SUPPRESS_SUBNET, arrayNode);
177 + }
178 + return this;
179 + }
180 +
181 + /**
182 + * Gets names of ports to which SegmentRouting does not push host rules.
183 + *
184 + * @return Set of port names, empty if not specified, or null
185 + * if not valid
186 + */
187 + public Set<ConnectPoint> suppressHost() {
188 + if (!object.has(SUPPRESS_HOST)) {
189 + return ImmutableSet.of();
190 + }
191 +
192 + ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
193 + ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST);
194 + for (JsonNode jsonNode : arrayNode) {
195 + String portName = jsonNode.asText(null);
196 + if (portName == null) {
197 + return null;
198 + }
199 + try {
200 + builder.add(ConnectPoint.deviceConnectPoint(portName));
201 + } catch (IllegalArgumentException e) {
202 + return null;
203 + }
146 } 204 }
147 return builder.build(); 205 return builder.build();
148 } 206 }
149 207
150 /** 208 /**
151 - * Sets names of ports that are ignored by SegmentRouting. 209 + * Sets names of ports to which SegmentRouting does not push host rules.
152 * 210 *
153 - * @param excludePorts names of ports that are ignored by SegmentRouting 211 + * @param suppressHost names of ports to which SegmentRouting does not push
212 + * host rules
154 * @return this {@link SegmentRoutingAppConfig} 213 * @return this {@link SegmentRoutingAppConfig}
155 */ 214 */
156 - public SegmentRoutingAppConfig setExcludePorts(Set<String> excludePorts) { 215 + public SegmentRoutingAppConfig setSuppressHost(Set<ConnectPoint> suppressHost) {
157 - if (excludePorts == null) { 216 + if (suppressHost == null) {
158 - object.remove(EXCLUDE_PORTS); 217 + object.remove(SUPPRESS_HOST);
159 } else { 218 } else {
160 ArrayNode arrayNode = mapper.createArrayNode(); 219 ArrayNode arrayNode = mapper.createArrayNode();
161 - excludePorts.forEach(portName -> { 220 + suppressHost.forEach(connectPoint -> {
162 - arrayNode.add(portName); 221 + arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port());
163 }); 222 });
164 - object.set(EXCLUDE_PORTS, arrayNode); 223 + object.set(SUPPRESS_HOST, arrayNode);
165 } 224 }
166 return this; 225 return this;
167 } 226 }
...@@ -170,7 +229,9 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> { ...@@ -170,7 +229,9 @@ public class SegmentRoutingAppConfig extends Config<ApplicationId> {
170 public String toString() { 229 public String toString() {
171 return toStringHelper(this) 230 return toStringHelper(this)
172 .add("vRouterMacs", vRouterMacs()) 231 .add("vRouterMacs", vRouterMacs())
173 - .add("excludePorts", excludePorts()) 232 + .add("vRouterId", vRouterId())
233 + .add("suppressSubnet", suppressSubnet())
234 + .add("suppressHost", suppressHost())
174 .toString(); 235 .toString();
175 } 236 }
176 } 237 }
......
...@@ -24,16 +24,17 @@ import org.junit.Test; ...@@ -24,16 +24,17 @@ import org.junit.Test;
24 import org.onlab.packet.MacAddress; 24 import org.onlab.packet.MacAddress;
25 import org.onosproject.core.ApplicationId; 25 import org.onosproject.core.ApplicationId;
26 import org.onosproject.TestApplicationId; 26 import org.onosproject.TestApplicationId;
27 +import org.onosproject.net.ConnectPoint;
27 import org.onosproject.net.DeviceId; 28 import org.onosproject.net.DeviceId;
28 import org.onosproject.net.config.Config; 29 import org.onosproject.net.config.Config;
29 import org.onosproject.net.config.ConfigApplyDelegate; 30 import org.onosproject.net.config.ConfigApplyDelegate;
30 import org.onosproject.segmentrouting.SegmentRoutingManager; 31 import org.onosproject.segmentrouting.SegmentRoutingManager;
32 +
33 +import java.util.Optional;
31 import java.util.Set; 34 import java.util.Set;
32 35
33 import static org.hamcrest.Matchers.is; 36 import static org.hamcrest.Matchers.is;
34 -import static org.junit.Assert.assertThat; 37 +import static org.junit.Assert.*;
35 -import static org.junit.Assert.assertTrue;
36 -import static org.junit.Assert.assertFalse;
37 38
38 /** 39 /**
39 * Tests for class {@link SegmentRoutingAppConfig}. 40 * Tests for class {@link SegmentRoutingAppConfig}.
...@@ -50,25 +51,29 @@ public class SegmentRoutingAppConfigTest { ...@@ -50,25 +51,29 @@ public class SegmentRoutingAppConfigTest {
50 " \"00:00:00:00:00:02\"" + 51 " \"00:00:00:00:00:02\"" +
51 "]," + 52 "]," +
52 "\"vRouterId\" : \"of:1\"," + 53 "\"vRouterId\" : \"of:1\"," +
53 - "\"excludePorts\" : [" + 54 + "\"suppressSubnet\" : [" +
54 - " \"port1\"," + 55 + " \"of:1/1\"," +
55 - " \"port2\"" + 56 + " \"of:1/2\"" +
57 + "]," +
58 + "\"suppressHost\" : [" +
59 + " \"of:1/1\"," +
60 + " \"of:1/2\"" +
56 "]}"; 61 "]}";
57 private static final String INVALID_JSON_STRING = "{" + 62 private static final String INVALID_JSON_STRING = "{" +
58 "\"vRouterMacs\" : [" + 63 "\"vRouterMacs\" : [" +
59 " \"00:00:00:00:00:01\"," + 64 " \"00:00:00:00:00:01\"," +
60 " \"00:00:00:00:00:02\"" + 65 " \"00:00:00:00:00:02\"" +
61 "]," + 66 "]," +
62 - "\"excludePorts\" : [" + 67 + "\"suppressSubnet\" : [" +
63 - " \"port1\"," + 68 + " \"of:1/1\"," +
64 - " \"port2\"" + 69 + " \"wrongport\"" +
65 "]}"; 70 "]}";
66 private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01"); 71 private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01");
67 private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02"); 72 private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02");
68 private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03"); 73 private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03");
69 - private static final String PORT_NAME_1 = "port1"; 74 + private static final ConnectPoint PORT_1 = ConnectPoint.deviceConnectPoint("of:1/1");
70 - private static final String PORT_NAME_2 = "port2"; 75 + private static final ConnectPoint PORT_2 = ConnectPoint.deviceConnectPoint("of:1/2");
71 - private static final String PORT_NAME_3 = "port3"; 76 + private static final ConnectPoint PORT_3 = ConnectPoint.deviceConnectPoint("of:1/3");
72 private static final DeviceId VROUTER_ID_1 = DeviceId.deviceId("of:1"); 77 private static final DeviceId VROUTER_ID_1 = DeviceId.deviceId("of:1");
73 private static final DeviceId VROUTER_ID_2 = DeviceId.deviceId("of:2"); 78 private static final DeviceId VROUTER_ID_2 = DeviceId.deviceId("of:2");
74 79
...@@ -109,11 +114,12 @@ public class SegmentRoutingAppConfigTest { ...@@ -109,11 +114,12 @@ public class SegmentRoutingAppConfigTest {
109 * @throws Exception 114 * @throws Exception
110 */ 115 */
111 @Test 116 @Test
112 - public void testVRouters() throws Exception { 117 + public void testVRouterMacs() throws Exception {
113 - Set<MacAddress> vRouters = config.vRouterMacs(); 118 + Set<MacAddress> vRouterMacs = config.vRouterMacs();
114 - assertThat(vRouters.size(), is(2)); 119 + assertNotNull("vRouterMacs should not be null", vRouterMacs);
115 - assertTrue(vRouters.contains(ROUTER_MAC_1)); 120 + assertThat(vRouterMacs.size(), is(2));
116 - assertTrue(vRouters.contains(ROUTER_MAC_2)); 121 + assertTrue(vRouterMacs.contains(ROUTER_MAC_1));
122 + assertTrue(vRouterMacs.contains(ROUTER_MAC_2));
117 } 123 }
118 124
119 /** 125 /**
...@@ -122,14 +128,14 @@ public class SegmentRoutingAppConfigTest { ...@@ -122,14 +128,14 @@ public class SegmentRoutingAppConfigTest {
122 * @throws Exception 128 * @throws Exception
123 */ 129 */
124 @Test 130 @Test
125 - public void testSetVRouters() throws Exception { 131 + public void testSetVRouterMacs() throws Exception {
126 ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder(); 132 ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder();
127 builder.add(ROUTER_MAC_3); 133 builder.add(ROUTER_MAC_3);
128 config.setVRouterMacs(builder.build()); 134 config.setVRouterMacs(builder.build());
129 135
130 - Set<MacAddress> macs = config.vRouterMacs(); 136 + Set<MacAddress> vRouterMacs = config.vRouterMacs();
131 - assertThat(macs.size(), is(1)); 137 + assertThat(vRouterMacs.size(), is(1));
132 - assertTrue(macs.contains(ROUTER_MAC_3)); 138 + assertTrue(vRouterMacs.contains(ROUTER_MAC_3));
133 } 139 }
134 140
135 /** 141 /**
...@@ -139,7 +145,9 @@ public class SegmentRoutingAppConfigTest { ...@@ -139,7 +145,9 @@ public class SegmentRoutingAppConfigTest {
139 */ 145 */
140 @Test 146 @Test
141 public void testVRouterId() throws Exception { 147 public void testVRouterId() throws Exception {
142 - assertThat(config.vRouterId(), is(VROUTER_ID_1)); 148 + Optional<DeviceId> vRouterId = config.vRouterId();
149 + assertTrue(vRouterId.isPresent());
150 + assertThat(vRouterId.get(), is(VROUTER_ID_1));
143 } 151 }
144 152
145 /** 153 /**
...@@ -150,36 +158,72 @@ public class SegmentRoutingAppConfigTest { ...@@ -150,36 +158,72 @@ public class SegmentRoutingAppConfigTest {
150 @Test 158 @Test
151 public void testSetVRouterId() throws Exception { 159 public void testSetVRouterId() throws Exception {
152 config.setVRouterId(VROUTER_ID_2); 160 config.setVRouterId(VROUTER_ID_2);
153 - assertThat(config.vRouterId(), is(VROUTER_ID_2)); 161 +
162 + Optional<DeviceId> vRouterId = config.vRouterId();
163 + assertTrue(vRouterId.isPresent());
164 + assertThat(vRouterId.get(), is(VROUTER_ID_2));
165 + }
166 +
167 + /**
168 + * Tests suppressSubnet getter.
169 + *
170 + * @throws Exception
171 + */
172 + @Test
173 + public void testSuppressSubnet() throws Exception {
174 + Set<ConnectPoint> suppressSubnet = config.suppressSubnet();
175 + assertNotNull("suppressSubnet should not be null", suppressSubnet);
176 + assertThat(suppressSubnet.size(), is(2));
177 + assertTrue(suppressSubnet.contains(PORT_1));
178 + assertTrue(suppressSubnet.contains(PORT_2));
179 + }
180 +
181 + /**
182 + * Tests suppressSubnet setter.
183 + *
184 + * @throws Exception
185 + */
186 + @Test
187 + public void testSetSuppressSubnet() throws Exception {
188 + ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
189 + builder.add(PORT_3);
190 + config.setSuppressSubnet(builder.build());
191 +
192 + Set<ConnectPoint> suppressSubnet = config.suppressSubnet();
193 + assertNotNull("suppressSubnet should not be null", suppressSubnet);
194 + assertThat(suppressSubnet.size(), is(1));
195 + assertTrue(suppressSubnet.contains(PORT_3));
154 } 196 }
155 197
156 /** 198 /**
157 - * Tests excludePort getter. 199 + * Tests suppressHost getter.
158 * 200 *
159 * @throws Exception 201 * @throws Exception
160 */ 202 */
161 @Test 203 @Test
162 - public void testExcludePorts() throws Exception { 204 + public void testSuppressHost() throws Exception {
163 - Set<String> excludePorts = config.excludePorts(); 205 + Set<ConnectPoint> suppressHost = config.suppressHost();
164 - assertThat(excludePorts.size(), is(2)); 206 + assertNotNull("suppressHost should not be null", suppressHost);
165 - assertTrue(excludePorts.contains(PORT_NAME_1)); 207 + assertThat(suppressHost.size(), is(2));
166 - assertTrue(excludePorts.contains(PORT_NAME_2)); 208 + assertTrue(suppressHost.contains(PORT_1));
209 + assertTrue(suppressHost.contains(PORT_2));
167 } 210 }
168 211
169 /** 212 /**
170 - * Tests excludePort setter. 213 + * Tests suppressHost setter.
171 * 214 *
172 * @throws Exception 215 * @throws Exception
173 */ 216 */
174 @Test 217 @Test
175 - public void testSetExcludePorts() throws Exception { 218 + public void testSetSuppressHost() throws Exception {
176 - ImmutableSet.Builder<String> builder = ImmutableSet.builder(); 219 + ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
177 - builder.add(PORT_NAME_3); 220 + builder.add(PORT_3);
178 - config.setExcludePorts(builder.build()); 221 + config.setSuppressHost(builder.build());
179 - 222 +
180 - Set<String> excludePorts = config.excludePorts(); 223 + Set<ConnectPoint> suppressHost = config.suppressHost();
181 - assertThat(excludePorts.size(), is(1)); 224 + assertNotNull("suppressHost should not be null", suppressHost);
182 - assertTrue(excludePorts.contains(PORT_NAME_3)); 225 + assertThat(suppressHost.size(), is(1));
226 + assertTrue(suppressHost.contains(PORT_3));
183 } 227 }
184 228
185 private class MockDelegate implements ConfigApplyDelegate { 229 private class MockDelegate implements ConfigApplyDelegate {
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
35 "of:0000000000000002/5" : { 35 "of:0000000000000002/5" : {
36 "interfaces" : [ 36 "interfaces" : [
37 { 37 {
38 - "name" : "2/5/1",
39 "ips" : [ "100.0.0.0/24" ], 38 "ips" : [ "100.0.0.0/24" ],
40 "vlan" : "-1" 39 "vlan" : "-1"
41 } 40 }
...@@ -123,8 +122,11 @@ ...@@ -123,8 +122,11 @@
123 "00:00:00:aa:00:02" 122 "00:00:00:aa:00:02"
124 ], 123 ],
125 "vRouterId" : "of:0000000000000002", 124 "vRouterId" : "of:0000000000000002",
126 - "excludePorts" : [ 125 + "suppressSubnet" : [
127 - "2/5/1" 126 + "of:0000000000000002/5"
127 + ],
128 + "suppressHost" : [
129 + "of:0000000000000002/5"
128 ] 130 ]
129 } 131 }
130 } 132 }
......