Skip to content

Commit

Permalink
#4964: add information about LACP connection tests
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pkazlenka committed Feb 10, 2023
1 parent 4ac1932 commit ba9a2e8
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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<Integer>, 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)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.openkilda.functionaltests.helpers.model;

import org.openkilda.testing.model.topology.TopologyDefinition.Switch

class SwitchFilter {
static final Closure<List<Switch>> HAS_CONNECTED_TRAFFGENS = { Switch sw -> !sw.getTraffGens().empty}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -52,6 +59,10 @@ class LagPortSpec extends HealthCheckSpecification {
@Shared
Provider<TraffExamService> traffExamProvider

@Autowired
@Shared
LAGFactory lagFactory

@Shared
Integer lagOffset = 2000

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ba9a2e8

Please sign in to comment.