From ba9a2e85c8fcb5ff4e77060be9cc2f44feb9e81d Mon Sep 17 00:00:00 2001 From: pkazlenka Date: Fri, 10 Feb 2023 13:17:15 +0100 Subject: [PATCH] #4964: add information about LACP connection tests * Added new test for LACP connection * New class LAG representing LAG business entity * New experimental approach to switches picking * Implemented new methods for new traffgen feature --- .../functionaltests/helpers/model/LAG.groovy | 85 +++++++++++++++++++ .../helpers/model/SwitchFilter.groovy | 7 ++ .../spec/switches/LagPortSpec.groovy | 45 +++++++++- .../northbound/NorthboundServiceV2.java | 3 + .../northbound/NorthboundServiceV2Impl.java | 17 +++- .../service/traffexam/TraffExamService.java | 13 +-- .../traffexam/TraffExamServiceImpl.java | 27 ++---- .../service/traffexam/model/LacpData.java | 46 ++++++++++ .../testing/tools/ConnectedDevice.java | 9 +- 9 files changed, 216 insertions(+), 36 deletions(-) create mode 100644 src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/LAG.groovy create mode 100644 src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchFilter.groovy create mode 100644 src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/model/LacpData.java diff --git a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/LAG.groovy b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/LAG.groovy new file mode 100644 index 00000000000..c65c18958da --- /dev/null +++ b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/LAG.groovy @@ -0,0 +1,85 @@ +package org.openkilda.functionaltests.helpers.model + +import org.openkilda.northbound.dto.v2.switches.LagPortRequest +import org.openkilda.testing.model.topology.TopologyDefinition +import org.openkilda.testing.service.northbound.NorthboundServiceV2 +import org.openkilda.testing.service.traffexam.model.LacpData +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.stereotype.Component + +/* This class represents Link Aggregation Group */ +class LAG { + NorthboundServiceV2 northboundServiceV2 + TopologyDefinition.Switch aSwitch + Integer physicalPort1 + Integer physicalPort2 + Integer logicalPort = null + Boolean lacpReply + + LAG(NorthboundServiceV2 northboundServiceV2, + TopologyDefinition.Switch aSwitch, + Integer physicalPort1, + Integer physicalPort2, + Boolean lacpReply) { + this.northboundServiceV2 = northboundServiceV2 + this.aSwitch = aSwitch + this.physicalPort1 = physicalPort1 + this.physicalPort2 = physicalPort2 + this.lacpReply = lacpReply + } + + void create() { + def payload = new LagPortRequest([physicalPort1, physicalPort2] as Set, lacpReply) + def response = northboundServiceV2.createLagLogicalPort(aSwitch.getDpId(), payload) + logicalPort = response.getLogicalPortNumber() + } + + void delete() { + northboundServiceV2.deleteLagLogicalPort(aSwitch.getDpId(), logicalPort) + } + + LacpData getLacpData() { + def data = northboundServiceV2.getLacpPortStatus(aSwitch.getDpId(), logicalPort).getData() + + return LacpData.builder() + .expired(data.stateExpired) + .defaulted(data.stateDefaulted) + .distributing(data.stateDistributing) + .collecting(data.stateCollecting) + .synchronization(data.stateSynchronised) + .aggregation(data.stateAggregatable) + .lacpTimeout(data.stateShortTimeout) + .lacpActivity(data.stateActive) + .build() + } +} + + +@Component +class LAGFactory { + @Autowired @Qualifier("islandNbV2") + NorthboundServiceV2 northboundServiceV2 + @Autowired + TopologyDefinition toplogy + + LAG get(TopologyDefinition.Switch aSwitch, + Integer physicalPort1, + Integer physicalPort2, + Boolean lacpReply=false) { + return new LAG(northboundServiceV2, aSwitch, physicalPort1, physicalPort2, lacpReply) + } + + LAG get(TopologyDefinition.Switch aSwitch) { + def ports = this.toplogy.getAllowedPortsForSwitch(aSwitch).shuffled()[0, 1] + return this.get(aSwitch, ports[0], ports[1]) + } + + LAG get(TopologyDefinition.Switch aSwitch, Integer mandatoryPhysicalPort, Boolean lacpReply) { + def freePorts = toplogy.getAllowedPortsForSwitch(aSwitch) + freePorts.removeAll([mandatoryPhysicalPort]) + def additionalPort = freePorts.shuffled().first() + return this.get(aSwitch, mandatoryPhysicalPort, additionalPort, lacpReply) + } +} + diff --git a/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchFilter.groovy b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchFilter.groovy new file mode 100644 index 00000000000..462b3b240d2 --- /dev/null +++ b/src-java/testing/functional-tests/src/main/groovy/org/openkilda/functionaltests/helpers/model/SwitchFilter.groovy @@ -0,0 +1,7 @@ +package org.openkilda.functionaltests.helpers.model; + +import org.openkilda.testing.model.topology.TopologyDefinition.Switch + +class SwitchFilter { + static final Closure> HAS_CONNECTED_TRAFFGENS = { Switch sw -> !sw.getTraffGens().empty} +} diff --git a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/LagPortSpec.groovy b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/LagPortSpec.groovy index 1b17e9a1bbf..ce7cec7027c 100644 --- a/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/LagPortSpec.groovy +++ b/src-java/testing/functional-tests/src/test/groovy/org/openkilda/functionaltests/spec/switches/LagPortSpec.groovy @@ -1,5 +1,12 @@ package org.openkilda.functionaltests.spec.switches +import org.openkilda.functionaltests.helpers.Wrappers +import org.openkilda.functionaltests.helpers.model.LAGFactory +import org.openkilda.testing.service.traffexam.model.LacpData +import org.openkilda.testing.tools.ConnectedDevice + +import static org.openkilda.functionaltests.helpers.model.SwitchFilter.HAS_CONNECTED_TRAFFGENS + import static groovyx.gpars.GParsPool.withPool import static org.junit.jupiter.api.Assumptions.assumeTrue import static org.openkilda.functionaltests.extension.tags.Tag.HARDWARE @@ -52,6 +59,10 @@ class LagPortSpec extends HealthCheckSpecification { @Shared Provider traffExamProvider + @Autowired + @Shared + LAGFactory lagFactory + @Shared Integer lagOffset = 2000 @@ -101,7 +112,7 @@ class LagPortSpec extends HealthCheckSpecification { def payloadUpdate = new LagPortRequest(portNumbers: portsArrayUpdate) def updateResponse = northboundV2.updateLagLogicalPort(sw.dpId, lagPort, payloadUpdate) - then: "Response reports successful updation of the LAG port" + then: "Response reports successful update of the LAG port" with(updateResponse) { logicalPortNumber == lagPort portNumbers.sort() == portsArrayUpdate.sort() @@ -1039,6 +1050,38 @@ class LagPortSpec extends HealthCheckSpecification { } } + @Tidy + def "Able to retrieve actual LACP connection status on LAG port"() { + given: "A switch with a connected traffgen" + def sw = topology.getActiveSwitches().findAll(HAS_CONNECTED_TRAFFGENS).shuffled().first() + def traffGen = sw.getTraffGens().first() + + and: "LAG port on a traffgen port" + def lag = lagFactory.get(sw, traffGen.getSwitchPort(), true) + lag.create() + + and: "LACP data example" + def lacpData = LacpData.builder() + .expired(true) + .defaulted(false) + .distributing(true) + .collecting(false) + .synchronization(true) + .aggregation(false) + .lacpTimeout(true) + .lacpActivity(false) + .build() + + when: "Send LACP dataunit to switch LAG port" + new ConnectedDevice(traffExamProvider.get(), traffGen, [100]).sendLacp(lacpData) + + then: "Information from LACP dataunit is available LACP status response" + lacpData == lag.getLacpData() + + cleanup: + Wrappers.silent(lag.delete()) + } + def getLagCookie(portNumber) { new PortColourCookie(CookieType.LACP_REPLY_INPUT, portNumber).toString() } diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2.java index d3f70591120..172d53ecf39 100644 --- a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2.java +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2.java @@ -15,6 +15,7 @@ package org.openkilda.testing.service.northbound; +import org.openkilda.messaging.nbtopology.response.SwitchLacpStatusResponse; import org.openkilda.messaging.payload.flow.FlowIdStatusPayload; import org.openkilda.model.SwitchId; import org.openkilda.northbound.dto.v2.flows.FlowHistoryStatusesResponse; @@ -171,4 +172,6 @@ BfdPropertiesPayload setLinkBfd(SwitchId srcSwId, Integer srcPort, SwitchId dstS SwitchValidationV2ExtendedResult validateSwitch(SwitchId switchId); SwitchValidationV2ExtendedResult validateSwitch(SwitchId switchId, String include, String exclude); + + SwitchLacpStatusResponse getLacpPortStatus(SwitchId switchId, int logicalPort); } diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2Impl.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2Impl.java index a04c8102935..0f8a6ff37f0 100644 --- a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2Impl.java +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/northbound/NorthboundServiceV2Impl.java @@ -16,6 +16,7 @@ package org.openkilda.testing.service.northbound; import org.openkilda.messaging.Utils; +import org.openkilda.messaging.nbtopology.response.SwitchLacpStatusResponse; import org.openkilda.messaging.payload.flow.FlowIdStatusPayload; import org.openkilda.model.SwitchId; import org.openkilda.northbound.dto.v2.flows.FlowHistoryStatusesResponse; @@ -144,7 +145,7 @@ public FlowRerouteResponseV2 rerouteFlow(String flowId) { @Override public FlowResponseV2 partialUpdate(String flowId, FlowPatchV2 patch) { return restTemplate.exchange("/api/v2/flows/{flow_id}", HttpMethod.PATCH, - new HttpEntity<>(patch, buildHeadersWithCorrelationId()), FlowResponseV2.class, flowId) + new HttpEntity<>(patch, buildHeadersWithCorrelationId()), FlowResponseV2.class, flowId) .getBody(); } @@ -296,7 +297,7 @@ public PortPropertiesResponse updatePortProperties(SwitchId switchId, Integer po @Override public SwitchDtoV2 partialSwitchUpdate(SwitchId switchId, SwitchPatchDto dto) { return restTemplate.exchange("/api/v2/switches/{switchId}", HttpMethod.PATCH, - new HttpEntity<>(dto, buildHeadersWithCorrelationId()), SwitchDtoV2.class, switchId) + new HttpEntity<>(dto, buildHeadersWithCorrelationId()), SwitchDtoV2.class, switchId) .getBody(); } @@ -511,4 +512,16 @@ public SwitchValidationV2ExtendedResult validateSwitch(SwitchId switchId, String new HttpEntity(buildHeadersWithCorrelationId()), SwitchValidationResultV2.class, switchId).getBody()); return new SwitchValidationV2ExtendedResult(switchId, result); } + + @Override + public SwitchLacpStatusResponse getLacpPortStatus(SwitchId switchId, int logicalPort) { + return restTemplate.exchange("/api/v2/switches/{switch_id}/lacp/{logical_port_number}", + HttpMethod.GET, + new HttpEntity(buildHeadersWithCorrelationId()), + SwitchLacpStatusResponse.class, + switchId, + logicalPort) + .getBody(); + } + } diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamService.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamService.java index c95c5883356..d774f5fc347 100644 --- a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamService.java +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamService.java @@ -15,16 +15,7 @@ package org.openkilda.testing.service.traffexam; -import org.openkilda.testing.service.traffexam.model.Address; -import org.openkilda.testing.service.traffexam.model.AddressStats; -import org.openkilda.testing.service.traffexam.model.ArpData; -import org.openkilda.testing.service.traffexam.model.Exam; -import org.openkilda.testing.service.traffexam.model.ExamReport; -import org.openkilda.testing.service.traffexam.model.ExamResources; -import org.openkilda.testing.service.traffexam.model.Host; -import org.openkilda.testing.service.traffexam.model.LldpData; -import org.openkilda.testing.service.traffexam.model.UdpData; -import org.openkilda.testing.service.traffexam.model.Vlan; +import org.openkilda.testing.service.traffexam.model.*; import org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException; import java.util.List; @@ -56,6 +47,8 @@ ExamResources startExam(Exam exam) void sendLldp(Address address, LldpData lldpData); + void sendLacp(Address address, LacpData lacpData); + void sendArp(Address address, ArpData arpData); void sendUdp(Address address, UdpData udpData); diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamServiceImpl.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamServiceImpl.java index 7449088c9fa..fafeada17a9 100644 --- a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamServiceImpl.java +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/TraffExamServiceImpl.java @@ -18,25 +18,7 @@ import org.openkilda.testing.model.topology.TopologyDefinition; import org.openkilda.testing.model.topology.TopologyDefinition.TraffGen; import org.openkilda.testing.model.topology.TopologyDefinition.TraffGenConfig; -import org.openkilda.testing.service.traffexam.model.Address; -import org.openkilda.testing.service.traffexam.model.AddressResponse; -import org.openkilda.testing.service.traffexam.model.AddressStats; -import org.openkilda.testing.service.traffexam.model.ArpData; -import org.openkilda.testing.service.traffexam.model.ConsumerEndpoint; -import org.openkilda.testing.service.traffexam.model.Endpoint; -import org.openkilda.testing.service.traffexam.model.EndpointAddress; -import org.openkilda.testing.service.traffexam.model.EndpointReport; -import org.openkilda.testing.service.traffexam.model.EndpointResponse; -import org.openkilda.testing.service.traffexam.model.Exam; -import org.openkilda.testing.service.traffexam.model.ExamReport; -import org.openkilda.testing.service.traffexam.model.ExamResources; -import org.openkilda.testing.service.traffexam.model.Host; -import org.openkilda.testing.service.traffexam.model.HostResource; -import org.openkilda.testing.service.traffexam.model.LldpData; -import org.openkilda.testing.service.traffexam.model.ProducerEndpoint; -import org.openkilda.testing.service.traffexam.model.ReportResponse; -import org.openkilda.testing.service.traffexam.model.UdpData; -import org.openkilda.testing.service.traffexam.model.Vlan; +import org.openkilda.testing.service.traffexam.model.*; import org.openkilda.testing.service.traffexam.networkpool.Inet4Network; import org.openkilda.testing.service.traffexam.networkpool.Inet4NetworkPool; import org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException; @@ -381,6 +363,13 @@ public void sendLldp(Address address, LldpData lldpData) { lldpData); } + @Override + public void sendLacp(Address address, LacpData lacpData) { + restTemplate.put( + makeHostUri(address.getHost()).path("address/").path(address.getId().toString()).path("/lacp").build(), + lacpData); + } + @Override public void sendArp(Address address, ArpData arpData) { restTemplate.put( diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/model/LacpData.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/model/LacpData.java new file mode 100644 index 00000000000..a25f31b1e06 --- /dev/null +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/service/traffexam/model/LacpData.java @@ -0,0 +1,46 @@ +/* Copyright 2019 Telstra Open Source + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openkilda.testing.service.traffexam.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +@Data +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonNaming(SnakeCaseStrategy.class) +public class LacpData { + @NonNull + Boolean expired; + @NonNull + Boolean defaulted; + @NonNull + Boolean distributing; + @NonNull + Boolean collecting; + @NonNull + Boolean synchronization; + @NonNull + Boolean aggregation; + @NonNull + Boolean lacpTimeout; + @NonNull + Boolean lacpActivity; +} diff --git a/src-java/testing/test-library/src/main/java/org/openkilda/testing/tools/ConnectedDevice.java b/src-java/testing/test-library/src/main/java/org/openkilda/testing/tools/ConnectedDevice.java index e92963a39cf..246287af5cf 100644 --- a/src-java/testing/test-library/src/main/java/org/openkilda/testing/tools/ConnectedDevice.java +++ b/src-java/testing/test-library/src/main/java/org/openkilda/testing/tools/ConnectedDevice.java @@ -18,10 +18,7 @@ import org.openkilda.testing.model.topology.TopologyDefinition.TraffGen; import org.openkilda.testing.service.traffexam.OperationalException; import org.openkilda.testing.service.traffexam.TraffExamService; -import org.openkilda.testing.service.traffexam.model.Address; -import org.openkilda.testing.service.traffexam.model.ArpData; -import org.openkilda.testing.service.traffexam.model.LldpData; -import org.openkilda.testing.service.traffexam.model.Vlan; +import org.openkilda.testing.service.traffexam.model.*; import org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException; import java.util.ArrayList; @@ -51,6 +48,10 @@ public void sendArp(ArpData data) { examService.sendArp(address, data); } + public void sendLacp(LacpData data) { + examService.sendLacp(address, data); + } + @Override public void close() { examService.releaseAddress(address);