Search in sources :

Example 11 with Switch

use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.

the class FlowSteps method requestMeters.

@When("^request all switch meters for switch '(.*)' and alias results as '(.*)'$")
public void requestMeters(String switchAlias, String meterAlias) {
    Switch sw = topologyUnderTest.getAliasedObject(switchAlias);
    topologyUnderTest.addAlias(meterAlias, floodlightService.getMeters(sw.getDpId()));
}
Also used : Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) When(cucumber.api.java.en.When)

Example 12 with Switch

use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.

the class StubServiceFactory method getFloodlightStub.

/**
 * Get a stub for {@link FloodlightService}. The instance is tied to the factory state.
 */
public FloodlightService getFloodlightStub() {
    FloodlightService serviceMock = mock(FloodlightService.class);
    when(serviceMock.getFlows(any())).thenAnswer(invocation -> {
        SwitchId switchId = (SwitchId) invocation.getArguments()[0];
        String switchVersion = topologyDefinition.getActiveSwitches().stream().filter(sw -> sw.getDpId().equals(switchId)).map(Switch::getOfVersion).findAny().orElse("OF_13");
        return buildFlowEntries(switchId, switchVersion);
    });
    when(serviceMock.getMeters(any())).then((Answer<MetersEntriesMap>) invocation -> {
        SwitchId switchId = (SwitchId) invocation.getArguments()[0];
        MetersEntriesMap result = new MetersEntriesMap();
        flows.values().forEach(flowPair -> {
            if (flowPair.getLeft().getSourceSwitch().equals(switchId) || flowPair.getRight().getSourceSwitch().equals(switchId)) {
                MeterEntry entry = new MeterEntry(emptyList(), flowPair.getLeft().getMeterId(), singletonList(new MeterBand(flowPair.getLeft().getBandwidth(), 0, "", 1)), "");
                result.put(entry.getMeterId(), entry);
            }
        });
        return result;
    });
    when(serviceMock.getSwitches()).then((Answer<List<SwitchEntry>>) invocation -> topologyDefinition.getActiveSwitches().stream().map(sw -> SwitchEntry.builder().switchId(sw.getDpId()).ofVersion(sw.getOfVersion()).build()).collect(toList()));
    return serviceMock;
}
Also used : Arrays(java.util.Arrays) SwitchChangeType(org.openkilda.messaging.info.event.SwitchChangeType) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Collections.singletonList(java.util.Collections.singletonList) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) FlowApplyActions(org.openkilda.testing.service.floodlight.model.FlowApplyActions) NorthboundService(org.openkilda.testing.service.northbound.NorthboundService) Map(java.util.Map) LocalTime(java.time.LocalTime) Exam(org.openkilda.testing.service.traffexam.model.Exam) SwitchLocationDto(org.openkilda.northbound.dto.v1.switches.SwitchLocationDto) FlowEntry(org.openkilda.testing.service.floodlight.model.FlowEntry) RulesValidationResult(org.openkilda.northbound.dto.v1.switches.RulesValidationResult) Collections.emptyList(java.util.Collections.emptyList) FlowDto(org.openkilda.messaging.model.FlowDto) FlowMatchField(org.openkilda.testing.service.floodlight.model.FlowMatchField) ASwitchFlow(org.openkilda.testing.service.lockkeeper.model.ASwitchFlow) Host(org.openkilda.testing.service.traffexam.model.Host) List(java.util.List) Stream(java.util.stream.Stream) FlowPairDto(org.openkilda.messaging.model.FlowPairDto) RulesSyncResult(org.openkilda.northbound.dto.v1.switches.RulesSyncResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) ExamReport(org.openkilda.testing.service.traffexam.model.ExamReport) MeterBand(org.openkilda.testing.service.floodlight.model.MeterBand) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HashMap(java.util.HashMap) IslChangeType(org.openkilda.messaging.info.event.IslChangeType) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) FlowEntriesMap(org.openkilda.testing.service.floodlight.model.FlowEntriesMap) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) MetersEntriesMap(org.openkilda.testing.service.floodlight.model.MetersEntriesMap) TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) FloodlightService(org.openkilda.testing.service.floodlight.FloodlightService) Mockito.when(org.mockito.Mockito.when) PathNode(org.openkilda.messaging.info.event.PathNode) MeterEntry(org.openkilda.testing.service.floodlight.model.MeterEntry) TraffExamService(org.openkilda.testing.service.traffexam.TraffExamService) Collectors.toList(java.util.stream.Collectors.toList) SwitchId(org.openkilda.model.SwitchId) LockKeeperService(org.openkilda.testing.service.lockkeeper.LockKeeperService) SwitchEntry(org.openkilda.testing.service.floodlight.model.SwitchEntry) FlowState(org.openkilda.messaging.payload.flow.FlowState) SwitchDto(org.openkilda.northbound.dto.v1.switches.SwitchDto) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) FlowInstructions(org.openkilda.testing.service.floodlight.model.FlowInstructions) MeterBand(org.openkilda.testing.service.floodlight.model.MeterBand) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) MeterEntry(org.openkilda.testing.service.floodlight.model.MeterEntry) FloodlightService(org.openkilda.testing.service.floodlight.FloodlightService) SwitchId(org.openkilda.model.SwitchId) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) MetersEntriesMap(org.openkilda.testing.service.floodlight.model.MetersEntriesMap)

Aggregations

Switch (org.openkilda.testing.model.topology.TopologyDefinition.Switch)12 TopologyDefinition (org.openkilda.testing.model.topology.TopologyDefinition)6 List (java.util.List)5 FlowSet (org.openkilda.atdd.staging.helpers.FlowSet)5 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 String.format (java.lang.String.format)3 Date (java.util.Date)3 Map (java.util.Map)3 Arrays (java.util.Arrays)2 Random (java.util.Random)2 Collectors.toList (java.util.stream.Collectors.toList)2 FlowBuilder (org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder)2 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)2 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)2 ASwitchFlow (org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)2 FloodlightResourceAddress (org.openkilda.testing.service.lockkeeper.model.FloodlightResourceAddress)2 TrafficControlRequest (org.openkilda.testing.service.lockkeeper.model.TrafficControlRequest)2 HttpEntity (org.springframework.http.HttpEntity)2