@Test public void testInstallLoadBalancedFlowRules() { ApplicationId appId = new DefaultApplicationId(1, "test"); SfcFlowRuleInstallerImpl flowRuleInstaller = new SfcFlowRuleInstallerImpl(); flowRuleInstaller.virtualPortService = virtualPortService; flowRuleInstaller.vtnRscService = vtnRscService; flowRuleInstaller.portPairService = portPairService; flowRuleInstaller.portPairGroupService = portPairGroupService; flowRuleInstaller.flowClassifierService = flowClassifierService; flowRuleInstaller.driverService = driverService; flowRuleInstaller.deviceService = deviceService; flowRuleInstaller.hostService = hostService; flowRuleInstaller.flowObjectiveService = flowObjectiveService; flowRuleInstaller.tenantNetworkService = tenantNetworkService; flowRuleInstaller.appId = appId; final PortChain portChain = createPortChain(); final String ppName1 = "PortPair1"; final String ppDescription1 = "PortPair1"; final String ingress1 = "d3333333-24fc-4fae-af4b-321c5e2eb3d1"; final String egress1 = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345"; DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder(); PortPair portPair1 = portPairBuilder.setId(portPairId1).setName(ppName1).setTenantId(tenantId) .setDescription(ppDescription1).setIngress(ingress1).setEgress(egress1).build(); final String ppName2 = "PortPair2"; final String ppDescription2 = "PortPair2"; final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1"; final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345"; PortPair portPair2 = portPairBuilder.setId(portPairId2).setName(ppName2).setTenantId(tenantId) .setDescription(ppDescription2).setIngress(ingress2).setEgress(egress2).build(); portPairService.createPortPair(portPair1); portPairService.createPortPair(portPair2); FlowClassifier fc1 = createFlowClassifier(flowClassifierId1); FlowClassifier fc2 = createFlowClassifier(flowClassifierId2); flowClassifierService.createFlowClassifier(fc1); flowClassifierService.createFlowClassifier(fc2); NshServicePathId nshSpiId = NshServicePathId.of(10); FiveTuple fiveTuple = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("3.3.3.3")) .setIpDst(IpAddress.valueOf("4.4.4.4")) .setPortSrc(PortNumber.portNumber(1500)) .setPortDst(PortNumber.portNumber(2000)) .setProtocol(IPv4.PROTOCOL_UDP) .setTenantId(TenantId.tenantId("bbb")) .build(); LoadBalanceId id = LoadBalanceId.of((byte) 1); List<PortPairId> path = Lists.newArrayList(); path.add(portPairId1); path.add(portPairId2); List<VirtualPort> virtualPortList = Lists.newArrayList(); virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress1))); virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress1))); virtualPortList.add(createVirtualPort(VirtualPortId.portId(ingress2))); virtualPortList.add(createVirtualPort(VirtualPortId.portId(egress2))); virtualPortService.createPorts(virtualPortList); portChain.addLoadBalancePath(fiveTuple, id, path); String physicalNetworkStr = "1234"; String segmentationIdStr = "1"; SegmentationId segmentationID = SegmentationId .segmentationId(segmentationIdStr); TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr); PhysicalNetwork physicalNetwork = PhysicalNetwork .physicalNetwork(physicalNetworkStr); TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false, TenantNetwork.State.ACTIVE, false, tenantId, false, TenantNetwork.Type.LOCAL, physicalNetwork, segmentationID); tenantNetworkService.createNetworks(Collections.singletonList(p1)); expect(driverService.createHandler(deviceId)).andReturn(driverHandler).anyTimes(); replay(driverService); flowRuleInstaller.installLoadBalancedFlowRules(portChain, fiveTuple, nshSpiId); ForwardingObjective forObj = ((FlowObjectiveAdapter) flowObjectiveService).forwardingObjective(); assertThat(forObj.selector().getCriterion(Criterion.Type.IN_PORT), instanceOf(PortCriterion.class)); List<Instruction> instructions = forObj.treatment().allInstructions(); for (Instruction instruction : instructions) { if (instruction.type() == Instruction.Type.OUTPUT) { assertThat(((OutputInstruction) instruction).port(), is(PortNumber.P0)); } } }
@Override public ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId) { checkNotNull(portChain, PORT_CHAIN_NOT_NULL); return installSfcFlowRules(portChain, fiveTuple, nshSpiId, Objective.Operation.ADD); }
SfcFlowRuleInstallerImpl implements SfcFlowRuleInstallerService { @Override public ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId) { checkNotNull(portChain, PORT_CHAIN_NOT_NULL); return installSfcFlowRules(portChain, fiveTuple, nshSpiId, Objective.Operation.ADD); } }
SfcFlowRuleInstallerImpl implements SfcFlowRuleInstallerService { @Override public ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId) { checkNotNull(portChain, PORT_CHAIN_NOT_NULL); return installSfcFlowRules(portChain, fiveTuple, nshSpiId, Objective.Operation.ADD); } SfcFlowRuleInstallerImpl();  SfcFlowRuleInstallerImpl(ApplicationId appId); }
SfcFlowRuleInstallerImpl implements SfcFlowRuleInstallerService { @Override public ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId) { checkNotNull(portChain, PORT_CHAIN_NOT_NULL); return installSfcFlowRules(portChain, fiveTuple, nshSpiId, Objective.Operation.ADD); } SfcFlowRuleInstallerImpl();  SfcFlowRuleInstallerImpl(ApplicationId appId); @Override ConnectPoint installFlowClassifier(PortChain portChain, NshServicePathId nshSpiId); @Override ConnectPoint unInstallFlowClassifier(PortChain portChain, NshServicePathId nshSpiId); @Override ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); @Override ConnectPoint unInstallLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); @Override ConnectPoint unInstallLoadBalancedClassifierRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); ConnectPoint installSfcFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId,
            Objective.Operation type); void installSfcTunnelReceiveRule(DeviceId deviceId, NshServicePathId nshSpiId, Objective.Operation type); void installSfcTunnelSendRule(DeviceId deviceId, NshServicePathId nshSpiId, Objective.Operation type); void installSfcEndRule(PortPair portPair, NshServicePathId nshSpiId, Objective.Operation type); void installSfcForwardRule(PortPair portPair, PortPair nextPortPair, NshServicePathId nshSpiId,
            Objective.Operation type); void installSfcEncapOutputRule(PortPair portPair, NshServicePathId nshSpiId, Objective.Operation type); ConnectPoint installSfcClassifierRules(PortChain portChain, PortPair portPair, NshServicePathId nshSpiId,
            FiveTuple fiveTuple, Objective.Operation type); TrafficSelector.Builder packClassifierSelector(FlowClassifier flowClassifier, FiveTuple fiveTuple); TrafficTreatment.Builder packClassifierTreatment(DeviceId deviceId, VirtualPort virtualPort,
            PortNumber port, NshServicePathId nshSpi, FlowClassifier flowClassifier); DeviceId getControllerId(Device device, Iterable<Device> devices); String getControllerIpOfSwitch(Device device); void sendSfcRule(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, DeviceId deviceId,
            Objective.Operation type, int priority); }
SfcFlowRuleInstallerImpl implements SfcFlowRuleInstallerService { @Override public ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId) { checkNotNull(portChain, PORT_CHAIN_NOT_NULL); return installSfcFlowRules(portChain, fiveTuple, nshSpiId, Objective.Operation.ADD); } SfcFlowRuleInstallerImpl();  SfcFlowRuleInstallerImpl(ApplicationId appId); @Override ConnectPoint installFlowClassifier(PortChain portChain, NshServicePathId nshSpiId); @Override ConnectPoint unInstallFlowClassifier(PortChain portChain, NshServicePathId nshSpiId); @Override ConnectPoint installLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); @Override ConnectPoint unInstallLoadBalancedFlowRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); @Override ConnectPoint unInstallLoadBalancedClassifierRules(PortChain portChain, FiveTuple fiveTuple,
            NshServicePathId nshSpiId); ConnectPoint installSfcFlowRules(PortChain portChain, FiveTuple fiveTuple, NshServicePathId nshSpiId,
            Objective.Operation type); void installSfcTunnelReceiveRule(DeviceId deviceId, NshServicePathId nshSpiId, Objective.Operation type); void installSfcTunnelSendRule(DeviceId deviceId, NshServicePathId nshSpiId, Objective.Operation type); void installSfcEndRule(PortPair portPair, NshServicePathId nshSpiId, Objective.Operation type); void installSfcForwardRule(PortPair portPair, PortPair nextPortPair, NshServicePathId nshSpiId,
            Objective.Operation type); void installSfcEncapOutputRule(PortPair portPair, NshServicePathId nshSpiId, Objective.Operation type); ConnectPoint installSfcClassifierRules(PortChain portChain, PortPair portPair, NshServicePathId nshSpiId,
            FiveTuple fiveTuple, Objective.Operation type); TrafficSelector.Builder packClassifierSelector(FlowClassifier flowClassifier, FiveTuple fiveTuple); TrafficTreatment.Builder packClassifierTreatment(DeviceId deviceId, VirtualPort virtualPort,
            PortNumber port, NshServicePathId nshSpi, FlowClassifier flowClassifier); DeviceId getControllerId(Device device, Iterable<Device> devices); String getControllerIpOfSwitch(Device device); void sendSfcRule(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, DeviceId deviceId,
            Objective.Operation type, int priority);  }