Committed by
Gerrit Code Review
[ONOS-3834] Install load balanced forwarding rules
Change-Id: I681d0b047feb332543307eac1a54ed20114993ef
Showing
3 changed files
with
221 additions
and
9 deletions
| ... | @@ -15,37 +15,48 @@ | ... | @@ -15,37 +15,48 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.sfc.forwarder; | 16 | package org.onosproject.sfc.forwarder; |
| 17 | 17 | ||
| 18 | -import org.onosproject.net.flowobjective.Objective; | 18 | +import java.util.List; |
| 19 | + | ||
| 19 | import org.onosproject.net.NshServicePathId; | 20 | import org.onosproject.net.NshServicePathId; |
| 20 | import org.onosproject.vtnrsc.PortChain; | 21 | import org.onosproject.vtnrsc.PortChain; |
| 22 | +import org.onosproject.vtnrsc.PortPairId; | ||
| 21 | 23 | ||
| 22 | /** | 24 | /** |
| 23 | - * Abstraction of an entity which provides Service function forwarder. | 25 | + * Abstraction of an entity which provides service function forwarder. |
| 24 | */ | 26 | */ |
| 25 | public interface ServiceFunctionForwarderService { | 27 | public interface ServiceFunctionForwarderService { |
| 26 | 28 | ||
| 27 | /** | 29 | /** |
| 28 | - * Install Forwarding rule. | 30 | + * Install forwarding rule. |
| 29 | * | 31 | * |
| 30 | * @param portChain port-chain | 32 | * @param portChain port-chain |
| 31 | * @param nshSpi nsh spi | 33 | * @param nshSpi nsh spi |
| 32 | */ | 34 | */ |
| 35 | + @Deprecated | ||
| 33 | void installForwardingRule(PortChain portChain, NshServicePathId nshSpi); | 36 | void installForwardingRule(PortChain portChain, NshServicePathId nshSpi); |
| 34 | 37 | ||
| 35 | /** | 38 | /** |
| 36 | - * Uninstall Forwarding rule. | 39 | + * Uninstall forwarding rule. |
| 37 | * | 40 | * |
| 38 | * @param portChain port-chain | 41 | * @param portChain port-chain |
| 39 | * @param nshSpi nsh spi | 42 | * @param nshSpi nsh spi |
| 40 | */ | 43 | */ |
| 44 | + @Deprecated | ||
| 41 | void unInstallForwardingRule(PortChain portChain, NshServicePathId nshSpi); | 45 | void unInstallForwardingRule(PortChain portChain, NshServicePathId nshSpi); |
| 42 | 46 | ||
| 43 | /** | 47 | /** |
| 44 | - * Prepare forwarding object for Service Function. | 48 | + * Install load balanced forwarding rules. |
| 45 | * | 49 | * |
| 46 | - * @param portChain port-chain | 50 | + * @param path load balanced path of port pairs |
| 47 | - * @param nshSpi nsh spi | 51 | + * @param nshSpi nsh service path index |
| 48 | - * @param type forwarding objective operation type | 52 | + */ |
| 53 | + void installLoadBalancedForwardingRule(List<PortPairId> path, NshServicePathId nshSpi); | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * Uninstall load balanced forwarding rules. | ||
| 57 | + * | ||
| 58 | + * @param path load balanced path of port pairs | ||
| 59 | + * @param nshSpi nsh service path index | ||
| 49 | */ | 60 | */ |
| 50 | - void prepareServiceFunctionForwarder(PortChain portChain, NshServicePathId nshSpi, Objective.Operation type); | 61 | + void unInstallLoadBalancedForwardingRule(List<PortPairId> path, NshServicePathId nshSpi); |
| 51 | } | 62 | } | ... | ... |
This diff is collapsed. Click to expand it.
| 1 | +/* | ||
| 2 | + * Copyright 2016 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 | +package org.onosproject.sfc.forwarder.impl; | ||
| 17 | + | ||
| 18 | +import static org.easymock.EasyMock.createMock; | ||
| 19 | +import static org.easymock.EasyMock.expect; | ||
| 20 | +import static org.easymock.EasyMock.replay; | ||
| 21 | +import static org.hamcrest.Matchers.instanceOf; | ||
| 22 | +import static org.hamcrest.Matchers.is; | ||
| 23 | +import static org.junit.Assert.assertThat; | ||
| 24 | + | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.Map; | ||
| 27 | +import java.util.Set; | ||
| 28 | + | ||
| 29 | +import org.junit.Test; | ||
| 30 | +import org.onlab.packet.IpAddress; | ||
| 31 | +import org.onlab.packet.MacAddress; | ||
| 32 | +import org.onosproject.core.ApplicationId; | ||
| 33 | +import org.onosproject.core.DefaultApplicationId; | ||
| 34 | +import org.onosproject.net.DeviceId; | ||
| 35 | +import org.onosproject.net.NshServicePathId; | ||
| 36 | +import org.onosproject.net.PortNumber; | ||
| 37 | +import org.onosproject.net.device.DeviceService; | ||
| 38 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
| 39 | +import org.onosproject.net.driver.DriverHandler; | ||
| 40 | +import org.onosproject.net.driver.DriverService; | ||
| 41 | +import org.onosproject.net.flow.criteria.Criterion; | ||
| 42 | +import org.onosproject.net.flow.criteria.PortCriterion; | ||
| 43 | +import org.onosproject.net.flow.instructions.Instruction; | ||
| 44 | +import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | ||
| 45 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 46 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 47 | +import org.onosproject.net.host.HostService; | ||
| 48 | +import org.onosproject.net.host.HostServiceAdapter; | ||
| 49 | +import org.onosproject.sfc.util.FlowClassifierAdapter; | ||
| 50 | +import org.onosproject.sfc.util.FlowObjectiveAdapter; | ||
| 51 | +import org.onosproject.sfc.util.MockDriverHandler; | ||
| 52 | +import org.onosproject.sfc.util.PortPairAdapter; | ||
| 53 | +import org.onosproject.sfc.util.PortPairGroupAdapter; | ||
| 54 | +import org.onosproject.sfc.util.VirtualPortAdapter; | ||
| 55 | +import org.onosproject.sfc.util.VtnRscAdapter; | ||
| 56 | +import org.onosproject.vtnrsc.AllowedAddressPair; | ||
| 57 | +import org.onosproject.vtnrsc.BindingHostId; | ||
| 58 | +import org.onosproject.vtnrsc.DefaultPortPair; | ||
| 59 | +import org.onosproject.vtnrsc.DefaultVirtualPort; | ||
| 60 | +import org.onosproject.vtnrsc.FixedIp; | ||
| 61 | +import org.onosproject.vtnrsc.PortPair; | ||
| 62 | +import org.onosproject.vtnrsc.PortPairId; | ||
| 63 | +import org.onosproject.vtnrsc.SecurityGroup; | ||
| 64 | +import org.onosproject.vtnrsc.SubnetId; | ||
| 65 | +import org.onosproject.vtnrsc.TenantId; | ||
| 66 | +import org.onosproject.vtnrsc.TenantNetworkId; | ||
| 67 | +import org.onosproject.vtnrsc.VirtualPort; | ||
| 68 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 69 | +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; | ||
| 70 | +import org.onosproject.vtnrsc.portpair.PortPairService; | ||
| 71 | +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; | ||
| 72 | +import org.onosproject.vtnrsc.service.VtnRscService; | ||
| 73 | +import org.onosproject.vtnrsc.virtualport.VirtualPortService; | ||
| 74 | + | ||
| 75 | +import com.google.common.collect.Lists; | ||
| 76 | +import com.google.common.collect.Maps; | ||
| 77 | +import com.google.common.collect.Sets; | ||
| 78 | + | ||
| 79 | +public class ServiceFunctionForwarderImplTest { | ||
| 80 | + | ||
| 81 | + FlowObjectiveService flowObjectiveService = new FlowObjectiveAdapter(); | ||
| 82 | + DeviceService deviceService = new DeviceServiceAdapter(); | ||
| 83 | + HostService hostService = new HostServiceAdapter(); | ||
| 84 | + VirtualPortService virtualPortService = new VirtualPortAdapter(); | ||
| 85 | + VtnRscService vtnRscService = new VtnRscAdapter(); | ||
| 86 | + PortPairService portPairService = new PortPairAdapter(); | ||
| 87 | + PortPairGroupService portPairGroupService = new PortPairGroupAdapter(); | ||
| 88 | + FlowClassifierService flowClassifierService = new FlowClassifierAdapter(); | ||
| 89 | + | ||
| 90 | + final DriverService driverService = createMock(DriverService.class); | ||
| 91 | + | ||
| 92 | + DeviceId deviceId = DeviceId.deviceId("of:000000000000001"); | ||
| 93 | + final TenantId tenantId = TenantId.tenantId("1"); | ||
| 94 | + | ||
| 95 | + final DriverHandler driverHandler = new MockDriverHandler(); | ||
| 96 | + | ||
| 97 | + private VirtualPort createVirtualPort(VirtualPortId id) { | ||
| 98 | + Set<FixedIp> fixedIps; | ||
| 99 | + Map<String, String> propertyMap; | ||
| 100 | + Set<AllowedAddressPair> allowedAddressPairs; | ||
| 101 | + Set<SecurityGroup> securityGroups = Sets.newHashSet(); | ||
| 102 | + | ||
| 103 | + String macAddressStr = "fa:12:3e:56:ee:a2"; | ||
| 104 | + String ipAddress = "10.1.1.1"; | ||
| 105 | + String tenantNetworkId = "1234567"; | ||
| 106 | + String subnet = "1212"; | ||
| 107 | + String hostIdStr = "fa:e2:3e:56:ee:a2"; | ||
| 108 | + String deviceOwner = "james"; | ||
| 109 | + propertyMap = Maps.newHashMap(); | ||
| 110 | + propertyMap.putIfAbsent("deviceOwner", deviceOwner); | ||
| 111 | + | ||
| 112 | + TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId); | ||
| 113 | + MacAddress macAddress = MacAddress.valueOf(macAddressStr); | ||
| 114 | + BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr); | ||
| 115 | + FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet), | ||
| 116 | + IpAddress.valueOf(ipAddress)); | ||
| 117 | + fixedIps = Sets.newHashSet(); | ||
| 118 | + fixedIps.add(fixedIp); | ||
| 119 | + | ||
| 120 | + allowedAddressPairs = Sets.newHashSet(); | ||
| 121 | + AllowedAddressPair allowedAddressPair = AllowedAddressPair | ||
| 122 | + .allowedAddressPair(IpAddress.valueOf(ipAddress), | ||
| 123 | + MacAddress.valueOf(macAddressStr)); | ||
| 124 | + allowedAddressPairs.add(allowedAddressPair); | ||
| 125 | + | ||
| 126 | + VirtualPort d1 = new DefaultVirtualPort(id, networkId, true, | ||
| 127 | + propertyMap, | ||
| 128 | + VirtualPort.State.ACTIVE, | ||
| 129 | + macAddress, tenantId, deviceId, | ||
| 130 | + fixedIps, bindingHostId, | ||
| 131 | + allowedAddressPairs, | ||
| 132 | + securityGroups); | ||
| 133 | + return d1; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @Test | ||
| 137 | + public void testInstallFlowClassifier() { | ||
| 138 | + | ||
| 139 | + PortPairId portPairId1 = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 140 | + PortPairId portPairId2 = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); | ||
| 141 | + | ||
| 142 | + final String ppName1 = "PortPair1"; | ||
| 143 | + final String ppDescription1 = "PortPair1"; | ||
| 144 | + final String ingress1 = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; | ||
| 145 | + final String egress1 = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; | ||
| 146 | + DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); | ||
| 147 | + PortPair portPair1 = portPairBuilder.setId(portPairId1).setName(ppName1).setTenantId(tenantId) | ||
| 148 | + .setDescription(ppDescription1).setIngress(ingress1).setEgress(egress1).build(); | ||
| 149 | + | ||
| 150 | + final String ppName2 = "PortPair2"; | ||
| 151 | + final String ppDescription2 = "PortPair2"; | ||
| 152 | + final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1"; | ||
| 153 | + final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345"; | ||
| 154 | + PortPair portPair2 = portPairBuilder.setId(portPairId2).setName(ppName2).setTenantId(tenantId) | ||
| 155 | + .setDescription(ppDescription2).setIngress(ingress2).setEgress(egress2).build(); | ||
| 156 | + | ||
| 157 | + ApplicationId appId = new DefaultApplicationId(1, "test"); | ||
| 158 | + ServiceFunctionForwarderImpl serviceFunctionForwarder = new ServiceFunctionForwarderImpl(); | ||
| 159 | + serviceFunctionForwarder.virtualPortService = virtualPortService; | ||
| 160 | + serviceFunctionForwarder.vtnRscService = vtnRscService; | ||
| 161 | + serviceFunctionForwarder.portPairService = portPairService; | ||
| 162 | + serviceFunctionForwarder.portPairGroupService = portPairGroupService; | ||
| 163 | + serviceFunctionForwarder.flowClassifierService = flowClassifierService; | ||
| 164 | + serviceFunctionForwarder.driverService = driverService; | ||
| 165 | + serviceFunctionForwarder.hostService = hostService; | ||
| 166 | + serviceFunctionForwarder.flowObjectiveService = flowObjectiveService; | ||
| 167 | + serviceFunctionForwarder.appId = appId; | ||
| 168 | + | ||
| 169 | + NshServicePathId nshSpiId = NshServicePathId.of(10); | ||
| 170 | + | ||
| 171 | + portPairService.createPortPair(portPair1); | ||
| 172 | + portPairService.createPortPair(portPair2); | ||
| 173 | + | ||
| 174 | + List<PortPairId> path = Lists.newArrayList(); | ||
| 175 | + path.add(portPairId1); | ||
| 176 | + path.add(portPairId2); | ||
| 177 | + | ||
| 178 | + List<VirtualPort> virtualPortList = Lists.newArrayList(); | ||
| 179 | + virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress1))); | ||
| 180 | + virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress2))); | ||
| 181 | + virtualPortService.createPorts(virtualPortList); | ||
| 182 | + | ||
| 183 | + expect(driverService.createHandler(deviceId)).andReturn(driverHandler).anyTimes(); | ||
| 184 | + replay(driverService); | ||
| 185 | + | ||
| 186 | + serviceFunctionForwarder.installLoadBalancedForwardingRule(path, nshSpiId); | ||
| 187 | + | ||
| 188 | + ForwardingObjective forObj = ((FlowObjectiveAdapter) flowObjectiveService).forwardingObjective(); | ||
| 189 | + | ||
| 190 | + // Check for Selector | ||
| 191 | + assertThat(forObj.selector().getCriterion(Criterion.Type.IN_PORT), instanceOf(PortCriterion.class)); | ||
| 192 | + | ||
| 193 | + // Check for treatment | ||
| 194 | + List<Instruction> instructions = forObj.treatment().allInstructions(); | ||
| 195 | + for (Instruction instruction : instructions) { | ||
| 196 | + if (instruction.type() == Instruction.Type.OUTPUT) { | ||
| 197 | + assertThat(((OutputInstruction) instruction).port(), is(PortNumber.P0)); | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment