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);
}
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);
}
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;
}
Aggregations