Committed by
Gerrit Code Review
ONOS-4534 Improve VLAN support in SDN-IP
Change-Id: Ib9cf64d8f896462ec18260c4371859f447e7c4de
Showing
7 changed files
with
1005 additions
and
127 deletions
... | @@ -202,15 +202,14 @@ public class PeerConnectivityManager { | ... | @@ -202,15 +202,14 @@ public class PeerConnectivityManager { |
202 | } | 202 | } |
203 | 203 | ||
204 | /** | 204 | /** |
205 | - * Builds the required intents between the two pairs of connect points and | 205 | + * Builds the required intents between a BGP speaker and an external router. |
206 | - * IP addresses. | ||
207 | * | 206 | * |
208 | - * @param portOne the first connect point | 207 | + * @param portOne the BGP speaker connect point |
209 | - * @param vlanOne the ingress VLAN | 208 | + * @param vlanOne the BGP speaker VLAN |
210 | - * @param ipOne the first IP address | 209 | + * @param ipOne the BGP speaker IP address |
211 | - * @param portTwo the second connect point | 210 | + * @param portTwo the external BGP peer connect point |
212 | - * @param vlanTwo the egress VLAN | 211 | + * @param vlanTwo the external BGP peer VLAN |
213 | - * @param ipTwo the second IP address | 212 | + * @param ipTwo the external BGP peer IP address |
214 | * @return the intents to install | 213 | * @return the intents to install |
215 | */ | 214 | */ |
216 | private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, | 215 | private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, |
... | @@ -239,9 +238,13 @@ public class PeerConnectivityManager { | ... | @@ -239,9 +238,13 @@ public class PeerConnectivityManager { |
239 | icmpProtocol = IPv6.PROTOCOL_ICMP6; | 238 | icmpProtocol = IPv6.PROTOCOL_ICMP6; |
240 | } | 239 | } |
241 | 240 | ||
242 | - // Add treatment for VLAN for traffic going from BGP speaker to BGP peer | 241 | + // Add VLAN treatment for traffic going from BGP speaker to BGP peer |
243 | - if (!vlanTwo.equals(VlanId.NONE)) { | 242 | + if (!vlanOne.equals(vlanTwo)) { |
244 | - treatmentToPeer.setVlanId(vlanTwo); | 243 | + if (vlanTwo.equals(VlanId.NONE)) { |
244 | + treatmentToPeer.popVlan(); | ||
245 | + } else { | ||
246 | + treatmentToPeer.setVlanId(vlanTwo); | ||
247 | + } | ||
245 | } | 248 | } |
246 | 249 | ||
247 | // Path from BGP speaker to BGP peer matching destination TCP port 179 | 250 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
... | @@ -305,9 +308,13 @@ public class PeerConnectivityManager { | ... | @@ -305,9 +308,13 @@ public class PeerConnectivityManager { |
305 | .priority(PRIORITY_OFFSET) | 308 | .priority(PRIORITY_OFFSET) |
306 | .build()); | 309 | .build()); |
307 | 310 | ||
308 | - // Add treatment for VLAN for traffic going from BGP peer to BGP speaker | 311 | + // Add VLAN treatment for traffic going from BGP peer to BGP speaker |
309 | - if (!vlanOne.equals(VlanId.NONE)) { | 312 | + if (!vlanTwo.equals(vlanOne)) { |
310 | - treatmentToSpeaker.setVlanId(vlanOne); | 313 | + if (vlanOne.equals(VlanId.NONE)) { |
314 | + treatmentToSpeaker.popVlan(); | ||
315 | + } else { | ||
316 | + treatmentToSpeaker.setVlanId(vlanOne); | ||
317 | + } | ||
311 | } | 318 | } |
312 | 319 | ||
313 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | 320 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | ... | ... |
... | @@ -158,23 +158,38 @@ public class SdnIpFib { | ... | @@ -158,23 +158,38 @@ public class SdnIpFib { |
158 | nextHopIpAddress); | 158 | nextHopIpAddress); |
159 | return null; | 159 | return null; |
160 | } | 160 | } |
161 | + ConnectPoint egressPort = egressInterface.connectPoint(); | ||
161 | 162 | ||
162 | - // Generate the intent itself | 163 | + Set<Interface> ingressInterfaces = new HashSet<>(); |
163 | Set<ConnectPoint> ingressPorts = new HashSet<>(); | 164 | Set<ConnectPoint> ingressPorts = new HashSet<>(); |
164 | - ConnectPoint egressPort = egressInterface.connectPoint(); | ||
165 | log.debug("Generating intent for prefix {}, next hop mac {}", | 165 | log.debug("Generating intent for prefix {}, next hop mac {}", |
166 | prefix, nextHopMacAddress); | 166 | prefix, nextHopMacAddress); |
167 | 167 | ||
168 | - for (Interface intf : interfaceService.getInterfaces()) { | 168 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
169 | - // TODO this should be only peering interfaces | 169 | + |
170 | - if (!intf.connectPoint().equals(egressInterface.connectPoint())) { | 170 | + // Get ingress interfaces and ports |
171 | - ConnectPoint srcPort = intf.connectPoint(); | 171 | + // TODO this should be only peering interfaces |
172 | - ingressPorts.add(srcPort); | 172 | + interfaceService.getInterfaces().stream() |
173 | + .filter(intf -> !intf.equals(egressInterface)) | ||
174 | + .forEach(intf -> { | ||
175 | + ingressInterfaces.add(intf); | ||
176 | + ConnectPoint ingressPort = intf.connectPoint(); | ||
177 | + ingressPorts.add(ingressPort); | ||
178 | + }); | ||
179 | + | ||
180 | + // By default the ingress traffic is not tagged | ||
181 | + VlanId ingressVlanId = VlanId.NONE; | ||
182 | + | ||
183 | + // Match VLAN Id ANY if the source VLAN Id is not null | ||
184 | + // TODO need to be able to set a different VLAN Id per ingress interface | ||
185 | + for (Interface intf : ingressInterfaces) { | ||
186 | + if (!intf.vlan().equals(VlanId.NONE)) { | ||
187 | + selector.matchVlanId(VlanId.ANY); | ||
188 | + ingressVlanId = intf.vlan(); | ||
173 | } | 189 | } |
174 | } | 190 | } |
175 | 191 | ||
176 | // Match the destination IP prefix at the first hop | 192 | // Match the destination IP prefix at the first hop |
177 | - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
178 | if (prefix.isIp4()) { | 193 | if (prefix.isIp4()) { |
179 | selector.matchEthType(Ethernet.TYPE_IPV4); | 194 | selector.matchEthType(Ethernet.TYPE_IPV4); |
180 | // if it is default route, then we do not need match destination | 195 | // if it is default route, then we do not need match destination |
... | @@ -189,22 +204,29 @@ public class SdnIpFib { | ... | @@ -189,22 +204,29 @@ public class SdnIpFib { |
189 | if (prefix.prefixLength() != 0) { | 204 | if (prefix.prefixLength() != 0) { |
190 | selector.matchIPv6Dst(prefix); | 205 | selector.matchIPv6Dst(prefix); |
191 | } | 206 | } |
192 | - | ||
193 | } | 207 | } |
194 | 208 | ||
195 | // Rewrite the destination MAC address | 209 | // Rewrite the destination MAC address |
196 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | 210 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
197 | .setEthDst(nextHopMacAddress); | 211 | .setEthDst(nextHopMacAddress); |
198 | - if (!egressInterface.vlan().equals(VlanId.NONE)) { | 212 | + |
199 | - treatment.setVlanId(egressInterface.vlan()); | 213 | + // Set egress VLAN Id |
200 | - // If we set VLAN ID, we have to make sure a VLAN tag exists. | 214 | + // TODO need to make the comparison with different ingress VLAN Ids |
201 | - // TODO support no VLAN -> VLAN routing | 215 | + if (!ingressVlanId.equals(egressInterface.vlan())) { |
202 | - selector.matchVlanId(VlanId.ANY); | 216 | + if (egressInterface.vlan().equals(VlanId.NONE)) { |
217 | + treatment.popVlan(); | ||
218 | + } else { | ||
219 | + treatment.setVlanId(egressInterface.vlan()); | ||
220 | + } | ||
203 | } | 221 | } |
204 | 222 | ||
223 | + // Set priority | ||
205 | int priority = | 224 | int priority = |
206 | prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; | 225 | prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET; |
226 | + | ||
227 | + // Set key | ||
207 | Key key = Key.of(prefix.toString(), appId); | 228 | Key key = Key.of(prefix.toString(), appId); |
229 | + | ||
208 | return MultiPointToSinglePointIntent.builder() | 230 | return MultiPointToSinglePointIntent.builder() |
209 | .appId(appId) | 231 | .appId(appId) |
210 | .key(key) | 232 | .key(key) | ... | ... |
... | @@ -68,7 +68,7 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ... | @@ -68,7 +68,7 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
68 | /** | 68 | /** |
69 | * Unit tests for SdnIpFib. | 69 | * Unit tests for SdnIpFib. |
70 | */ | 70 | */ |
71 | -public class SdnIpFibTest extends AbstractIntentTest { | 71 | +public class SdnIpFibNoVLansTest extends AbstractIntentTest { |
72 | 72 | ||
73 | private InterfaceService interfaceService; | 73 | private InterfaceService interfaceService; |
74 | 74 | ||
... | @@ -80,12 +80,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -80,12 +80,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
80 | DeviceId.deviceId("of:0000000000000002"), | 80 | DeviceId.deviceId("of:0000000000000002"), |
81 | PortNumber.portNumber(1)); | 81 | PortNumber.portNumber(1)); |
82 | 82 | ||
83 | - private static final ConnectPoint SW4_ETH1 = new ConnectPoint( | 83 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( |
84 | - DeviceId.deviceId("of:0000000000000004"), | 84 | + DeviceId.deviceId("of:0000000000000003"), |
85 | PortNumber.portNumber(1)); | 85 | PortNumber.portNumber(1)); |
86 | 86 | ||
87 | - private static final ConnectPoint SW5_ETH1 = new ConnectPoint( | 87 | + private static final ConnectPoint SW4_ETH1 = new ConnectPoint( |
88 | - DeviceId.deviceId("of:0000000000000005"), | 88 | + DeviceId.deviceId("of:0000000000000004"), |
89 | PortNumber.portNumber(1)); | 89 | PortNumber.portNumber(1)); |
90 | 90 | ||
91 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | 91 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); |
... | @@ -104,6 +104,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -104,6 +104,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
104 | super.setUp(); | 104 | super.setUp(); |
105 | 105 | ||
106 | interfaceService = createMock(InterfaceService.class); | 106 | interfaceService = createMock(InterfaceService.class); |
107 | + | ||
107 | interfaceService.addListener(anyObject(InterfaceListener.class)); | 108 | interfaceService.addListener(anyObject(InterfaceListener.class)); |
108 | expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | 109 | expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); |
109 | 110 | ||
... | @@ -124,29 +125,29 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -124,29 +125,29 @@ public class SdnIpFibTest extends AbstractIntentTest { |
124 | } | 125 | } |
125 | 126 | ||
126 | /** | 127 | /** |
127 | - * Sets up InterfaceService. | 128 | + * Sets up the interface service. |
128 | */ | 129 | */ |
129 | private void setUpInterfaceService() { | 130 | private void setUpInterfaceService() { |
130 | List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | 131 | List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); |
131 | interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | 132 | interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); |
132 | Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | 133 | Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, |
133 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | 134 | + interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), |
134 | - VlanId.NONE); | 135 | + VlanId.NONE); |
135 | interfaces.add(sw1Eth1); | 136 | interfaces.add(sw1Eth1); |
136 | 137 | ||
137 | List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | 138 | List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); |
138 | interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | 139 | interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); |
139 | Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | 140 | Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, |
140 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | 141 | + interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), |
141 | - VlanId.NONE); | 142 | + VlanId.NONE); |
142 | interfaces.add(sw2Eth1); | 143 | interfaces.add(sw2Eth1); |
143 | 144 | ||
144 | - InterfaceIpAddress interfaceIpAddress4 = InterfaceIpAddress.valueOf("192.168.40.101/24"); | 145 | + InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); |
145 | - Interface sw4Eth1 = new Interface("sw4-eth1", SW4_ETH1, | 146 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, |
146 | - Lists.newArrayList(interfaceIpAddress4), | 147 | + Lists.newArrayList(interfaceIpAddress3), |
147 | - MacAddress.valueOf("00:00:00:00:00:04"), | 148 | + MacAddress.valueOf("00:00:00:00:00:03"), |
148 | - VlanId.vlanId((short) 1)); | 149 | + VlanId.NONE); |
149 | - interfaces.add(sw4Eth1); | 150 | + interfaces.add(sw3Eth1); |
150 | 151 | ||
151 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | 152 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( |
152 | Collections.singleton(sw1Eth1)).anyTimes(); | 153 | Collections.singleton(sw1Eth1)).anyTimes(); |
... | @@ -156,24 +157,24 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -156,24 +157,24 @@ public class SdnIpFibTest extends AbstractIntentTest { |
156 | Collections.singleton(sw2Eth1)).anyTimes(); | 157 | Collections.singleton(sw2Eth1)).anyTimes(); |
157 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | 158 | expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) |
158 | .andReturn(sw2Eth1).anyTimes(); | 159 | .andReturn(sw2Eth1).anyTimes(); |
159 | - expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn( | 160 | + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( |
160 | - Collections.singleton(sw4Eth1)).anyTimes(); | 161 | + Collections.singleton(sw3Eth1)).anyTimes(); |
161 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1"))) | 162 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) |
162 | - .andReturn(sw4Eth1).anyTimes(); | 163 | + .andReturn(sw3Eth1).anyTimes(); |
163 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | 164 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
164 | } | 165 | } |
165 | 166 | ||
166 | /** | 167 | /** |
167 | - * Tests adding a route. | 168 | + * Tests adding a route. All interfaces have no VLAN Ids configured. |
168 | * | 169 | * |
169 | * We verify that the synchronizer records the correct state and that the | 170 | * We verify that the synchronizer records the correct state and that the |
170 | * correct intent is submitted to the IntentService. | 171 | * correct intent is submitted to the IntentService. |
171 | */ | 172 | */ |
172 | @Test | 173 | @Test |
173 | - public void testRouteAdd() { | 174 | + public void testRouteAddNoVlans() { |
174 | ResolvedRoute route = new ResolvedRoute(PREFIX1, | 175 | ResolvedRoute route = new ResolvedRoute(PREFIX1, |
175 | - Ip4Address.valueOf("192.168.10.1"), | 176 | + Ip4Address.valueOf("192.168.30.1"), |
176 | - MacAddress.valueOf("00:00:00:00:00:01")); | 177 | + MacAddress.valueOf("00:00:00:00:00:03")); |
177 | 178 | ||
178 | // Construct a MultiPointToSinglePointIntent intent | 179 | // Construct a MultiPointToSinglePointIntent intent |
179 | TrafficSelector.Builder selectorBuilder = | 180 | TrafficSelector.Builder selectorBuilder = |
... | @@ -182,56 +183,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -182,56 +183,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
182 | 183 | ||
183 | TrafficTreatment.Builder treatmentBuilder = | 184 | TrafficTreatment.Builder treatmentBuilder = |
184 | DefaultTrafficTreatment.builder(); | 185 | DefaultTrafficTreatment.builder(); |
185 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | 186 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); |
186 | - | ||
187 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
188 | - ingressPoints.add(SW2_ETH1); | ||
189 | - ingressPoints.add(SW4_ETH1); | ||
190 | - | ||
191 | - MultiPointToSinglePointIntent intent = | ||
192 | - MultiPointToSinglePointIntent.builder() | ||
193 | - .appId(APPID) | ||
194 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
195 | - .selector(selectorBuilder.build()) | ||
196 | - .treatment(treatmentBuilder.build()) | ||
197 | - .ingressPoints(ingressPoints) | ||
198 | - .egressPoint(SW1_ETH1) | ||
199 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
200 | - .build(); | ||
201 | - | ||
202 | - // Setup the expected intents | ||
203 | - intentSynchronizer.submit(eqExceptId(intent)); | ||
204 | - replay(intentSynchronizer); | ||
205 | - | ||
206 | - // Send in the added event | ||
207 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
208 | - | ||
209 | - verify(intentSynchronizer); | ||
210 | - } | ||
211 | - | ||
212 | - /** | ||
213 | - * Tests adding a route with to a next hop in a VLAN. | ||
214 | - * | ||
215 | - * We verify that the synchronizer records the correct state and that the | ||
216 | - * correct intent is submitted to the IntentService. | ||
217 | - */ | ||
218 | - @Test | ||
219 | - public void testRouteAddWithVlan() { | ||
220 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
221 | - Ip4Address.valueOf("192.168.40.1"), | ||
222 | - MacAddress.valueOf("00:00:00:00:00:04")); | ||
223 | - | ||
224 | - // Construct a MultiPointToSinglePointIntent intent | ||
225 | - TrafficSelector.Builder selectorBuilder = | ||
226 | - DefaultTrafficSelector.builder(); | ||
227 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
228 | - .matchIPDst(PREFIX1) | ||
229 | - .matchVlanId(VlanId.ANY); | ||
230 | - | ||
231 | - TrafficTreatment.Builder treatmentBuilder = | ||
232 | - DefaultTrafficTreatment.builder(); | ||
233 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:04")) | ||
234 | - .setVlanId(VlanId.vlanId((short) 1)); | ||
235 | 187 | ||
236 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 188 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
237 | ingressPoints.add(SW1_ETH1); | 189 | ingressPoints.add(SW1_ETH1); |
... | @@ -244,13 +196,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -244,13 +196,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
244 | .selector(selectorBuilder.build()) | 196 | .selector(selectorBuilder.build()) |
245 | .treatment(treatmentBuilder.build()) | 197 | .treatment(treatmentBuilder.build()) |
246 | .ingressPoints(ingressPoints) | 198 | .ingressPoints(ingressPoints) |
247 | - .egressPoint(SW4_ETH1) | 199 | + .egressPoint(SW3_ETH1) |
248 | .constraints(SdnIpFib.CONSTRAINTS) | 200 | .constraints(SdnIpFib.CONSTRAINTS) |
249 | .build(); | 201 | .build(); |
250 | 202 | ||
251 | // Setup the expected intents | 203 | // Setup the expected intents |
252 | intentSynchronizer.submit(eqExceptId(intent)); | 204 | intentSynchronizer.submit(eqExceptId(intent)); |
253 | - | ||
254 | replay(intentSynchronizer); | 205 | replay(intentSynchronizer); |
255 | 206 | ||
256 | // Send in the added event | 207 | // Send in the added event |
... | @@ -267,8 +218,8 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -267,8 +218,8 @@ public class SdnIpFibTest extends AbstractIntentTest { |
267 | */ | 218 | */ |
268 | @Test | 219 | @Test |
269 | public void testRouteUpdate() { | 220 | public void testRouteUpdate() { |
270 | - // Firstly add a route | 221 | + // Add a route first |
271 | - testRouteAdd(); | 222 | + testRouteAddNoVlans(); |
272 | 223 | ||
273 | // Start to construct a new route entry and new intent | 224 | // Start to construct a new route entry and new intent |
274 | ResolvedRoute route = new ResolvedRoute(PREFIX1, | 225 | ResolvedRoute route = new ResolvedRoute(PREFIX1, |
... | @@ -286,7 +237,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -286,7 +237,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
286 | 237 | ||
287 | Set<ConnectPoint> ingressPointsNew = new HashSet<>(); | 238 | Set<ConnectPoint> ingressPointsNew = new HashSet<>(); |
288 | ingressPointsNew.add(SW1_ETH1); | 239 | ingressPointsNew.add(SW1_ETH1); |
289 | - ingressPointsNew.add(SW4_ETH1); | 240 | + ingressPointsNew.add(SW3_ETH1); |
290 | 241 | ||
291 | MultiPointToSinglePointIntent intentNew = | 242 | MultiPointToSinglePointIntent intentNew = |
292 | MultiPointToSinglePointIntent.builder() | 243 | MultiPointToSinglePointIntent.builder() |
... | @@ -320,8 +271,8 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -320,8 +271,8 @@ public class SdnIpFibTest extends AbstractIntentTest { |
320 | */ | 271 | */ |
321 | @Test | 272 | @Test |
322 | public void testRouteDelete() { | 273 | public void testRouteDelete() { |
323 | - // Firstly add a route | 274 | + // Add a route first |
324 | - testRouteAdd(); | 275 | + testRouteAddNoVlans(); |
325 | 276 | ||
326 | // Construct the existing route entry | 277 | // Construct the existing route entry |
327 | ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); | 278 | ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); |
... | @@ -333,11 +284,11 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -333,11 +284,11 @@ public class SdnIpFibTest extends AbstractIntentTest { |
333 | 284 | ||
334 | TrafficTreatment.Builder treatmentBuilder = | 285 | TrafficTreatment.Builder treatmentBuilder = |
335 | DefaultTrafficTreatment.builder(); | 286 | DefaultTrafficTreatment.builder(); |
336 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | 287 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); |
337 | 288 | ||
338 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 289 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
290 | + ingressPoints.add(SW1_ETH1); | ||
339 | ingressPoints.add(SW2_ETH1); | 291 | ingressPoints.add(SW2_ETH1); |
340 | - ingressPoints.add(SW4_ETH1); | ||
341 | 292 | ||
342 | MultiPointToSinglePointIntent addedIntent = | 293 | MultiPointToSinglePointIntent addedIntent = |
343 | MultiPointToSinglePointIntent.builder() | 294 | MultiPointToSinglePointIntent.builder() |
... | @@ -346,7 +297,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -346,7 +297,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
346 | .selector(selectorBuilder.build()) | 297 | .selector(selectorBuilder.build()) |
347 | .treatment(treatmentBuilder.build()) | 298 | .treatment(treatmentBuilder.build()) |
348 | .ingressPoints(ingressPoints) | 299 | .ingressPoints(ingressPoints) |
349 | - .egressPoint(SW1_ETH1) | 300 | + .egressPoint(SW3_ETH1) |
350 | .constraints(SdnIpFib.CONSTRAINTS) | 301 | .constraints(SdnIpFib.CONSTRAINTS) |
351 | .build(); | 302 | .build(); |
352 | 303 | ||
... | @@ -364,7 +315,8 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -364,7 +315,8 @@ public class SdnIpFibTest extends AbstractIntentTest { |
364 | 315 | ||
365 | @Test | 316 | @Test |
366 | public void testAddInterface() { | 317 | public void testAddInterface() { |
367 | - testRouteAdd(); | 318 | + // Add a route first |
319 | + testRouteAddNoVlans(); | ||
368 | 320 | ||
369 | // Construct the existing MultiPointToSinglePoint intent | 321 | // Construct the existing MultiPointToSinglePoint intent |
370 | TrafficSelector.Builder selectorBuilder = | 322 | TrafficSelector.Builder selectorBuilder = |
... | @@ -373,12 +325,12 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -373,12 +325,12 @@ public class SdnIpFibTest extends AbstractIntentTest { |
373 | 325 | ||
374 | TrafficTreatment.Builder treatmentBuilder = | 326 | TrafficTreatment.Builder treatmentBuilder = |
375 | DefaultTrafficTreatment.builder(); | 327 | DefaultTrafficTreatment.builder(); |
376 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | 328 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); |
377 | 329 | ||
378 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 330 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
331 | + ingressPoints.add(SW1_ETH1); | ||
379 | ingressPoints.add(SW2_ETH1); | 332 | ingressPoints.add(SW2_ETH1); |
380 | ingressPoints.add(SW4_ETH1); | 333 | ingressPoints.add(SW4_ETH1); |
381 | - ingressPoints.add(SW5_ETH1); | ||
382 | 334 | ||
383 | MultiPointToSinglePointIntent addedIntent = | 335 | MultiPointToSinglePointIntent addedIntent = |
384 | MultiPointToSinglePointIntent.builder() | 336 | MultiPointToSinglePointIntent.builder() |
... | @@ -387,7 +339,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -387,7 +339,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
387 | .selector(selectorBuilder.build()) | 339 | .selector(selectorBuilder.build()) |
388 | .treatment(treatmentBuilder.build()) | 340 | .treatment(treatmentBuilder.build()) |
389 | .ingressPoints(ingressPoints) | 341 | .ingressPoints(ingressPoints) |
390 | - .egressPoint(SW1_ETH1) | 342 | + .egressPoint(SW3_ETH1) |
391 | .constraints(SdnIpFib.CONSTRAINTS) | 343 | .constraints(SdnIpFib.CONSTRAINTS) |
392 | .build(); | 344 | .build(); |
393 | 345 | ||
... | @@ -398,9 +350,9 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -398,9 +350,9 @@ public class SdnIpFibTest extends AbstractIntentTest { |
398 | 350 | ||
399 | replay(intentSynchronizer); | 351 | replay(intentSynchronizer); |
400 | 352 | ||
401 | - Interface intf = new Interface("newintf", SW5_ETH1, | 353 | + Interface intf = new Interface("sw4-eth1", SW4_ETH1, |
402 | - Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")), | 354 | + Collections.singletonList(InterfaceIpAddress.valueOf("192.168.40.101/24")), |
403 | - MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE); | 355 | + MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); |
404 | InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); | 356 | InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); |
405 | interfaceListener.event(intfEvent); | 357 | interfaceListener.event(intfEvent); |
406 | 358 | ||
... | @@ -409,7 +361,8 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -409,7 +361,8 @@ public class SdnIpFibTest extends AbstractIntentTest { |
409 | 361 | ||
410 | @Test | 362 | @Test |
411 | public void testRemoveInterface() { | 363 | public void testRemoveInterface() { |
412 | - testRouteAdd(); | 364 | + // Add a route first |
365 | + testRouteAddNoVlans(); | ||
413 | 366 | ||
414 | // Construct the existing MultiPointToSinglePoint intent | 367 | // Construct the existing MultiPointToSinglePoint intent |
415 | TrafficSelector.Builder selectorBuilder = | 368 | TrafficSelector.Builder selectorBuilder = |
... | @@ -418,7 +371,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -418,7 +371,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
418 | 371 | ||
419 | TrafficTreatment.Builder treatmentBuilder = | 372 | TrafficTreatment.Builder treatmentBuilder = |
420 | DefaultTrafficTreatment.builder(); | 373 | DefaultTrafficTreatment.builder(); |
421 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:01")); | 374 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); |
422 | 375 | ||
423 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 376 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
424 | ingressPoints.add(SW2_ETH1); | 377 | ingressPoints.add(SW2_ETH1); |
... | @@ -430,7 +383,7 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -430,7 +383,7 @@ public class SdnIpFibTest extends AbstractIntentTest { |
430 | .selector(selectorBuilder.build()) | 383 | .selector(selectorBuilder.build()) |
431 | .treatment(treatmentBuilder.build()) | 384 | .treatment(treatmentBuilder.build()) |
432 | .ingressPoints(ingressPoints) | 385 | .ingressPoints(ingressPoints) |
433 | - .egressPoint(SW1_ETH1) | 386 | + .egressPoint(SW3_ETH1) |
434 | .constraints(SdnIpFib.CONSTRAINTS) | 387 | .constraints(SdnIpFib.CONSTRAINTS) |
435 | .build(); | 388 | .build(); |
436 | 389 | ||
... | @@ -441,9 +394,9 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -441,9 +394,9 @@ public class SdnIpFibTest extends AbstractIntentTest { |
441 | 394 | ||
442 | replay(intentSynchronizer); | 395 | replay(intentSynchronizer); |
443 | 396 | ||
444 | - Interface intf = new Interface("newintf", SW4_ETH1, | 397 | + Interface intf = new Interface("sw1-eth1", SW1_ETH1, |
445 | - Collections.singletonList(InterfaceIpAddress.valueOf("192.168.50.101/24")), | 398 | + Collections.singletonList(InterfaceIpAddress.valueOf("192.168.10.101/24")), |
446 | - MacAddress.valueOf("00:00:00:00:00:02"), VlanId.NONE); | 399 | + MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE); |
447 | InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); | 400 | InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); |
448 | interfaceListener.event(intfEvent); | 401 | interfaceListener.event(intfEvent); |
449 | 402 | ||
... | @@ -460,14 +413,14 @@ public class SdnIpFibTest extends AbstractIntentTest { | ... | @@ -460,14 +413,14 @@ public class SdnIpFibTest extends AbstractIntentTest { |
460 | private class TestRouteService extends RouteServiceAdapter { | 413 | private class TestRouteService extends RouteServiceAdapter { |
461 | @Override | 414 | @Override |
462 | public void addListener(RouteListener routeListener) { | 415 | public void addListener(RouteListener routeListener) { |
463 | - SdnIpFibTest.this.routeListener = routeListener; | 416 | + SdnIpFibNoVLansTest.this.routeListener = routeListener; |
464 | } | 417 | } |
465 | } | 418 | } |
466 | 419 | ||
467 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | 420 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { |
468 | @Override | 421 | @Override |
469 | public void addListener(InterfaceListener listener) { | 422 | public void addListener(InterfaceListener listener) { |
470 | - SdnIpFibTest.this.interfaceListener = listener; | 423 | + SdnIpFibNoVLansTest.this.interfaceListener = listener; |
471 | } | 424 | } |
472 | } | 425 | } |
473 | } | 426 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.sdnip; | ||
18 | + | ||
19 | +import com.google.common.collect.Lists; | ||
20 | +import com.google.common.collect.Sets; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ethernet; | ||
24 | +import org.onlab.packet.Ip4Address; | ||
25 | +import org.onlab.packet.Ip4Prefix; | ||
26 | +import org.onlab.packet.IpPrefix; | ||
27 | +import org.onlab.packet.MacAddress; | ||
28 | +import org.onlab.packet.VlanId; | ||
29 | +import org.onosproject.TestApplicationId; | ||
30 | +import org.onosproject.core.ApplicationId; | ||
31 | +import org.onosproject.core.CoreServiceAdapter; | ||
32 | +import org.onosproject.incubator.net.intf.Interface; | ||
33 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
34 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
35 | +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
36 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
37 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
38 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
39 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
40 | +import org.onosproject.net.ConnectPoint; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.net.PortNumber; | ||
43 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
44 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
45 | +import org.onosproject.net.flow.TrafficSelector; | ||
46 | +import org.onosproject.net.flow.TrafficTreatment; | ||
47 | +import org.onosproject.net.host.InterfaceIpAddress; | ||
48 | +import org.onosproject.net.intent.AbstractIntentTest; | ||
49 | +import org.onosproject.net.intent.Key; | ||
50 | +import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
51 | +import org.onosproject.routing.IntentSynchronizationService; | ||
52 | + | ||
53 | +import java.util.Collections; | ||
54 | +import java.util.HashSet; | ||
55 | +import java.util.List; | ||
56 | +import java.util.Set; | ||
57 | + | ||
58 | +import static org.easymock.EasyMock.*; | ||
59 | +import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
60 | + | ||
61 | +/** | ||
62 | + * Unit tests for SdnIpFib. | ||
63 | + */ | ||
64 | +public class SdnIpFibNoVlanstoVlanTest extends AbstractIntentTest { | ||
65 | + | ||
66 | + private InterfaceService interfaceService; | ||
67 | + | ||
68 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
69 | + DeviceId.deviceId("of:0000000000000001"), | ||
70 | + PortNumber.portNumber(1)); | ||
71 | + | ||
72 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
73 | + DeviceId.deviceId("of:0000000000000002"), | ||
74 | + PortNumber.portNumber(1)); | ||
75 | + | ||
76 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
77 | + DeviceId.deviceId("of:0000000000000003"), | ||
78 | + PortNumber.portNumber(1)); | ||
79 | + | ||
80 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
81 | + | ||
82 | + private SdnIpFib sdnipFib; | ||
83 | + private IntentSynchronizationService intentSynchronizer; | ||
84 | + private final Set<Interface> interfaces = Sets.newHashSet(); | ||
85 | + | ||
86 | + private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
87 | + | ||
88 | + private RouteListener routeListener; | ||
89 | + private InterfaceListener interfaceListener; | ||
90 | + | ||
91 | + @Before | ||
92 | + public void setUp() throws Exception { | ||
93 | + super.setUp(); | ||
94 | + | ||
95 | + interfaceService = createMock(InterfaceService.class); | ||
96 | + | ||
97 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
98 | + expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
99 | + | ||
100 | + // These will set expectations on routingConfig and interfaceService | ||
101 | + setUpInterfaceService(); | ||
102 | + | ||
103 | + replay(interfaceService); | ||
104 | + | ||
105 | + intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
106 | + | ||
107 | + sdnipFib = new SdnIpFib(); | ||
108 | + sdnipFib.routeService = new TestRouteService(); | ||
109 | + sdnipFib.coreService = new TestCoreService(); | ||
110 | + sdnipFib.interfaceService = interfaceService; | ||
111 | + sdnipFib.intentSynchronizer = intentSynchronizer; | ||
112 | + | ||
113 | + sdnipFib.activate(); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Sets up the interface service. | ||
118 | + */ | ||
119 | + private void setUpInterfaceService() { | ||
120 | + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
121 | + interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
122 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
123 | + interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
124 | + VlanId.NONE); | ||
125 | + interfaces.add(sw1Eth1); | ||
126 | + | ||
127 | + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
128 | + interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
129 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
130 | + interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
131 | + VlanId.NONE); | ||
132 | + interfaces.add(sw2Eth1); | ||
133 | + | ||
134 | + InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
135 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
136 | + Lists.newArrayList(interfaceIpAddress3), | ||
137 | + MacAddress.valueOf("00:00:00:00:00:03"), | ||
138 | + VlanId.vlanId((short) 1)); | ||
139 | + interfaces.add(sw3Eth1); | ||
140 | + | ||
141 | + expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
142 | + Collections.singleton(sw1Eth1)).anyTimes(); | ||
143 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
144 | + .andReturn(sw1Eth1).anyTimes(); | ||
145 | + expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
146 | + Collections.singleton(sw2Eth1)).anyTimes(); | ||
147 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
148 | + .andReturn(sw2Eth1).anyTimes(); | ||
149 | + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
150 | + Collections.singleton(sw3Eth1)).anyTimes(); | ||
151 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
152 | + .andReturn(sw3Eth1).anyTimes(); | ||
153 | + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests adding a route. Ingresses with no VLAN and next hop with VLAN. | ||
158 | + * | ||
159 | + * We verify that the synchronizer records the correct state and that the | ||
160 | + * correct intent is submitted to the IntentService. | ||
161 | + */ | ||
162 | + @Test | ||
163 | + public void testRouteAdd() { | ||
164 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
165 | + Ip4Address.valueOf("192.168.30.1"), | ||
166 | + MacAddress.valueOf("00:00:00:00:00:03")); | ||
167 | + | ||
168 | + // Construct a MultiPointToSinglePointIntent intent | ||
169 | + TrafficSelector.Builder selectorBuilder = | ||
170 | + DefaultTrafficSelector.builder(); | ||
171 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
172 | + .matchIPDst(PREFIX1); | ||
173 | + | ||
174 | + TrafficTreatment.Builder treatmentBuilder = | ||
175 | + DefaultTrafficTreatment.builder(); | ||
176 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
177 | + .setVlanId(VlanId.vlanId((short) 1)); | ||
178 | + | ||
179 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
180 | + ingressPoints.add(SW1_ETH1); | ||
181 | + ingressPoints.add(SW2_ETH1); | ||
182 | + | ||
183 | + MultiPointToSinglePointIntent intent = | ||
184 | + MultiPointToSinglePointIntent.builder() | ||
185 | + .appId(APPID) | ||
186 | + .key(Key.of(PREFIX1.toString(), APPID)) | ||
187 | + .selector(selectorBuilder.build()) | ||
188 | + .treatment(treatmentBuilder.build()) | ||
189 | + .ingressPoints(ingressPoints) | ||
190 | + .egressPoint(SW3_ETH1) | ||
191 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
192 | + .build(); | ||
193 | + | ||
194 | + // Setup the expected intents | ||
195 | + intentSynchronizer.submit(eqExceptId(intent)); | ||
196 | + | ||
197 | + replay(intentSynchronizer); | ||
198 | + | ||
199 | + // Send in the added event | ||
200 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
201 | + | ||
202 | + verify(intentSynchronizer); | ||
203 | + } | ||
204 | + | ||
205 | + private class TestCoreService extends CoreServiceAdapter { | ||
206 | + @Override | ||
207 | + public ApplicationId getAppId(String name) { | ||
208 | + return APPID; | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + private class TestRouteService extends RouteServiceAdapter { | ||
213 | + @Override | ||
214 | + public void addListener(RouteListener routeListener) { | ||
215 | + SdnIpFibNoVlanstoVlanTest.this.routeListener = routeListener; | ||
216 | + } | ||
217 | + } | ||
218 | + | ||
219 | + private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
220 | + @Override | ||
221 | + public void addListener(InterfaceListener listener) { | ||
222 | + SdnIpFibNoVlanstoVlanTest.this.interfaceListener = listener; | ||
223 | + } | ||
224 | + } | ||
225 | +} |
1 | +/* | ||
2 | + * Copyright 2015-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.sdnip; | ||
18 | + | ||
19 | +import com.google.common.collect.Lists; | ||
20 | +import com.google.common.collect.Sets; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ethernet; | ||
24 | +import org.onlab.packet.Ip4Address; | ||
25 | +import org.onlab.packet.Ip4Prefix; | ||
26 | +import org.onlab.packet.IpPrefix; | ||
27 | +import org.onlab.packet.MacAddress; | ||
28 | +import org.onlab.packet.VlanId; | ||
29 | +import org.onosproject.TestApplicationId; | ||
30 | +import org.onosproject.core.ApplicationId; | ||
31 | +import org.onosproject.core.CoreServiceAdapter; | ||
32 | +import org.onosproject.incubator.net.intf.Interface; | ||
33 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
34 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
35 | +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
36 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
37 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
38 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
39 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
40 | +import org.onosproject.net.ConnectPoint; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.net.PortNumber; | ||
43 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
44 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
45 | +import org.onosproject.net.flow.TrafficSelector; | ||
46 | +import org.onosproject.net.flow.TrafficTreatment; | ||
47 | +import org.onosproject.net.host.InterfaceIpAddress; | ||
48 | +import org.onosproject.net.intent.AbstractIntentTest; | ||
49 | +import org.onosproject.net.intent.Key; | ||
50 | +import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
51 | +import org.onosproject.routing.IntentSynchronizationService; | ||
52 | + | ||
53 | +import java.util.Collections; | ||
54 | +import java.util.HashSet; | ||
55 | +import java.util.List; | ||
56 | +import java.util.Set; | ||
57 | + | ||
58 | +import static org.easymock.EasyMock.*; | ||
59 | +import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
60 | + | ||
61 | +/** | ||
62 | + * Unit tests for SdnIpFib. | ||
63 | + */ | ||
64 | +public class SdnIpFibVlansToVlanDifferentTest extends AbstractIntentTest { | ||
65 | + | ||
66 | + private InterfaceService interfaceService; | ||
67 | + | ||
68 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
69 | + DeviceId.deviceId("of:0000000000000001"), | ||
70 | + PortNumber.portNumber(1)); | ||
71 | + | ||
72 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
73 | + DeviceId.deviceId("of:0000000000000002"), | ||
74 | + PortNumber.portNumber(1)); | ||
75 | + | ||
76 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
77 | + DeviceId.deviceId("of:0000000000000003"), | ||
78 | + PortNumber.portNumber(1)); | ||
79 | + | ||
80 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
81 | + | ||
82 | + private SdnIpFib sdnipFib; | ||
83 | + private IntentSynchronizationService intentSynchronizer; | ||
84 | + private final Set<Interface> interfaces = Sets.newHashSet(); | ||
85 | + | ||
86 | + private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
87 | + | ||
88 | + private RouteListener routeListener; | ||
89 | + private InterfaceListener interfaceListener; | ||
90 | + | ||
91 | + @Before | ||
92 | + public void setUp() throws Exception { | ||
93 | + super.setUp(); | ||
94 | + | ||
95 | + interfaceService = createMock(InterfaceService.class); | ||
96 | + | ||
97 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
98 | + expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
99 | + | ||
100 | + // These will set expectations on routingConfig and interfaceService | ||
101 | + setUpInterfaceService(); | ||
102 | + | ||
103 | + replay(interfaceService); | ||
104 | + | ||
105 | + intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
106 | + | ||
107 | + sdnipFib = new SdnIpFib(); | ||
108 | + sdnipFib.routeService = new TestRouteService(); | ||
109 | + sdnipFib.coreService = new TestCoreService(); | ||
110 | + sdnipFib.interfaceService = interfaceService; | ||
111 | + sdnipFib.intentSynchronizer = intentSynchronizer; | ||
112 | + | ||
113 | + sdnipFib.activate(); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Sets up the interface service. | ||
118 | + */ | ||
119 | + private void setUpInterfaceService() { | ||
120 | + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
121 | + interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
122 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
123 | + interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
124 | + VlanId.vlanId((short) 1)); | ||
125 | + interfaces.add(sw1Eth1); | ||
126 | + | ||
127 | + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
128 | + interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
129 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
130 | + interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
131 | + VlanId.vlanId((short) 1)); | ||
132 | + interfaces.add(sw2Eth1); | ||
133 | + | ||
134 | + InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
135 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
136 | + Lists.newArrayList(interfaceIpAddress3), | ||
137 | + MacAddress.valueOf("00:00:00:00:00:03"), | ||
138 | + VlanId.vlanId((short) 2)); | ||
139 | + interfaces.add(sw3Eth1); | ||
140 | + | ||
141 | + expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
142 | + Collections.singleton(sw1Eth1)).anyTimes(); | ||
143 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
144 | + .andReturn(sw1Eth1).anyTimes(); | ||
145 | + expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
146 | + Collections.singleton(sw2Eth1)).anyTimes(); | ||
147 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
148 | + .andReturn(sw2Eth1).anyTimes(); | ||
149 | + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
150 | + Collections.singleton(sw3Eth1)).anyTimes(); | ||
151 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
152 | + .andReturn(sw3Eth1).anyTimes(); | ||
153 | + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
158 | + * | ||
159 | + * We verify that the synchronizer records the correct state and that the | ||
160 | + * correct intent is submitted to the IntentService. | ||
161 | + */ | ||
162 | + @Test | ||
163 | + public void testRouteAdd() { | ||
164 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
165 | + Ip4Address.valueOf("192.168.30.1"), | ||
166 | + MacAddress.valueOf("00:00:00:00:00:03")); | ||
167 | + | ||
168 | + // Construct a MultiPointToSinglePointIntent intent | ||
169 | + TrafficSelector.Builder selectorBuilder = | ||
170 | + DefaultTrafficSelector.builder(); | ||
171 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
172 | + .matchVlanId(VlanId.ANY); | ||
173 | + | ||
174 | + TrafficTreatment.Builder treatmentBuilder = | ||
175 | + DefaultTrafficTreatment.builder(); | ||
176 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
177 | + .setVlanId(VlanId.vlanId((short) 2)); | ||
178 | + | ||
179 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
180 | + ingressPoints.add(SW1_ETH1); | ||
181 | + ingressPoints.add(SW2_ETH1); | ||
182 | + | ||
183 | + MultiPointToSinglePointIntent intent = | ||
184 | + MultiPointToSinglePointIntent.builder() | ||
185 | + .appId(APPID) | ||
186 | + .key(Key.of(PREFIX1.toString(), APPID)) | ||
187 | + .selector(selectorBuilder.build()) | ||
188 | + .treatment(treatmentBuilder.build()) | ||
189 | + .ingressPoints(ingressPoints) | ||
190 | + .egressPoint(SW3_ETH1) | ||
191 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
192 | + .build(); | ||
193 | + | ||
194 | + // Setup the expected intents | ||
195 | + intentSynchronizer.submit(eqExceptId(intent)); | ||
196 | + replay(intentSynchronizer); | ||
197 | + | ||
198 | + // Send in the added event | ||
199 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
200 | + | ||
201 | + verify(intentSynchronizer); | ||
202 | + } | ||
203 | + | ||
204 | + private class TestCoreService extends CoreServiceAdapter { | ||
205 | + @Override | ||
206 | + public ApplicationId getAppId(String name) { | ||
207 | + return APPID; | ||
208 | + } | ||
209 | + } | ||
210 | + | ||
211 | + private class TestRouteService extends RouteServiceAdapter { | ||
212 | + @Override | ||
213 | + public void addListener(RouteListener routeListener) { | ||
214 | + SdnIpFibVlansToVlanDifferentTest.this.routeListener = routeListener; | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
219 | + @Override | ||
220 | + public void addListener(InterfaceListener listener) { | ||
221 | + SdnIpFibVlansToVlanDifferentTest.this.interfaceListener = listener; | ||
222 | + } | ||
223 | + } | ||
224 | +} |
1 | +/* | ||
2 | + * Copyright 2015-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.sdnip; | ||
18 | + | ||
19 | +import com.google.common.collect.Lists; | ||
20 | +import com.google.common.collect.Sets; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ethernet; | ||
24 | +import org.onlab.packet.Ip4Address; | ||
25 | +import org.onlab.packet.Ip4Prefix; | ||
26 | +import org.onlab.packet.IpPrefix; | ||
27 | +import org.onlab.packet.MacAddress; | ||
28 | +import org.onlab.packet.VlanId; | ||
29 | +import org.onosproject.TestApplicationId; | ||
30 | +import org.onosproject.core.ApplicationId; | ||
31 | +import org.onosproject.core.CoreServiceAdapter; | ||
32 | +import org.onosproject.incubator.net.intf.Interface; | ||
33 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
34 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
35 | +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
36 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
37 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
38 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
39 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
40 | +import org.onosproject.net.ConnectPoint; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.net.PortNumber; | ||
43 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
44 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
45 | +import org.onosproject.net.flow.TrafficSelector; | ||
46 | +import org.onosproject.net.flow.TrafficTreatment; | ||
47 | +import org.onosproject.net.host.InterfaceIpAddress; | ||
48 | +import org.onosproject.net.intent.AbstractIntentTest; | ||
49 | +import org.onosproject.net.intent.Key; | ||
50 | +import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
51 | +import org.onosproject.routing.IntentSynchronizationService; | ||
52 | + | ||
53 | +import java.util.Collections; | ||
54 | +import java.util.HashSet; | ||
55 | +import java.util.List; | ||
56 | +import java.util.Set; | ||
57 | + | ||
58 | +import static org.easymock.EasyMock.*; | ||
59 | +import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
60 | + | ||
61 | +/** | ||
62 | + * Unit tests for SdnIpFib. | ||
63 | + */ | ||
64 | +public class SdnIpFibVlansToVlanSameTest extends AbstractIntentTest { | ||
65 | + | ||
66 | + private InterfaceService interfaceService; | ||
67 | + | ||
68 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
69 | + DeviceId.deviceId("of:0000000000000001"), | ||
70 | + PortNumber.portNumber(1)); | ||
71 | + | ||
72 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
73 | + DeviceId.deviceId("of:0000000000000002"), | ||
74 | + PortNumber.portNumber(1)); | ||
75 | + | ||
76 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
77 | + DeviceId.deviceId("of:0000000000000003"), | ||
78 | + PortNumber.portNumber(1)); | ||
79 | + | ||
80 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
81 | + | ||
82 | + private SdnIpFib sdnipFib; | ||
83 | + private IntentSynchronizationService intentSynchronizer; | ||
84 | + private final Set<Interface> interfaces = Sets.newHashSet(); | ||
85 | + | ||
86 | + private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
87 | + | ||
88 | + private RouteListener routeListener; | ||
89 | + private InterfaceListener interfaceListener; | ||
90 | + | ||
91 | + @Before | ||
92 | + public void setUp() throws Exception { | ||
93 | + super.setUp(); | ||
94 | + | ||
95 | + interfaceService = createMock(InterfaceService.class); | ||
96 | + | ||
97 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
98 | + expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
99 | + | ||
100 | + // These will set expectations on routingConfig and interfaceService | ||
101 | + setUpInterfaceService(); | ||
102 | + | ||
103 | + replay(interfaceService); | ||
104 | + | ||
105 | + intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
106 | + | ||
107 | + sdnipFib = new SdnIpFib(); | ||
108 | + sdnipFib.routeService = new TestRouteService(); | ||
109 | + sdnipFib.coreService = new TestCoreService(); | ||
110 | + sdnipFib.interfaceService = interfaceService; | ||
111 | + sdnipFib.intentSynchronizer = intentSynchronizer; | ||
112 | + | ||
113 | + sdnipFib.activate(); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Sets up the interface service. | ||
118 | + */ | ||
119 | + private void setUpInterfaceService() { | ||
120 | + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
121 | + interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
122 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
123 | + interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
124 | + VlanId.vlanId((short) 1)); | ||
125 | + interfaces.add(sw1Eth1); | ||
126 | + | ||
127 | + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
128 | + interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
129 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
130 | + interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
131 | + VlanId.vlanId((short) 1)); | ||
132 | + interfaces.add(sw2Eth1); | ||
133 | + | ||
134 | + InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
135 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
136 | + Lists.newArrayList(interfaceIpAddress3), | ||
137 | + MacAddress.valueOf("00:00:00:00:00:03"), | ||
138 | + VlanId.vlanId((short) 1)); | ||
139 | + interfaces.add(sw3Eth1); | ||
140 | + | ||
141 | + expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
142 | + Collections.singleton(sw1Eth1)).anyTimes(); | ||
143 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
144 | + .andReturn(sw1Eth1).anyTimes(); | ||
145 | + expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
146 | + Collections.singleton(sw2Eth1)).anyTimes(); | ||
147 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
148 | + .andReturn(sw2Eth1).anyTimes(); | ||
149 | + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
150 | + Collections.singleton(sw3Eth1)).anyTimes(); | ||
151 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
152 | + .andReturn(sw3Eth1).anyTimes(); | ||
153 | + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
158 | + * | ||
159 | + * We verify that the synchronizer records the correct state and that the | ||
160 | + * correct intent is submitted to the IntentService. | ||
161 | + */ | ||
162 | + @Test | ||
163 | + public void testRouteAdd() { | ||
164 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
165 | + Ip4Address.valueOf("192.168.30.1"), | ||
166 | + MacAddress.valueOf("00:00:00:00:00:03")); | ||
167 | + | ||
168 | + // Construct a MultiPointToSinglePointIntent intent | ||
169 | + TrafficSelector.Builder selectorBuilder = | ||
170 | + DefaultTrafficSelector.builder(); | ||
171 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
172 | + .matchVlanId(VlanId.ANY); | ||
173 | + | ||
174 | + TrafficTreatment.Builder treatmentBuilder = | ||
175 | + DefaultTrafficTreatment.builder(); | ||
176 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | ||
177 | + | ||
178 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
179 | + ingressPoints.add(SW1_ETH1); | ||
180 | + ingressPoints.add(SW2_ETH1); | ||
181 | + | ||
182 | + MultiPointToSinglePointIntent intent = | ||
183 | + MultiPointToSinglePointIntent.builder() | ||
184 | + .appId(APPID) | ||
185 | + .key(Key.of(PREFIX1.toString(), APPID)) | ||
186 | + .selector(selectorBuilder.build()) | ||
187 | + .treatment(treatmentBuilder.build()) | ||
188 | + .ingressPoints(ingressPoints) | ||
189 | + .egressPoint(SW3_ETH1) | ||
190 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
191 | + .build(); | ||
192 | + | ||
193 | + // Setup the expected intents | ||
194 | + intentSynchronizer.submit(eqExceptId(intent)); | ||
195 | + replay(intentSynchronizer); | ||
196 | + | ||
197 | + // Send in the added event | ||
198 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
199 | + | ||
200 | + verify(intentSynchronizer); | ||
201 | + } | ||
202 | + | ||
203 | + private class TestCoreService extends CoreServiceAdapter { | ||
204 | + @Override | ||
205 | + public ApplicationId getAppId(String name) { | ||
206 | + return APPID; | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
210 | + private class TestRouteService extends RouteServiceAdapter { | ||
211 | + @Override | ||
212 | + public void addListener(RouteListener routeListener) { | ||
213 | + SdnIpFibVlansToVlanSameTest.this.routeListener = routeListener; | ||
214 | + } | ||
215 | + } | ||
216 | + | ||
217 | + private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
218 | + @Override | ||
219 | + public void addListener(InterfaceListener listener) { | ||
220 | + SdnIpFibVlansToVlanSameTest.this.interfaceListener = listener; | ||
221 | + } | ||
222 | + } | ||
223 | +} |
1 | +/* | ||
2 | + * Copyright 2015-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.sdnip; | ||
18 | + | ||
19 | +import com.google.common.collect.Lists; | ||
20 | +import com.google.common.collect.Sets; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ethernet; | ||
24 | +import org.onlab.packet.Ip4Address; | ||
25 | +import org.onlab.packet.Ip4Prefix; | ||
26 | +import org.onlab.packet.IpPrefix; | ||
27 | +import org.onlab.packet.MacAddress; | ||
28 | +import org.onlab.packet.VlanId; | ||
29 | +import org.onosproject.TestApplicationId; | ||
30 | +import org.onosproject.core.ApplicationId; | ||
31 | +import org.onosproject.core.CoreServiceAdapter; | ||
32 | +import org.onosproject.incubator.net.intf.Interface; | ||
33 | +import org.onosproject.incubator.net.intf.InterfaceListener; | ||
34 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
35 | +import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
36 | +import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
37 | +import org.onosproject.incubator.net.routing.RouteEvent; | ||
38 | +import org.onosproject.incubator.net.routing.RouteListener; | ||
39 | +import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
40 | +import org.onosproject.net.ConnectPoint; | ||
41 | +import org.onosproject.net.DeviceId; | ||
42 | +import org.onosproject.net.PortNumber; | ||
43 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
44 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
45 | +import org.onosproject.net.flow.TrafficSelector; | ||
46 | +import org.onosproject.net.flow.TrafficTreatment; | ||
47 | +import org.onosproject.net.host.InterfaceIpAddress; | ||
48 | +import org.onosproject.net.intent.AbstractIntentTest; | ||
49 | +import org.onosproject.net.intent.Key; | ||
50 | +import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
51 | +import org.onosproject.routing.IntentSynchronizationService; | ||
52 | + | ||
53 | +import java.util.Collections; | ||
54 | +import java.util.HashSet; | ||
55 | +import java.util.List; | ||
56 | +import java.util.Set; | ||
57 | + | ||
58 | +import static org.easymock.EasyMock.*; | ||
59 | +import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
60 | + | ||
61 | +/** | ||
62 | + * Unit tests for SdnIpFib. | ||
63 | + */ | ||
64 | +public class SdnIpFibVlanstoNoVlanTest extends AbstractIntentTest { | ||
65 | + | ||
66 | + private InterfaceService interfaceService; | ||
67 | + | ||
68 | + private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
69 | + DeviceId.deviceId("of:0000000000000001"), | ||
70 | + PortNumber.portNumber(1)); | ||
71 | + | ||
72 | + private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
73 | + DeviceId.deviceId("of:0000000000000002"), | ||
74 | + PortNumber.portNumber(1)); | ||
75 | + | ||
76 | + private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
77 | + DeviceId.deviceId("of:0000000000000003"), | ||
78 | + PortNumber.portNumber(1)); | ||
79 | + | ||
80 | + private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
81 | + | ||
82 | + private SdnIpFib sdnipFib; | ||
83 | + private IntentSynchronizationService intentSynchronizer; | ||
84 | + private final Set<Interface> interfaces = Sets.newHashSet(); | ||
85 | + | ||
86 | + private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
87 | + | ||
88 | + private RouteListener routeListener; | ||
89 | + private InterfaceListener interfaceListener; | ||
90 | + | ||
91 | + @Before | ||
92 | + public void setUp() throws Exception { | ||
93 | + super.setUp(); | ||
94 | + | ||
95 | + interfaceService = createMock(InterfaceService.class); | ||
96 | + | ||
97 | + interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
98 | + expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
99 | + | ||
100 | + // These will set expectations on routingConfig and interfaceService | ||
101 | + setUpInterfaceService(); | ||
102 | + | ||
103 | + replay(interfaceService); | ||
104 | + | ||
105 | + intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
106 | + | ||
107 | + sdnipFib = new SdnIpFib(); | ||
108 | + sdnipFib.routeService = new TestRouteService(); | ||
109 | + sdnipFib.coreService = new TestCoreService(); | ||
110 | + sdnipFib.interfaceService = interfaceService; | ||
111 | + sdnipFib.intentSynchronizer = intentSynchronizer; | ||
112 | + | ||
113 | + sdnipFib.activate(); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Sets up the interface service. | ||
118 | + */ | ||
119 | + private void setUpInterfaceService() { | ||
120 | + List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
121 | + interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
122 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
123 | + interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
124 | + VlanId.vlanId((short) 1)); | ||
125 | + interfaces.add(sw1Eth1); | ||
126 | + | ||
127 | + List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
128 | + interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
129 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
130 | + interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
131 | + VlanId.vlanId((short) 1)); | ||
132 | + interfaces.add(sw2Eth1); | ||
133 | + | ||
134 | + InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
135 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
136 | + Lists.newArrayList(interfaceIpAddress3), | ||
137 | + MacAddress.valueOf("00:00:00:00:00:03"), | ||
138 | + VlanId.NONE); | ||
139 | + interfaces.add(sw3Eth1); | ||
140 | + | ||
141 | + expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
142 | + Collections.singleton(sw1Eth1)).anyTimes(); | ||
143 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
144 | + .andReturn(sw1Eth1).anyTimes(); | ||
145 | + expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
146 | + Collections.singleton(sw2Eth1)).anyTimes(); | ||
147 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
148 | + .andReturn(sw2Eth1).anyTimes(); | ||
149 | + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
150 | + Collections.singleton(sw3Eth1)).anyTimes(); | ||
151 | + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
152 | + .andReturn(sw3Eth1).anyTimes(); | ||
153 | + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
158 | + * | ||
159 | + * We verify that the synchronizer records the correct state and that the | ||
160 | + * correct intent is submitted to the IntentService. | ||
161 | + */ | ||
162 | + @Test | ||
163 | + public void testRouteAdd() { | ||
164 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
165 | + Ip4Address.valueOf("192.168.30.1"), | ||
166 | + MacAddress.valueOf("00:00:00:00:00:03")); | ||
167 | + | ||
168 | + // Construct a MultiPointToSinglePointIntent intent | ||
169 | + TrafficSelector.Builder selectorBuilder = | ||
170 | + DefaultTrafficSelector.builder(); | ||
171 | + selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
172 | + .matchVlanId(VlanId.ANY); | ||
173 | + | ||
174 | + TrafficTreatment.Builder treatmentBuilder = | ||
175 | + DefaultTrafficTreatment.builder(); | ||
176 | + treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
177 | + .popVlan(); | ||
178 | + | ||
179 | + Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
180 | + ingressPoints.add(SW1_ETH1); | ||
181 | + ingressPoints.add(SW2_ETH1); | ||
182 | + | ||
183 | + MultiPointToSinglePointIntent intent = | ||
184 | + MultiPointToSinglePointIntent.builder() | ||
185 | + .appId(APPID) | ||
186 | + .key(Key.of(PREFIX1.toString(), APPID)) | ||
187 | + .selector(selectorBuilder.build()) | ||
188 | + .treatment(treatmentBuilder.build()) | ||
189 | + .ingressPoints(ingressPoints) | ||
190 | + .egressPoint(SW3_ETH1) | ||
191 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
192 | + .build(); | ||
193 | + | ||
194 | + // Setup the expected intents | ||
195 | + intentSynchronizer.submit(eqExceptId(intent)); | ||
196 | + replay(intentSynchronizer); | ||
197 | + | ||
198 | + // Send in the added event | ||
199 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
200 | + | ||
201 | + verify(intentSynchronizer); | ||
202 | + } | ||
203 | + | ||
204 | + private class TestCoreService extends CoreServiceAdapter { | ||
205 | + @Override | ||
206 | + public ApplicationId getAppId(String name) { | ||
207 | + return APPID; | ||
208 | + } | ||
209 | + } | ||
210 | + | ||
211 | + private class TestRouteService extends RouteServiceAdapter { | ||
212 | + @Override | ||
213 | + public void addListener(RouteListener routeListener) { | ||
214 | + SdnIpFibVlanstoNoVlanTest.this.routeListener = routeListener; | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
219 | + @Override | ||
220 | + public void addListener(InterfaceListener listener) { | ||
221 | + SdnIpFibVlanstoNoVlanTest.this.interfaceListener = listener; | ||
222 | + } | ||
223 | + } | ||
224 | +} |
-
Please register or login to post a comment