Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 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 | package org.onosproject.sfc.installer.impl; |
| 17 | |
| 18 | import static org.easymock.EasyMock.createMock; |
| 19 | import static org.easymock.EasyMock.expect; |
| 20 | import static org.easymock.EasyMock.replay; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 21 | import static org.hamcrest.Matchers.instanceOf; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.junit.Assert.assertThat; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 24 | import static org.onosproject.net.Device.Type.SWITCH; |
| 25 | import static org.onosproject.net.Port.Type.COPPER; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 26 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 27 | import java.util.Collections; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 28 | import java.util.LinkedList; |
| 29 | import java.util.List; |
| 30 | import java.util.Map; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import org.junit.Test; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 34 | import org.onlab.packet.ChassisId; |
| 35 | import org.onlab.packet.IPv4; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 36 | import org.onlab.packet.IpAddress; |
| 37 | import org.onlab.packet.IpPrefix; |
| 38 | import org.onlab.packet.MacAddress; |
| 39 | import org.onosproject.core.ApplicationId; |
| 40 | import org.onosproject.core.DefaultApplicationId; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 41 | import org.onosproject.net.AnnotationKeys; |
| 42 | import org.onosproject.net.Annotations; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 43 | import org.onosproject.net.ConnectPoint; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 44 | import org.onosproject.net.DefaultAnnotations; |
| 45 | import org.onosproject.net.DefaultDevice; |
| 46 | import org.onosproject.net.DefaultPort; |
| 47 | import org.onosproject.net.Device; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 48 | import org.onosproject.net.DeviceId; |
| 49 | import org.onosproject.net.HostLocation; |
| 50 | import org.onosproject.net.NshServicePathId; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 51 | import org.onosproject.net.Port; |
| 52 | import org.onosproject.net.PortNumber; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 53 | import org.onosproject.net.device.DeviceService; |
| 54 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 55 | import org.onosproject.net.driver.DriverHandler; |
| 56 | import org.onosproject.net.driver.DriverService; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 57 | import org.onosproject.net.flow.criteria.Criterion; |
| 58 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 59 | import org.onosproject.net.flow.instructions.Instruction; |
| 60 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Yoonseon Han | feb95f1 | 2016-08-24 16:37:46 -0700 | [diff] [blame] | 61 | import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 62 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 63 | import org.onosproject.net.flowobjective.ForwardingObjective; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 64 | import org.onosproject.net.host.HostService; |
| 65 | import org.onosproject.net.host.HostServiceAdapter; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 66 | import org.onosproject.net.provider.ProviderId; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 67 | import org.onosproject.sfc.util.FlowClassifierAdapter; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 68 | import org.onosproject.sfc.util.MockDriverHandler; |
| 69 | import org.onosproject.sfc.util.PortPairAdapter; |
| 70 | import org.onosproject.sfc.util.PortPairGroupAdapter; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 71 | import org.onosproject.sfc.util.TenantNetworkAdapter; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 72 | import org.onosproject.sfc.util.VirtualPortAdapter; |
| 73 | import org.onosproject.sfc.util.VtnRscAdapter; |
| 74 | import org.onosproject.vtnrsc.AllowedAddressPair; |
| 75 | import org.onosproject.vtnrsc.BindingHostId; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 76 | import org.onosproject.vtnrsc.DefaultFiveTuple; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 77 | import org.onosproject.vtnrsc.DefaultFlowClassifier; |
| 78 | import org.onosproject.vtnrsc.DefaultPortChain; |
| 79 | import org.onosproject.vtnrsc.DefaultPortPair; |
| 80 | import org.onosproject.vtnrsc.DefaultPortPairGroup; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 81 | import org.onosproject.vtnrsc.DefaultTenantNetwork; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 82 | import org.onosproject.vtnrsc.DefaultVirtualPort; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 83 | import org.onosproject.vtnrsc.FiveTuple; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 84 | import org.onosproject.vtnrsc.FixedIp; |
| 85 | import org.onosproject.vtnrsc.FlowClassifier; |
| 86 | import org.onosproject.vtnrsc.FlowClassifierId; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 87 | import org.onosproject.vtnrsc.LoadBalanceId; |
| 88 | import org.onosproject.vtnrsc.PhysicalNetwork; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 89 | import org.onosproject.vtnrsc.PortChain; |
| 90 | import org.onosproject.vtnrsc.PortChainId; |
| 91 | import org.onosproject.vtnrsc.PortPair; |
| 92 | import org.onosproject.vtnrsc.PortPairGroup; |
| 93 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 94 | import org.onosproject.vtnrsc.PortPairId; |
| 95 | import org.onosproject.vtnrsc.SecurityGroup; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 96 | import org.onosproject.vtnrsc.SegmentationId; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 97 | import org.onosproject.vtnrsc.SubnetId; |
| 98 | import org.onosproject.vtnrsc.TenantId; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 99 | import org.onosproject.vtnrsc.TenantNetwork; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 100 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 101 | import org.onosproject.vtnrsc.VirtualPort; |
| 102 | import org.onosproject.vtnrsc.VirtualPortId; |
| 103 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
| 104 | import org.onosproject.vtnrsc.portpair.PortPairService; |
| 105 | import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; |
| 106 | import org.onosproject.vtnrsc.service.VtnRscService; |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 107 | import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 108 | import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
| 109 | |
| 110 | import com.google.common.collect.Lists; |
| 111 | import com.google.common.collect.Maps; |
| 112 | import com.google.common.collect.Sets; |
| 113 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 114 | public class SfcFlowRuleInstallerImplTest { |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 115 | |
Yoonseon Han | feb95f1 | 2016-08-24 16:37:46 -0700 | [diff] [blame] | 116 | FlowObjectiveService flowObjectiveService = new FlowObjectiveServiceAdapter(); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 117 | DeviceService deviceService = new DeviceServiceAdapter(createPortList()); |
| 118 | |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 119 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 125 | TenantNetworkService tenantNetworkService = new TenantNetworkAdapter(); |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 126 | |
| 127 | final DriverService driverService = createMock(DriverService.class); |
| 128 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 129 | private final String networkIdStr = "123"; |
| 130 | |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 131 | 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 Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 151 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 162 | 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 Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 177 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 242 | private VirtualPort createVirtualPort(VirtualPortId id) { |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 243 | 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 Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 250 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 256 | TenantNetworkId networkId = TenantNetworkId.networkId(networkIdStr); |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 257 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 270 | VirtualPort d1 = new DefaultVirtualPort(id, networkId, true, |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 271 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 284 | SfcFlowRuleInstallerImpl flowClassifierInstaller = new SfcFlowRuleInstallerImpl(); |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 285 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 309 | virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress))); |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 310 | 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 Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 319 | |
| 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 | |
Yoonseon Han | feb95f1 | 2016-08-24 16:37:46 -0700 | [diff] [blame] | 404 | ForwardingObjective forObj = ((FlowObjectiveServiceAdapter) flowObjectiveService).forwardingObjective(); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 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 | } |