Search in sources :

Example 1 with ASwitchFlow

use of org.openkilda.testing.service.lockkeeper.model.ASwitchFlow in project open-kilda by telstra.

the class IslUtils method replug.

/**
 * Simulates a physical ISL replug from one switch-port to another switch-port. Uses a-switch.
 *
 * @param srcIsl The initial ISL which is going to be replugged. Should go through a-switch
 * @param replugSource replug source or destination end of the ISL
 * @param dstIsl The destination 'isl'. Usually a free link, which is connected to a-switch at one end
 * @param plugIntoSource Whether to connect to src or dst end of the dstIsl. Usually src end for not-connected ISLs
 * @param portDown Whether to simulate a 'port down' event when unplugging
 * @return New ISL which is expected to be discovered after the replug
 */
public TopologyDefinition.Isl replug(TopologyDefinition.Isl srcIsl, boolean replugSource, TopologyDefinition.Isl dstIsl, boolean plugIntoSource, boolean portDown) {
    ASwitchFlow srcASwitch = srcIsl.getAswitch();
    ASwitchFlow dstASwitch = dstIsl.getAswitch();
    // unplug
    List<Integer> portsToUnplug = Collections.singletonList(replugSource ? srcASwitch.getInPort() : srcASwitch.getOutPort());
    if (portDown) {
        lockKeeper.portsDown(portsToUnplug);
    }
    // delete old flow
    if (srcASwitch.getInPort() != null && srcASwitch.getOutPort() != null) {
        lockKeeper.removeFlows(Arrays.asList(srcASwitch, srcASwitch.getReversed()));
    }
    // create new flow
    ASwitchFlow aswFlowForward = new ASwitchFlow(replugSource ? srcASwitch.getOutPort() : srcASwitch.getInPort(), plugIntoSource ? dstASwitch.getInPort() : dstASwitch.getOutPort());
    lockKeeper.addFlows(Arrays.asList(aswFlowForward, aswFlowForward.getReversed()));
    // plug back
    if (portDown) {
        lockKeeper.portsUp(portsToUnplug);
    }
    return TopologyDefinition.Isl.factory(replugSource ? (plugIntoSource ? dstIsl.getSrcSwitch() : dstIsl.getDstSwitch()) : srcIsl.getSrcSwitch(), replugSource ? (plugIntoSource ? dstIsl.getSrcPort() : dstIsl.getDstPort()) : srcIsl.getSrcPort(), replugSource ? srcIsl.getDstSwitch() : (plugIntoSource ? dstIsl.getSrcSwitch() : dstIsl.getDstSwitch()), replugSource ? srcIsl.getDstPort() : (plugIntoSource ? dstIsl.getSrcPort() : dstIsl.getDstPort()), 0, plugIntoSource ? aswFlowForward.getReversed() : aswFlowForward);
}
Also used : ASwitchFlow(org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)

Example 2 with ASwitchFlow

use of org.openkilda.testing.service.lockkeeper.model.ASwitchFlow in project open-kilda by telstra.

the class LockKeeperServiceImpl method getAllFlows.

@Override
public List<ASwitchFlow> getAllFlows() {
    RestTemplate restTemplate = lockKeepersByRegion.values().iterator().next();
    ASwitchFlow[] flows = restTemplate.exchange("/flows", HttpMethod.GET, new HttpEntity(buildJsonHeaders()), ASwitchFlow[].class).getBody();
    return Arrays.asList(flows);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate) ASwitchFlow(org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)

Example 3 with ASwitchFlow

use of org.openkilda.testing.service.lockkeeper.model.ASwitchFlow in project open-kilda by telstra.

the class StubServiceFactory method getLockKeeperStub.

/**
 * Get a stub for {@link LockKeeperService}. The instance is tied to the factory state.
 */
public LockKeeperService getLockKeeperStub() {
    LockKeeperService serviceMock = mock(LockKeeperService.class);
    List<ASwitchFlow> aswitchFlows = topologyDefinition.getIslsForActiveSwitches().stream().filter(isl -> isl.getAswitch() != null).map(isl -> {
        ASwitchFlow asw = isl.getAswitch();
        return Arrays.asList(new ASwitchFlow(asw.getInPort(), asw.getOutPort()), new ASwitchFlow(asw.getOutPort(), asw.getInPort()));
    }).flatMap(List::stream).collect(toList());
    when(serviceMock.getAllFlows()).thenReturn(aswitchFlows);
    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) LockKeeperService(org.openkilda.testing.service.lockkeeper.LockKeeperService) ASwitchFlow(org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)

Aggregations

ASwitchFlow (org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)3 LocalTime (java.time.LocalTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 SerializationUtils (org.apache.commons.lang3.SerializationUtils)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Answer (org.mockito.stubbing.Answer)1 IslChangeType (org.openkilda.messaging.info.event.IslChangeType)1 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 SwitchChangeType (org.openkilda.messaging.info.event.SwitchChangeType)1