use of org.openkilda.model.PathId in project open-kilda by telstra.
the class TransitVlanPoolTest method vlanPoolTest.
@Test
public void vlanPoolTest() {
transactionManager.doInTransaction(() -> {
Set<Integer> transitVlans = new HashSet<>();
for (int i = MIN_TRANSIT_VLAN; i <= MAX_TRANSIT_VLAN; i++) {
Flow flow = Flow.builder().flowId(format("flow_%d", i)).srcSwitch(SWITCH_A).destSwitch(SWITCH_B).build();
transitVlans.add(transitVlanPool.allocate(flow, new PathId(format("path_%d", i)), new PathId(format("opposite_dummy_%d", i))).getTransitVlan().getVlan());
}
assertEquals(MAX_TRANSIT_VLAN - MIN_TRANSIT_VLAN + 1, transitVlans.size());
transitVlans.forEach(vlan -> assertTrue(vlan >= MIN_TRANSIT_VLAN && vlan <= MAX_TRANSIT_VLAN));
});
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldDetectSame2SwitchPaths.
@Test
public void shouldDetectSame2SwitchPaths() {
SwitchId switchId1 = new SwitchId(1);
Switch switch1 = Switch.builder().switchId(switchId1).build();
SwitchId switchId2 = new SwitchId(2);
Switch switch2 = Switch.builder().switchId(switchId2).build();
Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(Collections.singletonList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId2).destPort(2).build())).build();
PathId flowPathId = new PathId("test_path_id");
FlowPath flowPath = FlowPath.builder().srcSwitch(switch1).destSwitch(switch2).pathId(flowPathId).segments(Collections.singletonList(PathSegment.builder().pathId(flowPathId).srcSwitch(switch1).srcPort(1).destSwitch(switch2).destPort(2).build())).build();
assertTrue(builder.isSamePath(path, flowPath));
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor3SwitchPath.
@Test
public void shouldBuildFlowPathFor3SwitchPath() {
SwitchId switchId1 = new SwitchId(1);
SwitchId switchId2 = new SwitchId(2);
SwitchId switchId3 = new SwitchId(3);
Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(asList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId3).destPort(2).build(), Segment.builder().srcSwitchId(switchId3).srcPort(1).destSwitchId(switchId2).destPort(2).build())).build();
Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId1).build()).destSwitch(Switch.builder().switchId(switchId2).build()).build();
PathId pathId = new PathId("test_path_id");
MeterId meterId = new MeterId(MeterId.MIN_FLOW_METER_ID);
PathResources pathResources = PathResources.builder().pathId(pathId).meterId(meterId).build();
FlowSegmentCookie cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1);
FlowPath flowPath = builder.buildFlowPath(flow, pathResources, path, cookie, false, flow.getFlowId());
assertEquals(switchId1, flowPath.getSrcSwitchId());
assertEquals(switchId2, flowPath.getDestSwitchId());
assertEquals(pathId, flowPath.getPathId());
assertEquals(meterId, flowPath.getMeterId());
assertEquals(cookie, flowPath.getCookie());
assertThat(flowPath.getSegments(), hasSize(2));
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowPathBuilderTest method shouldBuildFlowPathFor1SwitchPath.
@Test
public void shouldBuildFlowPathFor1SwitchPath() {
SwitchId switchId = new SwitchId(1);
Path path = Path.builder().srcSwitchId(switchId).destSwitchId(switchId).segments(Collections.emptyList()).build();
Flow flow = Flow.builder().flowId("test_flow").srcSwitch(Switch.builder().switchId(switchId).build()).destSwitch(Switch.builder().switchId(switchId).build()).build();
PathId pathId = new PathId("test_path_id");
MeterId meterId = new MeterId(MeterId.MIN_FLOW_METER_ID);
PathResources pathResources = PathResources.builder().pathId(pathId).meterId(meterId).build();
FlowSegmentCookie cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1);
FlowPath flowPath = builder.buildFlowPath(flow, pathResources, path, cookie, false, flow.getFlowId());
assertEquals(pathId, flowPath.getPathId());
assertEquals(meterId, flowPath.getMeterId());
assertEquals(cookie, flowPath.getCookie());
assertThat(flowPath.getSegments(), empty());
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class PersistenceDummyEntityFactory method makeFlowPathPair.
private void makeFlowPathPair(Flow flow, FlowEndpoint source, FlowEndpoint dest, List<IslDirectionalReference> forwardPathHint, List<String> tags) {
long flowEffectiveId = idProvider.provideFlowEffectiveId();
makeFlowCookie(flow.getFlowId(), flowEffectiveId);
List<IslDirectionalReference> reversePathHint = forwardPathHint.stream().map(IslDirectionalReference::makeOpposite).collect(Collectors.toList());
// inline
Collections.reverse(reversePathHint);
PathId forwardPathId = idProvider.providePathId(flow.getFlowId(), Stream.concat(tags.stream(), Stream.of("forward")));
List<PathSegment> forwardSegments = makePathSegments(forwardPathId, source.getSwitchId(), dest.getSwitchId(), forwardPathHint);
flow.setForwardPath(makePath(flow, source, dest, forwardPathId, forwardSegments, new FlowSegmentCookie(FlowPathDirection.FORWARD, flowEffectiveId)));
PathId reversePathId = idProvider.providePathId(flow.getFlowId(), Stream.concat(tags.stream(), Stream.of("reverse")));
List<PathSegment> reverseSegments = makePathSegments(reversePathId, dest.getSwitchId(), source.getSwitchId(), reversePathHint);
flow.setReversePath(makePath(flow, dest, source, reversePathId, reverseSegments, new FlowSegmentCookie(FlowPathDirection.REVERSE, flowEffectiveId)));
}
Aggregations