use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowCrudSteps method eachFlowCanBeReadFromNorthbound.
@And("^each flow can be read from Northbound$")
public void eachFlowCanBeReadFromNorthbound() {
for (FlowPayload flow : flows) {
FlowPayload result = northboundService.getFlow(flow.getId());
assertNotNull(result);
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowCrudSteps method buildFlow.
private FlowPayload buildFlow(String flowId, Switch srcSwitch, Switch destSwitch) {
// Take the switch vlan ranges as the base
RangeSet<Integer> srcRangeSet = TreeRangeSet.create();
srcSwitch.getOutPorts().forEach(port -> srcRangeSet.addAll(port.getVlanRange()));
RangeSet<Integer> destRangeSet = TreeRangeSet.create();
destSwitch.getOutPorts().forEach(port -> destRangeSet.addAll(port.getVlanRange()));
// Exclude already allocated vlans
srcRangeSet.removeAll(allocatedVlans);
destRangeSet.removeAll(allocatedVlans);
if (srcRangeSet.isEmpty() || destRangeSet.isEmpty()) {
LOGGER.warn("Unable to define a flow between {} and {} as no vlan available.", srcSwitch, destSwitch);
return null;
}
// Calculate intersection of the ranges
RangeSet<Integer> interRangeSet = TreeRangeSet.create(srcRangeSet);
interRangeSet.removeAll(destRangeSet.complement());
// Same vlan for source and destination
final Optional<Integer> sameVlan = interRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
int srcVlan;
int destVlan;
if (sameVlan.isPresent()) {
srcVlan = sameVlan.get();
destVlan = sameVlan.get();
} else {
// Cross vlan flow
Optional<Integer> srcVlanOpt = srcRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
if (!srcVlanOpt.isPresent()) {
LOGGER.warn("Unable to allocate a vlan for the switch {}.", srcSwitch);
return null;
}
srcVlan = srcVlanOpt.get();
Optional<Integer> destVlanOpt = destRangeSet.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst();
if (!destVlanOpt.isPresent()) {
LOGGER.warn("Unable to allocate a vlan for the switch {}.", destSwitch);
return null;
}
destVlan = destVlanOpt.get();
}
boolean sameSwitchFlow = srcSwitch.getDpId().equals(destSwitch.getDpId());
Optional<OutPort> srcPort = srcSwitch.getOutPorts().stream().filter(p -> p.getVlanRange().contains(srcVlan)).findFirst();
int srcPortId = srcPort.orElseThrow(() -> new IllegalStateException("Unable to allocate a port in found vlan.")).getPort();
Optional<OutPort> destPort = destSwitch.getOutPorts().stream().filter(p -> p.getVlanRange().contains(destVlan)).filter(p -> !sameSwitchFlow || p.getPort() != srcPortId).findFirst();
if (!destPort.isPresent()) {
if (sameSwitchFlow) {
LOGGER.warn("Unable to define a same switch flow for {} as no ports available.", srcSwitch);
return null;
} else {
throw new IllegalStateException("Unable to allocate a port in found vlan.");
}
}
// Record used vlan to archive uniqueness
allocatedVlans.add(Range.singleton(srcVlan));
allocatedVlans.add(Range.singleton(destVlan));
FlowEndpointPayload srcEndpoint = new FlowEndpointPayload(srcSwitch.getDpId(), srcPortId, srcVlan);
FlowEndpointPayload destEndpoint = new FlowEndpointPayload(destSwitch.getDpId(), destPort.get().getPort(), destVlan);
return new FlowPayload(flowId, srcEndpoint, destEndpoint, 1, false, flowId, null);
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowCrudSteps method eachFlowCanBeUpdatedWithBandwidth.
@Then("^each flow can be updated with (\\d+) max bandwidth$")
public void eachFlowCanBeUpdatedWithBandwidth(int bandwidth) {
for (FlowPayload flow : flows) {
flow.setMaximumBandwidth(bandwidth);
FlowPayload result = northboundService.updateFlow(flow.getId(), flow);
assertNotNull(result);
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowCrudStepsTest method shouldDefineFlowCrossVlan.
@Test
public void shouldDefineFlowCrossVlan() {
// given
when(topologyEngineService.getPaths(eq("00:00:00:00:00:01"), eq("00:00:00:00:00:04"))).thenReturn(singletonList(new PathInfoData()));
// when
flowCrudSteps.defineFlowsOverAllSwitches();
// then
assertEquals(1, flowCrudSteps.flows.size());
final FlowPayload flowPayload = flowCrudSteps.flows.get(0);
assertEquals(20, (int) flowPayload.getSource().getPortId());
assertEquals(1, (int) flowPayload.getSource().getVlanId());
assertEquals(20, (int) flowPayload.getDestination().getPortId());
assertEquals(50, (int) flowPayload.getDestination().getVlanId());
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowCrudStepsTest method shouldDefineFlowsOver2Switches.
@Test
public void shouldDefineFlowsOver2Switches() {
// given
when(topologyEngineService.getPaths(eq("00:00:00:00:00:01"), eq("00:00:00:00:00:02"))).thenReturn(singletonList(new PathInfoData()));
// when
flowCrudSteps.defineFlowsOverAllSwitches();
// then
assertEquals(1, flowCrudSteps.flows.size());
final FlowPayload flowPayload = flowCrudSteps.flows.get(0);
assertEquals(20, (int) flowPayload.getSource().getPortId());
assertEquals(1, (int) flowPayload.getSource().getVlanId());
assertEquals(20, (int) flowPayload.getDestination().getPortId());
assertEquals(1, (int) flowPayload.getDestination().getVlanId());
}
Aggregations