blob: 61ad4e81ec72ff28a0373bc1d462c675b1475191 [file] [log] [blame]
Phaneendra Manda0f21ad62016-02-12 19:32:13 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Phaneendra Manda0f21ad62016-02-12 19:32:13 +05303 *
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 */
16package org.onosproject.sfc.installer.impl;
17
18import static org.easymock.EasyMock.createMock;
19import static org.easymock.EasyMock.expect;
20import static org.easymock.EasyMock.replay;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053021import static org.hamcrest.Matchers.instanceOf;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053022import static org.hamcrest.Matchers.is;
23import static org.junit.Assert.assertThat;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053024import static org.onosproject.net.Device.Type.SWITCH;
25import static org.onosproject.net.Port.Type.COPPER;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053026
Phaneendra Manda8db7d092016-06-04 00:17:24 +053027import java.util.Collections;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053028import java.util.LinkedList;
29import java.util.List;
30import java.util.Map;
31import java.util.Set;
32
33import org.junit.Test;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053034import org.onlab.packet.ChassisId;
35import org.onlab.packet.IPv4;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053036import org.onlab.packet.IpAddress;
37import org.onlab.packet.IpPrefix;
38import org.onlab.packet.MacAddress;
39import org.onosproject.core.ApplicationId;
40import org.onosproject.core.DefaultApplicationId;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053041import org.onosproject.net.AnnotationKeys;
42import org.onosproject.net.Annotations;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053043import org.onosproject.net.ConnectPoint;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053044import org.onosproject.net.DefaultAnnotations;
45import org.onosproject.net.DefaultDevice;
46import org.onosproject.net.DefaultPort;
47import org.onosproject.net.Device;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053048import org.onosproject.net.DeviceId;
49import org.onosproject.net.HostLocation;
50import org.onosproject.net.NshServicePathId;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053051import org.onosproject.net.Port;
52import org.onosproject.net.PortNumber;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053053import org.onosproject.net.device.DeviceService;
54import org.onosproject.net.device.DeviceServiceAdapter;
55import org.onosproject.net.driver.DriverHandler;
56import org.onosproject.net.driver.DriverService;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053057import org.onosproject.net.flow.criteria.Criterion;
58import org.onosproject.net.flow.criteria.PortCriterion;
59import org.onosproject.net.flow.instructions.Instruction;
60import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053061import org.onosproject.net.flowobjective.FlowObjectiveService;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053062import org.onosproject.net.flowobjective.ForwardingObjective;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053063import org.onosproject.net.host.HostService;
64import org.onosproject.net.host.HostServiceAdapter;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053065import org.onosproject.net.provider.ProviderId;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053066import org.onosproject.sfc.util.FlowClassifierAdapter;
67import org.onosproject.sfc.util.FlowObjectiveAdapter;
68import org.onosproject.sfc.util.MockDriverHandler;
69import org.onosproject.sfc.util.PortPairAdapter;
70import org.onosproject.sfc.util.PortPairGroupAdapter;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053071import org.onosproject.sfc.util.TenantNetworkAdapter;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053072import org.onosproject.sfc.util.VirtualPortAdapter;
73import org.onosproject.sfc.util.VtnRscAdapter;
74import org.onosproject.vtnrsc.AllowedAddressPair;
75import org.onosproject.vtnrsc.BindingHostId;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053076import org.onosproject.vtnrsc.DefaultFiveTuple;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053077import org.onosproject.vtnrsc.DefaultFlowClassifier;
78import org.onosproject.vtnrsc.DefaultPortChain;
79import org.onosproject.vtnrsc.DefaultPortPair;
80import org.onosproject.vtnrsc.DefaultPortPairGroup;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053081import org.onosproject.vtnrsc.DefaultTenantNetwork;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053082import org.onosproject.vtnrsc.DefaultVirtualPort;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053083import org.onosproject.vtnrsc.FiveTuple;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053084import org.onosproject.vtnrsc.FixedIp;
85import org.onosproject.vtnrsc.FlowClassifier;
86import org.onosproject.vtnrsc.FlowClassifierId;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053087import org.onosproject.vtnrsc.LoadBalanceId;
88import org.onosproject.vtnrsc.PhysicalNetwork;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053089import org.onosproject.vtnrsc.PortChain;
90import org.onosproject.vtnrsc.PortChainId;
91import org.onosproject.vtnrsc.PortPair;
92import org.onosproject.vtnrsc.PortPairGroup;
93import org.onosproject.vtnrsc.PortPairGroupId;
94import org.onosproject.vtnrsc.PortPairId;
95import org.onosproject.vtnrsc.SecurityGroup;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053096import org.onosproject.vtnrsc.SegmentationId;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053097import org.onosproject.vtnrsc.SubnetId;
98import org.onosproject.vtnrsc.TenantId;
Phaneendra Manda8db7d092016-06-04 00:17:24 +053099import org.onosproject.vtnrsc.TenantNetwork;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530100import org.onosproject.vtnrsc.TenantNetworkId;
101import org.onosproject.vtnrsc.VirtualPort;
102import org.onosproject.vtnrsc.VirtualPortId;
103import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
104import org.onosproject.vtnrsc.portpair.PortPairService;
105import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
106import org.onosproject.vtnrsc.service.VtnRscService;
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530107import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530108import org.onosproject.vtnrsc.virtualport.VirtualPortService;
109
110import com.google.common.collect.Lists;
111import com.google.common.collect.Maps;
112import com.google.common.collect.Sets;
113
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530114public class SfcFlowRuleInstallerImplTest {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530115
116 FlowObjectiveService flowObjectiveService = new FlowObjectiveAdapter();
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530117 DeviceService deviceService = new DeviceServiceAdapter(createPortList());
118
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530119 HostService hostService = new HostServiceAdapter();
120 VirtualPortService virtualPortService = new VirtualPortAdapter();
121 VtnRscService vtnRscService = new VtnRscAdapter();
122 PortPairService portPairService = new PortPairAdapter();
123 PortPairGroupService portPairGroupService = new PortPairGroupAdapter();
124 FlowClassifierService flowClassifierService = new FlowClassifierAdapter();
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530125 TenantNetworkService tenantNetworkService = new TenantNetworkAdapter();
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530126
127 final DriverService driverService = createMock(DriverService.class);
128
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530129 private final String networkIdStr = "123";
130
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530131 final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
132 final TenantId tenantId = TenantId.tenantId("1");
133 final String name = "PortChain";
134 final String description = "PortChain";
135 final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
136 final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
137 PortPairGroupId portPairGroupId1 = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
138 PortPairGroupId portPairGroupId2 = PortPairGroupId.of("73343531-fc23-aeb6-f44b-56dc5e2fb3af");
139
140 PortPairId portPairId1 = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
141 PortPairId portPairId2 = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
142
143 FlowClassifierId flowClassifierId1 = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
144 FlowClassifierId flowClassifierId2 = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
145
146 final String ppName = "PortPair";
147 final String ppDescription = "PortPair";
148 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
149 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
150
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530151 final String ppgName = "PortPairGroup";
152 final String ppgDescription = "PortPairGroup";
153 final List<PortPairId> portPairList = new LinkedList<PortPairId>();
154
155 VirtualPortId id1 = VirtualPortId.portId(ingress);
156 VirtualPortId id2 = VirtualPortId.portId("3414");
157
158 DeviceId deviceId = DeviceId.deviceId("of:000000000000001");
159
160 final DriverHandler driverHandler = new MockDriverHandler();
161
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530162 private List<Port> createPortList() {
163 List<Port> portList = Lists.newArrayList();
164 long sp1 = 1_000_000;
165 ProviderId pid = new ProviderId("of", "foo");
166 ChassisId cid = new ChassisId();
167 Device device = new DefaultDevice(pid, deviceId, SWITCH, "whitebox", "1.1.x", "3.9.1", "43311-12345", cid);
168 Annotations annotations = DefaultAnnotations
169 .builder()
170 .set(AnnotationKeys.PORT_NAME, "vxlan-0.0.0.0").build();
171 Port p1 = new DefaultPort(device, PortNumber.ANY, true, COPPER, sp1, annotations);
172 portList.add(p1);
173 return portList;
174 }
175
176 private PortPair createPortPair(PortPairId ppId) {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530177 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
178 PortPair portPair = portPairBuilder.setId(ppId).setName(ppName).setTenantId(tenantId)
179 .setDescription(ppDescription).setIngress(ingress).setEgress(egress).build();
180 return portPair;
181 }
182
183 private PortPairGroup createPortPairGroup(PortPairGroupId ppgId) {
184
185 portPairList.clear();
186 // Create same two port-pair-group objects.
187 portPairList.add(portPairId1);
188 portPairList.add(portPairId2);
189
190 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
191 PortPairGroup portPairGroup = portPairGroupBuilder.setId(ppgId).setTenantId(tenantId)
192 .setName(ppgName).setDescription(ppgDescription).setPortPairs(portPairList).build();
193
194 return portPairGroup;
195
196 }
197
198 private PortChain createPortChain() {
199
200 portPairGroups.clear();
201 flowClassifiers.clear();
202 // create list of Port Pair Groups.
203
204 portPairGroups.add(portPairGroupId1);
205 portPairGroups.add(portPairGroupId2);
206 // create list of Flow classifiers.
207 flowClassifiers.add(flowClassifierId1);
208 flowClassifiers.add(flowClassifierId2);
209
210 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
211 final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
212 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
213 .build();
214
215 return portChain;
216 }
217
218 private FlowClassifier createFlowClassifier(FlowClassifierId id) {
219 final String name = "FlowClassifier1";
220 final String description = "FlowClassifier1";
221 final String ethType = "IPv4";
222 final String protocol = "tcp";
223 final int minSrcPortRange = 5;
224 final int maxSrcPortRange = 10;
225 final int minDstPortRange = 5;
226 final int maxDstPortRange = 10;
227 final TenantId tenantId = TenantId.tenantId("1");
228 final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
229 final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0");
230 final VirtualPortId virtualSrcPort = id1;
231 final VirtualPortId virtualDstPort = id2;
232
233 DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
234 final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(id)
235 .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
236 .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
237 .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
238 .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
239 return flowClassifier;
240 }
241
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530242 private VirtualPort createVirtualPort(VirtualPortId id) {
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530243 Set<FixedIp> fixedIps;
244 Map<String, String> propertyMap;
245 Set<AllowedAddressPair> allowedAddressPairs;
246 Set<SecurityGroup> securityGroups = Sets.newHashSet();
247
248 String macAddressStr = "fa:12:3e:56:ee:a2";
249 String ipAddress = "10.1.1.1";
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530250 String subnet = "1212";
251 String hostIdStr = "fa:e2:3e:56:ee:a2";
252 String deviceOwner = "james";
253 propertyMap = Maps.newHashMap();
254 propertyMap.putIfAbsent("deviceOwner", deviceOwner);
255
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530256 TenantNetworkId networkId = TenantNetworkId.networkId(networkIdStr);
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530257 MacAddress macAddress = MacAddress.valueOf(macAddressStr);
258 BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);
259 FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
260 IpAddress.valueOf(ipAddress));
261 fixedIps = Sets.newHashSet();
262 fixedIps.add(fixedIp);
263
264 allowedAddressPairs = Sets.newHashSet();
265 AllowedAddressPair allowedAddressPair = AllowedAddressPair
266 .allowedAddressPair(IpAddress.valueOf(ipAddress),
267 MacAddress.valueOf(macAddressStr));
268 allowedAddressPairs.add(allowedAddressPair);
269
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530270 VirtualPort d1 = new DefaultVirtualPort(id, networkId, true,
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530271 propertyMap,
272 VirtualPort.State.ACTIVE,
273 macAddress, tenantId, deviceId,
274 fixedIps, bindingHostId,
275 allowedAddressPairs,
276 securityGroups);
277 return d1;
278 }
279
280 @Test
281 public void testInstallFlowClassifier() {
282
283 ApplicationId appId = new DefaultApplicationId(1, "test");
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530284 SfcFlowRuleInstallerImpl flowClassifierInstaller = new SfcFlowRuleInstallerImpl();
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530285 flowClassifierInstaller.virtualPortService = virtualPortService;
286 flowClassifierInstaller.vtnRscService = vtnRscService;
287 flowClassifierInstaller.portPairService = portPairService;
288 flowClassifierInstaller.portPairGroupService = portPairGroupService;
289 flowClassifierInstaller.flowClassifierService = flowClassifierService;
290 flowClassifierInstaller.driverService = driverService;
291 flowClassifierInstaller.deviceService = deviceService;
292 flowClassifierInstaller.hostService = hostService;
293 flowClassifierInstaller.flowObjectiveService = flowObjectiveService;
294 flowClassifierInstaller.appId = appId;
295
296 final PortChain portChain = createPortChain();
297 NshServicePathId nshSpiId = NshServicePathId.of(10);
298
299 portPairGroupService.createPortPairGroup(createPortPairGroup(portPairGroupId1));
300 portPairGroupService.createPortPairGroup(createPortPairGroup(portPairGroupId2));
301 portPairService.createPortPair(createPortPair(portPairId1));
302 portPairService.createPortPair(createPortPair(portPairId2));
303 FlowClassifier fc1 = createFlowClassifier(flowClassifierId1);
304 FlowClassifier fc2 = createFlowClassifier(flowClassifierId2);
305 flowClassifierService.createFlowClassifier(fc1);
306 flowClassifierService.createFlowClassifier(fc2);
307
308 List<VirtualPort> virtualPortList = Lists.newArrayList();
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530309 virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress)));
Phaneendra Manda0f21ad62016-02-12 19:32:13 +0530310 virtualPortService.createPorts(virtualPortList);
311
312 expect(driverService.createHandler(deviceId)).andReturn(driverHandler).anyTimes();
313 replay(driverService);
314
315 ConnectPoint connectPoint = flowClassifierInstaller.installFlowClassifier(portChain, nshSpiId);
316
317 assertThat(connectPoint, is(HostLocation.NONE));
318 }
Phaneendra Manda8db7d092016-06-04 00:17:24 +0530319
320 @Test
321 public void testInstallLoadBalancedFlowRules() {
322 ApplicationId appId = new DefaultApplicationId(1, "test");
323 SfcFlowRuleInstallerImpl flowRuleInstaller = new SfcFlowRuleInstallerImpl();
324 flowRuleInstaller.virtualPortService = virtualPortService;
325 flowRuleInstaller.vtnRscService = vtnRscService;
326 flowRuleInstaller.portPairService = portPairService;
327 flowRuleInstaller.portPairGroupService = portPairGroupService;
328 flowRuleInstaller.flowClassifierService = flowClassifierService;
329 flowRuleInstaller.driverService = driverService;
330 flowRuleInstaller.deviceService = deviceService;
331 flowRuleInstaller.hostService = hostService;
332 flowRuleInstaller.flowObjectiveService = flowObjectiveService;
333 flowRuleInstaller.tenantNetworkService = tenantNetworkService;
334 flowRuleInstaller.appId = appId;
335
336 final PortChain portChain = createPortChain();
337
338 final String ppName1 = "PortPair1";
339 final String ppDescription1 = "PortPair1";
340 final String ingress1 = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
341 final String egress1 = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
342 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
343 PortPair portPair1 = portPairBuilder.setId(portPairId1).setName(ppName1).setTenantId(tenantId)
344 .setDescription(ppDescription1).setIngress(ingress1).setEgress(egress1).build();
345
346 final String ppName2 = "PortPair2";
347 final String ppDescription2 = "PortPair2";
348 final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
349 final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
350 PortPair portPair2 = portPairBuilder.setId(portPairId2).setName(ppName2).setTenantId(tenantId)
351 .setDescription(ppDescription2).setIngress(ingress2).setEgress(egress2).build();
352
353 portPairService.createPortPair(portPair1);
354 portPairService.createPortPair(portPair2);
355
356 FlowClassifier fc1 = createFlowClassifier(flowClassifierId1);
357 FlowClassifier fc2 = createFlowClassifier(flowClassifierId2);
358 flowClassifierService.createFlowClassifier(fc1);
359 flowClassifierService.createFlowClassifier(fc2);
360
361 NshServicePathId nshSpiId = NshServicePathId.of(10);
362 FiveTuple fiveTuple = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("3.3.3.3"))
363 .setIpDst(IpAddress.valueOf("4.4.4.4"))
364 .setPortSrc(PortNumber.portNumber(1500))
365 .setPortDst(PortNumber.portNumber(2000))
366 .setProtocol(IPv4.PROTOCOL_UDP)
367 .setTenantId(TenantId.tenantId("bbb"))
368 .build();
369 LoadBalanceId id = LoadBalanceId.of((byte) 1);
370
371 List<PortPairId> path = Lists.newArrayList();
372 path.add(portPairId1);
373 path.add(portPairId2);
374
375 List<VirtualPort> virtualPortList = Lists.newArrayList();
376 virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress1)));
377 virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress1)));
378 virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress2)));
379 virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress2)));
380 virtualPortService.createPorts(virtualPortList);
381
382 portChain.addLoadBalancePath(fiveTuple, id, path);
383
384 String physicalNetworkStr = "1234";
385 String segmentationIdStr = "1";
386 SegmentationId segmentationID = SegmentationId
387 .segmentationId(segmentationIdStr);
388 TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr);
389 PhysicalNetwork physicalNetwork = PhysicalNetwork
390 .physicalNetwork(physicalNetworkStr);
391 TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false,
392 TenantNetwork.State.ACTIVE,
393 false, tenantId, false,
394 TenantNetwork.Type.LOCAL,
395 physicalNetwork,
396 segmentationID);
397 tenantNetworkService.createNetworks(Collections.singletonList(p1));
398
399 expect(driverService.createHandler(deviceId)).andReturn(driverHandler).anyTimes();
400 replay(driverService);
401
402 flowRuleInstaller.installLoadBalancedFlowRules(portChain, fiveTuple, nshSpiId);
403
404 ForwardingObjective forObj = ((FlowObjectiveAdapter) flowObjectiveService).forwardingObjective();
405
406 // Check for Selector
407 assertThat(forObj.selector().getCriterion(Criterion.Type.IN_PORT), instanceOf(PortCriterion.class));
408
409 // Check for treatment
410 List<Instruction> instructions = forObj.treatment().allInstructions();
411 for (Instruction instruction : instructions) {
412 if (instruction.type() == Instruction.Type.OUTPUT) {
413 assertThat(((OutputInstruction) instruction).port(), is(PortNumber.P0));
414 }
415 }
416 }
417}